Elin Decompiled Documentation EA 23.195 Nightly
Loading...
Searching...
No Matches
SerializedCards.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Linq;
3using Newtonsoft.Json;
4using UnityEngine;
5
6public class SerializedCards : EClass
7{
8 public class Data : EClass
9 {
10 [JsonProperty]
11 public int[] ints = new int[30];
12
13 [JsonProperty]
14 public string[] strs = new string[10];
15
16 [JsonProperty]
17 public Dictionary<int, object> obj;
18
19 [JsonProperty]
20 public Dictionary<int, string> cstr;
21
23
24 public int idDyeMat
25 {
26 get
27 {
28 return ints[2];
29 }
30 set
31 {
32 ints[2] = value;
33 }
34 }
35
36 public int idV
37 {
38 get
39 {
40 return ints[3];
41 }
42 set
43 {
44 ints[3] = value;
45 }
46 }
47
48 public int idMat
49 {
50 get
51 {
52 return ints[4];
53 }
54 set
55 {
56 ints[4] = value;
57 }
58 }
59
60 public int x
61 {
62 get
63 {
64 return ints[5];
65 }
66 set
67 {
68 ints[5] = value;
69 }
70 }
71
72 public int z
73 {
74 get
75 {
76 return ints[6];
77 }
78 set
79 {
80 ints[6] = value;
81 }
82 }
83
84 public int dir
85 {
86 get
87 {
88 return ints[7];
89 }
90 set
91 {
92 ints[7] = value;
93 }
94 }
95
96 public int placeState
97 {
98 get
99 {
100 return ints[8];
101 }
102 set
103 {
104 ints[8] = value;
105 }
106 }
107
108 public int altitude
109 {
110 get
111 {
112 return ints[9];
113 }
114 set
115 {
116 ints[9] = value;
117 }
118 }
119
120 public int fx
121 {
122 get
123 {
124 return ints[10];
125 }
126 set
127 {
128 ints[10] = value;
129 }
130 }
131
132 public int fy
133 {
134 get
135 {
136 return ints[11];
137 }
138 set
139 {
140 ints[11] = value;
141 }
142 }
143
144 public int lightColor
145 {
146 get
147 {
148 return ints[12];
149 }
150 set
151 {
152 ints[12] = value;
153 }
154 }
155
156 public int bits1
157 {
158 get
159 {
160 return ints[13];
161 }
162 set
163 {
164 ints[13] = value;
165 }
166 }
167
168 public int tile
169 {
170 get
171 {
172 return ints[14];
173 }
174 set
175 {
176 ints[14] = value;
177 }
178 }
179
180 public int refVal
181 {
182 get
183 {
184 return ints[15];
185 }
186 set
187 {
188 ints[15] = value;
189 }
190 }
191
192 public int idSkin
193 {
194 get
195 {
196 return ints[16];
197 }
198 set
199 {
200 ints[16] = value;
201 }
202 }
203
204 public int idBacker
205 {
206 get
207 {
208 return ints[17];
209 }
210 set
211 {
212 ints[17] = value;
213 }
214 }
215
216 public int bits2
217 {
218 get
219 {
220 return ints[18];
221 }
222 set
223 {
224 ints[18] = value;
225 }
226 }
227
228 public int uidEditor
229 {
230 get
231 {
232 return ints[19];
233 }
234 set
235 {
236 ints[19] = value;
237 }
238 }
239
240 public int lv
241 {
242 get
243 {
244 return ints[20];
245 }
246 set
247 {
248 ints[20] = value;
249 }
250 }
251
252 public int element
253 {
254 get
255 {
256 return ints[21];
257 }
258 set
259 {
260 ints[21] = value;
261 }
262 }
263
264 public int encLv
265 {
266 get
267 {
268 return ints[22];
269 }
270 set
271 {
272 ints[22] = value;
273 }
274 }
275
276 public string id
277 {
278 get
279 {
280 return strs[0];
281 }
282 set
283 {
284 strs[0] = value;
285 }
286 }
287
288 public string idEditor
289 {
290 get
291 {
292 return strs[1];
293 }
294 set
295 {
296 strs[1] = value;
297 }
298 }
299
300 public string idTrait
301 {
302 get
303 {
304 return strs[2];
305 }
306 set
307 {
308 strs[2] = value;
309 }
310 }
311
312 public string tags
313 {
314 get
315 {
316 return strs[3];
317 }
318 set
319 {
320 strs[3] = value;
321 }
322 }
323
324 public string idRender
325 {
326 get
327 {
328 return strs[4];
329 }
330 set
331 {
332 strs[4] = value;
333 }
334 }
335
336 public string traitVals
337 {
338 get
339 {
340 return strs[5];
341 }
342 set
343 {
344 strs[5] = value;
345 }
346 }
347
348 public string idRefCard
349 {
350 get
351 {
352 return strs[6];
353 }
354 set
355 {
356 strs[6] = value;
357 }
358 }
359
360 public string idDeity
361 {
362 get
363 {
364 return strs[7];
365 }
366 set
367 {
368 strs[7] = value;
369 }
370 }
371
372 public bool isDead
373 {
374 get
375 {
376 return _bits1[0];
377 }
378 set
379 {
380 _bits1[0] = value;
381 }
382 }
383
384 public bool isEmpty
385 {
386 get
387 {
388 return _bits1[1];
389 }
390 set
391 {
392 _bits1[1] = value;
393 }
394 }
395 }
396
397 [JsonProperty]
398 public List<Data> cards = new List<Data>();
399
400 [JsonProperty]
401 public int version = 2;
402
403 public List<Card> importedCards = new List<Card>();
404
405 public void Add(Card c)
406 {
407 Data data = new Data
408 {
409 id = c.id,
410 idEditor = c.c_idEditor,
411 idRefCard = c.c_idRefCard,
412 idTrait = c.c_idTrait,
413 tags = c.c_editorTags,
414 traitVals = c.c_editorTraitVal,
415 obj = c.mapObj,
416 idMat = c.material.id,
417 x = c.pos.x,
418 z = c.pos.z,
419 placeState = (int)c.placeState,
420 dir = c.dir,
421 altitude = c.altitude,
422 fx = (int)(c.fx * 1000f),
423 fy = (int)(c.fy * 1000f),
424 lightColor = c.c_lightColor,
425 bits1 = c._bits1.ToInt(),
426 bits2 = c._bits2.ToInt(),
427 tile = c.sourceCard.tiles[0],
428 idRender = c.sourceCard.idRenderData,
429 refVal = c.refVal,
430 idSkin = c.idSkin,
431 idDeity = c.c_idDeity,
432 isEmpty = (c.things.Count == 0 && c.c_lockLv == 0),
433 encLv = c.encLV
434 };
435 if (c.c_idBacker != 0)
436 {
437 SourceBacker.Row row = EClass.sources.backers.map.TryGetValue(c.c_idBacker);
438 if (row != null && row.isStatic != 0)
439 {
440 data.idBacker = c.c_idBacker;
441 }
442 }
443 if (c.material.id == c.DefaultMaterial.id)
444 {
445 data.idMat = -1;
446 }
447 data.idDyeMat = (c.isDyed ? c.c_dyeMat : (-1));
448 if (c.isChara)
449 {
450 Point orgPos = c.Chara.orgPos;
451 if (orgPos != null)
452 {
453 data.x = orgPos.x;
454 data.z = orgPos.z;
455 }
456 if (c.Chara.isDead)
457 {
458 data.isDead = true;
459 }
460 if (c.Chara.uidEditor == 0)
461 {
462 int num = 1;
463 foreach (Chara item in EClass._map.charas.Concat(EClass._map.deadCharas))
464 {
465 if (item.uidEditor >= num)
466 {
467 num = item.uidEditor + 1;
468 }
469 }
470 c.Chara.uidEditor = num;
471 }
472 data.lv = c.LV;
473 data.element = c.c_idMainElement;
474 data.uidEditor = c.Chara.uidEditor;
475 }
476 TryAddStr(52);
477 cards.Add(data);
478 data.ints[0] = data._bits1.ToInt();
479 void TryAddStr(int key)
480 {
481 string str = c.GetStr(key);
482 if (!str.IsEmpty())
483 {
484 if (data.cstr == null)
485 {
486 data.cstr = new Dictionary<int, string>();
487 }
488 data.cstr[key] = str;
489 }
490 }
491 }
492
493 public void Restore(Map map, Map orgMap, bool addToZone, PartialMap partial = null)
494 {
495 List<Thing> things = map.things;
496 List<Chara> serializedCharas = map.serializedCharas;
497 bool isUserZone = EClass._zone.IsUserZone;
498 Dictionary<int, int> dictionary = new Dictionary<int, int>();
499 Dictionary<int, int> dictionary2 = new Dictionary<int, int>();
500 importedCards.Clear();
501 foreach (Data card4 in cards)
502 {
503 int num = card4.dir;
504 Point point = new Point(card4.x, card4.z);
505 int index = point.index;
506 if (partial != null)
507 {
508 if (partial.result.ruined.Contains(point.index))
509 {
510 continue;
511 }
512 num -= partial.dir;
513 int num2 = point.x - partial.offsetX;
514 int num3 = point.z - partial.offsetZ;
515 switch (partial.dir)
516 {
517 case 1:
518 {
519 int num5 = num2;
520 num2 = num3;
521 num3 = -num5;
522 break;
523 }
524 case 2:
525 num2 = -num2;
526 num3 = -num3;
527 break;
528 case 3:
529 {
530 int num4 = num2;
531 num2 = -num3;
532 num3 = num4;
533 break;
534 }
535 }
536 point.x = num2 + partial.destX;
537 point.z = num3 + partial.destZ;
538 if (!partial.validPoints.Contains(point.index) || !point.IsValid)
539 {
540 continue;
541 }
542 if (!partial.editMode)
543 {
544 Card card = null;
545 string id = card4.id;
546 if (!(id == "sign_spawnThing"))
547 {
548 if (id == "sign_spawnChara")
549 {
551 }
552 }
553 else
554 {
556 }
557 if (card != null)
558 {
559 card.pos = point;
561 if (card.trait.IsDoor)
562 {
563 EClass._map.OnSetBlockOrDoor(card.pos.x, card.pos.z);
564 }
565 continue;
566 }
567 }
568 }
569 card4._bits1.SetInt(card4.ints[0]);
570 string text = card4.id;
571 if (card4.idV != 0)
572 {
573 text = card4.idV.ToString() ?? "";
574 }
575 if (addToZone && partial != null && !partial.editMode)
576 {
577 string id = card4.id;
578 if (!(id == "editor_torch"))
579 {
580 if (id == "editor_torch_wall")
581 {
582 text = EClass._zone.biome.style.GetIdLight(wall: true);
583 }
584 }
585 else
586 {
587 text = EClass._zone.biome.style.GetIdLight(wall: false);
588 }
589 }
590 CardRow source = EClass.sources.cards.map.TryGetValue(text);
591 if (source == null)
592 {
593 continue;
594 }
595 Card card2 = null;
596 if (source.isChara)
597 {
598 if (orgMap != null)
599 {
600 bool flag = false;
601 if (source.quality >= 4)
602 {
603 foreach (Chara value2 in EClass.game.cards.globalCharas.Values)
604 {
605 if (value2.id == text)
606 {
607 flag = true;
608 break;
609 }
610 }
611 }
612 if (!flag)
613 {
614 foreach (Chara item in orgMap.charas.Concat(orgMap.serializedCharas).Concat(orgMap.deadCharas))
615 {
616 if (source.quality >= 4 && item.id == text)
617 {
618 flag = true;
619 break;
620 }
621 if (item.id == text && item.orgPos != null && item.orgPos.Equals(point))
622 {
623 flag = true;
624 break;
625 }
626 }
627 }
628 if (flag)
629 {
630 continue;
631 }
632 }
633 if (isUserZone && ClassExtension.TryGetValue<int, int>((IDictionary<int, int>)dictionary, index, 0) >= 3)
634 {
635 continue;
636 }
637 card2 = CharaGen.Create(text);
638 if (card4.ints.Length > 20)
639 {
640 card2.Chara.SetLv(card4.lv);
641 if (card4.element != 0)
642 {
643 card2.Chara.SetMainElement(card4.element);
644 }
645 }
646 card2.Chara.orgPos = point.Copy();
647 if (card4.isDead)
648 {
649 card2.hp = -1;
650 card2.Chara.isDead = true;
651 }
652 card2.Chara.hunger.value = EClass.rnd(EClass.rnd(20) + 1);
653 if (!addToZone)
654 {
655 serializedCharas.Add(card2.Chara);
656 }
657 if (isUserZone)
658 {
659 dictionary[index] = ClassExtension.TryGetValue<int, int>((IDictionary<int, int>)dictionary, index, 0) + 1;
660 }
661 }
662 else
663 {
664 PlaceState placeState = card4.placeState.ToEnum<PlaceState>();
665 if (isUserZone && ((ClassExtension.TryGetValue<int, int>((IDictionary<int, int>)dictionary2, index, 0) >= 20 && text != "waystone" && text != "core_zone") || (placeState != PlaceState.installed && !card4.bits1.IsOn(13)) || text == "medal"))
666 {
667 continue;
668 }
669 if (source.isOrigin)
670 {
671 text = SpawnListThing.Get("origin_" + text, (SourceThing.Row a) => a.origin == source).GetFirst().id;
672 }
673 card2 = ThingGen.Create(text, -1, EClass._zone.DangerLv);
674 card2.ChangeMaterial((card4.idMat == -1) ? card2.DefaultMaterial.id : card4.idMat);
675 if (!addToZone)
676 {
677 things.Add(card2.Thing);
678 }
679 card2.altitude = card4.altitude;
680 card2.placeState = placeState;
681 card2.c_lightColor = card4.lightColor;
682 if (isUserZone)
683 {
684 dictionary2[index] = ClassExtension.TryGetValue<int, int>((IDictionary<int, int>)dictionary2, index, 0) + 1;
685 }
686 }
687 if (num < 0)
688 {
689 num = Mathf.Abs(card2.sourceCard.tiles.Length + num);
690 }
691 card2.pos = point;
692 card2.dir = num;
693 card2._bits1.SetInt(card4.bits1);
694 card2._bits2.SetInt(card4.bits2);
695 card2.isPlayerCreation = true;
696 card2.autoRefuel = true;
697 card2.c_editorTraitVal = card4.traitVals;
698 card2.c_idRefCard = card4.idRefCard;
699 card2.isImported = true;
700 card2.refVal = card4.refVal;
701 card2.idSkin = card4.idSkin;
702 card2.c_idDeity = card4.idDeity;
703 if (card4.idBacker != 0)
704 {
705 Debug.Log(card4.idBacker);
706 card2.c_idBacker = card4.idBacker;
707 }
708 if (version >= 2 && card4.idDyeMat != -1)
709 {
710 card2.Dye(EClass.sources.materials.rows.TryGet(card4.idDyeMat, 1));
711 }
712 card2.mapObj = card4.obj;
713 if (card2.mapObj?.TryGetValue(2) != null)
714 {
715 card2.mapObj.Remove(2);
716 }
717 if (card4.cstr != null)
718 {
719 foreach (KeyValuePair<int, string> item2 in card4.cstr)
720 {
721 card2.SetStr(item2.Key, item2.Value);
722 }
723 }
724 if (card2.freePos)
725 {
726 card2.fx = (float)card4.fx * 0.001f;
727 card2.fy = (float)card4.fy * 0.001f;
728 }
729 if (!card4.idEditor.IsEmpty())
730 {
731 card2.c_idEditor = card4.idEditor;
732 }
733 if (!card4.idTrait.IsEmpty())
734 {
735 card2.c_idTrait = card4.idTrait;
736 card2.ApplyTrait();
738 }
739 if (!card4.tags.IsEmpty())
740 {
741 card2.c_editorTags = card4.tags;
742 try
743 {
744 string[] array = card4.tags.Split(',');
745 foreach (string value in array)
746 {
747 card2.ApplyEditorTags(value.ToEnum<EditorTag>());
748 }
749 }
750 catch
751 {
752 Debug.LogWarning("Could not convert editor tag:" + card2.Name + "/" + card4.tags);
753 }
754 }
755 if (isUserZone)
756 {
757 if ((card2.isHidden || card2.isMasked) && ((card2.TileType.IsBlockPass && card2.IsInstalled) || card2.trait is TraitCoreZone || card2.trait is TraitWaystone))
758 {
759 Card card3 = card2;
760 bool isHidden = (card2.isMasked = false);
761 card3.isHidden = isHidden;
762 }
763 if (card2.IsContainer)
764 {
765 if (card4.isEmpty)
766 {
767 card2.things.DestroyAll();
768 card2.c_lockLv = 0;
769 }
770 else
771 {
772 card2.c_lockLv = 1;
773 }
774 }
775 if (card4.encLv != 0)
776 {
777 card2.SetEncLv(card4.encLv);
778 }
779 }
780 if (card2.isChara)
781 {
782 card2.Chara.homeZone = EClass._zone;
783 card2.Chara.uidEditor = card4.uidEditor;
784 if (card2.isBackerContent)
785 {
786 card2.ApplyBacker(card2.c_idBacker);
787 }
788 card2.SetObj(5, null);
790 {
791 card2.Chara.ScaleByPrincipal();
792 }
793 }
794 if (card2.trait is TraitFakeBlock)
795 {
796 card2._CreateRenderer();
797 }
798 if (addToZone)
799 {
800 EClass._zone.AddCard(card2, card2.pos);
801 if (card2.trait.IsDoor)
802 {
803 EClass._map.OnSetBlockOrDoor(card2.pos.x, card2.pos.z);
804 }
805 if (partial != null && !card2.sourceCard.lightData.IsEmpty())
806 {
807 partial.result.hasLight = true;
808 }
809 }
810 importedCards.Add(card2);
811 }
812 foreach (Card importedCard in importedCards)
813 {
814 if (importedCard.trait is TraitShackle)
815 {
816 foreach (Card importedCard2 in importedCards)
817 {
818 if (importedCard2.isRestrained && importedCard2.pos.Equals(importedCard.pos))
819 {
820 importedCard.c_uidRefCard = importedCard2.uid;
821 }
822 }
823 }
824 importedCard.trait.OnImportMap();
825 }
826 }
827}
EditorTag
Definition: EditorTag.cs:2
PlaceState
Definition: PlaceState.cs:2
void SetStr(int id, string value=null)
Definition: BaseCard.cs:63
void SetObj(int id, object o)
Definition: BaseCard.cs:91
string GetStr(int id, string defaultStr=null)
Definition: BaseCard.cs:54
Dictionary< int, object > mapObj
Definition: BaseCard.cs:7
string GetRandomThingId()
string GetRandomCharaId()
string GetIdLight(bool wall)
GlobalCharaList globalCharas
Definition: CardManager.cs:46
override string idRenderData
Definition: CardRow.cs:62
int quality
Definition: CardRow.cs:19
bool isChara
Definition: CardRow.cs:55
bool isOrigin
Definition: CardRow.cs:52
string lightData
Definition: CardRow.cs:13
Definition: Card.cs:11
BitArray32 _bits1
Definition: Card.cs:77
virtual Chara Chara
Definition: Card.cs:2032
bool isMasked
Definition: Card.cs:576
int c_idMainElement
Definition: Card.cs:1387
string id
Definition: Card.cs:33
bool isRestrained
Definition: Card.cs:552
float fy
Definition: Card.cs:252
SourceMaterial.Row material
Definition: Card.cs:2013
string c_idDeity
Definition: Card.cs:1555
Card ChangeMaterial(int idNew, bool ignoreFixedMaterial=false)
Definition: Card.cs:2994
string c_idTrait
Definition: Card.cs:1699
virtual SourceMaterial.Row DefaultMaterial
Definition: Card.cs:2383
BitArray32 _bits2
Definition: Card.cs:79
virtual CardRenderer _CreateRenderer()
Definition: Card.cs:5730
Card SetLv(int a)
Definition: Card.cs:2858
string Name
Definition: Card.cs:2099
PlaceState placeState
Definition: Card.cs:81
string c_idEditor
Definition: Card.cs:1663
Point pos
Definition: Card.cs:57
string c_editorTags
Definition: Card.cs:1675
int c_lightColor
Definition: Card.cs:1070
int uid
Definition: Card.cs:120
void Dye(string idMat)
Definition: Card.cs:5768
int refVal
Definition: Card.cs:192
void ApplyTrait()
Definition: Card.cs:2837
Trait trait
Definition: Card.cs:51
virtual void ApplyEditorTags(EditorTag tag)
Definition: Card.cs:2812
int encLV
Definition: Card.cs:312
int altitude
Definition: Card.cs:216
void SetEncLv(int a)
Definition: Card.cs:3762
int c_idBacker
Definition: Card.cs:1411
ThingContainer things
Definition: Card.cs:36
bool IsInstalled
Definition: Card.cs:2343
virtual bool isChara
Definition: Card.cs:2045
virtual Thing Thing
Definition: Card.cs:2020
bool isHidden
Definition: Card.cs:516
int idSkin
Definition: Card.cs:348
int dir
Definition: Card.cs:144
void ApplyBacker(int bid)
Definition: Card.cs:6735
virtual CardRow sourceCard
Definition: Card.cs:2093
Thing Add(string id, int num=1, int lv=1)
Definition: Card.cs:3034
bool IsContainer
Definition: Card.cs:2051
bool freePos
Definition: Card.cs:504
string c_editorTraitVal
Definition: Card.cs:1687
int LV
Definition: Card.cs:372
bool isBackerContent
Definition: Card.cs:899
string c_idRefCard
Definition: Card.cs:1711
static Chara CreateFromFilter(string id, int lv=-1, int levelRange=-1)
Definition: CharaGen.cs:22
static Chara Create(string id, int lv=-1)
Definition: CharaGen.cs:17
Definition: Chara.cs:10
void SetMainElement(string id, int v=0, bool elemental=false)
Definition: Chara.cs:2031
int uidEditor
Definition: Chara.cs:351
Point orgPos
Definition: Chara.cs:21
Chara ScaleByPrincipal()
Definition: Chara.cs:1677
bool isDead
Definition: Chara.cs:387
Definition: EClass.cs:5
static Game game
Definition: EClass.cs:8
static Zone _zone
Definition: EClass.cs:20
static Map _map
Definition: EClass.cs:18
static int rnd(long a)
Definition: EClass.cs:58
static SourceManager sources
Definition: EClass.cs:42
CardManager cards
Definition: Game.cs:155
Definition: Map.cs:13
List< Thing > things
Definition: Map.cs:49
List< Chara > deadCharas
Definition: Map.cs:46
List< Chara > serializedCharas
Definition: Map.cs:43
void OnSetBlockOrDoor(int x, int z)
Definition: Map.cs:1024
List< Chara > charas
Definition: Map.cs:81
Definition: Point.cs:9
int index
Definition: Point.cs:49
Point Copy()
Definition: Point.cs:479
int x
Definition: Point.cs:36
int z
Definition: Point.cs:39
bool Equals(int _x, int _z)
Definition: Point.cs:944
bool IsValid
Definition: Point.cs:88
int[] tiles
Definition: RenderRow.cs:10
Dictionary< int, object > obj
Dictionary< int, string > cstr
void Add(Card c)
List< Data > cards
List< Card > importedCards
void Restore(Map map, Map orgMap, bool addToZone, PartialMap partial=null)
Dictionary< string, CardRow > map
Definition: SourceCard.cs:8
SourceMaterial materials
SourceCard cards
SourceBacker backers
int lv
Definition: Spatial.cs:142
static SpawnList Get(string id, Func< SourceThing.Row, bool > func)
string id
Definition: SpawnList.cs:10
void DestroyAll(Func< Thing, bool > funcExclude=null)
static Thing CreateFromFilter(string id, int lv=-1)
Definition: ThingGen.cs:63
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
virtual void OnImportMap()
Definition: Trait.cs:649
virtual bool IsDoor
Definition: Trait.cs:57
virtual void OnCreate(int lv)
Definition: Trait.cs:661
BiomeProfile biome
Definition: Zone.cs:126
virtual bool ShouldScaleImportedChara(Chara c)
Definition: Zone.cs:537
virtual bool IsUserZone
Definition: Zone.cs:266
override int DangerLv
Definition: Zone.cs:107
Card AddCard(Card t, Point point)
Definition: Zone.cs:1935
void SetInt(int i)
Definition: BitArray32.cs:89
int ToInt()
Definition: BitArray32.cs:84