Elin Modding Docs Doc
Loading...
Searching...
No Matches
MapGenDungen.cs
1using System;
2using System.Collections.Generic;
3using System.Runtime.CompilerServices;
4using Dungen;
5using UnityEngine;
6
7// Token: 0x0200066E RID: 1646
8public class MapGenDungen : BaseMapGen
9{
10 // Token: 0x17000D16 RID: 3350
11 // (get) Token: 0x06002E2B RID: 11819 RVA: 0x00103E31 File Offset: 0x00102031
12 public static MapGenDungen Instance
13 {
14 get
15 {
16 MapGenDungen result;
17 if ((result = MapGenDungen._Instance) == null)
18 {
19 result = (MapGenDungen._Instance = new MapGenDungen());
20 }
21 return result;
22 }
23 }
24
25 // Token: 0x06002E2C RID: 11820 RVA: 0x00103E48 File Offset: 0x00102048
26 protected override bool OnGenerateTerrain()
27 {
28 MapGenDungen.<>c__DisplayClass3_0 CS$<>8__locals1;
29 CS$<>8__locals1.<>4__this = this;
30 DunGen.Init();
31 MapGenerator generator = this.zone.Generator;
32 MapData mapData = DunGen.Generate(generator, 0);
33 this.width = mapData.size_X + 2;
34 this.height = mapData.size_Y + 2;
35 base.SetSize(Mathf.Max(this.width, this.height), 10);
36 this.map.CreateNew(this.Size, true);
37 this.map.poiMap.Reset();
38 this.map.SetZone(this.zone);
39 this.map.config.blockHeight = EClass.core.gameSetting.gen.defaultBlockHeight;
40 CS$<>8__locals1.biome = this.zone.biome;
41 if (this.zone is Zone_Void)
42 {
43 CS$<>8__locals1.biome = CS$<>8__locals1.biome.Instantiate<BiomeProfile>();
44 CS$<>8__locals1.biome.interior.block.mat = MATERIAL.GetRandomMaterialFromCategory(this.zone.lv % 50 + 10, "rock", EClass.sources.materials.alias["granite"]).id;
45 CS$<>8__locals1.biome.interior.block.matSub = MATERIAL.GetRandomMaterialFromCategory(this.zone.lv % 50 + 10, "rock", EClass.sources.materials.alias["granite"]).id;
46 CS$<>8__locals1.biome.interior.floor.mat = MATERIAL.GetRandomMaterialFromCategory(this.zone.lv % 50 + 10, "rock", EClass.sources.materials.alias["granite"]).id;
47 CS$<>8__locals1.biome.interior.floor.matSub = MATERIAL.GetRandomMaterialFromCategory(this.zone.lv % 50 + 10, "rock", EClass.sources.materials.alias["granite"]).id;
48 CS$<>8__locals1.biome.exterior.block.mat = MATERIAL.GetRandomMaterialFromCategory(this.zone.lv % 50 + 10, "rock", EClass.sources.materials.alias["granite"]).id;
49 CS$<>8__locals1.biome.exterior.block.matSub = MATERIAL.GetRandomMaterialFromCategory(this.zone.lv % 50 + 10, "rock", EClass.sources.materials.alias["granite"]).id;
50 CS$<>8__locals1.biome.exterior.floor.mat = MATERIAL.GetRandomMaterialFromCategory(this.zone.lv % 50 + 10, "rock", EClass.sources.materials.alias["granite"]).id;
51 CS$<>8__locals1.biome.exterior.floor.matSub = MATERIAL.GetRandomMaterialFromCategory(this.zone.lv % 50 + 10, "rock", EClass.sources.materials.alias["granite"]).id;
52 }
53 BiomeProfile.TileFloor floor = CS$<>8__locals1.biome.exterior.floor;
54 BiomeProfile.TileBlock block = CS$<>8__locals1.biome.exterior.block;
55 bool flag = this.zone.lv <= 0;
56 bool flag2 = false;
57 bool flag3 = false;
58 Point point = new Point();
59 Thing thing = null;
60 Thing thing2 = null;
61 for (int i = 0; i < mapData.size_X + 2; i++)
62 {
63 for (int j = 0; j < mapData.size_Y + 2; j++)
64 {
65 if (i == 0 || j == 0 || i >= mapData.size_X || j >= mapData.size_Y)
66 {
67 base.SetFloor(floor, i, j);
68 base.SetBlock(block, i, j);
69 }
70 else
71 {
72 Dungen.Cell cell = mapData.cellsOnMap[i - 1, j - 1];
73 CellType type = cell.type;
74 point.Set(i, j);
75 base.SetFloor(floor, i, j);
76 string name = type.name;
77 if (!(name == "Entrance"))
78 {
79 if (!(name == "Exit"))
80 {
81 if (!(name == "Door"))
82 {
83 if (!(name == "Abyss"))
84 {
85 if (type.passable == generator.reversePassage)
86 {
87 base.SetBlock(block, i, j);
88 }
89 }
90 else
91 {
92 base.SetBlock(block, i, j);
93 }
94 }
95 else if (CS$<>8__locals1.biome.style.doorChance >= Rand.Range(0f, 1f))
96 {
97 base.SetBlock(block, i, j);
98 Thing t3 = ThingGen.Create(CS$<>8__locals1.biome.style.GetIdDoor(), CS$<>8__locals1.biome.style.matDoor, -1);
99 this.zone.AddCard(t3, i, j).Install();
100 }
101 }
102 else if (this.zone.ShouldMakeExit)
103 {
104 if (flag3)
105 {
106 Debug.LogError("exception: already created exit");
107 }
108 else
109 {
110 flag3 = true;
111 Thing thing3 = ThingGen.Create(EClass._zone.LockExit ? "stairs_locked" : CS$<>8__locals1.biome.style.GetIdStairs(!flag), CS$<>8__locals1.biome.style.matStairs, -1);
112 if (flag)
113 {
114 thing = thing3;
115 }
116 else
117 {
118 thing2 = thing3;
119 }
120 this.zone.AddCard(thing3, i, j).Install();
121 }
122 }
123 }
124 else if (flag2)
125 {
126 Debug.LogError("exception: already created entrance");
127 }
128 else
129 {
130 flag2 = true;
131 Thing thing4 = ThingGen.Create(CS$<>8__locals1.biome.style.GetIdStairs(flag), CS$<>8__locals1.biome.style.matStairs, -1);
132 if (!flag)
133 {
134 thing = thing4;
135 }
136 else
137 {
138 thing2 = thing4;
139 }
140 this.zone.AddCard(thing4, i, j).Install();
141 }
142 if (!cell.isRoomCell)
143 {
144 CS$<>8__locals1.biome.Populate(point, false);
145 }
146 }
147 }
148 }
149 if (!flag2)
150 {
151 Debug.LogError("exception: Failed to create entrance:");
152 return false;
153 }
154 if (this.zone.ShouldMakeExit && !flag3)
155 {
156 Debug.LogError("exception: Failed to create exist:");
157 return false;
158 }
159 if (thing2 != null)
160 {
161 thing2.pos.cell._block = 0;
162 thing2.pos.cell.obj = 0;
163 }
164 if (thing != null)
165 {
166 thing.pos.cell._block = 0;
167 thing.pos.cell.obj = 0;
168 }
169 CS$<>8__locals1.rooms = new Dictionary<int, GenRoom>();
170 CS$<>8__locals1.count = 0;
171 int num = 0;
172 foreach (Dungen.Room room in mapData.rooms)
173 {
174 if (room.width != 0 && room.height != 0)
175 {
176 num++;
177 }
178 }
179 if (num == 0)
180 {
181 mapData.rooms.Clear();
182 }
183 if (mapData.rooms.Count == 0)
184 {
185 GenRoomBig genRoomBig = new GenRoomBig();
186 genRoomBig.Init(1, 1, this.width - 1, this.height - 1);
187 this.<OnGenerateTerrain>g__SetRoom|3_0(genRoomBig, ref CS$<>8__locals1);
188 }
189 else
190 {
191 foreach (Dungen.Room room2 in mapData.rooms)
192 {
193 GenRoom genRoom = this.ChooseRoom();
194 genRoom.Init(room2);
195 this.<OnGenerateTerrain>g__SetRoom|3_0(genRoom, ref CS$<>8__locals1);
196 }
197 }
198 this.map.RefreshAllTiles();
199 foreach (GenRoom genRoom2 in CS$<>8__locals1.rooms.Values)
200 {
201 genRoom2.Populate();
202 }
203 this.zone.OnGenerateRooms(this);
204 this.map.ReloadRoom();
205 Debug.Log(string.Concat(new string[]
206 {
207 "Dungen: room:",
208 CS$<>8__locals1.rooms.Count.ToString(),
209 "/",
210 mapData.rooms.Count.ToString(),
211 " width:",
212 this.width.ToString(),
213 " height:",
214 this.height.ToString()
215 }));
216 int num2 = EClass.rnd(this.Size * this.Size / 50 + EClass.rnd(20)) + 5;
217 num2 = num2 * Mathf.Min(20 + this.zone.DangerLv * 5, 100) / 100;
218 for (int k = 0; k < num2; k++)
219 {
220 point = EClass._map.GetRandomPoint();
221 if (!point.cell.isModified && !point.HasThing && !point.HasBlock && !point.HasObj)
222 {
223 Thing t2 = ThingGen.CreateFromCategory("trap", this.zone.DangerLv);
224 EClass._zone.AddCard(t2, point).Install();
225 }
226 }
227 this.map.things.ForeachReverse(delegate(Thing t)
228 {
229 TraitDoor traitDoor = t.trait as TraitDoor;
230 if (traitDoor == null)
231 {
232 return;
233 }
234 if (!traitDoor.IsValid())
235 {
236 string str = "Purging Door:";
237 string name2 = t.Name;
238 string str2 = "/";
239 Point pos = t.pos;
240 Debug.Log(str + name2 + str2 + ((pos != null) ? pos.ToString() : null));
241 t.Destroy();
242 }
243 });
244 if (thing != null)
245 {
246 MapGenDungen.<OnGenerateTerrain>g__ClearPos|3_2(thing);
247 }
248 if (thing2 != null)
249 {
250 MapGenDungen.<OnGenerateTerrain>g__ClearPos|3_2(thing2);
251 }
252 return true;
253 }
254
255 // Token: 0x06002E2D RID: 11821 RVA: 0x001047F4 File Offset: 0x001029F4
256 public GenRoom ChooseRoom()
257 {
258 if (EClass.rnd(100) < 5)
259 {
260 return new GenRoomMonsterHouse();
261 }
262 return new GenRoom();
263 }
264
265 // Token: 0x06002E2F RID: 11823 RVA: 0x00104814 File Offset: 0x00102A14
266 [CompilerGenerated]
267 private void <OnGenerateTerrain>g__SetRoom|3_0(GenRoom room, ref MapGenDungen.<>c__DisplayClass3_0 A_2)
268 {
269 room.map = this.map;
270 room.zone = this.zone;
271 room.gen = this;
272 room.group = A_2.biome.interior;
273 A_2.rooms[room.Index] = room;
274 room.Fill();
275 Debug.Log(string.Concat(new string[]
276 {
277 "Room",
278 A_2.count.ToString(),
279 " ",
280 room.width.ToString(),
281 "*",
282 room.height.ToString(),
283 " ",
284 (room != null) ? room.ToString() : null
285 }));
286 int count = A_2.count;
287 A_2.count = count + 1;
288 }
289
290 // Token: 0x06002E30 RID: 11824 RVA: 0x001048E4 File Offset: 0x00102AE4
291 [CompilerGenerated]
292 internal static void <OnGenerateTerrain>g__ClearPos|3_2(Thing t)
293 {
294 foreach (Card card in t.pos.ListCards(false))
295 {
296 if (card != t && card.isThing)
297 {
298 card.Destroy();
299 }
300 }
301 t.pos.SetObj(0, 1, 0);
302 t.pos.SetBlock(0, 0);
303 t.pos.cell.height = 0;
304 }
305
306 // Token: 0x04001A3D RID: 6717
307 private static MapGenDungen _Instance;
308}
Definition Card.cs:13
Definition Point.cs:11
Definition Thing.cs:10