Elin Decompiled Documentation EA 23.253 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 ByWallFace = 11,
476 Space = 20,
477 SpaceByWall = 21
478 }
479
480 [Serializable]
481 public class BaseItem : BaseTile
482 {
483 public float chance = 1f;
484
485 public string material;
486
487 [NonSerialized]
488 public string[] _material;
489
490 public virtual bool IsSpawnOnBlock => false;
491
492 public virtual bool IsSpawnOnWater => false;
493
494 public int GetIdMaterial()
495 {
496 if (material.IsEmpty())
497 {
498 return -1;
499 }
500 if (_material == null)
501 {
502 _material = material.Split(',');
503 }
504 return EClass.sources.materials.alias[_material.RandomItem()].id;
505 }
506 }
507
508 [Serializable]
509 public class Item : BaseItem
510 {
511 public int idObj;
512
513 public override bool IsSpawnOnBlock => EClass.sources.objs.rows[idObj].tileType.IsBlockMount;
514
515 public override bool IsSpawnOnWater => EClass.sources.objs.rows[idObj].tileType.CanSpawnOnWater;
516
517 public string obj
518 {
519 get
520 {
521 return _GetObj(idObj);
522 }
523 set
524 {
525 _SetObj(ref idObj, value);
526 }
527 }
528 }
529
530 [Serializable]
531 public class ItemThing : BaseItem
532 {
533 public string id;
534
535 public bool alignDir;
536
537 public string _id
538 {
539 get
540 {
541 return _GetThing(id);
542 }
543 set
544 {
545 _SetThing(ref id, value);
546 }
547 }
548 }
549
550 public Type type;
551
552 public float density;
553
554 public virtual bool TryCreate(Point p)
555 {
556 return false;
557 }
558 }
559
560 [Serializable]
561 public class ClusterObj : Cluster
562 {
563 public List<Item> items;
564
565 public override bool TryCreate(Point p)
566 {
567 Item item = items.RandomItem();
568 if (Rand.Range(0f, 1f) > item.chance)
569 {
570 return false;
571 }
572 Cell cell = p.cell;
573 if (cell.HasBlock)
574 {
575 if (!item.IsSpawnOnBlock)
576 {
577 return false;
578 }
579 }
580 else if (item.IsSpawnOnBlock)
581 {
582 return false;
583 }
584 p.SetObj(item.idObj);
585 int idMaterial = item.GetIdMaterial();
586 if (idMaterial != -1)
587 {
588 cell.objMat = (byte)idMaterial;
589 }
590 cell.objDir = EScriptable.rnd(8);
591 if (cell.sourceObj.HasGrowth && !EClass._zone.IsPCFactionOrTent && cell.sourceObj.id != 103)
592 {
593 cell.growth.SetRandomStage();
594 }
595 return true;
596 }
597 }
598
599 [Serializable]
600 public class ClusterThing : Cluster
601 {
602 public List<ItemThing> items;
603
604 public override bool TryCreate(Point p)
605 {
606 ItemThing itemThing = items.RandomItem();
607 if (Rand.Range(0f, 1f) > itemThing.chance)
608 {
609 return false;
610 }
611 Cell cell = p.cell;
612 if (cell.HasBlock)
613 {
614 if (!itemThing.IsSpawnOnBlock)
615 {
616 return false;
617 }
618 }
619 else if (itemThing.IsSpawnOnBlock)
620 {
621 return false;
622 }
623 if (cell.IsTopWater)
624 {
625 if (!itemThing.IsSpawnOnWater)
626 {
627 return false;
628 }
629 }
630 else if (itemThing.IsSpawnOnWater)
631 {
632 return false;
633 }
634 Thing thing = ThingGen.Create(itemThing.id, itemThing.GetIdMaterial());
635 int num = thing.TileType.GetDesiredDir(p, 0);
636 if (itemThing.alignDir)
637 {
638 if (cell.Back.HasBlock)
639 {
640 num = 0;
641 }
642 else if (cell.Left.HasBlock)
643 {
644 num = 1;
645 }
646 else if (cell.Front.HasBlock)
647 {
648 num = 2;
649 }
650 else if (cell.Right.HasBlock)
651 {
652 num = 3;
653 }
654 if (itemThing.id == "coffin_stone")
655 {
656 num++;
657 }
658 }
659 if (num != -1)
660 {
661 thing.dir = num;
662 }
663 EClass._zone.AddCard(thing, p).Install();
664 return true;
665 }
666 }
667
668 public static bool forceInitialize;
669
670 public NoiseLayer layerBlock;
671
672 public BiomeID id;
673
674 public Color color;
675
677
679
681
682 public Style style;
683
684 public Spawns spawn;
685
687
688 public string tags;
689
690 public int floor_height;
691
692 [NonSerialized]
694
695 [NonSerialized]
697
699
701 {
702 get
703 {
704 if (_interior.floor.id != 0)
705 {
706 return _interior;
707 }
708 return exterior;
709 }
710 }
711
713
714 public SourceMaterial.Row MatSub => _matSub ?? (_matSub = ((exterior.floor.matSub == 0) ? MatFloor : EClass.sources.materials.map[exterior.floor.matSub]));
715
716 public void Populate(Point point, bool interior = false, float mtpDensity = 1f)
717 {
718 Cell cell = point.cell;
719 if (cell.obj != 0 || cell.Things.Count > 0)
720 {
721 return;
722 }
723 int count = this.cluster.obj.Count;
724 for (int i = 0; i < count + this.cluster.thing.Count; i++)
725 {
726 Cluster cluster = ((i >= count) ? ((Cluster)this.cluster.thing[i - count]) : ((Cluster)this.cluster.obj[i]));
727 if (cluster.density == 0f)
728 {
729 break;
730 }
731 if (Rand.Range(0f, 1f) > cluster.density * mtpDensity)
732 {
733 continue;
734 }
735 switch (cluster.type)
736 {
737 case Cluster.Type.ScatterExterior:
738 if (interior)
739 {
740 continue;
741 }
742 break;
743 case Cluster.Type.ScatterInterior:
744 if (!interior)
745 {
746 continue;
747 }
748 break;
749 case Cluster.Type.ScatterNonObstacle:
750 if ((cell.Left.HasObstacle() ? 1 : 0) + (cell.Right.HasObstacle() ? 1 : 0) + (cell.Front.HasObstacle() ? 1 : 0) + (cell.Back.HasObstacle() ? 1 : 0) > 0)
751 {
752 continue;
753 }
754 break;
755 case Cluster.Type.ByWall:
756 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))
757 {
758 continue;
759 }
760 break;
761 case Cluster.Type.ByWallFace:
762 if (cell.Left.hasDoor || cell.Right.hasDoor || cell.Front.hasDoor || cell.Back.hasDoor || (!cell.Left.HasBlock && !cell.Back.HasBlock))
763 {
764 continue;
765 }
766 break;
767 case Cluster.Type.SpaceByWall:
768 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) || !interior)
769 {
770 continue;
771 }
772 break;
773 }
774 if (cluster.TryCreate(point))
775 {
776 break;
777 }
778 }
779 }
780
781 public static void Init()
782 {
783 if (!forceInitialize)
784 {
785 return;
786 }
787 Debug.Log("Initializing Clusters");
788 foreach (BiomeProfile value in EClass.core.refs.biomes.dict.Values)
789 {
790 value.Reset();
791 }
792 forceInitialize = false;
793 }
794
795 public void Reset()
796 {
797 _mat = null;
798 _matSub = null;
799 }
800}
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
void Populate(Point point, bool interior=false, float mtpDensity=1f)
NoiseLayer layerBlock
TileGroup interior
SourceMaterial.Row _mat
SourceMaterial.Row _matSub
static void Init()
Clusters cluster
SourceMaterial.Row MatSub
TileGroup _exterior
TileGroup _interior
SourceMaterial.Row MatFloor
TileType TileType
Definition: Card.cs:2135
Card Install()
Definition: Card.cs:3741
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:1134
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:146
Biomes biomes
Definition: CoreRef.cs:341
CoreRef refs
Definition: Core.cs:51
Definition: EClass.cs:6
static Core core
Definition: EClass.cs:7
static Zone _zone
Definition: EClass.cs:21
static SourceManager sources
Definition: EClass.cs:43
static SourceManager editorSources
Definition: EClass.cs:45
static int rnd(int a)
Definition: EScriptable.cs:5
void SetRandomStage()
Definition: GrowSystem.cs:245
Definition: Point.cs:9
void SetObj(int id=0, int value=1, int dir=0)
Definition: Point.cs:928
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:378
ICollection< TValue > Values
Definition: UDictionary.cs:29
bool IsPCFactionOrTent
Definition: Zone.cs:476
Card AddCard(Card t, Point point)
Definition: Zone.cs:1977