Elin Decompiled Documentation EA 23.355 Stable
Loading...
Searching...
No Matches
Map.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.IO;
4using System.Linq;
5using System.Runtime.Serialization;
6using Algorithms;
7using FloodSpill;
8using Ionic.Zip;
9using Newtonsoft.Json;
10using UnityEngine;
11
13{
14 public static HashSet<int> sunMap = new HashSet<int>();
15
16 public static bool isDirtySunMap;
17
18 [JsonProperty]
19 public int seed;
20
21 [JsonProperty]
22 public int _bits;
23
24 [JsonProperty]
26
27 [JsonProperty]
28 public Dictionary<string, int> cellWidths = new Dictionary<string, int>();
29
30 [JsonProperty]
32
33 [JsonProperty]
35
36 [JsonProperty]
38
39 [JsonProperty]
40 public MapConfig config = new MapConfig();
41
42 [JsonProperty]
44
45 [JsonProperty]
46 public List<Chara> serializedCharas = new List<Chara>();
47
48 [JsonProperty]
49 public List<Chara> deadCharas = new List<Chara>();
50
51 [JsonProperty]
52 public List<Thing> things = new List<Thing>();
53
54 [JsonProperty]
55 public MapBounds bounds = new MapBounds();
56
57 [JsonProperty]
58 public List<int> _plDay = new List<int>();
59
60 [JsonProperty]
61 public List<int> _plNight = new List<int>();
62
63 [JsonProperty]
64 public Dictionary<int, int> gatherCounts = new Dictionary<int, int>();
65
66 [JsonProperty]
67 public Dictionary<int, CellEffect> cellEffects = new Dictionary<int, CellEffect>();
68
69 [JsonProperty]
70 public Dictionary<int, int> backerObjs = new Dictionary<int, int>();
71
72 [JsonProperty]
73 public Dictionary<int, PlantData> plants = new Dictionary<int, PlantData>();
74
75 [JsonProperty]
77
79
80 public Playlist plDay;
81
82 public Playlist plNight;
83
84 public List<Chara> charas = new List<Chara>();
85
86 public List<TransAnime> pointAnimes = new List<TransAnime>();
87
88 public Cell[,] cells;
89
90 public Zone zone;
91
93
95
96 public FloodSpiller flood = new FloodSpiller();
97
99
101
102 public List<Footmark> footmarks = new List<Footmark>();
103
105
106 private static readonly int[] CellIdWidths = new int[3] { 1, 2, 4 };
107
108 public bool revealed;
109
110 private HashSet<int> roomHash = new HashSet<int>();
111
112 private List<Thing> _things = new List<Thing>();
113
114 public bool isBreakerDown
115 {
116 get
117 {
118 return bits[0];
119 }
120 set
121 {
122 bits[0] = value;
123 }
124 }
125
127
129
131
132 public float sizeModifier => 1f / (16384f / (float)SizeXZ);
133
134 public bool isGenerated => Size != 0;
135
136 public bool IsIndoor => config.indoor;
137
138 public int SizeXZ => Size * Size;
139
140 public IEnumerable<Card> Cards => ((IEnumerable<Card>)things).Concat((IEnumerable<Card>)charas);
141
143 private void OnSerializing(StreamingContext context)
144 {
145 _bits = (int)bits.Bits;
146 }
147
148 protected virtual void OnSerializing()
149 {
150 }
151
153 private void OnDeserialized(StreamingContext context)
154 {
155 bits.Bits = (uint)_bits;
156 }
157
158 public void CreateNew(int size, bool setReference = true)
159 {
160 Debug.Log("Map CreateNew:");
161 Size = size;
162 cells = new Cell[Size, Size];
163 bounds = new MapBounds
164 {
165 x = 0,
166 z = 0,
167 maxX = Size - 1,
168 maxZ = Size - 1,
169 Size = Size
170 };
171 SetBounds(0, 0, Size - 1, Size - 1);
172 ForeachXYZ(delegate(int x, int z)
173 {
174 cells[x, z] = new Cell
175 {
176 x = (byte)x,
177 z = (byte)z
178 };
179 });
180 if (setReference)
181 {
182 SetReference();
183 }
184 }
185
186 public void SetZone(Zone _zone)
187 {
188 zone = _zone;
189 zone.bounds = bounds;
190 bounds.Size = Size;
191 SetReference();
192 props.Init();
193 EClass.scene.profile = SceneProfile.Load(config.idSceneProfile.IsEmpty("default"));
194 if (!config.idFowProfile.IsEmpty())
195 {
197 }
198 }
199
200 public void SetReference()
201 {
202 Fov.map = (Cell.map = (Wall.map = (Point.map = (CellDetail.map = this))));
203 Cell.Size = Size;
204 Cell.cells = cells;
206 WeightCell[,] weightMap = cells;
207 pathfinder.Init(this, weightMap, Size);
208 }
209
210 public void OnDeactivate()
211 {
212 charas.ForeachReverse(delegate(Chara c)
213 {
214 c.ai = new NoGoal();
215 if (c.IsGlobal)
216 {
217 zone.RemoveCard(c);
218 c.currentZone = zone;
219 }
220 });
221 foreach (Thing thing in things)
222 {
223 if (thing.renderer.hasActor)
224 {
225 thing.renderer.KillActor();
226 }
227 }
229 }
230
231 public void Resize(int newSize)
232 {
233 Point p = new Point(0, 0);
234 foreach (Thing thing in EClass._map.things)
235 {
236 if (thing.pos.x >= newSize || thing.pos.z >= newSize)
237 {
238 MoveCard(p, thing);
239 }
240 }
241 foreach (Chara chara in EClass._map.charas)
242 {
243 if (chara.pos.x >= newSize || chara.pos.z >= newSize)
244 {
245 MoveCard(p, chara);
246 }
247 }
248 Size = (bounds.Size = newSize);
249 maxX = (maxZ = Size);
250 cells = Util.ResizeArray(EClass._map.cells, newSize, newSize, (int x, int y) => new Cell
251 {
252 x = (byte)x,
253 z = (byte)y,
254 isSeen = true
255 });
256 Reload();
257 }
258
259 public void Shift(Vector2Int offset)
260 {
261 TweenUtil.Tween(0.1f, null, delegate
262 {
263 foreach (Card item in ((IEnumerable<Card>)EClass._map.things).Concat((IEnumerable<Card>)EClass._map.charas))
264 {
265 item.pos.x += offset.x;
266 item.pos.z += offset.y;
267 item.pos.Clamp();
268 }
269 Cell[,] array = new Cell[Size, Size];
270 for (int i = 0; i < Size; i++)
271 {
272 int num = i - offset.y;
273 for (int j = 0; j < Size; j++)
274 {
275 int num2 = j - offset.x;
276 if (num2 >= 0 && num2 < Size && num >= 0 && num < Size)
277 {
278 array[j, i] = cells[num2, num];
279 }
280 else
281 {
282 array[j, i] = new Cell
283 {
284 x = (byte)j,
285 z = (byte)i
286 };
287 }
288 }
289 }
290 cells = array;
291 bounds.x += offset.x;
292 bounds.z += offset.y;
293 bounds.maxX += offset.x;
294 bounds.maxZ += offset.y;
295 if (bounds.x < 0)
296 {
297 bounds.x = 0;
298 }
299 if (bounds.z < 0)
300 {
301 bounds.z = 0;
302 }
303 if (bounds.maxX > Size)
304 {
305 bounds.maxX = Size;
306 }
307 if (bounds.maxZ > Size)
308 {
309 bounds.maxZ = Size;
310 }
311 Reload();
312 });
313 }
314
315 public void Reload()
316 {
317 rooms = new RoomManager();
318 SetReference();
319 string id = Game.id;
320 EClass.game.Save();
321 EClass.scene.Init(Scene.Mode.None);
322 Game.Load(id, cloud: false);
323 RevealAll();
324 TweenUtil.Tween(0.1f, null, delegate
325 {
326 ReloadRoom();
327 });
328 }
329
330 public void ReloadRoom()
331 {
332 List<Thing> list = new List<Thing>();
333 foreach (Thing thing in things)
334 {
335 if (thing.trait.IsDoor)
336 {
337 list.Add(thing);
338 }
339 }
340 foreach (Thing item in list)
341 {
342 Point pos = item.pos;
344 EClass._zone.AddCard(item, pos);
345 item.Install();
346 }
348 }
349
350 public void Reset()
351 {
352 for (int i = 0; i < Size; i++)
353 {
354 for (int j = 0; j < Size; j++)
355 {
356 cells[i, j].Reset();
357 }
358 }
359 SetReference();
360 }
361
362 public void ResetEditorPos()
363 {
365 foreach (Chara chara in charas)
366 {
367 if (chara.isPlayerCreation && chara.orgPos != null)
368 {
369 MoveCard(chara.orgPos, chara);
370 }
371 }
372 foreach (Thing thing in things)
373 {
374 if (thing.trait is TraitDoor)
375 {
376 (thing.trait as TraitDoor).ForceClose();
377 }
378 }
379 }
380
381 public void Save(string path, ZoneExportData export = null, PartialMap partial = null)
382 {
384 Debug.Log("#io saving map:" + path);
385 IO.CreateDirectory(path);
386 int num = 0;
387 int num2 = 0;
388 int num3 = Size;
389 int num4 = Size;
390 if (partial != null)
391 {
392 num = partial.offsetX;
393 num2 = partial.offsetZ;
394 num3 = partial.w;
395 num4 = partial.h;
396 }
397 int num5 = num3 * num4;
398 byte[] array = new byte[num5];
399 int[] array2 = new int[num5];
400 int[] array3 = new int[num5];
401 int[] array4 = new int[num5];
402 int[] array5 = new int[num5];
403 int[] array6 = new int[num5];
404 int[] array7 = new int[num5];
405 byte[] array8 = new byte[num5];
406 byte[] array9 = new byte[num5];
407 byte[] array10 = new byte[num5];
408 byte[] array11 = new byte[num5];
409 byte[] array12 = new byte[num5];
410 int[] array13 = new int[num5];
411 int[] array14 = new int[num5];
412 byte[] array15 = new byte[num5];
413 int[] array16 = new int[num5];
414 byte[] array17 = new byte[num5];
415 int[] array18 = new int[num5];
416 int[] array19 = new int[num5];
417 int[] array20 = new int[num5];
418 int[] array21 = new int[num5];
419 cellEffects.Clear();
420 int num6 = 0;
421 for (int i = num; i < num + num3; i++)
422 {
423 for (int j = num2; j < num2 + num4; j++)
424 {
425 Cell cell = cells[i, j];
426 array[num6] = cell.objVal;
427 array3[num6] = cell._blockMat;
428 array2[num6] = cell._block;
429 array5[num6] = cell._floorMat;
430 array4[num6] = cell._floor;
431 array6[num6] = cell.obj;
432 array20[num6] = cell._deco;
433 array21[num6] = cell._decoMat;
434 array7[num6] = cell.objMat;
435 array8[num6] = cell.decal;
436 array9[num6] = cell._dirs;
437 array12[num6] = cell.height;
438 array13[num6] = cell._bridge;
439 array14[num6] = cell._bridgeMat;
440 array15[num6] = cell.bridgeHeight;
441 array17[num6] = cell._roofBlockDir;
442 array18[num6] = cell._roofBlock;
443 array19[num6] = cell._roofBlockMat;
444 array16[num6] = cell.bridgePillar;
445 array10[num6] = array10[num6].SetBit(1, cell.isSeen);
446 array10[num6] = array10[num6].SetBit(2, cell.isHarvested);
447 array10[num6] = array10[num6].SetBit(3, cell.impassable);
448 array10[num6] = array10[num6].SetBit(4, cell.isModified);
449 array10[num6] = array10[num6].SetBit(5, cell.isClearSnow);
450 array10[num6] = array10[num6].SetBit(6, cell.isForceFloat);
451 array10[num6] = array10[num6].SetBit(7, cell.isToggleWallPillar);
452 array11[num6] = array11[num6].SetBit(0, cell.isWatered);
453 array11[num6] = array11[num6].SetBit(1, cell.isObjDyed);
454 array11[num6] = array11[num6].SetBit(2, cell.crossWall);
455 array11[num6] = array11[num6].SetBit(3, cell.hidePillar);
456 array11[num6] = array11[num6].SetBit(4, cell.toggleOcclusion);
457 if (cell.effect != null)
458 {
459 cellEffects[j * num4 + i] = cell.effect;
460 }
461 num6++;
462 }
463 }
464 compression = ((!EClass.core.config.test.compressSave) ? IO.Compression.None : IO.Compression.LZ4);
465 cellWidths.Clear();
466 Write("objVals", array);
467 WriteIds("blocks", array2);
468 WriteIds("blockMats", array3);
469 WriteIds("floors", array4);
470 WriteIds("floorMats", array5);
471 WriteIds("objs", array6);
472 WriteIds("objMats", array7);
473 Write("decal", array8);
474 Write("flags", array10);
475 Write("flags2", array11);
476 Write("dirs", array9);
477 Write("heights", array12);
478 WriteIds("bridges", array13);
479 WriteIds("bridgeMats", array14);
480 Write("bridgeHeights", array15);
481 WriteIds("bridgePillars", array16);
482 WriteIds("roofBlocks", array18);
483 WriteIds("roofBlockMats", array19);
484 Write("roofBlockDirs", array17);
485 WriteIds("decos", array20);
486 WriteIds("decoMats", array21);
487 things.Sort((Thing a, Thing b) => a.stackOrder - b.stackOrder);
488 if (export == null)
489 {
490 foreach (Chara chara in charas)
491 {
492 if (!chara.IsGlobal)
493 {
494 serializedCharas.Add(chara);
495 }
496 }
497 GameIO.SaveFile(path + "map", this);
498 }
499 else
500 {
501 export.serializedCards.cards.Clear();
502 if (partial == null)
503 {
504 MapExportSetting mapExportSetting = exportSetting ?? new MapExportSetting();
505 foreach (Chara chara2 in charas)
506 {
507 if (export.usermap)
508 {
509 if ((!mapExportSetting.clearLocalCharas || chara2.IsPCFactionOrMinion) && !chara2.trait.IsUnique && !chara2.IsPC)
510 {
511 export.serializedCards.Add(chara2);
512 }
513 }
514 else if (!chara2.IsGlobal && chara2.isPlayerCreation)
515 {
516 export.serializedCards.Add(chara2);
517 }
518 }
519 foreach (Thing thing in things)
520 {
521 if (thing.isPlayerCreation && thing.c_altName != "DebugContainer")
522 {
523 export.serializedCards.Add(thing);
524 }
525 }
526 }
527 else
528 {
529 foreach (Thing thing2 in things)
530 {
531 if ((ActionMode.Copy.IsActive || thing2.trait.CanCopyInBlueprint) && thing2.pos.x >= num && thing2.pos.z >= num2 && thing2.pos.x < num + num3 && thing2.pos.z < num2 + num4)
532 {
533 export.serializedCards.Add(thing2);
534 }
535 }
536 }
537 List<Thing> list = things;
538 things = new List<Thing>();
539 GameIO.SaveFile(path + "map", this);
540 things = list;
541 }
542 serializedCharas.Clear();
543 void Write(string name, byte[] bytes)
544 {
545 IO.WriteLZ4(path + name, bytes, compression);
546 }
547 void WriteIds(string name, int[] ids)
548 {
549 int num7 = WriteCellIds(path + name, ids, compression);
550 if (num7 > 1)
551 {
552 cellWidths[name] = num7;
553 }
554 }
555 }
556
557 public byte[] TryLoadFile(string path, string s, int size)
558 {
559 byte[] array = IO.ReadLZ4(path + s, size, compression);
560 if (array == null)
561 {
562 Debug.Log("Couldn't load:" + s);
563 return new byte[size];
564 }
565 return array;
566 }
567
568 private static string CellIdPath(string path, int width)
569 {
570 if (width != 1)
571 {
572 return path + ".w" + width;
573 }
574 return path;
575 }
576
577 private static int WriteCellIds(string path, int[] ids, IO.Compression compression)
578 {
579 int num = 0;
580 int[] array = ids;
581 foreach (int b in array)
582 {
583 num = Mathf.Max(num, b);
584 }
585 int num2 = ((num <= 255) ? 1 : ((num <= 65535) ? 2 : 4));
586 byte[] array2 = new byte[ids.Length * num2];
587 for (int j = 0; j < ids.Length; j++)
588 {
589 for (int k = 0; k < num2; k++)
590 {
591 array2[j * num2 + k] = (byte)(ids[j] >> 8 * k);
592 }
593 }
594 IO.WriteLZ4(CellIdPath(path, num2), array2, compression);
595 array = CellIdWidths;
596 foreach (int num3 in array)
597 {
598 if (num3 != num2)
599 {
600 string text = CellIdPath(path, num3);
601 IO.DeleteFile(text);
602 for (int l = 1; l < 5; l++)
603 {
604 IO.DeleteFile(text + ".b" + l);
605 }
606 }
607 }
608 return num2;
609 }
610
611 private int[] ReadCellIds(string file, string s, int size, int width)
612 {
613 byte[] array = IO.ReadLZ4(file, size * width, compression);
614 if (array == null)
615 {
616 return null;
617 }
618 if ((width != 1 && width != 2 && width != 4) || array.Length != (long)size * (long)width)
619 {
620 Debug.Log("Couldn't load:" + s);
621 return null;
622 }
623 int[] array2 = new int[size];
624 for (int i = 0; i < size; i++)
625 {
626 for (int j = 0; j < width; j++)
627 {
628 array2[i] |= array[i * width + j] << 8 * j;
629 }
630 }
631 return array2;
632 }
633
634 public void Load(string path, bool import = false, PartialMap partial = null)
635 {
636 if (partial == null)
637 {
638 Debug.Log("Map Load:" + compression.ToString() + ": " + path);
639 }
640 int num = Size;
641 int num2 = Size;
642 if (partial != null)
643 {
644 num = partial.w;
645 num2 = partial.h;
646 Debug.Log(compression.ToString() + ": " + num + "/" + num2);
647 }
648 int size = num * num2;
649 cells = new Cell[num, num2];
650 if (bounds.maxX == 0)
651 {
652 bounds.SetBounds(0, 0, num - 1, num2 - 1);
653 }
654 SetBounds(0, 0, num - 1, num2 - 1);
655 byte[] data = TryLoad("objVals");
656 int[] data2 = TryLoadIds("blockMats");
657 int[] data3 = TryLoadIds("blocks");
658 int[] data4 = TryLoadIds("floorMats");
659 int[] data5 = TryLoadIds("floors");
660 int[] data6 = TryLoadIds("objs");
661 int[] data7 = TryLoadIds("objMats");
662 byte[] data8 = TryLoad("decal");
663 int[] data9 = TryLoadIds("decos");
664 int[] data10 = TryLoadIds("decoMats");
665 byte[] data11 = TryLoad("dirs");
666 byte[] data12 = TryLoad("flags");
667 byte[] data13 = TryLoad("flags2");
668 byte[] data14 = TryLoad("heights");
669 int[] data15 = TryLoadIds("bridges");
670 int[] data16 = TryLoadIds("bridgeMats");
671 byte[] data17 = TryLoad("bridgeHeights");
672 int[] data18 = TryLoadIds("bridgePillars");
673 int[] data19 = TryLoadIds("roofBlocks");
674 int[] data20 = TryLoadIds("roofBlockMats");
675 byte[] data21 = TryLoad("roofBlockDirs");
676 if (data18.Length < size)
677 {
678 data18 = new int[size];
679 }
680 if (data.Length < size)
681 {
682 data = new byte[size];
683 }
684 if (data13.Length < size)
685 {
686 data13 = new byte[size];
687 }
688 Validate<byte>(ref data, "objVals");
689 Validate<int>(ref data2, "blockMats");
690 Validate<int>(ref data3, "blocks");
691 Validate<int>(ref data4, "floorMats");
692 Validate<int>(ref data5, "floors");
693 Validate<int>(ref data6, "objs");
694 Validate<int>(ref data7, "objMats");
695 Validate<byte>(ref data8, "decal");
696 Validate<int>(ref data9, "decos");
697 Validate<int>(ref data10, "decoMats");
698 Validate<byte>(ref data11, "dirs");
699 Validate<byte>(ref data12, "flags");
700 Validate<byte>(ref data13, "flags2");
701 Validate<byte>(ref data14, "heights");
702 Validate<int>(ref data15, "bridges");
703 Validate<int>(ref data16, "bridgeMats");
704 Validate<byte>(ref data17, "bridgeHeights");
705 Validate<int>(ref data18, "bridgePillars");
706 Validate<int>(ref data19, "roofBlocks");
707 Validate<int>(ref data20, "roofBlockMats");
708 Validate<byte>(ref data21, "roofBlockDirs");
709 int num3 = 0;
710 for (int i = 0; i < num; i++)
711 {
712 for (int j = 0; j < num2; j++)
713 {
714 Cell cell = (cells[i, j] = new Cell
715 {
716 x = (byte)i,
717 z = (byte)j,
718 objVal = data[num3],
719 _blockMat = data2[num3],
720 _block = data3[num3],
721 _floorMat = data4[num3],
722 _floor = data5[num3],
723 obj = data6[num3],
724 objMat = data7[num3],
725 decal = data8[num3],
726 _deco = data9[num3],
727 _decoMat = data10[num3],
728 _dirs = data11[num3],
729 height = data14[num3],
730 _bridge = data15[num3],
731 _bridgeMat = data16[num3],
732 bridgeHeight = data17[num3],
733 bridgePillar = data18[num3],
734 _roofBlock = data19[num3],
735 _roofBlockMat = data20[num3],
736 _roofBlockDir = data21[num3],
737 isSeen = data12[num3].GetBit(1),
738 isHarvested = data12[num3].GetBit(2),
739 impassable = data12[num3].GetBit(3),
740 isModified = data12[num3].GetBit(4),
741 isClearSnow = data12[num3].GetBit(5),
742 isForceFloat = data12[num3].GetBit(6),
743 isToggleWallPillar = data12[num3].GetBit(7),
744 isWatered = data13[num3].GetBit(0),
745 isObjDyed = data13[num3].GetBit(1),
746 crossWall = data13[num3].GetBit(2),
747 hidePillar = data13[num3].GetBit(3),
748 toggleOcclusion = data13[num3].GetBit(4)
749 });
750 if (version.IsBelow(0, 23, 344) && cell.bridgePillar == 255)
751 {
752 cell.bridgePillar = 0;
753 cell.hidePillar = true;
754 }
755 if (!EClass.sources.floors.map.ContainsKey(cell._bridge))
756 {
757 cell._bridge = 0;
758 }
759 if (!EClass.sources.materials.map.ContainsKey(cell._bridgeMat))
760 {
761 cell._bridgeMat = 1;
762 }
764 num3++;
765 }
766 }
767 things.ForeachReverse(delegate(Thing t)
768 {
769 if (t.Num <= 0 || t.isDestroyed)
770 {
771 Debug.Log("[bug] Removing bugged thing:" + t.Num + "/" + t.isDestroyed + "/" + t);
772 things.Remove(t);
773 }
774 });
775 foreach (KeyValuePair<int, CellEffect> cellEffect in cellEffects)
776 {
777 int key = cellEffect.Key;
778 int num4 = key % Size;
779 int num5 = key / Size;
780 cells[num4, num5].effect = cellEffect.Value;
781 if (cellEffect.Value.IsFire)
782 {
783 effectManager.GetOrCreate(new Point(num4, num5));
784 }
785 }
786 cellEffects.Clear();
788 byte[] TryLoad(string s)
789 {
790 return TryLoadFile(path, s, size);
791 }
792 int[] TryLoadIds(string s)
793 {
794 int value;
795 int width = ((cellWidths == null || !cellWidths.TryGetValue(s, out value)) ? 1 : value);
796 return ReadCellIds(CellIdPath(path + s, width), s, size, width) ?? new int[size];
797 }
798 void Validate<T>(ref T[] reference, string id)
799 {
800 if (reference.Length < size)
801 {
802 Debug.LogError("exception: size invalid:" + id + " " + reference.Length + "/" + size);
803 reference = new T[size];
804 }
805 }
806 }
807
808 public void ValidateVersion()
809 {
811 }
812
813 public void OnLoad()
814 {
815 rooms.OnLoad();
816 tasks.OnLoad();
817 }
818
819 public void OnImport(ZoneExportData data)
820 {
821 tasks = new TaskManager();
822 data.serializedCards.Restore(this, data.orgMap, addToZone: false);
823 }
824
825 public void ExportMetaData(string _path, string id, PartialMap partial = null)
826 {
827 if (custom == null)
828 {
829 custom = new CustomData();
830 }
831 MapMetaData mapMetaData = new MapMetaData
832 {
833 name = EClass._zone.Name,
835 tag = (EClass._map.exportSetting?.tag ?? ""),
836 partial = partial,
837 underwater = EClass._zone.IsUnderwater
838 };
839 custom.id = (mapMetaData.id = id);
840 IO.SaveFile(_path + "meta", mapMetaData);
841 }
842
843 public static MapMetaData GetMetaData(string pathZip)
844 {
845 try
846 {
847 using ZipFile zipFile = ZipFile.Read(pathZip);
848 ZipEntry zipEntry = zipFile["meta"];
849 if (zipEntry != null)
850 {
851 using (MemoryStream stream = new MemoryStream())
852 {
853 zipEntry.Extract(stream);
854 MapMetaData mapMetaData = IO.LoadStreamJson<MapMetaData>(stream);
855 mapMetaData.path = pathZip;
856 return mapMetaData;
857 }
858 }
859 }
860 catch (Exception message)
861 {
862 if (Application.isEditor)
863 {
864 Debug.Log(message);
865 }
866 }
867 return null;
868 }
869
870 public static void UpdateMetaData(string pathZip, PartialMap partial = null)
871 {
872 IO.CreateTempDirectory();
873 ZipFile zipFile = ZipFile.Read(pathZip);
874 zipFile.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently;
875 zipFile.ExtractAll(IO.TempPath);
876 zipFile.Dispose();
877 EClass._map.ExportMetaData(IO.TempPath + "/", Path.GetFileNameWithoutExtension(pathZip), partial);
878 using (zipFile = new ZipFile())
879 {
880 zipFile.ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently;
881 zipFile.AddDirectory(IO.TempPath);
882 zipFile.Save(pathZip);
883 zipFile.Dispose();
884 }
885 IO.DeleteTempDirectory();
886 }
887
888 public void AddCardOnActivate(Card c)
889 {
890 c.parent = zone;
892 Chara chara = c.Chara;
893 if (chara != null)
894 {
895 chara.currentZone = EClass._zone;
896 }
897 if (c.isChara)
898 {
899 if (!c.pos.IsInBounds)
900 {
902 }
903 }
904 else if (!c.pos.IsValid)
905 {
907 }
908 _AddCard(c.pos.x, c.pos.z, c, onAddToZone: true);
909 }
910
911 public void OnCardAddedToZone(Card t, int x, int z)
912 {
913 if (t.isChara)
914 {
915 charas.Add(t.Chara);
916 }
917 else
918 {
919 things.Add(t.Thing);
920 }
922 if (t.isChara && new Point(x, z).cell.HasFullBlock)
923 {
924 DestroyBlock(x, z);
925 }
926 _AddCard(x, z, t, onAddToZone: true);
928 }
929
931 {
934 _RemoveCard(t);
935 t.parent = null;
936 if (t.isChara)
937 {
938 charas.RemoveFromEnd(t.Chara);
939 }
940 else
941 {
942 things.RemoveFromEnd(t.Thing);
943 }
944 }
945
946 public void MoveCard(Point p, Card t)
947 {
948 _AddCard(p.x, p.z, t, onAddToZone: false);
949 }
950
951 public void _AddCard(int x, int z, Card t, bool onAddToZone)
952 {
953 if (!onAddToZone)
954 {
955 _RemoveCard(t);
956 }
957 t.lastPos.Set(t.pos);
958 t.pos.Set(x, z);
959 if (t.IsMultisize)
960 {
961 t.ForeachPoint(delegate(Point p, bool main)
962 {
963 p.cell.AddCard(t);
964 });
965 }
966 else
967 {
968 t.Cell.AddCard(t);
969 }
970 t.CalculateFOV();
971 if (t.isThing && !t.trait.IDActorEx.IsEmpty())
972 {
974 }
975 }
976
977 public void _RemoveCard(Card t)
978 {
979 if (t.IsMultisize)
980 {
981 t.ForeachPoint(delegate(Point p, bool main)
982 {
983 p.cell.RemoveCard(t);
984 });
985 }
986 else
987 {
988 t.Cell.RemoveCard(t);
989 }
990 t.ClearFOV();
991 }
992
993 public Cell GetCell(int index)
994 {
995 return cells[index % Size, index % SizeXZ / Size];
996 }
997
998 public void SetSeen(int x, int z, bool seen = true, bool refresh = true)
999 {
1000 if (cells[x, z].isSeen != seen)
1001 {
1002 cells[x, z].isSeen = seen;
1003 if (refresh)
1004 {
1006 }
1008 }
1009 }
1010
1011 public void RevealAll(bool reveal = true)
1012 {
1013 for (int i = 0; i < Size; i++)
1014 {
1015 for (int j = 0; j < Size; j++)
1016 {
1017 EClass._map.SetSeen(i, j, reveal, refresh: false);
1018 }
1019 }
1020 revealed = !revealed;
1022 }
1023
1024 public void Reveal(Point center, int power = 100)
1025 {
1026 ForeachSphere(center.x, center.z, 10 + power / 5, delegate(Point p)
1027 {
1028 if (EClass.rnd(power) >= Mathf.Min(p.Distance(center) * 10, power - 10))
1029 {
1030 EClass._map.SetSeen(p.x, p.z);
1031 }
1032 });
1033 }
1034
1035 public void RefreshFOV(int x, int z, int radius = 6, bool recalculate = false)
1036 {
1037 ForeachSphere(x, z, radius, delegate(Point p)
1038 {
1039 List<Card> list = p.ListCards();
1040 if (recalculate)
1041 {
1042 foreach (Card item in list)
1043 {
1044 item.RecalculateFOV();
1045 }
1046 return;
1047 }
1048 foreach (Card item2 in list)
1049 {
1050 item2.CalculateFOV();
1051 }
1052 });
1053 }
1054
1055 public void RefreshFOVAll()
1056 {
1057 foreach (Card item in ((IEnumerable<Card>)EClass._map.things).Concat((IEnumerable<Card>)EClass._map.charas))
1058 {
1059 item.RecalculateFOV();
1060 }
1061 }
1062
1063 public void SetFloor(int x, int z, int idMat = 0, int idFloor = 0)
1064 {
1065 SetFloor(x, z, idMat, idFloor, 0);
1066 }
1067
1068 public void SetFloor(int x, int z, int idMat, int idFloor, int dir)
1069 {
1070 Cell cell = cells[x, z];
1071 cell._floorMat = idMat;
1072 cell._floor = idFloor;
1073 cell.floorDir = dir;
1074 cell.isWatered = false;
1075 Critter.RebuildCritter(cell);
1077 }
1078
1079 public void SetDeco(int x, int z, int idMat, int idDeco)
1080 {
1081 Cell cell = cells[x, z];
1082 cell._decoMat = idMat;
1083 cell._deco = idDeco;
1085 }
1086
1087 public void SetBridge(int x, int z, int height = 0, int idMat = 0, int idBridge = 0, int dir = 0, int idPillar = 0, bool hidePillar = false)
1088 {
1089 Cell cell = cells[x, z];
1090 cell.bridgeHeight = (byte)height;
1091 cell._bridgeMat = idMat;
1092 cell._bridge = idBridge;
1093 cell.bridgePillar = idPillar;
1094 cell.hidePillar = hidePillar;
1095 cell.floorDir = dir;
1096 if (cell.room != null)
1097 {
1098 cell.room.SetDirty();
1099 }
1101 }
1102
1103 public void SetRoofBlock(int x, int z, int idMat, int idBlock, int dir, int height)
1104 {
1105 Cell cell = cells[x, z];
1106 cell._roofBlockMat = idMat;
1107 cell._roofBlock = idBlock;
1108 cell._roofBlockDir = (byte)(dir + height * 4);
1110 }
1111
1112 public void SetBlock(int x, int z, int idMat = 0, int idBlock = 0)
1113 {
1114 SetBlock(x, z, idMat, idBlock, 0);
1115 }
1116
1117 public void SetBlock(int x, int z, int idMat, int idBlock, int dir)
1118 {
1119 Cell cell = cells[x, z];
1120 bool hasFloodBlock = cell.HasFloodBlock;
1121 cell._blockMat = idMat;
1122 cell._block = idBlock;
1123 cell.blockDir = dir;
1124 if (cell.effect == null || !cell.effect.IsFire)
1125 {
1126 cell.effect = null;
1127 }
1128 cell.isToggleWallPillar = false;
1129 if (cell.room != null)
1130 {
1131 cell.room.SetDirty();
1132 }
1133 if (hasFloodBlock || cell.HasFloodBlock)
1134 {
1136 }
1138 }
1139
1140 public void OnSetBlockOrDoor(int x, int z)
1141 {
1142 new Point(x, z);
1143 TryRemoveRoom(x, z);
1144 if (x > 0)
1145 {
1146 TryRemoveRoom(x - 1, z);
1147 }
1148 if (x < Size - 1)
1149 {
1150 TryRemoveRoom(x + 1, z);
1151 }
1152 if (z > 0)
1153 {
1154 TryRemoveRoom(x, z - 1);
1155 }
1156 if (z < Size - 1)
1157 {
1158 TryRemoveRoom(x, z + 1);
1159 }
1160 if (x > 0 && z < Size - 1)
1161 {
1162 TryRemoveRoom(x - 1, z + 1);
1163 }
1164 roomHash.Clear();
1165 TryAddRoom(x, z);
1166 if (x > 0)
1167 {
1168 TryAddRoom(x - 1, z);
1169 }
1170 if (x < Size - 1)
1171 {
1172 TryAddRoom(x + 1, z);
1173 }
1174 if (z > 0)
1175 {
1176 TryAddRoom(x, z - 1);
1177 }
1178 if (z < Size - 1)
1179 {
1180 TryAddRoom(x, z + 1);
1181 }
1182 if (x > 0 && z < Size - 1)
1183 {
1184 TryAddRoom(x - 1, z + 1);
1185 }
1186 }
1187
1188 public void TryRemoveRoom(int x, int z)
1189 {
1190 if (!cells[x, z].HasFloodBlock)
1191 {
1192 Room room = cells[x, z].room;
1193 if (room != null)
1194 {
1195 rooms.RemoveRoom(room);
1196 }
1197 }
1198 }
1199
1200 public void TryAddRoom(int x, int z)
1201 {
1202 if (EClass._zone.DisableRooms || roomHash.Contains(x + z * Size) || cells[x, z].HasFloodBlock)
1203 {
1204 return;
1205 }
1206 FloodSpiller floodSpiller = flood;
1207 IFloodCell[,] array = cells;
1208 FloodSpiller.Result result = floodSpiller.SpillFlood(array, x, z);
1209 if (!result.IsValid)
1210 {
1211 return;
1212 }
1213 bool flag = false;
1214 foreach (IFloodCell item in result.visited)
1215 {
1216 if (item.hasDoor)
1217 {
1218 flag = true;
1219 break;
1220 }
1221 Cell cell = item as Cell;
1222 if (cell.sourceBlock.tileType.IsFloodDoor || cell.Front.hasDoor || cell.Right.hasDoor || cell.FrontRight.hasDoor || cell.Back.hasDoor || cell.Left.hasDoor || cell.BackLeft.hasDoor)
1223 {
1224 flag = true;
1225 break;
1226 }
1227 }
1228 if (!flag && IsIndoor)
1229 {
1230 foreach (IFloodCell item2 in result.visited)
1231 {
1232 Cell cell2 = item2 as Cell;
1233 if (cell2.detail == null || cell2.detail.things.Count == 0)
1234 {
1235 continue;
1236 }
1237 foreach (Thing thing in cell2.detail.things)
1238 {
1239 if (thing.trait is TraitRoomPlate || thing.trait is TraitHouseBoard)
1240 {
1241 flag = true;
1242 break;
1243 }
1244 }
1245 if (flag)
1246 {
1247 break;
1248 }
1249 }
1250 }
1251 if (!flag)
1252 {
1253 return;
1254 }
1255 Room room = rooms.AddRoom(new Room());
1256 foreach (IFloodCell item3 in result.visited)
1257 {
1258 Cell cell3 = item3 as Cell;
1259 byte b = cell3.x;
1260 byte b2 = cell3.z;
1261 room.AddPoint(new Point(b, b2));
1262 roomHash.Add(b + b2 * Size);
1263 if (b2 > 0 && cell3.Front.HasFloodBlock && cell3.Front.room == null)
1264 {
1265 room.AddPoint(new Point(b, b2 - 1));
1266 roomHash.Add(b + (b2 - 1) * Size);
1267 }
1268 if (b < Size - 1 && cell3.Right.HasFloodBlock && cell3.Right.room == null)
1269 {
1270 room.AddPoint(new Point(b + 1, b2));
1271 roomHash.Add(b + 1 + b2 * Size);
1272 }
1273 if (b2 > 0 && b < Size - 1 && cell3.FrontRight.HasFloodBlock && cell3.FrontRight.room == null)
1274 {
1275 room.AddPoint(new Point(b + 1, b2 - 1));
1276 roomHash.Add(b + 1 + (b2 - 1) * Size);
1277 }
1278 }
1279 }
1280
1281 public void SetBlockDir(int x, int z, int dir)
1282 {
1283 Cell cell = cells[x, z];
1284 cell._block = cell.sourceBlock.id;
1285 cell.blockDir = dir;
1286 }
1287
1288 public void ModFire(int x, int z, int amount)
1289 {
1290 Cell cell = cells[x, z];
1291 if (amount <= 0 || (!cell.IsTopWaterAndNoSnow && !cell.IsSnowTile && !EClass._zone.IsUnderwater))
1292 {
1293 if (cell.effect == null && amount > 0)
1294 {
1295 SE.Play("fire");
1296 }
1297 int num = amount + (cell.effect?.FireAmount ?? 0);
1298 if (num > 20)
1299 {
1300 num = 20;
1301 }
1302 if (num <= 0)
1303 {
1304 cell.effect = null;
1305 return;
1306 }
1307 cell.effect = new CellEffect
1308 {
1309 id = 3,
1310 amount = num
1311 };
1313 }
1314 }
1315
1316 public void TryShatter(Point pos, int ele, int power, Card CC = null)
1317 {
1318 bool flag = false;
1319 if (CC != null && CC.IsPCFactionOrMinion && (CC.HasElement(1651) || EClass.pc.Evalue(1651) >= 2))
1320 {
1321 flag = true;
1322 }
1323 Element element = Element.Create(ele);
1324 List<Card> list = new List<Card>();
1325 bool fire = ele == 910;
1326 bool cold = ele == 911;
1327 _ = fire;
1328 List<Card> list2 = pos.ListCards();
1329 if (fire && (pos.cell.IsSnowTile || pos.cell.IsTopWater))
1330 {
1331 return;
1332 }
1333 foreach (Card item in list2)
1334 {
1335 if (item.ResistLvFrom(ele) >= 3 || item.trait is TraitBlanket || (EClass.rnd(3) == 0 && !CanCook(item)) || (item.IsPCFaction && EClass.rnd(3) == 0) || (fire && item.HasCondition<ConWet>()) || (cold && item.HasCondition<ConBurning>()))
1336 {
1337 continue;
1338 }
1339 if (flag)
1340 {
1341 if (item.isChara)
1342 {
1343 if (item.IsPCFactionOrMinion)
1344 {
1345 continue;
1346 }
1347 }
1348 else if (!CanCook(item))
1349 {
1350 continue;
1351 }
1352 }
1354 {
1355 Card rootCard = item.GetRootCard();
1356 if (!rootCard.isChara || rootCard.Chara.IsPCFaction)
1357 {
1358 if (pos.IsSync)
1359 {
1360 Msg.Say("damage_protectCore", item);
1361 }
1362 continue;
1363 }
1364 }
1365 if (item.isThing && item.things.Count == 0)
1366 {
1367 list.Add(item);
1368 }
1369 else
1370 {
1371 if (ele == 911 && item.HasElement(1236))
1372 {
1373 continue;
1374 }
1375 Thing thing = ((ele == 910) ? item.things.FindBest<TraitBlanketFireproof>((Thing t) => -t.c_charges) : item.things.FindBest<TraitBlanketColdproof>((Thing t) => -t.c_charges));
1376 if (thing != null)
1377 {
1378 thing.ModCharge(-1);
1379 Card rootCard2 = item.GetRootCard();
1380 if (pos.IsSync)
1381 {
1382 Msg.Say((item.isChara ? "blanketInv_" : "blanketGround_") + element.source.alias, thing, item);
1383 }
1384 if (thing.c_charges <= 0)
1385 {
1386 thing.Die(element);
1387 if (rootCard2.IsPCParty)
1388 {
1390 }
1391 }
1392 continue;
1393 }
1394 foreach (Thing item2 in item.things.List((Thing a) => a.things.Count == 0))
1395 {
1396 Card parentCard = item2.parentCard;
1397 if (parentCard == null || (!(parentCard.trait is TraitChestMerchant) && !parentCard.HasEditorTag(EditorTag.PreciousContainer)))
1398 {
1399 list.Add(item2);
1400 }
1401 }
1402 }
1403 }
1404 list.Shuffle();
1405 int num = 0;
1406 bool flag2 = false;
1407 foreach (Card item3 in list)
1408 {
1409 if (!item3.trait.CanBeDestroyed || item3.category.IsChildOf("currency") || item3.trait is TraitDoor || item3.trait is TraitFigure || item3.trait is TraitTrainingDummy || item3.rarity >= Rarity.Legendary)
1410 {
1411 continue;
1412 }
1413 Card rootCard3 = item3.GetRootCard();
1414 if (item3.IsEquipmentOrRangedOrAmmo && (EClass.rnd(4) != 0 || ((item3.IsRangedWeapon || item3.Thing.isEquipped) && rootCard3.IsPCFaction && EClass.rnd(4) != 0)))
1415 {
1416 continue;
1417 }
1418 switch (ele)
1419 {
1420 case 910:
1421 if (item3.isFireproof || (!item3.category.IsChildOf("book") && EClass.rnd(2) == 0))
1422 {
1423 continue;
1424 }
1425 break;
1426 case 911:
1427 if (!item3.category.IsChildOf("drink") && EClass.rnd(5) == 0)
1428 {
1429 continue;
1430 }
1431 break;
1432 }
1433 if (EClass.rnd(num * num) != 0)
1434 {
1435 continue;
1436 }
1437 bool flag3 = CanCook(item3);
1438 string text = "";
1439 if (flag3)
1440 {
1441 if (fire)
1442 {
1443 List<SourceThing.Row> list3 = new List<SourceThing.Row>();
1444 foreach (RecipeSource item4 in RecipeManager.list)
1445 {
1446 if (!(item4.row is SourceThing.Row { isOrigin: false, chance: not 0 } row) || row.components.IsEmpty() || (row.components.Length >= 3 && !row.components[2].StartsWith('+')) || !row.Category.IsChildOf("meal") || (row.HasTag(CTAG.dish_fail) && power > EClass.rnd(500)))
1447 {
1448 continue;
1449 }
1450 if (!row.factory.IsEmpty())
1451 {
1452 switch (row.factory[0])
1453 {
1454 case "chopper":
1455 case "mixer":
1456 case "camppot":
1457 case "cauldron":
1458 continue;
1459 }
1460 }
1461 if (row.components[0].Split('|').Contains(item3.id) || row.components[0].Split('|').Contains(item3.sourceCard._origin))
1462 {
1463 list3.Add(row);
1464 }
1465 }
1466 if (list3.Count > 0)
1467 {
1468 text = list3.RandomItemWeighted((SourceThing.Row r) => r.chance)?.id;
1469 }
1470 }
1471 else
1472 {
1473 text = "711";
1474 }
1475 }
1476 if (flag3 && !text.IsEmpty())
1477 {
1478 Thing thing2 = item3.Split(1);
1479 List<Thing> list4 = new List<Thing>();
1480 list4.Add(thing2);
1481 Thing thing3 = ThingGen.Create(text);
1482 CraftUtil.MakeDish(thing3, list4, 999);
1483 thing3.elements.ModBase(2, EClass.curve(power / 10, 50, 10));
1484 if (pos.IsSync)
1485 {
1486 Msg.Say(((rootCard3 == item3) ? "cook_groundItem" : "cook_invItem") + (fire ? "" : "_cold"), thing2, rootCard3, thing3.Name);
1487 }
1488 if (rootCard3 == item3)
1489 {
1490 EClass._zone.AddCard(thing3, item3.pos);
1491 }
1492 else if (rootCard3.isChara)
1493 {
1494 rootCard3.Chara.Pick(thing3, msg: false);
1495 }
1496 else
1497 {
1498 rootCard3.AddThing(thing3);
1499 }
1500 thing2.Destroy();
1501 }
1502 else
1503 {
1504 int num2 = EClass.rnd(item3.Num) / 2 + 1;
1505 if (item3.Num > num2)
1506 {
1507 Thing thing4 = item3.Split(num2);
1508 if (pos.IsSync)
1509 {
1510 Msg.Say((rootCard3 == item3) ? "damage_groundItem" : "damage_invItem", thing4, rootCard3);
1511 }
1512 thing4.Destroy();
1513 if (rootCard3.IsPCFaction)
1514 {
1515 WidgetPopText.Say("popDestroy".lang(thing4.Name, rootCard3.Name));
1516 }
1517 }
1518 else
1519 {
1520 item3.Die(element);
1521 if (rootCard3.IsPCFaction)
1522 {
1523 WidgetPopText.Say("popDestroy".lang(item3.Name, rootCard3.Name));
1524 }
1525 }
1526 }
1527 if (rootCard3.IsPCParty)
1528 {
1530 }
1531 if (!flag2)
1532 {
1533 pos.PlayEffect(fire ? "Element/eleFire" : "Element/eleCold");
1534 flag2 = true;
1535 }
1536 num++;
1537 }
1538 _ValidateInstalled(pos.x, pos.z);
1539 bool CanCook(Card c)
1540 {
1541 if ((fire || cold) && c.IsFood)
1542 {
1543 return c.category.IsChildOf("foodstuff");
1544 }
1545 return false;
1546 }
1547 }
1548
1549 public void Burn(int x, int z, bool instant = false)
1550 {
1551 Cell cell = cells[x, z];
1552 Point sharedPoint = cell.GetSharedPoint();
1553 if ((instant || EClass.rnd(10) == 0) && cell.HasObj)
1554 {
1555 if (cell.sourceObj.tileType is TileTypeTree)
1556 {
1557 SetObj(x, z, cell.matObj_fixed.id, 59, 0, EClass.rnd(4));
1558 }
1559 else
1560 {
1561 SetObj(x, z);
1562 if (EClass.rnd(2) == 0)
1563 {
1564 EClass._zone.AddCard(ThingGen.Create((EClass.rnd(2) == 0) ? "ash" : "ash2"), sharedPoint);
1565 }
1566 }
1567 }
1568 if ((instant || EClass.rnd(5) == 0) && cell._block != 0 && cell._block != 96)
1569 {
1570 if (EClass.rnd(10) == 0 || !cell.sourceBlock.tileType.IsWall)
1571 {
1572 cell._block = 0;
1573 }
1574 else
1575 {
1576 cell._block = 96;
1577 }
1578 SetObj(x, z);
1579 if (cell.room != null)
1580 {
1581 cell.room.SetDirty();
1582 }
1584 }
1585 if (instant || EClass.rnd(10) == 0)
1586 {
1587 if (EClass.rnd(4) != 0)
1588 {
1589 cell._floor = 49;
1590 }
1591 if (cell._bridge != 0 && EClass.rnd(5) != 0)
1592 {
1593 cell._bridge = 49;
1594 }
1595 }
1596 foreach (Card item in sharedPoint.ListCards())
1597 {
1598 if (item.trait.CanBeDestroyed && !item.trait.IsDoor && !item.isFireproof && !item.category.IsChildOf("currency") && item.rarity < Rarity.Legendary && !(item.trait is TraitFigure) && item.isThing)
1599 {
1600 if (instant)
1601 {
1602 item.Destroy();
1603 EClass._zone.AddCard(ThingGen.Create((EClass.rnd(2) == 0) ? "ash" : "ash2"), sharedPoint);
1604 }
1605 else
1606 {
1607 item.DamageHP(30L, 910);
1608 }
1609 }
1610 }
1611 if (instant)
1612 {
1613 cell.effect = null;
1614 }
1615 }
1616
1617 public void SetLiquid(int x, int z, CellEffect effect = null)
1618 {
1619 Cell cell = cells[x, z];
1620 if (!cell.IsTopWaterAndNoSnow || effect == null)
1621 {
1622 cell.effect = effect;
1623 }
1624 }
1625
1626 public void SetLiquid(int x, int z, int id, int value = 1)
1627 {
1628 Cell cell = cells[x, z];
1629 if (!cell.IsTopWaterAndNoSnow || value == 0)
1630 {
1631 if (value > 3)
1632 {
1633 value = 3;
1634 }
1635 if (value <= 0)
1636 {
1637 cell.effect = null;
1638 return;
1639 }
1640 cell.effect = new CellEffect
1641 {
1642 id = id,
1643 amount = value
1644 };
1645 }
1646 }
1647
1648 public void SetEffect(int x, int z, CellEffect effect = null)
1649 {
1650 cells[x, z].effect = effect;
1651 }
1652
1653 public void ModLiquid(int x, int z, int amount)
1654 {
1655 Cell cell = cells[x, z];
1656 if (!cell.IsTopWaterAndNoSnow && cell.effect != null)
1657 {
1658 cell.effect.amount += amount;
1659 if (cell.effect.amount <= 0)
1660 {
1661 cell.effect = null;
1662 }
1663 }
1664 }
1665
1666 public void ClearRainAndDecal()
1667 {
1668 ForeachCell(delegate(Cell c)
1669 {
1670 c.effect = null;
1671 c.decal = 0;
1672 });
1673 }
1674
1675 public void SetObj(int x, int z, int id = 0, int value = 1, int dir = 0)
1676 {
1677 SetObj(x, z, EClass.sources.objs[id].DefaultMaterial.id, id, value, dir);
1678 }
1679
1680 public void SetObj(int x, int z, int idMat, int idObj, int value, int dir, bool ignoreRandomMat = false)
1681 {
1682 Cell cell = cells[x, z];
1683 if (cell.sourceObj.id == 118 || idObj == 118)
1684 {
1685 EClass._zone.dirtyElectricity = true;
1686 }
1687 cell.obj = idObj;
1688 cell.objVal = (byte)value;
1689 cell.objMat = idMat;
1690 cell.objDir = dir;
1691 cell.isHarvested = false;
1692 cell.isObjDyed = false;
1693 SourceObj.Row sourceObj = cell.sourceObj;
1694 if (!ignoreRandomMat && !sourceObj.matCategory.IsEmpty())
1695 {
1696 int num = EClass._zone.DangerLv;
1697 if (sourceObj.tag.Contains("spot"))
1698 {
1699 num += EClass.pc.Evalue(1656) * 5;
1700 }
1701 cell.objMat = MATERIAL.GetRandomMaterialFromCategory(num, sourceObj.matCategory.Split(','), cell.matObj).id;
1702 }
1703 if (backerObjs.ContainsKey(cell.index))
1704 {
1705 backerObjs.Remove(cell.index);
1706 }
1707 if (plants.ContainsKey(cell.index))
1708 {
1709 plants.Remove(cell.index);
1710 }
1711 cell.growth?.OnSetObj();
1712 Critter.RebuildCritter(cell);
1714 }
1715
1716 public void AddBackerTree(bool draw)
1717 {
1719 int num = ((!draw) ? 1 : 2);
1720 EClass._map.bounds.ForeachCell(delegate(Cell c)
1721 {
1722 if (num > 0 && c.growth != null && c.growth.IsTree && c.growth.IsMature && (!EClass.player.doneBackers.Contains(item.id) || EClass.core.config.test.ignoreBackerDestoryFlag) && (c.sourceObj.alias == item.tree || item.tree == "random"))
1723 {
1724 backerObjs[c.index] = item.id;
1725 Debug.Log(c.index + "/" + c.x + "/" + c.z + "/" + item.id + "/" + item.Name + "/" + item.tree);
1726 num--;
1728 }
1729 });
1730 }
1731
1733 {
1734 if (!backerObjs.ContainsKey(p.index))
1735 {
1736 return null;
1737 }
1738 return EClass.sources.backers.map.TryGetValue(backerObjs[p.index]);
1739 }
1740
1741 public void ApplyBackerObj(Point p, int id = -1)
1742 {
1743 if (!p.HasObj)
1744 {
1745 return;
1746 }
1747 bool flag = p.sourceObj.id == 82;
1748 SourceBacker.Row row = ((id != -1) ? EClass.sources.backers.map.TryGetValue(id) : (flag ? EClass.sources.backers.listRemain.NextItem(ref BackerContent.indexRemain) : EClass.sources.backers.listTree.NextItem(ref BackerContent.indexTree)));
1749 if (row == null)
1750 {
1751 return;
1752 }
1754 {
1755 backerObjs[p.index] = row.id;
1756 if (flag)
1757 {
1758 p.cell.objDir = row.skin;
1759 }
1760 }
1761 else
1762 {
1763 backerObjs.Remove(p.index);
1764 }
1765 }
1766
1767 public void DropBlockComponent(Point point, TileRow r, SourceMaterial.Row mat, bool recoverBlock, bool isPlatform = false, Chara c = null)
1768 {
1770 {
1771 return;
1772 }
1773 Thing thing = null;
1774 if (r.components.Length == 0)
1775 {
1776 return;
1777 }
1779 if (recoverBlock)
1780 {
1781 thing = ((!(r is SourceFloor.Row)) ? ThingGen.CreateBlock(r.id, mat.id) : ThingGen.CreateFloor(r.id, mat.id, isPlatform));
1782 }
1783 else
1784 {
1785 RecipeSource recipeSource = RecipeManager.Get(r.RecipeID + (isPlatform ? "-b" : ""));
1786 if (recipeSource == null)
1787 {
1788 return;
1789 }
1790 string iDIngredient = recipeSource.GetIDIngredient();
1791 if (iDIngredient == null)
1792 {
1793 return;
1794 }
1795 thing = ThingGen.Create(iDIngredient);
1796 thing.ChangeMaterial(mat.alias);
1797 }
1799 {
1800 PutAway(thing);
1801 }
1802 else
1803 {
1804 TrySmoothPick(point, thing, c);
1805 }
1806 }
1807
1808 public void MineBlock(Point point, bool recoverBlock = false, Chara c = null, bool mineObj = true)
1809 {
1810 bool flag = ActionMode.Mine.IsRoofEditMode() && point.cell._roofBlock != 0;
1811 if (!point.IsValid || (!flag && !point.cell.HasBlock))
1812 {
1813 return;
1814 }
1815 SourceMaterial.Row row = (flag ? point.matRoofBlock : point.matBlock);
1816 int num = (flag ? point.cell._roofBlock : point.cell._block);
1818 Effect.Get("smoke").Play(point);
1819 Effect.Get("mine").Play(point).SetParticleColor(row.GetColor())
1820 .Emit(10 + EClass.rnd(10));
1821 point.PlaySound(row.GetSoundDead(row2));
1822 row.AddBlood(point, 8);
1823 bool flag2 = c == null || c.IsAgent || c.IsPCFactionOrMinion;
1825 {
1826 flag2 = false;
1827 }
1828 if (flag)
1829 {
1830 point.cell._roofBlock = 0;
1831 RefreshSingleTile(point.x, point.z);
1832 }
1833 else
1834 {
1835 if (point.cell.HasFullBlock)
1836 {
1837 RemoveLonelyRamps(point.cell);
1838 }
1839 point.SetBlock();
1840 if (flag2 && point.sourceObj.tileType.IsBlockMount && mineObj)
1841 {
1842 MineObj(point, null, c);
1843 }
1844 }
1845 if (flag2)
1846 {
1847 DropBlockComponent(point, row2, row, recoverBlock, isPlatform: false, c);
1848 }
1849 RefreshShadow(point.x, point.z);
1850 RefreshShadow(point.x, point.z - 1);
1851 ValidateInstalled(point);
1852 RefreshFOV(point.x, point.z);
1853 if (flag2 && !point.cell.isModified && !flag)
1854 {
1855 if (num == 17 || EClass.rnd(100) == 0)
1856 {
1857 zone.AddCard(ThingGen.Create("money2"), point);
1858 }
1859 if (EClass._zone.DangerLv >= 10 && EClass.rnd(200) == 0)
1860 {
1861 zone.AddCard(ThingGen.Create("crystal_earth"), point);
1862 }
1863 if (EClass._zone.DangerLv >= 25 && EClass.rnd(200) == 0)
1864 {
1865 zone.AddCard(ThingGen.Create("crystal_sun"), point);
1866 }
1867 if (EClass._zone.DangerLv >= 40 && EClass.rnd(200) == 0)
1868 {
1869 zone.AddCard(ThingGen.Create("crystal_mana"), point);
1870 }
1871 point.cell.isModified = true;
1872 }
1873 }
1874
1875 public void MineRamp(Point point, int ramp, bool recoverBlock = false)
1876 {
1877 if (point.IsValid && point.cell.HasFullBlock)
1878 {
1879 SourceMaterial.Row matBlock = point.matBlock;
1880 int block = point.cell._block;
1881 Effect.Get("smoke").Play(point);
1882 Effect.Get("mine").Play(point).SetParticleColor(point.matBlock.GetColor())
1883 .Emit(10 + EClass.rnd(10));
1884 MineObj(point);
1885 int rampDir = EClass._map.GetRampDir(point.x, point.z, EClass.sources.blocks[ramp].tileType);
1886 RemoveLonelyRamps(point.cell);
1887 SetBlock(point.x, point.z, point.cell._blockMat, ramp, rampDir);
1888 DropBlockComponent(point, EClass.sources.blocks[block], matBlock, recoverBlock);
1889 }
1890 }
1891
1892 public void MineFloor(Point point, Chara c = null, bool recoverBlock = false, bool removePlatform = true)
1893 {
1894 if (!point.IsValid || (!point.HasFloor && !point.HasBridge))
1895 {
1896 return;
1897 }
1898 SourceMaterial.Row row = (point.cell.HasBridge ? point.matBridge : point.matFloor);
1899 SourceFloor.Row c2 = (point.cell.HasBridge ? point.sourceBridge : point.sourceFloor);
1900 Effect.Get("mine").Play(point).SetParticleColor(row.GetColor())
1901 .Emit(10 + EClass.rnd(10));
1902 point.PlaySound(row.GetSoundDead(c2));
1903 MineObj(point, null, c);
1904 if (point.cell.HasBridge && removePlatform)
1905 {
1906 DropBlockComponent(EClass.pc.pos, point.sourceBridge, point.matBridge, recoverBlock, isPlatform: true, c);
1907 EClass._map.SetBridge(point.x, point.z);
1908 if (point.IsSky)
1909 {
1910 EClass.pc.Kick(point, ignoreSelf: true);
1911 }
1912 return;
1913 }
1915 {
1916 DropBlockComponent(EClass.pc.pos, point.sourceFloor, row, recoverBlock, isPlatform: false, c);
1917 SetFloor(point.x, point.z, 0, 90);
1918 if (point.IsSky)
1919 {
1920 EClass.pc.Kick(point, ignoreSelf: true);
1921 }
1922 return;
1923 }
1924 if (zone.IsRegion || point.cell._floor == 40)
1925 {
1926 Thing thing = ThingGen.CreateRawMaterial(row);
1927 thing.ChangeMaterial(row.alias);
1928 TrySmoothPick(point, thing, c);
1929 }
1930 else
1931 {
1932 DropBlockComponent(point, point.sourceFloor, row, recoverBlock, isPlatform: false, c);
1933 }
1934 if (!EClass._zone.IsRegion && !point.sourceFloor.components[0].Contains("chunk@soil"))
1935 {
1936 point.SetFloor(EClass.sources.floors[1].DefaultMaterial.id, 40);
1937 }
1938 }
1939
1940 public void RefreshShadow(int x, int z)
1941 {
1942 }
1943
1944 public void TrySmoothPick(Cell cell, Thing t, Chara c)
1945 {
1946 TrySmoothPick(cell.GetPoint(), t, c);
1947 }
1948
1949 public void TrySmoothPick(Point p, Thing t, Chara c)
1950 {
1951 if (c != null && c.IsAgent)
1952 {
1953 EClass.pc.PickOrDrop(p, t);
1954 }
1955 else if (c != null && c.IsPC && (c.pos.Equals(p) || EClass.core.config.game.smoothPick || EClass._zone.IsRegion))
1956 {
1957 c.PickOrDrop(p, t);
1958 }
1959 else
1960 {
1961 EClass._zone.AddCard(t, p);
1962 }
1963 }
1964
1965 public void DestroyObj(Point point)
1966 {
1967 Cell cell = point.cell;
1968 SourceObj.Row sourceObj = cell.sourceObj;
1969 SourceMaterial.Row row = (cell.isObjDyed ? sourceObj.DefaultMaterial : cell.matObj);
1970 if (sourceObj.tileType.IsBlockPass)
1971 {
1972 Effect.Get("smoke").Play(point);
1973 }
1974 Effect.Get("mine").Play(point).SetParticleColor(row.GetColor())
1975 .Emit(10 + EClass.rnd(10));
1976 point.PlaySound(row.GetSoundDead());
1977 row.AddBlood(point, 3);
1978 }
1979
1980 public void MineObj(Point point, Task task = null, Chara c = null)
1981 {
1982 if (!point.IsValid || !point.HasObj)
1983 {
1984 return;
1985 }
1986 Cell cell = point.cell;
1987 SourceObj.Row sourceObj = cell.sourceObj;
1988 if (c == null && task != null)
1989 {
1990 c = task.owner;
1991 }
1992 bool num = c == null || c.IsAgent || c.IsPCFactionOrMinion;
1993 DestroyObj(point);
1994 if (num)
1995 {
1996 SourceMaterial.Row matObj_fixed = cell.matObj_fixed;
1997 if (task is TaskHarvest { IsReapSeed: not false })
1998 {
1999 int num2 = 1 + EClass.rnd(2) + ((EClass.rnd(3) == 0) ? 1 : 0);
2000 int soilCost = EClass._zone.GetSoilCost();
2001 int maxSoil = EClass._zone.MaxSoil;
2002 if (soilCost > maxSoil)
2003 {
2004 num2 -= EClass.rnd(2 + (soilCost - maxSoil) / 10);
2005 }
2006 if (num2 <= 0)
2007 {
2008 Msg.Say("seedSpoiled", cell.GetObjName());
2009 }
2010 else if (!EClass._zone.IsUserZone)
2011 {
2012 Thing t = TraitSeed.MakeSeed(cell).SetNum(num2);
2013 EClass.pc.PickOrDrop(point, t);
2014 }
2015 if (cell.growth.IsTree)
2016 {
2017 cell.isHarvested = true;
2018 return;
2019 }
2020 }
2021 else if (sourceObj.HasGrowth)
2022 {
2023 cell.growth.PopMineObj(c);
2024 }
2025 else
2026 {
2027 if (cell.HasBlock && (sourceObj.id == 18 || sourceObj.id == 19))
2028 {
2029 MineBlock(point, recoverBlock: false, c, mineObj: false);
2030 }
2032 {
2033 if (EClass.game.survival.OnMineWreck(point))
2034 {
2035 Rand.SetSeed();
2036 return;
2037 }
2038 Rand.SetSeed();
2039 }
2040 switch (sourceObj.alias)
2041 {
2042 case "nest_bird":
2043 if (EClass.rnd(5) <= 1)
2044 {
2045 Pop(ThingGen.Create((EClass.rnd(10) == 0) ? "egg_fertilized" : "_egg").TryMakeRandomItem());
2046 }
2047 break;
2048 }
2049 int num3 = EClass.rnd(EClass.rnd(sourceObj.components.Length) + 1);
2050 string[] array = sourceObj.components[num3].Split('/');
2051 Thing thing = ThingGen.Create(array[0].Split('|')[0], matObj_fixed.alias);
2052 if (array.Length > 1)
2053 {
2054 thing.SetNum(EClass.rnd(array[1].ToInt()) + 1);
2055 }
2056 Pop(thing);
2057 }
2058 }
2059 SetObj(point.x, point.z);
2060 cell.gatherCount = 0;
2061 void Pop(Thing thing2)
2062 {
2064 {
2066 {
2067 EClass._map.PutAway(thing2);
2068 }
2069 else
2070 {
2071 TrySmoothPick(point, thing2, c);
2072 }
2073 }
2074 }
2075 }
2076
2077 public void MineObjSound(Point point)
2078 {
2079 point.PlaySound(point.cell.matObj.GetSoundDead(point.cell.sourceObj));
2080 }
2081
2083 {
2084 return plants.TryGetValue(p.index);
2085 }
2086
2088 {
2089 return plants.TryGetValue(c.index);
2090 }
2091
2093 {
2094 PlantData plantData = new PlantData
2095 {
2096 seed = seed
2097 };
2098 plants[pos.index] = plantData;
2099 return plantData;
2100 }
2101
2102 public void RemovePlant(Point pos)
2103 {
2104 plants.Remove(pos.index);
2105 }
2106
2108 {
2109 _ValidateInstalled(p.x, p.z);
2110 _ValidateInstalled(p.x + 1, p.z);
2111 _ValidateInstalled(p.x - 1, p.z);
2112 _ValidateInstalled(p.x, p.z + 1);
2113 _ValidateInstalled(p.x, p.z - 1);
2114 }
2115
2116 public void _ValidateInstalled(int x, int y)
2117 {
2118 Point point = Point.shared.Set(x, y);
2119 if (!point.IsValid)
2120 {
2121 return;
2122 }
2123 List<Card> list = point.ListCards();
2124 CellDetail detail = point.cell.detail;
2125 if (detail == null)
2126 {
2127 return;
2128 }
2129 foreach (Card item in list)
2130 {
2131 if (!item.isThing || !item.trait.CanBeDestroyed || !item.IsInstalled)
2132 {
2133 continue;
2134 }
2135 HitResult hitResult = item.TileType._HitTest(point, item.Thing, canIgnore: false);
2136 if (item.Thing.stackOrder != detail.things.IndexOf(item.Thing) || (hitResult != HitResult.Valid && hitResult != HitResult.Warning))
2137 {
2138 if (EClass._zone.IsPCFaction || (!item.isNPCProperty && !(item.trait is TraitHarvest)))
2139 {
2140 item.SetPlaceState(PlaceState.roaming);
2141 }
2142 else if (item.rarity < Rarity.Legendary)
2143 {
2144 item.Die();
2145 }
2146 }
2147 }
2148 }
2149
2150 public void RemoveLonelyRamps(Cell cell)
2151 {
2152 for (int i = 0; i < 4; i++)
2153 {
2154 Cell dependedRamp = GetDependedRamp(cell);
2155 if (dependedRamp != null)
2156 {
2157 MineBlock(dependedRamp.GetPoint());
2158 continue;
2159 }
2160 break;
2161 }
2162 }
2163
2164 public void DestroyBlock(int x, int z)
2165 {
2166 SetBlock(x, z);
2167 }
2168
2169 public void AddDecal(int x, int z, int id, int amount = 1, bool refresh = true)
2170 {
2171 if (x < 0 || z < 0 || x >= Size || z >= Size)
2172 {
2173 return;
2174 }
2175 Cell cell = cells[x, z];
2176 if (cell.sourceFloor.tileType.AllowBlood && (cell.decal / 8 == id || cell.decal % 8 <= amount))
2177 {
2178 if (cell.decal / 8 != id && cell.decal % 8 == 0)
2179 {
2180 amount--;
2181 }
2182 int num = Mathf.Clamp(((cell.decal / 8 == id) ? (cell.decal % 8) : 0) + amount, 0, 7);
2183 cell.decal = (byte)(id * 8 + num);
2184 if (refresh)
2185 {
2187 }
2188 }
2189 }
2190
2191 public void SetDecal(int x, int z, int id = 0, int amount = 1, bool refresh = true)
2192 {
2193 cells[x, z].decal = (byte)((id != 0 && amount != 0) ? ((uint)(id * 8 + amount)) : 0u);
2194 if (refresh)
2195 {
2197 }
2198 }
2199
2200 public void SetFoormark(Point pos, int id, int angle, int offset = 0)
2201 {
2202 Cell cell = pos.cell;
2203 int tile = AngleToIndex(angle) + offset;
2204 Footmark footmark = new Footmark
2205 {
2206 tile = tile,
2207 remaining = 10
2208 };
2209 footmark.pos.Set(pos);
2210 footmarks.Add(footmark);
2211 cell.GetOrCreateDetail().footmark = footmark;
2212 }
2213
2214 public int AngleToIndex(int a)
2215 {
2216 if (EClass._zone.IsRegion)
2217 {
2218 return a switch
2219 {
2220 135 => 7,
2221 180 => 0,
2222 225 => 1,
2223 -90 => 2,
2224 -45 => 3,
2225 0 => 4,
2226 45 => 5,
2227 _ => 6,
2228 };
2229 }
2230 return a switch
2231 {
2232 135 => 0,
2233 180 => 1,
2234 225 => 2,
2235 -90 => 3,
2236 -45 => 4,
2237 0 => 5,
2238 45 => 6,
2239 _ => 7,
2240 };
2241 }
2242
2243 public void RefreshSingleTile(int x, int z)
2244 {
2245 cells[x, z].Refresh();
2246 }
2247
2248 public void RefreshAllTiles()
2249 {
2250 for (int i = 0; i < Size; i++)
2251 {
2252 for (int j = 0; j < Size; j++)
2253 {
2254 cells[i, j].Refresh();
2255 }
2256 }
2257 }
2258
2259 public void RefreshNeighborTiles(int x, int z)
2260 {
2261 cells[x, z].Refresh();
2262 for (int i = x - 2; i < x + 3; i++)
2263 {
2264 if (i < 0 || i >= Size)
2265 {
2266 continue;
2267 }
2268 for (int j = z - 2; j < z + 3; j++)
2269 {
2270 if (j >= 0 && j < Size && (x != i || z != j))
2271 {
2272 cells[i, j].Refresh();
2273 }
2274 }
2275 }
2276 }
2277
2278 public void QuickRefreshTile(int x, int z)
2279 {
2280 Cell cell = cells[x, z];
2281 Cell cell2 = ((x > 0) ? cells[x - 1, z] : Cell.Void);
2282 Cell cell3 = ((x + 1 < Size) ? cells[x + 1, z] : Cell.Void);
2283 Cell cell4 = ((z > 0) ? cells[x, z - 1] : Cell.Void);
2284 Cell cell5 = ((z + 1 < Size) ? cells[x, z + 1] : Cell.Void);
2285 Cell cell6 = ((x > 0 && z > 0) ? cells[x - 1, z - 1] : Cell.Void);
2286 Cell cell7 = ((x + 1 < Size && z > 0) ? cells[x + 1, z - 1] : Cell.Void);
2287 Cell cell8 = ((x > 0 && z + 1 < Size) ? cells[x - 1, z + 1] : Cell.Void);
2288 Cell cell9 = ((x + 1 < Size && z + 1 < Size) ? cells[x + 1, z + 1] : Cell.Void);
2289 cell.isSurrounded4d = cell2.HasFullBlock && cell3.HasFullBlock && cell4.HasFullBlock && cell5.HasFullBlock;
2290 cell.isSurrounded = cell.isSurrounded4d && cell6.HasFullBlock && cell7.HasFullBlock && cell8.HasFullBlock && cell9.HasFullBlock;
2291 }
2292
2293 public int GetRampDir(int x, int z, TileType blockType = null)
2294 {
2295 Cell cell = cells[x, z];
2296 if (cell.HasFullBlock)
2297 {
2298 if (blockType == null)
2299 {
2300 blockType = cell.sourceBlock.tileType;
2301 }
2302 Cell right = cell.Right;
2303 Cell front = cell.Front;
2304 Cell left = cell.Left;
2305 Cell back = cell.Back;
2306 if (!right.HasBlock && !right.IsVoid && left.HasFullBlock && front.CanBuildRamp(1) && back.CanBuildRamp(1))
2307 {
2308 return 1;
2309 }
2310 if (!front.HasBlock && !front.IsVoid && back.HasFullBlock && left.CanBuildRamp(0) && right.CanBuildRamp(0))
2311 {
2312 return 0;
2313 }
2314 if (!left.HasBlock && !left.IsVoid && right.HasFullBlock && front.CanBuildRamp(3) && back.CanBuildRamp(3))
2315 {
2316 return 3;
2317 }
2318 if (!back.HasBlock && !back.IsVoid && front.HasFullBlock && left.CanBuildRamp(2) && right.CanBuildRamp(2))
2319 {
2320 return 2;
2321 }
2322 if (!blockType.IsRamp)
2323 {
2324 return 0;
2325 }
2326 }
2327 return -1;
2328 }
2329
2331 {
2332 Cell right = cell.Right;
2333 if (right.HasRamp && !right.HasStairs && right.blockDir == 1)
2334 {
2335 return right;
2336 }
2337 Cell front = cell.Front;
2338 if (front.HasRamp && !front.HasStairs && front.blockDir == 0)
2339 {
2340 return front;
2341 }
2342 Cell left = cell.Left;
2343 if (left.HasRamp && !left.HasStairs && left.blockDir == 3)
2344 {
2345 return left;
2346 }
2347 Cell back = cell.Back;
2348 if (back.HasRamp && !back.HasStairs && back.blockDir == 2)
2349 {
2350 return back;
2351 }
2352 return null;
2353 }
2354
2355 public Point GetRandomPoint(Point center, int radius, int tries = 100, bool mustBeWalkable = true, bool requireLos = true)
2356 {
2357 Point point = new Point();
2358 for (int i = 0; i < tries; i++)
2359 {
2360 point.x = center.x + EClass.rnd(radius * 2 + 1) - radius;
2361 point.z = center.z + EClass.rnd(radius * 2 + 1) - radius;
2362 point.Clamp();
2363 if ((!mustBeWalkable || !point.cell.blocked) && (!requireLos || Los.IsVisible(center, point)))
2364 {
2365 return point;
2366 }
2367 }
2368 Debug.Log("GetRandomPoint failed center:" + center?.ToString() + " rad:" + radius);
2369 point.IsValid = false;
2370 return point;
2371 }
2372
2373 public new Point GetRandomEdge(int r = 3)
2374 {
2375 int num = 0;
2376 int num2 = 0;
2377 for (int i = 0; i < 10000; i++)
2378 {
2379 if (EClass.rnd(2) == 0)
2380 {
2381 num = ((EClass.rnd(2) == 0) ? EClass.rnd(r) : (Size - 1 - EClass.rnd(r)));
2382 num2 = EClass.rnd(Size);
2383 }
2384 else
2385 {
2386 num2 = ((EClass.rnd(2) == 0) ? EClass.rnd(r) : (Size - 1 - EClass.rnd(r)));
2387 num = EClass.rnd(Size);
2388 }
2389 Point surface = GetSurface(num, num2, walkable: false);
2390 if (surface.IsValid)
2391 {
2392 return surface;
2393 }
2394 }
2395 return GetSurface(Size / 2, Size / 2, walkable: false);
2396 }
2397
2399 {
2400 Point point = new Point();
2401 int num = ((EClass.rnd(2) == 0) ? 1 : (-1));
2402 int num2 = ((EClass.rnd(2) == 0) ? 1 : (-1));
2403 for (int i = 0; i < 3; i++)
2404 {
2405 point.x = center.x - num + i * num;
2406 for (int j = 0; j < 3; j++)
2407 {
2408 point.z = center.z - num2 + j * num2;
2409 if (point.IsValid && point.area == null && point.cell.CanHarvest())
2410 {
2411 return point;
2412 }
2413 }
2414 }
2415 return Point.Invalid;
2416 }
2417
2418 public List<Point> ListPointsInCircle(Point center, float radius, bool mustBeWalkable = true, bool los = true)
2419 {
2420 List<Point> list = new List<Point>();
2421 ForeachSphere(center.x, center.z, radius, delegate(Point p)
2422 {
2423 if ((!mustBeWalkable || !p.cell.blocked) && (!los || Los.IsVisible(center, p)))
2424 {
2425 list.Add(p.Copy());
2426 }
2427 });
2428 return list;
2429 }
2430
2431 public List<Point> ListPointsInSquare(Point center, int radius, bool mustBeWalkable = true, bool los = true)
2432 {
2433 List<Point> list = new List<Point>();
2434 ForeachSquare(center.x, center.z, radius, delegate(Point p)
2435 {
2436 if ((!mustBeWalkable || !p.cell.blocked) && (!los || Los.IsVisible(center, p)))
2437 {
2438 list.Add(p.Copy());
2439 }
2440 });
2441 return list;
2442 }
2443
2444 public List<Point> ListPointsOnEdge(Point center, int destDist, bool mustBeWalkable = true, bool los = true)
2445 {
2446 List<Point> list = new List<Point>();
2447 ForeachSphere(center.x, center.z, destDist, delegate(Point p)
2448 {
2449 if (center.Distance(p) == destDist && (!mustBeWalkable || !p.cell.blocked) && (!los || Los.IsVisible(center, p)))
2450 {
2451 list.Add(p.Copy());
2452 }
2453 });
2454 return list;
2455 }
2456
2457 public List<Chara> ListCharasInCircle(Point center, float radius, bool los = true)
2458 {
2459 List<Chara> list = new List<Chara>();
2460 foreach (Point item in ListPointsInCircle(center, radius, mustBeWalkable: false, los))
2461 {
2462 CellDetail detail = item.detail;
2463 if (detail == null || detail.charas.Count <= 0)
2464 {
2465 continue;
2466 }
2467 foreach (Chara chara in item.detail.charas)
2468 {
2469 list.Add(chara);
2470 }
2471 }
2472 return list;
2473 }
2474
2475 public List<Point> ListPointsInArc(Point center, Point to, int radius, float angle)
2476 {
2477 Point to2 = new Point((to.x > center.x) ? 1 : ((to.x < center.x) ? (-1) : 0), (to.z > center.z) ? 1 : ((to.z < center.z) ? (-1) : 0));
2478 Point point = new Point(0, 0);
2479 List<Point> list = new List<Point>();
2480 float diff = point.GetAngle2(to2);
2481 ForeachSphere(center.x, center.z, radius, delegate(Point p)
2482 {
2483 float angle2 = center.GetAngle2(p);
2484 if ((Mathf.Abs(diff - angle2) < angle || Mathf.Abs(diff - angle2 + 360f) < angle || Mathf.Abs(360f - diff + angle2) < angle) && Los.IsVisible(center, p) && !p.IsBlocked)
2485 {
2486 list.Add(p.Copy());
2487 }
2488 });
2489 return list;
2490 }
2491
2492 public List<Point> ListPointsInLine(Point center, Point to, int radius, bool returnOnBlocked = true)
2493 {
2494 return Los.ListVisible(center, to, radius, null, returnOnBlocked);
2495 }
2496
2497 public void SetBounds(int size)
2498 {
2499 if (size > Size / 2 + 1)
2500 {
2501 size = Size / 2 - 1;
2502 }
2503 bounds.SetBounds(Size / 2 - size, Size / 2 - size, Size / 2 + size, Size / 2 + size);
2504 }
2505
2506 public void SetBounds(MapBounds b)
2507 {
2508 bounds.SetBounds(b.x, b.z, b.maxX, b.maxZ);
2509 bounds.Size = b.Size;
2510 }
2511
2512 public new void ForeachCell(Action<Cell> action)
2513 {
2514 for (int i = 0; i < Size; i++)
2515 {
2516 for (int j = 0; j < Size; j++)
2517 {
2518 action(cells[i, j]);
2519 }
2520 }
2521 }
2522
2523 public new void ForeachPoint(Action<Point> action)
2524 {
2525 Point point = new Point();
2526 for (int i = 0; i < Size; i++)
2527 {
2528 for (int j = 0; j < Size; j++)
2529 {
2530 action(point.Set(i, j));
2531 }
2532 }
2533 }
2534
2535 public new void ForeachXYZ(Action<int, int> action)
2536 {
2537 for (int i = 0; i < Size; i++)
2538 {
2539 for (int j = 0; j < Size; j++)
2540 {
2541 action(i, j);
2542 }
2543 }
2544 }
2545
2546 public void ForeachSphere(int _x, int _z, float r, Action<Point> action)
2547 {
2548 Point point = new Point();
2549 int num = (int)Mathf.Ceil(r);
2550 for (int i = _x - num; i < _x + num + 1; i++)
2551 {
2552 if (i < 0 || i >= Size)
2553 {
2554 continue;
2555 }
2556 for (int j = _z - num; j < _z + num + 1; j++)
2557 {
2558 if (j >= 0 && j < Size && (float)((i - _x) * (i - _x) + (j - _z) * (j - _z)) < r * r)
2559 {
2560 point.Set(i, j);
2561 action(point);
2562 }
2563 }
2564 }
2565 }
2566
2567 public void ForeachSquare(int _x, int _z, int r, Action<Point> action)
2568 {
2569 Point point = new Point();
2570 for (int i = _x - r; i < _x + r + 1; i++)
2571 {
2572 if (i < 0 || i >= Size)
2573 {
2574 continue;
2575 }
2576 for (int j = _z - r; j < _z + r + 1; j++)
2577 {
2578 if (j >= 0 && j < Size)
2579 {
2580 point.Set(i, j);
2581 action(point);
2582 }
2583 }
2584 }
2585 }
2586
2587 public void ForeachNeighbor(Point center, Action<Point> action)
2588 {
2589 int num = center.x;
2590 int num2 = center.z;
2591 Point point = new Point();
2592 for (int i = num - 1; i < num + 2; i++)
2593 {
2594 if (i < 0 || i >= Size)
2595 {
2596 continue;
2597 }
2598 for (int j = num2 - 1; j < num2 + 2; j++)
2599 {
2600 if (j >= 0 && j < Size)
2601 {
2602 point.Set(i, j);
2603 action(point);
2604 }
2605 }
2606 }
2607 }
2608
2609 public void Quake()
2610 {
2611 Point point = new Point();
2612 int num;
2613 for (num = 0; num < Size; num++)
2614 {
2615 int num2;
2616 for (num2 = 0; num2 < Size; num2++)
2617 {
2618 point.x = num;
2619 point.z = num2;
2620 point.Copy().Animate(AnimeID.Quake, animeBlock: true);
2621 num2 += EClass.rnd(2);
2622 }
2623 num += EClass.rnd(2);
2624 }
2625 }
2626
2627 public int CountChara(Faction faction)
2628 {
2629 int num = 0;
2630 foreach (Chara chara in charas)
2631 {
2632 if (chara.faction == faction)
2633 {
2634 num++;
2635 }
2636 }
2637 return num;
2638 }
2639
2640 public int CountGuest()
2641 {
2642 int num = 0;
2643 foreach (Chara chara in charas)
2644 {
2645 if (chara.IsGuest())
2646 {
2647 num++;
2648 }
2649 }
2650 return num;
2651 }
2652
2653 public int CountHostile()
2654 {
2655 int num = 0;
2656 foreach (Chara chara in charas)
2657 {
2658 if (!chara.IsPCFaction && chara.IsHostile())
2659 {
2660 num++;
2661 }
2662 }
2663 return num;
2664 }
2665
2666 public int CountWildAnimal()
2667 {
2668 int num = 0;
2669 foreach (Chara chara in charas)
2670 {
2671 if (!chara.IsPCFaction && chara.IsAnimal)
2672 {
2673 num++;
2674 }
2675 }
2676 return num;
2677 }
2678
2679 public int CountNonHostile()
2680 {
2681 int num = 0;
2682 foreach (Chara chara in charas)
2683 {
2684 if (!chara.IsPCFaction && !chara.IsHostile())
2685 {
2686 num++;
2687 }
2688 }
2689 return num;
2690 }
2691
2692 public List<Chara> ListChara(Faction faction)
2693 {
2694 List<Chara> list = new List<Chara>();
2695 foreach (Chara chara in charas)
2696 {
2697 if (chara.faction == faction)
2698 {
2699 list.Add(chara);
2700 }
2701 }
2702 return list;
2703 }
2704
2705 public List<Thing> ListThing<T>() where T : Trait
2706 {
2707 List<Thing> list = new List<Thing>();
2708 foreach (Thing thing in things)
2709 {
2710 if (thing.IsInstalled && thing.trait is T)
2711 {
2712 list.Add(thing);
2713 }
2714 }
2715 return list;
2716 }
2717
2718 public bool PutAway(Card c)
2719 {
2721 {
2722 return false;
2723 }
2724 if (c.isChara)
2725 {
2727 {
2728 return false;
2729 }
2730 c.Destroy();
2731 return true;
2732 }
2733 Thing thing = c.Thing;
2734 if (thing.parent != null)
2735 {
2736 thing.parent.RemoveCard(thing);
2737 }
2738 thing.isMasked = false;
2739 thing.isRoofItem = false;
2740 if (EClass._zone.IsPCFaction && EClass._map.props.installed.traits.GetRandomThing<TraitSpotStockpile>() != null)
2741 {
2742 EClass._zone.TryAddThingInSpot<TraitSpotStockpile>(thing);
2743 return true;
2744 }
2745 if (EClass.debug.enable)
2746 {
2748 return true;
2749 }
2750 EClass.pc.Pick(thing, msg: false);
2751 return true;
2752 }
2753
2754 public Chara FindChara(string id)
2755 {
2756 foreach (Chara chara in charas)
2757 {
2758 if (chara.id == id)
2759 {
2760 return chara;
2761 }
2762 }
2763 return null;
2764 }
2765
2766 public Chara FindChara(int uid)
2767 {
2768 foreach (Chara chara in charas)
2769 {
2770 if (chara.uid == uid)
2771 {
2772 return chara;
2773 }
2774 }
2775 return null;
2776 }
2777
2778 public Thing FindThing(Func<Thing, bool> func)
2779 {
2780 foreach (Thing thing in things)
2781 {
2782 if (func(thing))
2783 {
2784 return thing;
2785 }
2786 }
2787 return null;
2788 }
2789
2790 public Thing FindThing(int uid)
2791 {
2792 foreach (Thing thing in things)
2793 {
2794 if (thing.uid == uid)
2795 {
2796 return thing;
2797 }
2798 }
2799 return null;
2800 }
2801
2802 public T FindThing<T>() where T : Trait
2803 {
2804 foreach (Thing thing in things)
2805 {
2806 if (thing.trait is T)
2807 {
2808 return thing.trait as T;
2809 }
2810 }
2811 return null;
2812 }
2813
2814 public Thing FindThing(Type type, Chara c = null)
2815 {
2816 if (type == null)
2817 {
2818 return null;
2819 }
2820 _things.Clear();
2821 foreach (Thing thing in EClass._map.props.installed.things)
2822 {
2823 if (type.IsAssignableFrom(thing.trait.GetType()) && thing.pos.IsPublicSpace())
2824 {
2825 _things.Add(thing);
2826 }
2827 }
2828 if (_things.Count <= 0)
2829 {
2830 return null;
2831 }
2832 return _things.RandomItem();
2833 }
2834
2835 public Thing FindThing(Type type, BaseArea area1, BaseArea area2 = null)
2836 {
2837 if (type == null || (area1 == null && area2 == null))
2838 {
2839 return null;
2840 }
2841 Thing thing = Find(area1);
2842 if (thing == null && area2 != null)
2843 {
2844 thing = Find(area2);
2845 }
2846 return thing;
2847 Thing Find(BaseArea a)
2848 {
2849 _things.Clear();
2850 foreach (Thing thing2 in EClass._map.props.installed.things)
2851 {
2852 if (type.IsAssignableFrom(thing2.trait.GetType()) && thing2.pos.HasRoomOrArea(a))
2853 {
2854 _things.Add(thing2);
2855 }
2856 }
2857 if (_things.Count <= 0)
2858 {
2859 return null;
2860 }
2861 return _things.RandomItem();
2862 }
2863 }
2864
2865 public Thing FindThing(string workTag, BaseArea area1 = null, BaseArea area2 = null)
2866 {
2867 if (area1 == null && area2 == null)
2868 {
2869 return null;
2870 }
2871 Thing thing = null;
2872 PropSet orCreate = EClass._map.Installed.workMap.GetOrCreate(workTag);
2873 if (area1 != null)
2874 {
2875 IEnumerable<Card> enumerable = orCreate.Where((Card a) => a.pos.HasRoomOrArea(area1));
2876 if (enumerable.Count() > 0)
2877 {
2878 thing = enumerable.RandomItem() as Thing;
2879 }
2880 }
2881 if (thing == null && area2 != null)
2882 {
2883 IEnumerable<Card> enumerable2 = orCreate.Where((Card a) => a.pos.HasRoomOrArea(area2));
2884 if (enumerable2.Count() > 0)
2885 {
2886 thing = enumerable2.RandomItem() as Thing;
2887 }
2888 }
2889 return thing;
2890 }
2891
2892 public Thing FindThing(string workTag, Chara c)
2893 {
2894 Thing result = null;
2895 IEnumerable<Card> enumerable = from a in EClass._map.Installed.workMap.GetOrCreate(workTag)
2896 where a.pos.IsPublicSpace()
2897 select a;
2898 if (enumerable.Count() > 0)
2899 {
2900 result = enumerable.RandomItem() as Thing;
2901 }
2902 return result;
2903 }
2904
2906 {
2907 return (from a in ((IEnumerable<BaseArea>)rooms.listArea).Concat((IEnumerable<BaseArea>)rooms.listRoom)
2908 where a.type.IsPublicArea
2909 select a).RandomItem();
2910 }
2911
2912 public void RefreshSunMap()
2913 {
2914 if (!isDirtySunMap)
2915 {
2916 return;
2917 }
2918 sunMap.Clear();
2919 foreach (Card sun in EClass._map.props.installed.traits.suns)
2920 {
2921 foreach (Point item in sun.trait.ListPoints(null, onlyPassable: false))
2922 {
2923 sunMap.Add(item.index);
2924 }
2925 }
2926 isDirtySunMap = false;
2927 }
2928}
AnimeID
Definition: AnimeID.cs:2
CTAG
Definition: CTAG.cs:2
static bool not(DramaManager dm, Dictionary< string, string > line, params string[] parameters)
EditorTag
Definition: EditorTag.cs:2
HitResult
Definition: HitResult.cs:2
PlaceState
Definition: PlaceState.cs:2
Rarity
Definition: Rarity.cs:2
int itemLost
Definition: AM_Adv.cs:110
override bool IsRoofEditMode(Card c=null)
Definition: AM_Mine.cs:19
void Add(Act a, string s="")
Definition: ActPlan.cs:11
static AM_Copy Copy
Definition: ActionMode.cs:45
bool IsActive
Definition: ActionMode.cs:121
virtual bool IsBuildMode
Definition: ActionMode.cs:181
static AM_Mine Mine
Definition: ActionMode.cs:33
static AM_Adv Adv
Definition: ActionMode.cs:15
static int indexTree
Definition: BackerContent.cs:3
static int indexRemain
Definition: BackerContent.cs:5
Version version
Definition: BaseCore.cs:17
static BaseCore Instance
Definition: BaseCore.cs:11
void KillActor()
Definition: Card.cs:11
bool isDestroyed
Definition: Card.cs:78
Thing TryMakeRandomItem(int lv=-1, TryMakeRandomItemSource itemSource=TryMakeRandomItemSource.Default, Chara crafter=null)
Definition: Card.cs:5758
bool IsPCFactionOrMinion
Definition: Card.cs:2342
virtual bool IsMultisize
Definition: Card.cs:2212
virtual bool isThing
Definition: Card.cs:2133
virtual Chara Chara
Definition: Card.cs:2122
Thing Split(int a)
Definition: Card.cs:3665
bool IsAgent
Definition: Card.cs:2303
void SetPlaceState(PlaceState newState, bool byPlayer=false)
Definition: Card.cs:3928
ElementContainerCard elements
Definition: Card.cs:42
string id
Definition: Card.cs:36
virtual void Die(Element e=null, Card origin=null, AttackSource attackSource=AttackSource.None, Chara originalTarget=null)
Definition: Card.cs:5245
Card ChangeMaterial(int idNew, bool ignoreFixedMaterial=false)
Definition: Card.cs:3217
string c_altName
Definition: Card.cs:1633
virtual bool IsPCParty
Definition: Card.cs:2203
void CalculateFOV()
Definition: Card.cs:6979
Thing AddThing(string id, int lv=-1)
Definition: Card.cs:3280
string Name
Definition: Card.cs:2191
ICardParent parent
Definition: Card.cs:56
void Kick(Point p, bool ignoreSelf=false, bool checkWall=true)
Definition: Card.cs:6315
Thing SetNum(int a)
Definition: Card.cs:3676
void ForeachPoint(Action< Point, bool > action)
Definition: Card.cs:8406
bool IsFood
Definition: Card.cs:2229
Point pos
Definition: Card.cs:60
void ClearFOV()
Definition: Card.cs:7069
int uid
Definition: Card.cs:125
Trait trait
Definition: Card.cs:54
void ModCharge(int a, bool destroy=false)
Definition: Card.cs:4131
void Destroy()
Definition: Card.cs:5314
bool HasEditorTag(EditorTag tag)
Definition: Card.cs:2733
ThingContainer things
Definition: Card.cs:39
bool IsInstalled
Definition: Card.cs:2451
virtual bool IsPC
Definition: Card.cs:2197
virtual bool isChara
Definition: Card.cs:2135
virtual Thing Thing
Definition: Card.cs:2110
Card GetRootCard()
Definition: Card.cs:3607
int Evalue(int ele)
Definition: Card.cs:2704
virtual bool IsPCFaction
Definition: Card.cs:2339
Cell Cell
Definition: Card.cs:2107
bool isPlayerCreation
Definition: Card.cs:497
Card parentCard
Definition: Card.cs:106
Thing Add(string id, int num=1, int lv=1)
Definition: Card.cs:3257
int Num
Definition: Card.cs:161
SourceCategory.Row category
Definition: Card.cs:2101
Point lastPos
Definition: Card.cs:62
int c_charges
Definition: Card.cs:1309
CardRenderer renderer
Definition: Card.cs:64
List< Thing > things
Definition: CellDetail.cs:11
List< Chara > charas
Definition: CellDetail.cs:13
Footmark footmark
Definition: CellDetail.cs:17
int amount
Definition: CellEffect.cs:26
int FireAmount
Definition: CellEffect.cs:162
bool IsFire
Definition: CellEffect.cs:147
Definition: Cell.cs:7
int _bridgeMat
Definition: Cell.cs:56
bool CanHarvest()
Definition: Cell.cs:1736
Room room
Definition: Cell.cs:122
void RemoveCard(Card c)
Definition: Cell.cs:1638
SourceBlock.Row sourceBlock
Definition: Cell.cs:1090
bool IsSnowTile
Definition: Cell.cs:818
int _floor
Definition: Cell.cs:46
bool HasBlock
Definition: Cell.cs:679
bool CanBuildRamp(int dir)
Definition: Cell.cs:1183
SourceFloor.Row sourceFloor
Definition: Cell.cs:1092
CellEffect effect
Definition: Cell.cs:114
Cell Back
Definition: Cell.cs:175
bool HasStairs
Definition: Cell.cs:891
bool toggleOcclusion
Definition: Cell.cs:666
byte decal
Definition: Cell.cs:70
int obj
Definition: Cell.cs:50
int objMat
Definition: Cell.cs:52
bool HasBridge
Definition: Cell.cs:707
Point GetSharedPoint()
Definition: Cell.cs:1146
bool isHarvested
Definition: Cell.cs:342
bool IsTopWaterAndNoSnow
Definition: Cell.cs:748
bool isClearSnow
Definition: Cell.cs:462
Cell Front
Definition: Cell.cs:151
SourceMaterial.Row matObj
Definition: Cell.cs:1074
CellDetail GetOrCreateDetail()
Definition: Cell.cs:1605
int _roofBlock
Definition: Cell.cs:58
byte objVal
Definition: Cell.cs:68
void Refresh()
Definition: Cell.cs:1192
void Reset()
Definition: Cell.cs:1597
int bridgePillar
Definition: Cell.cs:74
bool isModified
Definition: Cell.cs:450
int _floorMat
Definition: Cell.cs:48
bool IsTopWater
Definition: Cell.cs:736
byte height
Definition: Cell.cs:94
GrowSystem growth
Definition: Cell.cs:247
bool isWatered
Definition: Cell.cs:354
CellDetail detail
Definition: Cell.cs:112
int _roofBlockMat
Definition: Cell.cs:60
byte _roofBlockDir
Definition: Cell.cs:72
bool HasFloodBlock
Definition: Cell.cs:1053
bool isToggleWallPillar
Definition: Cell.cs:570
byte z
Definition: Cell.cs:78
Cell Left
Definition: Cell.cs:187
bool isSeen
Definition: Cell.cs:294
void AddCard(Card c)
Definition: Cell.cs:1622
bool hidePillar
Definition: Cell.cs:654
SourceObj.Row sourceObj
Definition: Cell.cs:1112
int _decoMat
Definition: Cell.cs:64
Cell BackLeft
Definition: Cell.cs:235
string GetObjName()
Definition: Cell.cs:1676
bool isForceFloat
Definition: Cell.cs:318
int _blockMat
Definition: Cell.cs:44
byte x
Definition: Cell.cs:76
Point GetPoint()
Definition: Cell.cs:1141
bool impassable
Definition: Cell.cs:414
static Cell Void
Definition: Cell.cs:10
bool HasObj
Definition: Cell.cs:677
Cell Right
Definition: Cell.cs:163
bool crossWall
Definition: Cell.cs:642
bool isObjDyed
Definition: Cell.cs:630
bool HasRamp
Definition: Cell.cs:873
byte bridgeHeight
Definition: Cell.cs:96
int index
Definition: Cell.cs:136
bool hasDoor
Definition: Cell.cs:279
int blockDir
Definition: Cell.cs:934
byte _dirs
Definition: Cell.cs:66
int _bridge
Definition: Cell.cs:54
bool HasFullBlock
Definition: Cell.cs:853
bool IsVoid
Definition: Cell.cs:995
SourceMaterial.Row matObj_fixed
Definition: Cell.cs:1077
Cell FrontRight
Definition: Cell.cs:199
int _deco
Definition: Cell.cs:62
int _block
Definition: Cell.cs:42
Definition: Chara.cs:10
new TraitChara trait
Definition: Chara.cs:511
Faction faction
Definition: Chara.cs:433
override bool IsPC
Definition: Chara.cs:632
override bool IsGlobal
Definition: Chara.cs:630
Point orgPos
Definition: Chara.cs:23
bool IsAnimal
Definition: Chara.cs:916
void PickOrDrop(Point p, string idThing, int idMat=-1, int num=1, bool msg=true)
Definition: Chara.cs:4592
override bool IsPCFaction
Definition: Chara.cs:691
bool IsGuest()
Definition: Chara.cs:7043
bool IsHostile()
Definition: Chara.cs:6952
Thing Pick(Thing t, bool msg=true, bool tryStack=true)
Definition: Chara.cs:4612
Definition: ConWet.cs:2
bool ignoreBackerDestoryFlag
Definition: CoreConfig.cs:578
new GameConfig game
Definition: CoreConfig.cs:629
bool enable
Definition: CoreDebug.cs:302
bool godBuild
Definition: CoreDebug.cs:320
Thing GetOrCreateDebugContainer()
Definition: CoreDebug.cs:794
bool ignoreBuildRule
Definition: CoreDebug.cs:201
CoreConfig config
Definition: Core.cs:70
static void MakeDish(Thing food, int lv, Chara crafter=null, int seed=-1)
Definition: CraftUtil.cs:62
static void RebuildCritter(Cell cell)
Definition: Critter.cs:93
Definition: EClass.cs:6
static Game game
Definition: EClass.cs:9
static int curve(long _a, int start, int step, int rate=75)
Definition: EClass.cs:69
static Scene scene
Definition: EClass.cs:31
static Core core
Definition: EClass.cs:7
static Zone _zone
Definition: EClass.cs:21
static Map _map
Definition: EClass.cs:19
static int rnd(long a)
Definition: EClass.cs:59
static SourceManager sources
Definition: EClass.cs:43
static FactionBranch Branch
Definition: EClass.cs:23
static Player player
Definition: EClass.cs:13
static Chara pc
Definition: EClass.cs:15
static CoreDebug debug
Definition: EClass.cs:49
Definition: Effect.cs:7
static Effect Get(Effect original)
Definition: Effect.cs:80
void Play(float delay, Point from, float fixY=0f, Point to=null, Sprite sprite=null)
Definition: Effect.cs:100
Element ModBase(int ele, int v)
static Element Create(int id, int v=0)
Definition: ELEMENT.cs:1163
bool HasItemProtection
Point pos
Definition: Footmark.cs:3
static FowProfile Load(string id)
Definition: FowProfile.cs:9
Definition: GameIO.cs:11
static void SaveFile(string path, object obj)
Definition: GameIO.cs:257
bool disableUsermapBenefit
Definition: Game.cs:9
SurvivalManager survival
Definition: Game.cs:228
static void Load(string id, bool cloud)
Definition: Game.cs:322
GamePrincipal principal
Definition: Game.cs:225
static string id
Definition: Game.cs:148
bool Save(bool isAutoSave=false, bool silent=false)
Definition: Game.cs:1089
bool IsSurvival
Definition: Game.cs:276
void PopMineObj(Chara c=null)
Definition: GrowSystem.cs:552
virtual bool IsMature
Definition: GrowSystem.cs:117
virtual void OnSetObj()
Definition: GrowSystem.cs:288
virtual bool IsTree
Definition: GrowSystem.cs:101
Compression
Definition: IO.cs:12
LogicalPoint GetOrCreate(Point point)
Definition: Los.cs:5
static List< Point > ListVisible(Point p1, Point p2, int radius, Action< Point, bool > _onVisit=null, bool returnOnBlocked=true)
Definition: Los.cs:90
static bool IsVisible(Point p1, Point p2, Action< Point, bool > _onVisit=null)
Definition: Los.cs:167
static SourceMaterial.Row GetRandomMaterialFromCategory(int lv, string cat, SourceMaterial.Row fallback)
Definition: MATERIAL.cs:93
int Size
Definition: MapBounds.cs:20
int maxZ
Definition: MapBounds.cs:17
void SetBounds(int _x, int _z, int _maxX, int _maxZ)
Definition: MapBounds.cs:30
Point GetSurface(int x, int z, bool walkable=true)
Definition: MapBounds.cs:171
int maxX
Definition: MapBounds.cs:14
void ForeachCell(Action< Cell > action)
Definition: MapBounds.cs:279
int x
Definition: MapBounds.cs:8
Point GetCenterPos()
Definition: MapBounds.cs:52
string idSceneProfile
Definition: MapConfig.cs:8
bool indoor
Definition: MapConfig.cs:29
string idFowProfile
Definition: MapConfig.cs:11
Definition: Map.cs:13
bool IsIndoor
Definition: Map.cs:136
new void ForeachXYZ(Action< int, int > action)
Definition: Map.cs:2535
List< int > _plNight
Definition: Map.cs:61
new void ForeachCell(Action< Cell > action)
Definition: Map.cs:2512
void TrySmoothPick(Point p, Thing t, Chara c)
Definition: Map.cs:1949
Thing FindThing(Type type, BaseArea area1, BaseArea area2=null)
Definition: Map.cs:2835
void ResetEditorPos()
Definition: Map.cs:362
void RefreshNeighborTiles(int x, int z)
Definition: Map.cs:2259
Thing FindThing(Func< Thing, bool > func)
Definition: Map.cs:2778
bool isGenerated
Definition: Map.cs:134
Cell GetCell(int index)
Definition: Map.cs:993
PlantData TryGetPlant(Point p)
Definition: Map.cs:2082
void ForeachSphere(int _x, int _z, float r, Action< Point > action)
Definition: Map.cs:2546
Dictionary< int, int > gatherCounts
Definition: Map.cs:64
void SetBridge(int x, int z, int height=0, int idMat=0, int idBridge=0, int dir=0, int idPillar=0, bool hidePillar=false)
Definition: Map.cs:1087
BitArray32 bits
Definition: Map.cs:78
static readonly int[] CellIdWidths
Definition: Map.cs:106
void Shift(Vector2Int offset)
Definition: Map.cs:259
Thing FindThing(Type type, Chara c=null)
Definition: Map.cs:2814
void ExportMetaData(string _path, string id, PartialMap partial=null)
Definition: Map.cs:825
Chara FindChara(string id)
Definition: Map.cs:2754
IEnumerable< Card > Cards
Definition: Map.cs:140
void RefreshSunMap()
Definition: Map.cs:2912
int[] ReadCellIds(string file, string s, int size, int width)
Definition: Map.cs:611
void RefreshSingleTile(int x, int z)
Definition: Map.cs:2243
Point GetRandomPoint(Point center, int radius, int tries=100, bool mustBeWalkable=true, bool requireLos=true)
Definition: Map.cs:2355
void RemovePlant(Point pos)
Definition: Map.cs:2102
BaseArea FindPublicArea()
Definition: Map.cs:2905
static void UpdateMetaData(string pathZip, PartialMap partial=null)
Definition: Map.cs:870
void DestroyObj(Point point)
Definition: Map.cs:1965
void Save(string path, ZoneExportData export=null, PartialMap partial=null)
Definition: Map.cs:381
void Reset()
Definition: Map.cs:350
int SizeXZ
Definition: Map.cs:138
PropsInstalled Installed
Definition: Map.cs:128
void TrySmoothPick(Cell cell, Thing t, Chara c)
Definition: Map.cs:1944
Dictionary< string, int > cellWidths
Definition: Map.cs:28
void AddCardOnActivate(Card c)
Definition: Map.cs:888
Thing FindThing(int uid)
Definition: Map.cs:2790
Dictionary< int, CellEffect > cellEffects
Definition: Map.cs:67
void RefreshFOV(int x, int z, int radius=6, bool recalculate=false)
Definition: Map.cs:1035
List< Point > ListPointsInArc(Point center, Point to, int radius, float angle)
Definition: Map.cs:2475
HashSet< int > roomHash
Definition: Map.cs:110
int CountNonHostile()
Definition: Map.cs:2679
void MoveCard(Point p, Card t)
Definition: Map.cs:946
Thing FindThing(string workTag, Chara c)
Definition: Map.cs:2892
void AddBackerTree(bool draw)
Definition: Map.cs:1716
void Reveal(Point center, int power=100)
Definition: Map.cs:1024
FloodSpiller flood
Definition: Map.cs:96
void SetBlockDir(int x, int z, int dir)
Definition: Map.cs:1281
void SetBounds(int size)
Definition: Map.cs:2497
void MineObj(Point point, Task task=null, Chara c=null)
Definition: Map.cs:1980
void OnDeactivate()
Definition: Map.cs:210
void SetLiquid(int x, int z, CellEffect effect=null)
Definition: Map.cs:1617
void OnCardRemovedFromZone(Card t)
Definition: Map.cs:930
void SetZone(Zone _zone)
Definition: Map.cs:186
Point GetNearbyResourcePoint(Point center)
Definition: Map.cs:2398
void SetDecal(int x, int z, int id=0, int amount=1, bool refresh=true)
Definition: Map.cs:2191
PropsRoaming Roaming
Definition: Map.cs:130
PlantData TryGetPlant(Cell c)
Definition: Map.cs:2087
int CountChara(Faction faction)
Definition: Map.cs:2627
void MineBlock(Point point, bool recoverBlock=false, Chara c=null, bool mineObj=true)
Definition: Map.cs:1808
bool revealed
Definition: Map.cs:108
List< Chara > ListCharasInCircle(Point center, float radius, bool los=true)
Definition: Map.cs:2457
int CountHostile()
Definition: Map.cs:2653
void SetFloor(int x, int z, int idMat, int idFloor, int dir)
Definition: Map.cs:1068
List< Thing > things
Definition: Map.cs:52
void OnDeserialized(StreamingContext context)
Definition: Map.cs:153
void SetFoormark(Point pos, int id, int angle, int offset=0)
Definition: Map.cs:2200
void RefreshFOVAll()
Definition: Map.cs:1055
byte[] TryLoadFile(string path, string s, int size)
Definition: Map.cs:557
void _ValidateInstalled(int x, int y)
Definition: Map.cs:2116
int GetRampDir(int x, int z, TileType blockType=null)
Definition: Map.cs:2293
List< Thing > ListThing< T >()
Definition: Map.cs:2705
Dictionary< int, int > backerObjs
Definition: Map.cs:70
int CountGuest()
Definition: Map.cs:2640
List< int > _plDay
Definition: Map.cs:58
Playlist plDay
Definition: Map.cs:80
int AngleToIndex(int a)
Definition: Map.cs:2214
CustomData custom
Definition: Map.cs:43
List< Chara > deadCharas
Definition: Map.cs:49
void ModFire(int x, int z, int amount)
Definition: Map.cs:1288
void SetDeco(int x, int z, int idMat, int idDeco)
Definition: Map.cs:1079
void _AddCard(int x, int z, Card t, bool onAddToZone)
Definition: Map.cs:951
void Burn(int x, int z, bool instant=false)
Definition: Map.cs:1549
void MineObjSound(Point point)
Definition: Map.cs:2077
void OnSerializing(StreamingContext context)
Definition: Map.cs:143
void SetSeen(int x, int z, bool seen=true, bool refresh=true)
Definition: Map.cs:998
PropsManager props
Definition: Map.cs:94
void ModLiquid(int x, int z, int amount)
Definition: Map.cs:1653
void MineFloor(Point point, Chara c=null, bool recoverBlock=false, bool removePlatform=true)
Definition: Map.cs:1892
void SetFloor(int x, int z, int idMat=0, int idFloor=0)
Definition: Map.cs:1063
void SetBounds(MapBounds b)
Definition: Map.cs:2506
void TryShatter(Point pos, int ele, int power, Card CC=null)
Definition: Map.cs:1316
int seed
Definition: Map.cs:19
void SetBlock(int x, int z, int idMat=0, int idBlock=0)
Definition: Map.cs:1112
PlantData AddPlant(Point pos, Thing seed)
Definition: Map.cs:2092
RoomManager rooms
Definition: Map.cs:34
bool PutAway(Card c)
Definition: Map.cs:2718
void ForeachSquare(int _x, int _z, int r, Action< Point > action)
Definition: Map.cs:2567
void TryRemoveRoom(int x, int z)
Definition: Map.cs:1188
void SetReference()
Definition: Map.cs:200
BiomeProfile[,] biomes
Definition: Map.cs:98
List< Footmark > footmarks
Definition: Map.cs:102
POIMap poiMap
Definition: Map.cs:100
void SetRoofBlock(int x, int z, int idMat, int idBlock, int dir, int height)
Definition: Map.cs:1103
void ClearRainAndDecal()
Definition: Map.cs:1666
void Reload()
Definition: Map.cs:315
new Point GetRandomEdge(int r=3)
Definition: Map.cs:2373
void OnLoad()
Definition: Map.cs:813
void OnImport(ZoneExportData data)
Definition: Map.cs:819
List< Point > ListPointsInSquare(Point center, int radius, bool mustBeWalkable=true, bool los=true)
Definition: Map.cs:2431
int CountWildAnimal()
Definition: Map.cs:2666
new void ForeachPoint(Action< Point > action)
Definition: Map.cs:2523
void TryAddRoom(int x, int z)
Definition: Map.cs:1200
void DestroyBlock(int x, int z)
Definition: Map.cs:2164
void QuickRefreshTile(int x, int z)
Definition: Map.cs:2278
List< Chara > serializedCharas
Definition: Map.cs:46
float sizeModifier
Definition: Map.cs:132
Cell[,] cells
Definition: Map.cs:88
static bool isDirtySunMap
Definition: Map.cs:16
static MapMetaData GetMetaData(string pathZip)
Definition: Map.cs:843
virtual void OnSerializing()
Definition: Map.cs:148
List< Thing > _things
Definition: Map.cs:112
void _RemoveCard(Card t)
Definition: Map.cs:977
Zone zone
Definition: Map.cs:90
static int WriteCellIds(string path, int[] ids, IO.Compression compression)
Definition: Map.cs:577
void RemoveLonelyRamps(Cell cell)
Definition: Map.cs:2150
void SetBlock(int x, int z, int idMat, int idBlock, int dir)
Definition: Map.cs:1117
T FindThing< T >()
Definition: Map.cs:2802
int _bits
Definition: Map.cs:22
void SetLiquid(int x, int z, int id, int value=1)
Definition: Map.cs:1626
TaskManager tasks
Definition: Map.cs:37
void ValidateInstalled(Point p)
Definition: Map.cs:2107
void DropBlockComponent(Point point, TileRow r, SourceMaterial.Row mat, bool recoverBlock, bool isPlatform=false, Chara c=null)
Definition: Map.cs:1767
MapExportSetting exportSetting
Definition: Map.cs:76
void SetEffect(int x, int z, CellEffect effect=null)
Definition: Map.cs:1648
void OnCardAddedToZone(Card t, int x, int z)
Definition: Map.cs:911
Version version
Definition: Map.cs:31
Thing FindThing(string workTag, BaseArea area1=null, BaseArea area2=null)
Definition: Map.cs:2865
FowProfile fowProfile
Definition: Map.cs:104
void ForeachNeighbor(Point center, Action< Point > action)
Definition: Map.cs:2587
bool isBreakerDown
Definition: Map.cs:115
MapConfig config
Definition: Map.cs:40
void OnSetBlockOrDoor(int x, int z)
Definition: Map.cs:1140
void Load(string path, bool import=false, PartialMap partial=null)
Definition: Map.cs:634
Chara FindChara(int uid)
Definition: Map.cs:2766
Playlist plNight
Definition: Map.cs:82
CellEffectManager effectManager
Definition: Map.cs:92
void ReloadRoom()
Definition: Map.cs:330
List< Point > ListPointsOnEdge(Point center, int destDist, bool mustBeWalkable=true, bool los=true)
Definition: Map.cs:2444
List< Point > ListPointsInLine(Point center, Point to, int radius, bool returnOnBlocked=true)
Definition: Map.cs:2492
Cell GetDependedRamp(Cell cell)
Definition: Map.cs:2330
PropsStocked Stocked
Definition: Map.cs:126
void MineRamp(Point point, int ramp, bool recoverBlock=false)
Definition: Map.cs:1875
void ValidateVersion()
Definition: Map.cs:808
List< Point > ListPointsInCircle(Point center, float radius, bool mustBeWalkable=true, bool los=true)
Definition: Map.cs:2418
void CreateNew(int size, bool setReference=true)
Definition: Map.cs:158
List< Chara > charas
Definition: Map.cs:84
void AddDecal(int x, int z, int id, int amount=1, bool refresh=true)
Definition: Map.cs:2169
void RevealAll(bool reveal=true)
Definition: Map.cs:1011
IO.Compression compression
Definition: Map.cs:25
void SetObj(int x, int z, int idMat, int idObj, int value, int dir, bool ignoreRandomMat=false)
Definition: Map.cs:1680
void Resize(int newSize)
Definition: Map.cs:231
Dictionary< int, PlantData > plants
Definition: Map.cs:73
void RefreshAllTiles()
Definition: Map.cs:2248
void Quake()
Definition: Map.cs:2609
List< Chara > ListChara(Faction faction)
Definition: Map.cs:2692
List< TransAnime > pointAnimes
Definition: Map.cs:86
void RefreshShadow(int x, int z)
Definition: Map.cs:1940
void ApplyBackerObj(Point p, int id=-1)
Definition: Map.cs:1741
void SetObj(int x, int z, int id=0, int value=1, int dir=0)
Definition: Map.cs:1675
SourceBacker.Row GetBackerObj(Point p)
Definition: Map.cs:1732
static string CellIdPath(string path, int width)
Definition: Map.cs:568
static HashSet< int > sunMap
Definition: Map.cs:14
MapBounds bounds
Definition: Map.cs:55
Definition: Msg.cs:5
static string Say(string idLang, string ref1, string ref2=null, string ref3=null, string ref4=null)
Definition: Msg.cs:58
Definition: NoGoal.cs:4
Definition: POIMap.cs:4
IPathfinder pathfinder
Definition: PathManager.cs:24
static PathManager Instance
Definition: PathManager.cs:16
HashSet< int > doneBackers
Definition: Player.cs:1143
void ClearMapHighlights()
Definition: Player.cs:2544
Definition: Point.cs:9
static Point shared
Definition: Point.cs:20
SourceMaterial.Row matBlock
Definition: Point.cs:55
SourceMaterial.Row matFloor
Definition: Point.cs:57
int index
Definition: Point.cs:49
static Point Invalid
Definition: Point.cs:28
bool HasBridge
Definition: Point.cs:221
List< Card > ListCards(bool includeMasked=false)
Definition: Point.cs:1057
Point Copy()
Definition: Point.cs:491
bool IsSky
Definition: Point.cs:224
Point Set(int _x, int _z)
Definition: Point.cs:503
bool IsBlocked
Definition: Point.cs:363
int x
Definition: Point.cs:36
int z
Definition: Point.cs:39
SourceMaterial.Row matBridge
Definition: Point.cs:59
void SetFloor(int idMat=0, int idFloor=0)
Definition: Point.cs:929
SoundSource PlaySound(string id, bool synced=true, float v=1f, bool spatial=true)
Definition: Point.cs:1259
SourceObj.Row sourceObj
Definition: Point.cs:69
bool Equals(int _x, int _z)
Definition: Point.cs:966
SourceFloor.Row sourceFloor
Definition: Point.cs:65
void SetBlock(int idMat=0, int idBlock=0)
Definition: Point.cs:924
bool IsValid
Definition: Point.cs:88
bool HasObj
Definition: Point.cs:137
bool HasRoomOrArea(BaseArea a)
Definition: Point.cs:421
Area area
Definition: Point.cs:73
bool HasFloor
Definition: Point.cs:219
int Distance(Point p)
Definition: Point.cs:995
Point Clamp(bool useBounds=false)
Definition: Point.cs:1014
bool IsInBounds
Definition: Point.cs:104
Cell cell
Definition: Point.cs:51
float GetAngle2(Point to)
Definition: Point.cs:618
void Animate(AnimeID id, bool animeBlock=false)
Definition: Point.cs:1308
SourceFloor.Row sourceBridge
Definition: Point.cs:67
bool IsPublicSpace()
Definition: Point.cs:449
PropsInstalled installed
Definition: PropsManager.cs:8
PropsRoaming roaming
Definition: PropsManager.cs:10
void OnCardAddedToZone(Card c)
Definition: PropsManager.cs:25
PropsStocked stocked
Definition: PropsManager.cs:6
TraitManager traits
Definition: Props.cs:18
List< Thing > things
Definition: Props.cs:20
Dictionary< string, PropSet > workMap
Definition: Props.cs:16
Definition: Rand.cs:4
static void SetSeed(int a=-1)
Definition: Rand.cs:44
static void BuildList()
static List< RecipeSource > list
static RecipeSource Get(string id)
RenderRow row
Definition: RecipeSource.cs:5
string GetIDIngredient()
string[] tag
Definition: RenderRow.cs:58
virtual string RecipeID
Definition: RenderRow.cs:108
TileType tileType
Definition: RenderRow.cs:77
string[] components
Definition: RenderRow.cs:52
Room AddRoom(Room r)
Definition: RoomManager.cs:110
void RefreshAll()
Definition: RoomManager.cs:43
void RemoveRoom(Room r)
Definition: RoomManager.cs:119
List< Room > listRoom
Definition: RoomManager.cs:13
List< Area > listArea
Definition: RoomManager.cs:10
void OnLoad()
Definition: RoomManager.cs:26
Definition: Room.cs:4
void SetDirty()
Definition: Room.cs:210
static SceneProfile Load(string id)
Definition: SceneProfile.cs:18
Definition: Scene.cs:8
ActionMode actionMode
Definition: Scene.cs:79
void AddActorEx(Card c, Action< ActorEx > onBeforeSetOwner=null)
Definition: Scene.cs:1021
void Init(Mode newMode)
Definition: Scene.cs:178
Mode
Definition: Scene.cs:10
void Restore(Map map, Map orgMap, bool addToZone, PartialMap partial=null)
List< Row > listRemain
List< Row > listTree
SourceMaterial materials
SourceObj objs
SourceBlock blocks
SourceBacker backers
SourceFloor floors
void AddBlood(Point p, int a=1)
string GetSoundDead(RenderRow c=null)
bool HasGrowth
Definition: SourceObj.cs:29
string matCategory
Definition: SourceObj.cs:24
virtual bool IsRegion
Definition: Spatial.cs:515
virtual string Name
Definition: Spatial.cs:509
bool OnMineWreck(Point point)
void OnLoad()
Definition: TaskManager.cs:66
Definition: Task.cs:4
static Thing CreateRawMaterial(SourceMaterial.Row m)
Definition: ThingGen.cs:68
static Thing CreateBlock(int id, int idMat)
Definition: ThingGen.cs:101
static Thing CreateFloor(int id, int idMat, bool platform=false)
Definition: ThingGen.cs:108
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
Definition: Thing.cs:8
int stackOrder
Definition: Thing.cs:13
string alias
Definition: TileRow.cs:13
int id
Definition: TileRow.cs:9
virtual bool IsBlockPass
Definition: TileType.cs:161
virtual bool IsUnique
Definition: TraitChara.cs:34
TraitMap suns
Definition: TraitManager.cs:14
static Thing MakeSeed(string idSource)
Definition: TraitSeed.cs:105
Definition: Trait.cs:7
virtual string IDActorEx
Definition: Trait.cs:187
virtual bool IsDoor
Definition: Trait.cs:58
virtual void OnAddedToZone()
Definition: Trait.cs:720
virtual bool CanCopyInBlueprint
Definition: Trait.cs:166
virtual void OnRemovedFromZone()
Definition: Trait.cs:724
virtual List< Point > ListPoints(Point center=null, bool onlyPassable=true, bool allowChara=true)
Definition: Trait.cs:868
virtual bool CanOnlyCarry
Definition: Trait.cs:305
static void UpdateMap(List< Cell > newPoints)
static void Say(string text, FontColor fontColor=FontColor.Default, Sprite sprite=null)
SerializedCards serializedCards
Definition: Zone.cs:12
void Revive()
Definition: Zone.cs:1219
virtual bool IsSkyLevel
Definition: Zone.cs:274
virtual bool DisableRooms
Definition: Zone.cs:126
virtual int MaxSoil
Definition: Zone.cs:523
virtual bool IsUserZone
Definition: Zone.cs:278
void RemoveCard(Card t)
Definition: Zone.cs:2199
override int DangerLv
Definition: Zone.cs:115
bool IsPCFaction
Definition: Zone.cs:480
virtual bool IsUnderwater
Definition: Zone.cs:276
int GetSoilCost()
Definition: Zone.cs:4049
Card AddCard(Card t, Point point)
Definition: Zone.cs:2159
void RemoveCard(Card c)
void Init(IPathfindGrid _grid, WeightCell[,] _weightMap, int size)
uint Bits
Definition: BitArray32.cs:6
bool IsBelow(int _major, int _minor, int _batch)
Definition: Version.cs:49
int GetInt()
Definition: Version.cs:39