Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
BiomeProfile.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using NoiseSystem;
5using UnityEngine;
6
8{
9 public enum DoorStyle
10 {
13 Stone,
14 Jail,
15 Rune
16 }
17
18 public enum StairsStyle
19 {
20 Soil,
21 Wood,
22 Stone,
23 Rock
24 }
25
26 public class BaseTile
27 {
28 public enum SubType
29 {
30 None = 0,
31 Rnd5 = 10,
32 Rnd10 = 11,
33 Rnd20 = 12,
34 Pattern = 20
35 }
36
37 public enum DirType
38 {
39 Random8,
42 }
43
44 protected string _GetThing(string id)
45 {
46 if (id.IsEmpty())
47 {
48 return "-";
49 }
50 SourceThing.Row row = EClass.editorSources.things.rows.First((SourceThing.Row a) => a.id == id);
51 if (row != null)
52 {
53 return row.id + "-(" + row.name_JP + ")";
54 }
55 return "-";
56 }
57
58 protected void _SetThing(ref string id, string value)
59 {
60 id = EClass.editorSources.things.rows.First((SourceThing.Row a) => a.id == value.Split('-')[0]).id;
61 }
62
63 protected IEnumerable<string> ThingRows()
64 {
65 return EClass.editorSources.things.GetListString();
66 }
67
68 protected string _GetObj(int id)
69 {
70 SourceObj.Row row = EClass.editorSources.objs.rows.First((SourceObj.Row a) => a.id == id);
71 if (row != null)
72 {
73 return row.id + "-" + row.alias + "(" + row.name_JP + ")";
74 }
75 return "-";
76 }
77
78 protected void _SetObj(ref int id, string value)
79 {
80 id = EClass.editorSources.objs.rows.First((SourceObj.Row a) => a.id == int.Parse(value.Split('-')[0])).id;
81 }
82
83 protected IEnumerable<string> ObjRows()
84 {
85 return EClass.editorSources.objs.GetListString();
86 }
87
88 protected string _GetFloor(int id)
89 {
90 SourceFloor.Row row = EClass.editorSources.floors.rows.First((SourceFloor.Row a) => a.id == id);
91 if (row != null)
92 {
93 return row.id + "-" + row.alias + "(" + row.name_JP + ")";
94 }
95 return "-";
96 }
97
98 protected void _SetFloor(ref int id, string value)
99 {
100 id = EClass.editorSources.floors.rows.First((SourceFloor.Row a) => a.id == int.Parse(value.Split('-')[0])).id;
101 }
102
103 protected IEnumerable<string> FloorRows()
104 {
105 return EClass.editorSources.floors.GetListString();
106 }
107
108 protected string _GetBlock(int id)
109 {
110 SourceBlock.Row row = EClass.editorSources.blocks.rows.First((SourceBlock.Row a) => a.id == id);
111 if (row != null)
112 {
113 return row.id + "-" + row.alias + "(" + row.name_JP + ")";
114 }
115 return "-";
116 }
117
118 protected void _SetBlock(ref int id, string value)
119 {
120 id = EClass.editorSources.blocks.rows.First((SourceBlock.Row a) => a.id == int.Parse(value.Split('-')[0])).id;
121 }
122
123 protected IEnumerable<string> BlockRows()
124 {
125 return EClass.editorSources.blocks.GetListString();
126 }
127
128 protected string _GetMat(int id)
129 {
130 if (id == -1)
131 {
132 id = 0;
133 }
134 SourceMaterial.Row row = EClass.editorSources.materials.rows.First((SourceMaterial.Row a) => a.id == id);
135 if (row != null)
136 {
137 return row.id + "-" + row.alias + "(" + row.name_JP + ")";
138 }
139 return "-";
140 }
141
142 protected void _SetMat(ref int id, string value)
143 {
144 id = EClass.editorSources.materials.rows.First((SourceMaterial.Row a) => a.id == int.Parse(value.Split('-')[0])).id;
145 }
146
147 protected IEnumerable<string> MatRows()
148 {
149 return EClass.editorSources.materials.GetListString();
150 }
151
152 protected string _GetSpawnList(string id)
153 {
154 if (id.IsEmpty() || !EClass.editorSources.spawnLists.map.ContainsKey(id))
155 {
156 return "-";
157 }
158 SourceSpawnList.Row row = EClass.editorSources.spawnLists.rows.First((SourceSpawnList.Row a) => a.id == id);
159 if (row != null)
160 {
161 return row.id;
162 }
163 return "-";
164 }
165
166 protected void _SetSpawnList(ref string id, string value)
167 {
168 id = ((value == null) ? "" : EClass.editorSources.spawnLists.rows.First((SourceSpawnList.Row a) => a.id == value).id);
169 }
170
171 protected IEnumerable<string> _SpawnList()
172 {
173 return EClass.editorSources.spawnLists.GetListString();
174 }
175 }
176
177 [Serializable]
178 public class Tile : BaseTile
179 {
180 [HideInInspector]
181 public int id;
182
183 [HideInInspector]
184 public int mat;
185
186 [HideInInspector]
187 public int idSub;
188
189 [HideInInspector]
190 public int matSub;
191
193
195
196 public string _mat
197 {
198 get
199 {
200 return _GetMat(mat);
201 }
202 set
203 {
204 _SetMat(ref mat, value);
205 }
206 }
207
208 public string _matSub
209 {
210 get
211 {
212 return _GetMat(matSub);
213 }
214 set
215 {
216 _SetMat(ref matSub, value);
217 }
218 }
219
220 public int GetDir()
221 {
222 return dirType switch
223 {
224 DirType.Random8 => EScriptable.rnd(8),
225 DirType.RandomSqrt8 => EScriptable.rnd(EScriptable.rnd(8) + 1),
226 DirType.RandomSqrtSqrt8 => EScriptable.rnd(EScriptable.rnd(EScriptable.rnd(8) + 1) + 1),
227 _ => EScriptable.rnd(8),
228 };
229 }
230 }
231
232 [Serializable]
233 public class TileFloor : Tile
234 {
235 public string _id
236 {
237 get
238 {
239 return _GetFloor(id);
240 }
241 set
242 {
243 _SetFloor(ref id, value);
244 }
245 }
246
247 public string _idSub
248 {
249 get
250 {
251 return _GetFloor(idSub);
252 }
253 set
254 {
255 _SetFloor(ref idSub, value);
256 }
257 }
258 }
259
260 [Serializable]
261 public class TileBlock : Tile
262 {
263 public string _id
264 {
265 get
266 {
267 return _GetBlock(id);
268 }
269 set
270 {
271 _SetBlock(ref id, value);
272 }
273 }
274
275 public string _idSub
276 {
277 get
278 {
279 return _GetBlock(idSub);
280 }
281 set
282 {
283 _SetBlock(ref idSub, value);
284 }
285 }
286 }
287
288 [Serializable]
289 public class TileGroup
290 {
292
294 }
295
296 [Serializable]
297 public class Style : BaseTile
298 {
299 public float doorChance = 0.9f;
300
302
303 [HideInInspector]
304 public int matDoor;
305
307
308 [HideInInspector]
309 public int matStairs;
310
312
313 public string _matDoor
314 {
315 get
316 {
317 return _GetMat(matDoor);
318 }
319 set
320 {
321 _SetMat(ref matDoor, value);
322 }
323 }
324
325 public string _matStairs
326 {
327 get
328 {
329 return _GetMat(matStairs);
330 }
331 set
332 {
333 _SetMat(ref matStairs, value);
334 }
335 }
336
337 public string GetIdLight(bool wall)
338 {
339 if (lights.Count > 0)
340 {
341 foreach (Cluster.ItemThing light in lights)
342 {
343 if (EClass.sources.cards.map[light.id].tileType.UseMountHeight == wall)
344 {
345 return light.id;
346 }
347 }
348 }
349 if (!wall)
350 {
351 return "torch";
352 }
353 return "torch_wall";
354 }
355
356 public string GetIdStairs(bool upstairs)
357 {
358 switch (stairsStyle)
359 {
360 case StairsStyle.Wood:
361 if (!upstairs)
362 {
363 return "381";
364 }
365 return "376";
366 case StairsStyle.Stone:
367 if (!upstairs)
368 {
369 return "932";
370 }
371 return "379";
372 case StairsStyle.Rock:
373 if (!upstairs)
374 {
375 return "380";
376 }
377 return "377";
378 default:
379 if (!upstairs)
380 {
381 return "stairsDown_cave";
382 }
383 return "stairs_cave";
384 }
385 }
386
387 public string GetIdDoor()
388 {
389 return doorStyle switch
390 {
391 DoorStyle.FirmWood => "46",
392 DoorStyle.Stone => "42",
393 DoorStyle.Jail => "40",
394 DoorStyle.Rune => "43",
395 _ => "45",
396 };
397 }
398 }
399
400 [Serializable]
401 public class Spawns
402 {
403 public List<SpawnListChara> chara;
404
405 public List<SpawnListThing> thing;
406
407 public string GetRandomCharaId()
408 {
409 if (chara.Count != 0)
410 {
411 return chara.RandomItemWeighted((SpawnListChara a) => a.chance).id;
412 }
413 return "c_dungeon";
414 }
415
416 public string GetRandomThingId()
417 {
418 if (thing.Count != 0)
419 {
420 return thing.RandomItemWeighted((SpawnListThing a) => a.chance).id;
421 }
422 return "dungeon";
423 }
424 }
425
426 [Serializable]
427 public class SpawnList : BaseTile
428 {
429 public float chance = 1f;
430
431 [HideInInspector]
432 public string id;
433
434 public string _id
435 {
436 get
437 {
438 return _GetSpawnList(id);
439 }
440 set
441 {
442 _SetSpawnList(ref id, value);
443 }
444 }
445 }
446
447 [Serializable]
449 {
450 }
451
452 [Serializable]
454 {
455 }
456
457 [Serializable]
458 public class Clusters
459 {
460 public List<ClusterObj> obj;
461
462 public List<ClusterThing> thing;
463 }
464
465 [Serializable]
466 public class Cluster
467 {
468 public enum Type
469 {
470 Scatter = 0,
471 ScatterExterior = 1,
472 ScatterInterior = 2,
474 ByWall = 10
475 }
476
477 [Serializable]
478 public class BaseItem : BaseTile
479 {
480 public float chance = 1f;
481
482 public virtual bool IsSpawnOnBlock => false;
483
484 public virtual bool IsSpawnOnWater => false;
485 }
486
487 [Serializable]
488 public class Item : BaseItem
489 {
490 public int idObj;
491
492 public override bool IsSpawnOnBlock => EClass.sources.objs.rows[idObj].tileType.IsBlockMount;
493
494 public override bool IsSpawnOnWater => EClass.sources.objs.rows[idObj].tileType.CanSpawnOnWater;
495
496 public string obj
497 {
498 get
499 {
500 return _GetObj(idObj);
501 }
502 set
503 {
504 _SetObj(ref idObj, value);
505 }
506 }
507 }
508
509 [Serializable]
510 public class ItemThing : BaseItem
511 {
512 public string id;
513
514 public string _id
515 {
516 get
517 {
518 return _GetThing(id);
519 }
520 set
521 {
522 _SetThing(ref id, value);
523 }
524 }
525 }
526
527 public Type type;
528
529 public float density;
530
531 public virtual bool TryCreate(Point p)
532 {
533 return false;
534 }
535 }
536
537 [Serializable]
538 public class ClusterObj : Cluster
539 {
540 public List<Item> items;
541
542 public override bool TryCreate(Point p)
543 {
544 Item item = items.RandomItem();
545 if (Rand.Range(0f, 1f) > item.chance)
546 {
547 return false;
548 }
549 Cell cell = p.cell;
550 if (cell.HasBlock)
551 {
552 if (!item.IsSpawnOnBlock)
553 {
554 return false;
555 }
556 }
557 else if (item.IsSpawnOnBlock)
558 {
559 return false;
560 }
561 p.SetObj(item.idObj);
562 cell.objDir = EScriptable.rnd(8);
563 if (cell.sourceObj.HasGrowth && cell.sourceObj.id != 103)
564 {
565 cell.growth.SetRandomStage();
566 }
567 return true;
568 }
569 }
570
571 [Serializable]
572 public class ClusterThing : Cluster
573 {
574 public List<ItemThing> items;
575
576 public override bool TryCreate(Point p)
577 {
578 ItemThing itemThing = items.RandomItem();
579 if (Rand.Range(0f, 1f) > itemThing.chance)
580 {
581 return false;
582 }
583 Cell cell = p.cell;
584 if (cell.HasBlock)
585 {
586 if (!itemThing.IsSpawnOnBlock)
587 {
588 return false;
589 }
590 }
591 else if (itemThing.IsSpawnOnBlock)
592 {
593 return false;
594 }
595 if (cell.IsTopWater)
596 {
597 if (!itemThing.IsSpawnOnWater)
598 {
599 return false;
600 }
601 }
602 else if (itemThing.IsSpawnOnWater)
603 {
604 return false;
605 }
606 Thing thing = ThingGen.Create(itemThing.id);
607 int desiredDir = thing.TileType.GetDesiredDir(p, 0);
608 if (desiredDir != -1)
609 {
610 thing.dir = desiredDir;
611 }
612 EClass._zone.AddCard(thing, p).Install();
613 return true;
614 }
615 }
616
617 public static bool forceInitialize;
618
619 public NoiseLayer layerBlock;
620
621 public BiomeID id;
622
623 public Color color;
624
626
628
630
631 public Style style;
632
633 public Spawns spawn;
634
636
637 public string tags;
638
639 public int floor_height;
640
641 [NonSerialized]
643
644 [NonSerialized]
646
648
650 {
651 get
652 {
653 if (_interior.floor.id != 0)
654 {
655 return _interior;
656 }
657 return exterior;
658 }
659 }
660
662
663 public SourceMaterial.Row MatSub => _matSub ?? (_matSub = ((exterior.floor.matSub == 0) ? MatFloor : EClass.sources.materials.map[exterior.floor.matSub]));
664
665 public void Populate(Point point, bool interior = false)
666 {
667 Cell cell = point.cell;
668 if (cell.obj != 0 || cell.Things.Count > 0)
669 {
670 return;
671 }
672 int count = this.cluster.obj.Count;
673 for (int i = 0; i < count + this.cluster.thing.Count; i++)
674 {
675 Cluster cluster = ((i >= count) ? ((Cluster)this.cluster.thing[i - count]) : ((Cluster)this.cluster.obj[i]));
676 if (cluster.density == 0f)
677 {
678 break;
679 }
680 if (Rand.Range(0f, 1f) > cluster.density)
681 {
682 continue;
683 }
684 switch (cluster.type)
685 {
686 case Cluster.Type.ScatterExterior:
687 if (interior)
688 {
689 continue;
690 }
691 break;
692 case Cluster.Type.ScatterInterior:
693 if (!interior)
694 {
695 continue;
696 }
697 break;
698 case Cluster.Type.ScatterNonObstacle:
699 if ((cell.Left.HasObstacle() ? 1 : 0) + (cell.Right.HasObstacle() ? 1 : 0) + (cell.Front.HasObstacle() ? 1 : 0) + (cell.Back.HasObstacle() ? 1 : 0) > 0)
700 {
701 continue;
702 }
703 break;
704 case Cluster.Type.ByWall:
705 if (cell.Left.hasDoor || cell.Right.hasDoor || cell.Front.hasDoor || cell.Back.hasDoor || (!cell.Left.HasBlock && !cell.Right.HasBlock && !cell.Front.HasBlock && !cell.Back.HasBlock))
706 {
707 continue;
708 }
709 break;
710 }
711 if (cluster.TryCreate(point))
712 {
713 break;
714 }
715 }
716 }
717
718 public static void Init()
719 {
720 if (!forceInitialize)
721 {
722 return;
723 }
724 Debug.Log("Initializing Clusters");
725 foreach (BiomeProfile value in EClass.core.refs.biomes.dict.Values)
726 {
727 value.Reset();
728 }
729 forceInitialize = false;
730 }
731
732 public void Reset()
733 {
734 _mat = null;
735 _matSub = null;
736 }
737}
BiomeID
Definition: BiomeID.cs:2
void _SetObj(ref int id, string value)
Definition: BiomeProfile.cs:78
string _GetSpawnList(string id)
void _SetBlock(ref int id, string value)
string _GetFloor(int id)
Definition: BiomeProfile.cs:88
IEnumerable< string > _SpawnList()
IEnumerable< string > MatRows()
void _SetFloor(ref int id, string value)
Definition: BiomeProfile.cs:98
string _GetObj(int id)
Definition: BiomeProfile.cs:68
IEnumerable< string > ThingRows()
Definition: BiomeProfile.cs:63
string _GetThing(string id)
Definition: BiomeProfile.cs:44
IEnumerable< string > ObjRows()
Definition: BiomeProfile.cs:83
void _SetSpawnList(ref string id, string value)
void _SetMat(ref int id, string value)
IEnumerable< string > FloorRows()
string _GetBlock(int id)
void _SetThing(ref string id, string value)
Definition: BiomeProfile.cs:58
IEnumerable< string > BlockRows()
string _GetMat(int id)
override bool TryCreate(Point p)
List< ItemThing > items
override bool TryCreate(Point p)
override bool IsSpawnOnWater
override bool IsSpawnOnBlock
virtual bool TryCreate(Point p)
List< ClusterObj > obj
List< ClusterThing > thing
List< SpawnListChara > chara
string GetRandomThingId()
List< SpawnListThing > thing
string GetRandomCharaId()
string GetIdLight(bool wall)
List< Cluster.ItemThing > lights
StairsStyle stairsStyle
string GetIdStairs(bool upstairs)
TileGroup exterior
FowProfile fowProfile
static bool forceInitialize
NoiseLayer layerBlock
TileGroup interior
SourceMaterial.Row _mat
SourceMaterial.Row _matSub
static void Init()
Clusters cluster
SourceMaterial.Row MatSub
TileGroup _exterior
void Populate(Point point, bool interior=false)
TileGroup _interior
SourceMaterial.Row MatFloor
TileType TileType
Definition: Card.cs:2011
Card Install()
Definition: Card.cs:3448
Definition: Cell.cs:7
bool HasBlock
Definition: Cell.cs:643
Cell Back
Definition: Cell.cs:153
Cell Front
Definition: Cell.cs:129
List< Thing > Things
Definition: Cell.cs:986
bool HasObstacle()
Definition: Cell.cs:1130
bool IsTopWater
Definition: Cell.cs:700
GrowSystem growth
Definition: Cell.cs:225
Cell Left
Definition: Cell.cs:165
byte obj
Definition: Cell.cs:38
SourceObj.Row sourceObj
Definition: Cell.cs:1072
Cell Right
Definition: Cell.cs:141
bool hasDoor
Definition: Cell.cs:258
UD_Biome dict
Definition: CoreRef.cs:142
Biomes biomes
Definition: CoreRef.cs:325
CoreRef refs
Definition: Core.cs:51
Definition: EClass.cs:5
static Core core
Definition: EClass.cs:6
static Zone _zone
Definition: EClass.cs:20
static SourceManager sources
Definition: EClass.cs:42
static SourceManager editorSources
Definition: EClass.cs:44
static int rnd(int a)
Definition: EScriptable.cs:5
void SetRandomStage()
Definition: GrowSystem.cs:241
Definition: Point.cs:9
void SetObj(int id=0, int value=1, int dir=0)
Definition: Point.cs:892
Cell cell
Definition: Point.cs:51
Definition: Rand.cs:4
static int Range(int min, int max)
Definition: Rand.cs:42
Dictionary< string, CardRow > map
Definition: SourceCard.cs:8
SourceMaterial materials
SourceCard cards
SourceObj objs
SourceThing things
SourceSpawnList spawnLists
SourceBlock blocks
SourceFloor floors
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
Definition: Thing.cs:8
virtual int GetDesiredDir(Point p, int d)
Definition: TileType.cs:362
ICollection< TValue > Values
Definition: UDictionary.cs:29
Card AddCard(Card t, Point point)
Definition: Zone.cs:1893