Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
DNA.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Runtime.Serialization;
4using Newtonsoft.Json;
5using UnityEngine;
6
7public class DNA : EClass
8{
9 public enum Type
10 {
11 Inferior = 0,
12 Default = 3,
13 Superior = 5,
14 Brain = 8
15 }
16
17 [JsonProperty]
18 public string id;
19
20 [JsonProperty]
21 public int[] ints = new int[6];
22
23 [JsonProperty]
24 public List<int> vals = new List<int>();
25
27
28 public Type type
29 {
30 get
31 {
32 return ints[0].ToEnum<Type>();
33 }
34 set
35 {
36 ints[0] = (int)value;
37 }
38 }
39
40 public int cost
41 {
42 get
43 {
44 return ints[1];
45 }
46 set
47 {
48 ints[1] = value;
49 }
50 }
51
52 public int lv
53 {
54 get
55 {
56 return ints[2];
57 }
58 set
59 {
60 ints[2] = value;
61 }
62 }
63
64 public int seed
65 {
66 get
67 {
68 return ints[3];
69 }
70 set
71 {
72 ints[3] = value;
73 }
74 }
75
76 public int slot
77 {
78 get
79 {
80 return ints[5];
81 }
82 set
83 {
84 ints[5] = value;
85 }
86 }
87
88 [OnSerializing]
89 private void _OnSerializing(StreamingContext context)
90 {
91 ints[4] = bits.ToInt();
92 }
93
94 [OnDeserialized]
95 private void _OnDeserialized(StreamingContext context)
96 {
97 if (ints.Length < 6)
98 {
99 Array.Resize(ref ints, 6);
100 slot = 1;
101 }
102 }
103
104 public static Thing GenerateGene(Chara c, Type? type = null)
105 {
106 Thing thing = ThingGen.Create((type == Type.Brain) ? "gene_brain" : "gene");
107 DNA dNA = new DNA();
108 thing.MakeRefFrom(c);
109 dNA.id = c.id;
110 dNA.lv = c.LV;
111 dNA.seed = EClass.rnd(20000);
112 thing.c_DNA = dNA;
113 dNA.GenerateWithGene(type ?? dNA.GetRandomType(), thing, c);
114 return thing;
115 }
116
117 public static Thing GenerateGene(CardRow r, Type? type = null, int lv = -1, int seed = -1)
118 {
119 Thing thing = ThingGen.Create((type == Type.Brain) ? "gene_brain" : "gene");
120 DNA dNA = new DNA();
121 thing.MakeRefFrom(r.id);
122 dNA.id = r.id;
123 dNA.lv = ((lv == -1) ? r.LV : lv);
124 dNA.seed = ((seed == -1) ? EClass.rnd(20000) : seed);
125 thing.c_DNA = dNA;
126 dNA.GenerateWithGene(type ?? dNA.GetRandomType(), thing);
127 return thing;
128 }
129
130 public static Thing CopyDNA(Thing from, Thing to)
131 {
132 to.c_DNA = from.c_DNA;
133 to.c_idRefCard = from.c_idRefCard;
134 to.ChangeMaterial(from.material);
135 return to;
136 }
137
138 public static Thing GenerateRandomGene(int lv = -1, int seed = -1)
139 {
140 if (lv == -1)
141 {
143 }
145 CardRow r = SpawnList.Get("chara").Select(100);
146 Rand.SetSeed();
147 return GenerateGene(r, Type.Superior, lv, seed);
148 }
149
150 public static Thing GenerateManiGene(Card owner)
151 {
152 owner.things.DestroyAll();
153 Debug.Log("Mani:" + owner.c_seed);
154 Rand.SetSeed(owner.c_seed);
155 CardRow r = SpawnList.Get("chara").Select(100);
156 Rand.SetSeed(owner.c_seed);
157 Thing thing = GenerateGene(r, Type.Superior, owner.LV, owner.c_seed);
158 thing.c_DNA.cost = thing.c_DNA.cost / 2;
159 thing.MakeRefFrom("mani");
160 Rand.SetSeed();
161 owner.c_seed++;
162 return thing;
163 }
164
165 public void Apply(Chara c)
166 {
167 if (c.c_genes == null)
168 {
169 c.c_genes = new CharaGenes();
170 }
171 CharaGenes c_genes = c.c_genes;
172 if (type == Type.Inferior)
173 {
174 c.c_genes.inferior++;
175 return;
176 }
177 c.feat -= cost;
178 Apply(c, reverse: false);
179 c_genes.items.Add(this);
180 }
181
182 public void Apply(Chara c, bool reverse)
183 {
184 if (type == Type.Brain)
185 {
186 c._tactics = null;
187 return;
188 }
189 for (int i = 0; i < vals.Count; i += 2)
190 {
191 int num = vals[i];
192 int num2 = vals[i + 1];
194 switch (row.category)
195 {
196 case "slot":
197 if (reverse)
198 {
199 c.body.RemoveBodyPart(row.id);
200 }
201 else
202 {
203 c.body.AddBodyPart(row.id);
204 }
206 break;
207 case "feat":
208 c.SetFeat(num, c.elements.ValueWithoutLink(num) + ((!reverse) ? 1 : (-1)), !reverse);
209 break;
210 case "ability":
211 if (reverse)
212 {
213 c.ability.Remove(num * ((num2 >= 0) ? 1 : (-1)));
214 }
215 else
216 {
217 c.ability.Add(num, Mathf.Abs(num2), num2 < 0);
218 }
219 break;
220 default:
221 if (!reverse && c.elements.ValueWithoutLink(row.id) == 0)
222 {
223 c.elements.Learn(row.id, num2);
224 }
225 else
226 {
227 c.elements.ModBase(num, reverse ? (-num2) : num2);
228 }
229 break;
230 }
231 }
232 }
233
234 public bool CanRemove()
235 {
236 for (int i = 0; i < vals.Count; i += 2)
237 {
238 int num = vals[i];
239 if (num == 1237 || num == 1415)
240 {
241 return false;
242 }
243 }
244 return true;
245 }
246
247 public void GenerateWithGene(Type _type, Card gene, Chara model = null)
248 {
249 Generate(_type, model);
251 gene.elements.SetTo(10, 0);
252 }
253
254 public void Generate(Type _type, Chara model = null)
255 {
256 type = _type;
257 cost = 0;
258 slot = 0;
259 vals.Clear();
260 Debug.Log(seed);
262 if (model == null)
263 {
264 model = CharaGen.Create(id);
265 if (lv > model.LV)
266 {
267 model.SetLv(lv);
268 }
269 }
270 if (type == Type.Inferior || model == null)
271 {
272 type = Type.Inferior;
273 return;
274 }
275 if (type == Type.Brain)
276 {
277 cost = 4;
278 return;
279 }
280 int body = 0;
281 int action = 0;
282 int feat = 0;
283 int maxSlot = 1;
284 List<Element> listAttb = model.elements.ListBestAttributes();
285 List<Element> listSkill = model.elements.ListBestSkills();
286 List<Element> listFeat = model.elements.ListGeneFeats();
288 if (listFeat.Count == 0)
289 {
290 listFeat = model.ListAvailabeFeats(pet: true);
291 }
293 switch (type)
294 {
295 case Type.Default:
296 AddRandom(EClass.rnd(EClass.rnd(4)) + 1);
297 if (EClass.rnd(3) == 0 || vals.Count == 0)
298 {
299 AddSpecial();
300 }
301 break;
302 case Type.Superior:
303 AddRandom(EClass.rnd(EClass.rnd(4)) + 3);
304 if (EClass.rnd(3) == 0)
305 {
306 AddSpecial();
307 }
308 AddSpecial();
309 break;
310 }
311 if (vals.Count == 0)
312 {
313 for (int i = 0; i < 10; i++)
314 {
315 if (EClass.rnd(4) == 0)
316 {
317 AddSpecial();
318 }
319 else
320 {
321 AddRandom(1);
322 }
323 if (vals.Count > 0)
324 {
325 break;
326 }
327 }
328 }
329 Rand.SetSeed();
330 CalcCost();
331 CalcSlot();
332 void AddAction()
333 {
334 if (model.ability.list.items.Count != 0)
335 {
336 ActList.Item a = model.ability.list.items.RandomItem();
337 if (!(a.act.source.category != "ability"))
338 {
339 AddVal(a.act.source.id, a.chance * ((!a.pt) ? 1 : (-1)), allowStack: false, (int v) => 8 + a.act.source.cost[0] / 10 * 2);
340 action++;
341 }
342 }
343 }
344 void AddAttribute()
345 {
346 Element element = listAttb[EClass.rnd(3)];
347 AddVal(element.id, EClass.rndHalf(element.ValueWithoutLink / 2), allowStack: true, (int v) => v / 5 + 1);
348 }
349 void AddBody()
350 {
351 if (body == 0)
352 {
353 BodySlot bodySlot = null;
354 for (int j = 0; j < 100; j++)
355 {
356 BodySlot bodySlot2 = model.body.slots.RandomItem();
357 if (bodySlot2 != null && bodySlot2.elementId != 40)
358 {
359 bodySlot = bodySlot2;
360 break;
361 }
362 }
363 if (bodySlot != null)
364 {
365 AddVal(bodySlot.elementId, 1, allowStack: false, (int v) => 20);
366 body++;
367 }
368 }
369 }
370 void AddFeat()
371 {
372 if (listFeat.Count != 0)
373 {
374 feat++;
375 Element e = listFeat.RandomItem();
376 if (maxSlot <= 1 || e.source.geneSlot <= 1)
377 {
378 if (e.source.geneSlot > maxSlot)
379 {
380 maxSlot = e.source.geneSlot;
381 }
382 AddVal(e.id, 1, allowStack: false, (int v) => e.source.cost[0] * 5);
383 }
384 }
385 }
386 void AddRandom(int n)
387 {
388 for (int l = 0; l < n; l++)
389 {
390 if (EClass.debug.enable && EClass.rnd(2) == 0)
391 {
392 AddSpecial();
393 }
394 else if (EClass.rnd(2) == 0)
395 {
396 AddSkill();
397 }
398 else
399 {
400 AddAttribute();
401 }
402 }
403 }
404 void AddSkill()
405 {
406 Element element2 = listSkill[Mathf.Clamp(EClass.rnd(6), 0, listSkill.Count - 1)];
407 AddVal(element2.id, EClass.rndHalf(element2.ValueWithoutLink / 2), allowStack: true, (int v) => v / 5 + 1);
408 }
409 void AddSpecial()
410 {
411 if (EClass.rnd(3) == 0)
412 {
413 AddAction();
414 }
415 else if (EClass.rnd(5) == 0)
416 {
417 AddBody();
418 }
419 else if (listFeat.Count > 0)
420 {
421 AddFeat();
422 }
423 else if (EClass.rnd(2) == 0)
424 {
425 AddSkill();
426 }
427 else
428 {
429 AddAttribute();
430 }
431 }
432 void AddVal(int id, int v, bool allowStack, Func<int, int> funcCost)
433 {
434 bool flag = false;
435 int num = EClass.curve(v, 20, 10, 90);
436 v = EClass.curve(v, 20, 10, 80);
437 for (int k = 0; k < vals.Count; k += 2)
438 {
439 if (vals[k] == id)
440 {
441 if (allowStack)
442 {
443 v /= 2;
444 num /= 2;
445 vals[k + 1] += v;
446 Debug.Log(vals[k + 1] + ": " + v + "/" + num);
447 flag = true;
448 break;
449 }
450 return;
451 }
452 }
453 if (v != 0)
454 {
455 if (!flag)
456 {
457 vals.Add(id);
458 vals.Add(v);
459 }
460 cost += Mathf.Max(0, funcCost(num));
461 }
462 }
463 }
464
465 public void CalcCost()
466 {
467 if (cost < 0)
468 {
469 cost = 0;
470 }
471 }
472
473 public void CalcSlot()
474 {
475 slot = 0;
476 for (int i = 0; i < vals.Count; i += 2)
477 {
478 Element element = Element.Create(vals[i], vals[i + 1]);
479 if (element.source.geneSlot < 0)
480 {
481 slot = 99;
482 }
483 if (element.source.geneSlot > slot)
484 {
485 slot = element.source.geneSlot;
486 }
487 }
488 if (slot < 0)
489 {
490 slot = 0;
491 }
492 }
493
494 public static Type GetType(string idMat)
495 {
496 return idMat switch
497 {
498 "jelly" => Type.Default,
499 "gold" => Type.Superior,
500 "amethyst" => Type.Brain,
501 _ => Type.Inferior,
502 };
503 }
504
505 public string GetMaterialId(Type type)
506 {
507 return type switch
508 {
509 Type.Default => "jelly",
510 Type.Superior => "gold",
511 Type.Brain => "amethyst",
512 _ => "process",
513 };
514 }
515
516 public int GetDurationHour()
517 {
518 return cost * cost / 2;
519 }
520
522 {
523 if (EClass.rnd(5) == 0)
524 {
525 return Type.Superior;
526 }
527 if (EClass.rnd(10) == 0)
528 {
529 return Type.Inferior;
530 }
531 return Type.Default;
532 }
533
534 public string GetText()
535 {
536 return "gene".lang((EClass.sources.cards.map.TryGetValue(id)?.GetName() ?? "???").ToTitleCase(), cost.ToString() ?? "");
537 }
538
539 public void WriteNote(UINote n)
540 {
541 if (slot >= 1)
542 {
543 n.AddText("isGeneReqSlots".lang(slot.ToString() ?? ""), FontColor.Warning);
544 }
545 if (!CanRemove())
546 {
547 n.AddText("isPermaGene".lang(), FontColor.Warning);
548 }
549 n.Space(4);
550 if (type == Type.Brain)
551 {
552 SourceChara.Row row = EClass.sources.charas.map.TryGetValue(id);
553 if (row != null)
554 {
555 string key = row.tactics.IsEmpty(EClass.sources.tactics.map.TryGetValue(row.id)?.id ?? EClass.sources.tactics.map.TryGetValue(row.job)?.id ?? "predator");
556 n.AddText("gene_info".lang(EClass.sources.tactics.map[key].GetName().ToTitleCase(), ""), FontColor.ButtonGeneral);
557 }
558 for (int i = 0; i < vals.Count; i += 2)
559 {
560 int num = vals[i];
561 int num2 = vals[i + 1];
562 FontColor color = ((num2 >= 0) ? FontColor.Good : FontColor.Bad);
563 string @ref = (num + 1).ToString() ?? "";
564 string text = "";
565 num2 = Mathf.Abs(num2 / 20) + 1;
566 text = text + "[" + "*".Repeat(Mathf.Clamp(num2, 1, 5)) + ((num2 > 5) ? "+" : "") + "]";
567 n.AddText("gene_info_brain".lang(@ref, text), color);
568 }
569 return;
570 }
571 for (int j = 0; j < vals.Count; j += 2)
572 {
573 Element element = Element.Create(vals[j], vals[j + 1]);
574 string text2 = "";
575 int num3 = element.Value / 10;
576 FontColor color2 = FontColor.Good;
577 switch (element.source.category)
578 {
579 case "slot":
580 color2 = FontColor.Myth;
581 num3 = -1;
582 break;
583 case "feat":
584 color2 = FontColor.FoodMisc;
585 num3 = -1;
586 break;
587 case "ability":
588 color2 = FontColor.Topic2;
589 num3 = -1;
590 break;
591 }
592 if (num3 >= 0)
593 {
594 text2 = text2 + "[" + "*".Repeat(Mathf.Clamp(num3, 1, 5)) + ((num3 > 5) ? "+" : "") + "]";
595 }
597 {
598 text2 = text2 + " " + element.Value;
599 }
600 n.AddText("gene_info".lang(element.Name.ToTitleCase(wholeText: true), text2), color2);
601 }
602 }
603
605 {
606 for (int i = 0; i < vals.Count; i += 2)
607 {
608 Element element = Element.Create(vals[i], vals[i + 1]);
609 if (element.source.category == "feat" && c.Evalue(element.id) >= element.source.max)
610 {
611 return element;
612 }
613 }
614 return null;
615 }
616
618 {
619 for (int i = 0; i < vals.Count; i += 2)
620 {
621 Element element = Element.Create(vals[i], vals[i + 1]);
622 if (!(element.source.category == "ability"))
623 {
624 continue;
625 }
626 foreach (ActList.Item item in c.ability.list.items)
627 {
628 if (item.act.source.id == element.id)
629 {
630 return element;
631 }
632 }
633 }
634 return null;
635 }
636}
FontColor
Definition: FontColor.cs:2
int chance
Definition: ActList.cs:9
bool pt
Definition: ActList.cs:11
Act act
Definition: ActList.cs:7
List< Item > items
Definition: ActList.cs:14
int elementId
Definition: BodySlot.cs:6
string id
Definition: CardRow.cs:7
Definition: Card.cs:11
void MakeRefFrom(string id)
Definition: Card.cs:5094
ElementContainerCard elements
Definition: Card.cs:37
string id
Definition: Card.cs:31
SourceMaterial.Row material
Definition: Card.cs:1927
Card ChangeMaterial(int idNew, bool ignoreFixedMaterial=false)
Definition: Card.cs:2838
Card SetLv(int a)
Definition: Card.cs:2735
int c_seed
Definition: Card.cs:1241
CharaGenes c_genes
Definition: Card.cs:1745
ThingContainer things
Definition: Card.cs:34
int Evalue(int ele)
Definition: Card.cs:2431
DNA c_DNA
Definition: Card.cs:1781
int LV
Definition: Card.cs:370
string c_idRefCard
Definition: Card.cs:1637
ActList list
Definition: CharaAbility.cs:12
void Add(int id, int chance, bool pt)
void Remove(int id)
void AddBodyPart(int ele, Thing thing=null)
Definition: CharaBody.cs:261
void RefreshBodyParts()
Definition: CharaBody.cs:287
void RemoveBodyPart(int ele)
Definition: CharaBody.cs:310
static Chara Create(string id, int lv=-1)
Definition: CharaGen.cs:17
int inferior
Definition: CharaGenes.cs:10
List< DNA > items
Definition: CharaGenes.cs:7
Definition: Chara.cs:10
CharaBody body
Definition: Chara.cs:91
void SetFeat(int id, int value=1, bool msg=false)
Definition: Chara.cs:8964
CharaAbility ability
Definition: Chara.cs:409
bool showExtra
Definition: CoreDebug.cs:167
bool enable
Definition: CoreDebug.cs:285
Definition: DNA.cs:8
void Apply(Chara c, bool reverse)
Definition: DNA.cs:182
string id
Definition: DNA.cs:18
Type type
Definition: DNA.cs:29
int cost
Definition: DNA.cs:41
void GenerateWithGene(Type _type, Card gene, Chara model=null)
Definition: DNA.cs:247
void _OnDeserialized(StreamingContext context)
Definition: DNA.cs:95
Element GetInvalidFeat(Chara c)
Definition: DNA.cs:604
int seed
Definition: DNA.cs:65
static Thing GenerateGene(CardRow r, Type? type=null, int lv=-1, int seed=-1)
Definition: DNA.cs:117
void _OnSerializing(StreamingContext context)
Definition: DNA.cs:89
Type
Definition: DNA.cs:10
Type GetRandomType()
Definition: DNA.cs:521
static Thing CopyDNA(Thing from, Thing to)
Definition: DNA.cs:130
static Thing GenerateRandomGene(int lv=-1, int seed=-1)
Definition: DNA.cs:138
int slot
Definition: DNA.cs:77
static Type GetType(string idMat)
Definition: DNA.cs:494
int[] ints
Definition: DNA.cs:21
BitArray32 bits
Definition: DNA.cs:26
static Thing GenerateManiGene(Card owner)
Definition: DNA.cs:150
void CalcSlot()
Definition: DNA.cs:473
string GetMaterialId(Type type)
Definition: DNA.cs:505
void Generate(Type _type, Chara model=null)
Definition: DNA.cs:254
void Apply(Chara c)
Definition: DNA.cs:165
int GetDurationHour()
Definition: DNA.cs:516
void CalcCost()
Definition: DNA.cs:465
bool CanRemove()
Definition: DNA.cs:234
int lv
Definition: DNA.cs:53
string GetText()
Definition: DNA.cs:534
static Thing GenerateGene(Chara c, Type? type=null)
Definition: DNA.cs:104
List< int > vals
Definition: DNA.cs:24
Element GetInvalidAction(Chara c)
Definition: DNA.cs:617
void WriteNote(UINote n)
Definition: DNA.cs:539
Definition: EClass.cs:5
static int curve(int a, int start, int step, int rate=75)
Definition: EClass.cs:55
static int rnd(int a)
Definition: EClass.cs:50
static Zone _zone
Definition: EClass.cs:20
static SourceManager sources
Definition: EClass.cs:42
static int rndHalf(int a)
Definition: EClass.cs:74
static CoreDebug debug
Definition: EClass.cs:48
void Learn(int ele, int v=1)
int ValueWithoutLink(int ele)
Element ModBase(int ele, int v)
void SetTo(int id, int v)
int ValueWithoutLink
Definition: ELEMENT.cs:284
int id
Definition: ELEMENT.cs:240
SourceElement.Row source
Definition: ELEMENT.cs:263
int Value
Definition: ELEMENT.cs:282
virtual string Name
Definition: ELEMENT.cs:294
static Element Create(int id, int v=0)
Definition: ELEMENT.cs:913
Definition: Rand.cs:4
static void SetSeed(int a=-1)
Definition: Rand.cs:37
int LV
Definition: RenderRow.cs:22
Dictionary< string, CardRow > map
Definition: SourceCard.cs:8
SourceCard cards
SourceElement elements
SourceChara charas
SourceTactics tactics
static SpawnList Get(string id, string parent=null, CardFilter filter=null)
Definition: SpawnList.cs:18
CardRow Select(int lv=-1, int levelRange=-1)
Definition: SpawnList.cs:139
void DestroyAll(Func< Thing, bool > funcExclude=null)
static Thing Create(string id, int idMat=-1, int lv=-1)
Definition: ThingGen.cs:53
Definition: Thing.cs:8
Definition: UINote.cs:6
UIItem AddText(string text, FontColor color=FontColor.DontChange)
Definition: UINote.cs:113
void Space(int sizeY=0, int sizeX=1)
Definition: UINote.cs:62
override int ContentLv
Definition: Zone.cs:95
int ToInt()
Definition: BitArray32.cs:84