Elin Decompiled Documentation EA 23.102 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 string id
265 {
266 get
267 {
268 return strs[0];
269 }
270 set
271 {
272 strs[0] = value;
273 }
274 }
275
276 public string idEditor
277 {
278 get
279 {
280 return strs[1];
281 }
282 set
283 {
284 strs[1] = value;
285 }
286 }
287
288 public string idTrait
289 {
290 get
291 {
292 return strs[2];
293 }
294 set
295 {
296 strs[2] = value;
297 }
298 }
299
300 public string tags
301 {
302 get
303 {
304 return strs[3];
305 }
306 set
307 {
308 strs[3] = value;
309 }
310 }
311
312 public string idRender
313 {
314 get
315 {
316 return strs[4];
317 }
318 set
319 {
320 strs[4] = value;
321 }
322 }
323
324 public string traitVals
325 {
326 get
327 {
328 return strs[5];
329 }
330 set
331 {
332 strs[5] = value;
333 }
334 }
335
336 public string idRefCard
337 {
338 get
339 {
340 return strs[6];
341 }
342 set
343 {
344 strs[6] = value;
345 }
346 }
347
348 public string idDeity
349 {
350 get
351 {
352 return strs[7];
353 }
354 set
355 {
356 strs[7] = value;
357 }
358 }
359
360 public bool isDead
361 {
362 get
363 {
364 return _bits1[0];
365 }
366 set
367 {
368 _bits1[0] = value;
369 }
370 }
371
372 public bool isEmpty
373 {
374 get
375 {
376 return _bits1[1];
377 }
378 set
379 {
380 _bits1[1] = value;
381 }
382 }
383 }
384
385 [JsonProperty]
386 public List<Data> cards = new List<Data>();
387
388 [JsonProperty]
389 public int version = 2;
390
391 public List<Card> importedCards = new List<Card>();
392
393 public void Add(Card c)
394 {
395 Data data = new Data
396 {
397 id = c.id,
398 idEditor = c.c_idEditor,
399 idRefCard = c.c_idRefCard,
400 idTrait = c.c_idTrait,
401 tags = c.c_editorTags,
402 traitVals = c.c_editorTraitVal,
403 obj = c.mapObj,
404 idMat = c.material.id,
405 x = c.pos.x,
406 z = c.pos.z,
407 placeState = (int)c.placeState,
408 dir = c.dir,
409 altitude = c.altitude,
410 fx = (int)(c.fx * 1000f),
411 fy = (int)(c.fy * 1000f),
412 lightColor = c.c_lightColor,
413 bits1 = c._bits1.ToInt(),
414 bits2 = c._bits2.ToInt(),
415 tile = c.sourceCard.tiles[0],
416 idRender = c.sourceCard.idRenderData,
417 refVal = c.refVal,
418 idSkin = c.idSkin,
419 idDeity = c.c_idDeity,
420 isEmpty = (c.things.Count == 0)
421 };
422 if (c.c_idBacker != 0)
423 {
424 SourceBacker.Row row = EClass.sources.backers.map.TryGetValue(c.c_idBacker);
425 if (row != null && row.isStatic != 0)
426 {
427 data.idBacker = c.c_idBacker;
428 }
429 }
430 if (c.material.id == c.DefaultMaterial.id)
431 {
432 data.idMat = -1;
433 }
434 data.idDyeMat = (c.isDyed ? c.c_dyeMat : (-1));
435 if (c.isChara)
436 {
437 Point orgPos = c.Chara.orgPos;
438 if (orgPos != null)
439 {
440 data.x = orgPos.x;
441 data.z = orgPos.z;
442 }
443 if (c.Chara.isDead)
444 {
445 data.isDead = true;
446 }
447 if (c.Chara.uidEditor == 0)
448 {
449 int num = 1;
450 foreach (Chara item in EClass._map.charas.Concat(EClass._map.deadCharas))
451 {
452 if (item.uidEditor >= num)
453 {
454 num = item.uidEditor + 1;
455 }
456 }
457 c.Chara.uidEditor = num;
458 }
459 data.lv = c.LV;
460 data.element = c.c_idMainElement;
461 data.uidEditor = c.Chara.uidEditor;
462 }
463 TryAddStr(52);
464 cards.Add(data);
465 data.ints[0] = data._bits1.ToInt();
466 void TryAddStr(int key)
467 {
468 string str = c.GetStr(key);
469 if (!str.IsEmpty())
470 {
471 if (data.cstr == null)
472 {
473 data.cstr = new Dictionary<int, string>();
474 }
475 data.cstr[key] = str;
476 }
477 }
478 }
479
480 public void Restore(Map map, Map orgMap, bool addToZone, PartialMap partial = null)
481 {
482 List<Thing> things = map.things;
483 List<Chara> serializedCharas = map.serializedCharas;
484 bool isUserZone = EClass._zone.IsUserZone;
485 Dictionary<int, int> dictionary = new Dictionary<int, int>();
486 Dictionary<int, int> dictionary2 = new Dictionary<int, int>();
487 importedCards.Clear();
488 foreach (Data card4 in cards)
489 {
490 int num = card4.dir;
491 Point point = new Point(card4.x, card4.z);
492 int index = point.index;
493 if (partial != null)
494 {
495 if (partial.result.ruined.Contains(point.index))
496 {
497 continue;
498 }
499 num -= partial.dir;
500 int num2 = point.x - partial.offsetX;
501 int num3 = point.z - partial.offsetZ;
502 switch (partial.dir)
503 {
504 case 1:
505 {
506 int num5 = num2;
507 num2 = num3;
508 num3 = -num5;
509 break;
510 }
511 case 2:
512 num2 = -num2;
513 num3 = -num3;
514 break;
515 case 3:
516 {
517 int num4 = num2;
518 num2 = -num3;
519 num3 = num4;
520 break;
521 }
522 }
523 point.x = num2 + partial.destX;
524 point.z = num3 + partial.destZ;
525 if (!partial.validPoints.Contains(point.index) || !point.IsValid)
526 {
527 continue;
528 }
529 if (!partial.editMode)
530 {
531 Card card = null;
532 string id = card4.id;
533 if (!(id == "sign_spawnThing"))
534 {
535 if (id == "sign_spawnChara")
536 {
538 }
539 }
540 else
541 {
543 }
544 if (card != null)
545 {
546 card.pos = point;
548 if (card.trait.IsDoor)
549 {
550 EClass._map.OnSetBlockOrDoor(card.pos.x, card.pos.z);
551 }
552 continue;
553 }
554 }
555 }
556 card4._bits1.SetInt(card4.ints[0]);
557 string text = card4.id;
558 if (card4.idV != 0)
559 {
560 text = card4.idV.ToString() ?? "";
561 }
562 if (addToZone && partial != null && !partial.editMode)
563 {
564 string id = card4.id;
565 if (!(id == "editor_torch"))
566 {
567 if (id == "editor_torch_wall")
568 {
569 text = EClass._zone.biome.style.GetIdLight(wall: true);
570 }
571 }
572 else
573 {
574 text = EClass._zone.biome.style.GetIdLight(wall: false);
575 }
576 }
577 CardRow source = EClass.sources.cards.map.TryGetValue(text);
578 if (source == null)
579 {
580 continue;
581 }
582 Card card2 = null;
583 if (source.isChara)
584 {
585 if (orgMap != null)
586 {
587 bool flag = false;
588 if (source.quality >= 4)
589 {
590 foreach (Chara value2 in EClass.game.cards.globalCharas.Values)
591 {
592 if (value2.id == text)
593 {
594 flag = true;
595 break;
596 }
597 }
598 }
599 if (!flag)
600 {
601 foreach (Chara item in orgMap.charas.Concat(orgMap.serializedCharas).Concat(orgMap.deadCharas))
602 {
603 if (source.quality >= 4 && item.id == text)
604 {
605 flag = true;
606 break;
607 }
608 if (item.id == text && item.orgPos != null && item.orgPos.Equals(point))
609 {
610 flag = true;
611 break;
612 }
613 }
614 }
615 if (flag)
616 {
617 continue;
618 }
619 }
620 if (isUserZone && ClassExtension.TryGetValue<int, int>((IDictionary<int, int>)dictionary, index, 0) >= 3)
621 {
622 continue;
623 }
624 card2 = CharaGen.Create(text);
625 if (card4.ints.Length > 20)
626 {
627 card2.Chara.SetLv(card4.lv);
628 if (card4.element != 0)
629 {
630 card2.Chara.SetMainElement(card4.element);
631 }
632 }
633 card2.Chara.orgPos = point.Copy();
634 if (card4.isDead)
635 {
636 card2.hp = -1;
637 card2.Chara.isDead = true;
638 }
639 card2.Chara.hunger.value = EClass.rnd(EClass.rnd(20) + 1);
640 if (!addToZone)
641 {
642 serializedCharas.Add(card2.Chara);
643 }
644 if (isUserZone)
645 {
646 dictionary[index] = ClassExtension.TryGetValue<int, int>((IDictionary<int, int>)dictionary, index, 0) + 1;
647 }
648 }
649 else
650 {
651 PlaceState placeState = card4.placeState.ToEnum<PlaceState>();
652 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"))
653 {
654 continue;
655 }
656 if (source.isOrigin)
657 {
658 text = SpawnListThing.Get("origin_" + text, (SourceThing.Row a) => a.origin == source).GetFirst().id;
659 }
660 card2 = ThingGen.Create(text, -1, EClass._zone.DangerLv);
661 card2.ChangeMaterial((card4.idMat == -1) ? card2.DefaultMaterial.id : card4.idMat);
662 if (!addToZone)
663 {
664 things.Add(card2.Thing);
665 }
666 card2.altitude = card4.altitude;
667 card2.placeState = placeState;
668 card2.c_lightColor = card4.lightColor;
669 if (isUserZone)
670 {
671 dictionary2[index] = ClassExtension.TryGetValue<int, int>((IDictionary<int, int>)dictionary2, index, 0) + 1;
672 }
673 }
674 if (num < 0)
675 {
676 num = Mathf.Abs(card2.sourceCard.tiles.Length + num);
677 }
678 card2.pos = point;
679 card2.dir = num;
680 card2._bits1.SetInt(card4.bits1);
681 card2._bits2.SetInt(card4.bits2);
682 card2.isPlayerCreation = true;
683 card2.autoRefuel = true;
684 card2.c_editorTraitVal = card4.traitVals;
685 card2.c_idRefCard = card4.idRefCard;
686 card2.isImported = true;
687 card2.refVal = card4.refVal;
688 card2.idSkin = card4.idSkin;
689 card2.c_idDeity = card4.idDeity;
690 if (card4.idBacker != 0)
691 {
692 Debug.Log(card4.idBacker);
693 card2.c_idBacker = card4.idBacker;
694 }
695 if (version >= 2 && card4.idDyeMat != -1)
696 {
697 card2.Dye(EClass.sources.materials.rows[card4.idDyeMat]);
698 }
699 card2.mapObj = card4.obj;
700 if (card2.mapObj?.TryGetValue(2) != null)
701 {
702 card2.mapObj.Remove(2);
703 }
704 if (card4.cstr != null)
705 {
706 foreach (KeyValuePair<int, string> item2 in card4.cstr)
707 {
708 card2.SetStr(item2.Key, item2.Value);
709 }
710 }
711 if (card2.freePos)
712 {
713 card2.fx = (float)card4.fx * 0.001f;
714 card2.fy = (float)card4.fy * 0.001f;
715 }
716 if (!card4.idEditor.IsEmpty())
717 {
718 card2.c_idEditor = card4.idEditor;
719 }
720 if (!card4.idTrait.IsEmpty())
721 {
722 card2.c_idTrait = card4.idTrait;
723 card2.ApplyTrait();
725 }
726 if (!card4.tags.IsEmpty())
727 {
728 card2.c_editorTags = card4.tags;
729 try
730 {
731 string[] array = card4.tags.Split(',');
732 foreach (string value in array)
733 {
734 card2.ApplyEditorTags(value.ToEnum<EditorTag>());
735 }
736 }
737 catch
738 {
739 Debug.LogWarning("Could not convert editor tag:" + card2.Name + "/" + card4.tags);
740 }
741 }
742 if (isUserZone)
743 {
744 if ((card2.isHidden || card2.isMasked) && ((card2.TileType.IsBlockPass && card2.IsInstalled) || card2.trait is TraitCoreZone || card2.trait is TraitWaystone))
745 {
746 Card card3 = card2;
747 bool isHidden = (card2.isMasked = false);
748 card3.isHidden = isHidden;
749 }
750 if (card2.IsContainer && card4.isEmpty)
751 {
752 card2.things.DestroyAll();
753 }
754 }
755 if (card2.isChara)
756 {
757 card2.Chara.homeZone = EClass._zone;
758 card2.Chara.uidEditor = card4.uidEditor;
759 if (card2.isBackerContent)
760 {
761 card2.ApplyBacker(card2.c_idBacker);
762 }
763 card2.SetObj(5, null);
764 }
765 if (addToZone)
766 {
767 EClass._zone.AddCard(card2, card2.pos);
768 if (card2.trait.IsDoor)
769 {
770 EClass._map.OnSetBlockOrDoor(card2.pos.x, card2.pos.z);
771 }
772 if (partial != null && !card2.sourceCard.lightData.IsEmpty())
773 {
774 partial.result.hasLight = true;
775 }
776 }
777 importedCards.Add(card2);
778 }
779 foreach (Card importedCard in importedCards)
780 {
781 if (importedCard.trait is TraitShackle)
782 {
783 foreach (Card importedCard2 in importedCards)
784 {
785 if (importedCard2.isRestrained && importedCard2.pos.Equals(importedCard.pos))
786 {
787 importedCard.c_uidRefCard = importedCard2.uid;
788 }
789 }
790 }
791 importedCard.trait.OnImportMap();
792 }
793 }
794}
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:75
virtual Chara Chara
Definition: Card.cs:1946
bool isMasked
Definition: Card.cs:562
int c_idMainElement
Definition: Card.cs:1337
string id
Definition: Card.cs:31
bool isRestrained
Definition: Card.cs:538
float fy
Definition: Card.cs:250
SourceMaterial.Row material
Definition: Card.cs:1927
string c_idDeity
Definition: Card.cs:1481
Card ChangeMaterial(int idNew, bool ignoreFixedMaterial=false)
Definition: Card.cs:2838
string c_idTrait
Definition: Card.cs:1625
virtual SourceMaterial.Row DefaultMaterial
Definition: Card.cs:2281
BitArray32 _bits2
Definition: Card.cs:77
Card SetLv(int a)
Definition: Card.cs:2735
string Name
Definition: Card.cs:2013
PlaceState placeState
Definition: Card.cs:79
string c_idEditor
Definition: Card.cs:1589
Point pos
Definition: Card.cs:55
string c_editorTags
Definition: Card.cs:1601
int c_lightColor
Definition: Card.cs:1056
int uid
Definition: Card.cs:118
void Dye(string idMat)
Definition: Card.cs:5267
int refVal
Definition: Card.cs:190
void ApplyTrait()
Definition: Card.cs:2714
Trait trait
Definition: Card.cs:49
virtual void ApplyEditorTags(EditorTag tag)
Definition: Card.cs:2689
int altitude
Definition: Card.cs:214
int c_idBacker
Definition: Card.cs:1361
ThingContainer things
Definition: Card.cs:34
bool IsInstalled
Definition: Card.cs:2241
virtual bool isChara
Definition: Card.cs:1959
virtual Thing Thing
Definition: Card.cs:1934
bool isHidden
Definition: Card.cs:502
int idSkin
Definition: Card.cs:346
int dir
Definition: Card.cs:142
void ApplyBacker(int bid)
Definition: Card.cs:6193
virtual CardRow sourceCard
Definition: Card.cs:2007
Thing Add(string id, int num=1, int lv=1)
Definition: Card.cs:2878
bool IsContainer
Definition: Card.cs:1965
bool freePos
Definition: Card.cs:490
string c_editorTraitVal
Definition: Card.cs:1613
int LV
Definition: Card.cs:370
bool isBackerContent
Definition: Card.cs:885
string c_idRefCard
Definition: Card.cs:1637
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:1804
int uidEditor
Definition: Chara.cs:338
Point orgPos
Definition: Chara.cs:21
bool isDead
Definition: Chara.cs:374
Definition: EClass.cs:5
static Game game
Definition: EClass.cs:8
static int rnd(int a)
Definition: EClass.cs:50
static Zone _zone
Definition: EClass.cs:20
static Map _map
Definition: EClass.cs:18
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:1018
List< Chara > charas
Definition: Map.cs:81
Definition: Point.cs:9
int index
Definition: Point.cs:49
Point Copy()
Definition: Point.cs:467
int x
Definition: Point.cs:36
int z
Definition: Point.cs:39
bool Equals(int _x, int _z)
Definition: Point.cs:924
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:606
virtual bool IsDoor
Definition: Trait.cs:56
virtual void OnCreate(int lv)
Definition: Trait.cs:618
BiomeProfile biome
Definition: Zone.cs:126
virtual bool IsUserZone
Definition: Zone.cs:264
override int DangerLv
Definition: Zone.cs:107
Card AddCard(Card t, Point point)
Definition: Zone.cs:1893
void SetInt(int i)
Definition: BitArray32.cs:89
int ToInt()
Definition: BitArray32.cs:84