Elin Modding Docs Doc
Loading...
Searching...
No Matches
DNA.cs
1using System;
2using System.Collections.Generic;
3using System.Runtime.CompilerServices;
4using Newtonsoft.Json;
5using UnityEngine;
6
7// Token: 0x02000298 RID: 664
8public class DNA : EClass
9{
10 // Token: 0x1700059E RID: 1438
11 // (get) Token: 0x060013DD RID: 5085 RVA: 0x000826FB File Offset: 0x000808FB
12 // (set) Token: 0x060013DE RID: 5086 RVA: 0x0008270A File Offset: 0x0008090A
13 public DNA.Type type
14 {
15 get
16 {
17 return this.ints[0].ToEnum<DNA.Type>();
18 }
19 set
20 {
21 this.ints[0] = (int)value;
22 }
23 }
24
25 // Token: 0x1700059F RID: 1439
26 // (get) Token: 0x060013DF RID: 5087 RVA: 0x00082715 File Offset: 0x00080915
27 // (set) Token: 0x060013E0 RID: 5088 RVA: 0x0008271F File Offset: 0x0008091F
28 public int cost
29 {
30 get
31 {
32 return this.ints[1];
33 }
34 set
35 {
36 this.ints[1] = value;
37 }
38 }
39
40 // Token: 0x170005A0 RID: 1440
41 // (get) Token: 0x060013E1 RID: 5089 RVA: 0x0008272A File Offset: 0x0008092A
42 // (set) Token: 0x060013E2 RID: 5090 RVA: 0x00082734 File Offset: 0x00080934
43 public int lv
44 {
45 get
46 {
47 return this.ints[2];
48 }
49 set
50 {
51 this.ints[2] = value;
52 }
53 }
54
55 // Token: 0x170005A1 RID: 1441
56 // (get) Token: 0x060013E3 RID: 5091 RVA: 0x0008273F File Offset: 0x0008093F
57 // (set) Token: 0x060013E4 RID: 5092 RVA: 0x00082749 File Offset: 0x00080949
58 public int seed
59 {
60 get
61 {
62 return this.ints[3];
63 }
64 set
65 {
66 this.ints[3] = value;
67 }
68 }
69
70 // Token: 0x060013E5 RID: 5093 RVA: 0x00082754 File Offset: 0x00080954
71 public static Thing GenerateGene(Chara c, DNA.Type? type = null)
72 {
73 DNA.Type? type2 = type;
74 DNA.Type type3 = DNA.Type.Brain;
75 Thing thing = ThingGen.Create((type2.GetValueOrDefault() == type3 & type2 != null) ? "gene_brain" : "gene", -1, -1);
76 DNA dna = new DNA();
77 thing.MakeRefFrom(c, null);
78 dna.id = c.id;
79 dna.lv = c.LV;
80 dna.seed = EClass.rnd(20000);
81 thing.c_DNA = dna;
82 dna.GenerateWithGene(type ?? dna.GetRandomType(), thing, c);
83 return thing;
84 }
85
86 // Token: 0x060013E6 RID: 5094 RVA: 0x000827F0 File Offset: 0x000809F0
87 public static Thing GenerateGene(CardRow r, DNA.Type? type = null, int lv = -1, int seed = -1)
88 {
89 DNA.Type? type2 = type;
90 DNA.Type type3 = DNA.Type.Brain;
91 Thing thing = ThingGen.Create((type2.GetValueOrDefault() == type3 & type2 != null) ? "gene_brain" : "gene", -1, -1);
92 DNA dna = new DNA();
93 thing.MakeRefFrom(r.id);
94 dna.id = r.id;
95 dna.lv = ((lv == -1) ? r.LV : lv);
96 dna.seed = ((seed == -1) ? EClass.rnd(20000) : seed);
97 thing.c_DNA = dna;
98 dna.GenerateWithGene(type ?? dna.GetRandomType(), thing, null);
99 return thing;
100 }
101
102 // Token: 0x060013E7 RID: 5095 RVA: 0x0008289C File Offset: 0x00080A9C
103 public void Apply(Chara c)
104 {
105 if (c.c_genes == null)
106 {
107 c.c_genes = new CharaGenes();
108 }
109 CharaGenes c_genes = c.c_genes;
110 if (this.type == DNA.Type.Inferior)
111 {
112 c.c_genes.inferior++;
113 return;
114 }
115 c.feat -= this.cost;
116 this.Apply(c, false);
117 c_genes.items.Add(this);
118 }
119
120 // Token: 0x060013E8 RID: 5096 RVA: 0x00082908 File Offset: 0x00080B08
121 public void Apply(Chara c, bool reverse)
122 {
123 if (this.type == DNA.Type.Brain)
124 {
125 c._tactics = null;
126 return;
127 }
128 for (int i = 0; i < this.vals.Count; i += 2)
129 {
130 int num = this.vals[i];
131 int num2 = this.vals[i + 1];
132 SourceElement.Row row = EClass.sources.elements.map[num];
133 string category = row.category;
134 if (!(category == "slot"))
135 {
136 if (!(category == "feat"))
137 {
138 if (!(category == "ability"))
139 {
140 if (!reverse && c.elements.ValueWithoutLink(row.id) == 0)
141 {
142 c.elements.Learn(row.id, num2);
143 }
144 else
145 {
146 c.elements.ModBase(num, reverse ? (-num2) : num2);
147 }
148 }
149 else if (reverse)
150 {
151 c.ability.Remove(num * ((num2 < 0) ? -1 : 1));
152 }
153 else
154 {
155 c.ability.Add(num, Mathf.Abs(num2), num2 < 0);
156 }
157 }
158 else
159 {
160 c.SetFeat(num, c.elements.ValueWithoutLink(num) + (reverse ? -1 : 1), true);
161 }
162 }
163 else
164 {
165 if (reverse)
166 {
167 c.body.RemoveBodyPart(row.id);
168 }
169 else
170 {
171 c.body.AddBodyPart(row.id, null);
172 }
173 c.body.RefreshBodyParts();
174 }
175 }
176 }
177
178 // Token: 0x060013E9 RID: 5097 RVA: 0x00082A72 File Offset: 0x00080C72
179 public void GenerateWithGene(DNA.Type _type, Card gene, Chara model = null)
180 {
181 this.Generate(_type, model);
182 gene.ChangeMaterial(this.GetMaterialId(this.type));
183 gene.elements.SetTo(10, 0);
184 }
185
186 // Token: 0x060013EA RID: 5098 RVA: 0x00082AA0 File Offset: 0x00080CA0
187 public void Generate(DNA.Type _type, Chara model = null)
188 {
189 DNA.<>c__DisplayClass21_0 CS$<>8__locals1;
190 CS$<>8__locals1.<>4__this = this;
191 CS$<>8__locals1.model = model;
192 this.type = _type;
193 this.cost = 0;
194 this.vals.Clear();
195 Debug.Log(this.seed);
196 Rand.SetSeed(this.seed);
197 if (CS$<>8__locals1.model == null)
198 {
199 CS$<>8__locals1.model = CharaGen.Create(this.id, this.lv);
200 }
201 if (this.type == DNA.Type.Inferior || CS$<>8__locals1.model == null)
202 {
203 this.type = DNA.Type.Inferior;
204 return;
205 }
206 if (this.type == DNA.Type.Brain)
207 {
208 this.cost = 4;
209 return;
210 }
211 CS$<>8__locals1.body = 0;
212 CS$<>8__locals1.action = 0;
213 CS$<>8__locals1.feat = 0;
214 CS$<>8__locals1.listAttb = CS$<>8__locals1.model.elements.ListBestAttributes();
215 CS$<>8__locals1.listSkill = CS$<>8__locals1.model.elements.ListBestSkills();
216 CS$<>8__locals1.listFeat = CS$<>8__locals1.model.elements.ListGeneFeats();
217 Rand.SetSeed(this.seed);
218 if (CS$<>8__locals1.listFeat.Count == 0)
219 {
220 CS$<>8__locals1.listFeat = CS$<>8__locals1.model.ListAvailabeFeats(true);
221 }
222 Rand.SetSeed(this.seed);
223 DNA.Type type = this.type;
224 if (type != DNA.Type.Default)
225 {
226 if (type == DNA.Type.Superior)
227 {
228 this.<Generate>g__AddRandom|21_6(EClass.rnd(EClass.rnd(4)) + 3, ref CS$<>8__locals1);
229 if (EClass.rnd(3) == 0)
230 {
231 this.<Generate>g__AddSpecial|21_7(ref CS$<>8__locals1);
232 }
233 this.<Generate>g__AddSpecial|21_7(ref CS$<>8__locals1);
234 }
235 }
236 else
237 {
238 this.<Generate>g__AddRandom|21_6(EClass.rnd(EClass.rnd(4)) + 1, ref CS$<>8__locals1);
239 if (EClass.rnd(3) == 0 || this.vals.Count == 0)
240 {
241 this.<Generate>g__AddSpecial|21_7(ref CS$<>8__locals1);
242 }
243 }
244 if (this.vals.Count == 0)
245 {
246 for (int i = 0; i < 10; i++)
247 {
248 if (EClass.rnd(4) == 0)
249 {
250 this.<Generate>g__AddSpecial|21_7(ref CS$<>8__locals1);
251 }
252 else
253 {
254 this.<Generate>g__AddRandom|21_6(1, ref CS$<>8__locals1);
255 }
256 if (this.vals.Count > 0)
257 {
258 break;
259 }
260 }
261 }
262 Rand.SetSeed(-1);
263 this.CalcCost();
264 }
265
266 // Token: 0x060013EB RID: 5099 RVA: 0x00082C90 File Offset: 0x00080E90
267 public void CalcCost()
268 {
269 for (int i = 0; i < this.vals.Count; i += 2)
270 {
271 Element.Create(this.vals[i], this.vals[i + 1]);
272 }
273 }
274
275 // Token: 0x060013EC RID: 5100 RVA: 0x00082CD3 File Offset: 0x00080ED3
276 public static DNA.Type GetType(string idMat)
277 {
278 if (idMat == "jelly")
279 {
280 return DNA.Type.Default;
281 }
282 if (idMat == "gold")
283 {
284 return DNA.Type.Superior;
285 }
286 if (!(idMat == "amethyst"))
287 {
288 return DNA.Type.Inferior;
289 }
290 return DNA.Type.Brain;
291 }
292
293 // Token: 0x060013ED RID: 5101 RVA: 0x00082D05 File Offset: 0x00080F05
294 public string GetMaterialId(DNA.Type type)
295 {
296 if (type == DNA.Type.Default)
297 {
298 return "jelly";
299 }
300 if (type == DNA.Type.Superior)
301 {
302 return "gold";
303 }
304 if (type != DNA.Type.Brain)
305 {
306 return "process";
307 }
308 return "amethyst";
309 }
310
311 // Token: 0x060013EE RID: 5102 RVA: 0x00082D2C File Offset: 0x00080F2C
312 public int GetDurationHour()
313 {
314 return this.cost * this.cost / 2;
315 }
316
317 // Token: 0x060013EF RID: 5103 RVA: 0x00082D3D File Offset: 0x00080F3D
318 public DNA.Type GetRandomType()
319 {
320 if (EClass.rnd(5) == 0)
321 {
322 return DNA.Type.Superior;
323 }
324 if (EClass.rnd(10) == 0)
325 {
326 return DNA.Type.Inferior;
327 }
328 return DNA.Type.Default;
329 }
330
331 // Token: 0x060013F0 RID: 5104 RVA: 0x00082D58 File Offset: 0x00080F58
332 public string GetText()
333 {
334 string s = "gene";
335 CardRow cardRow = EClass.sources.cards.map.TryGetValue(this.id, null);
336 return s.lang((((cardRow != null) ? cardRow.GetName() : null) ?? "???").ToTitleCase(false), this.cost.ToString() ?? "", null, null, null);
337 }
338
339 // Token: 0x060013F1 RID: 5105 RVA: 0x00082DC0 File Offset: 0x00080FC0
340 public void WriteNote(UINote n)
341 {
342 if (this.type == DNA.Type.Brain)
343 {
344 SourceChara.Row row = EClass.sources.charas.map.TryGetValue(this.id, null);
345 if (row != null)
346 {
347 string tactics = row.tactics;
348 SourceTactics.Row row2 = EClass.sources.tactics.map.TryGetValue(row.id, null);
349 string defaultStr;
350 if ((defaultStr = ((row2 != null) ? row2.id : null)) == null)
351 {
352 SourceTactics.Row row3 = EClass.sources.tactics.map.TryGetValue(row.job, null);
353 defaultStr = (((row3 != null) ? row3.id : null) ?? "predator");
354 }
355 string key = tactics.IsEmpty(defaultStr);
356 n.AddText("gene_info".lang(EClass.sources.tactics.map[key].GetName().ToTitleCase(false), "", null, null, null), FontColor.ButtonGeneral);
357 }
358 for (int i = 0; i < this.vals.Count; i += 2)
359 {
360 int num = this.vals[i];
361 int num2 = this.vals[i + 1];
362 FontColor color = (num2 >= 0) ? FontColor.Good : FontColor.Bad;
363 string @ref = (num + 1).ToString() ?? "";
364 string text = "";
365 num2 = Mathf.Abs(num2 / 20) + 1;
366 text = string.Concat(new string[]
367 {
368 text,
369 "[",
370 "*".Repeat(Mathf.Clamp(num2, 1, 5)),
371 (num2 > 5) ? "+" : "",
372 "]"
373 });
374 n.AddText("gene_info_brain".lang(@ref, text, null, null, null), color);
375 }
376 return;
377 }
378 for (int j = 0; j < this.vals.Count; j += 2)
379 {
380 Element element = Element.Create(this.vals[j], this.vals[j + 1]);
381 string text2 = "";
382 int num3 = element.Value / 10;
383 FontColor color2 = FontColor.Good;
384 string category = element.source.category;
385 if (!(category == "slot"))
386 {
387 if (!(category == "feat"))
388 {
389 if (category == "ability")
390 {
391 color2 = FontColor.Topic2;
392 num3 = -1;
393 }
394 }
395 else
396 {
397 color2 = FontColor.FoodMisc;
398 num3 = -1;
399 }
400 }
401 else
402 {
403 color2 = FontColor.Myth;
404 num3 = -1;
405 }
406 if (num3 >= 0)
407 {
408 text2 = string.Concat(new string[]
409 {
410 text2,
411 "[",
412 "*".Repeat(Mathf.Clamp(num3, 1, 5)),
413 (num3 > 5) ? "+" : "",
414 "]"
415 });
416 }
417 if (EClass.debug.showExtra)
418 {
419 text2 = text2 + " " + element.Value.ToString();
420 }
421 n.AddText("gene_info".lang(element.Name.ToTitleCase(true), text2, null, null, null), color2);
422 }
423 }
424
425 // Token: 0x060013F2 RID: 5106 RVA: 0x000830B8 File Offset: 0x000812B8
426 public Element GetInvalidFeat(Chara c)
427 {
428 for (int i = 0; i < this.vals.Count; i += 2)
429 {
430 Element element = Element.Create(this.vals[i], this.vals[i + 1]);
431 if (element.source.category == "feat" && c.Evalue(element.id) >= element.source.max)
432 {
433 return element;
434 }
435 }
436 return null;
437 }
438
439 // Token: 0x060013F3 RID: 5107 RVA: 0x00083130 File Offset: 0x00081330
440 public Element GetInvalidAction(Chara c)
441 {
442 for (int i = 0; i < this.vals.Count; i += 2)
443 {
444 Element element = Element.Create(this.vals[i], this.vals[i + 1]);
445 if (element.source.category == "ability")
446 {
447 using (List<ActList.Item>.Enumerator enumerator = c.ability.list.items.GetEnumerator())
448 {
449 while (enumerator.MoveNext())
450 {
451 if (enumerator.Current.act.source.id == element.id)
452 {
453 return element;
454 }
455 }
456 }
457 }
458 }
459 return null;
460 }
461
462 // Token: 0x060013F5 RID: 5109 RVA: 0x00083218 File Offset: 0x00081418
463 [CompilerGenerated]
464 private void <Generate>g__AddVal|21_0(int id, int v, bool allowStack, Func<int, int> funcCost, ref DNA.<>c__DisplayClass21_0 A_5)
465 {
466 bool flag = false;
467 int num = EClass.curve(v, 20, 10, 90);
468 v = EClass.curve(v, 20, 10, 80);
469 int i = 0;
470 while (i < this.vals.Count)
471 {
472 if (this.vals[i] == id)
473 {
474 if (!allowStack)
475 {
476 return;
477 }
478 v /= 2;
479 num /= 2;
480 List<int> list = this.vals;
481 int index = i + 1;
482 list[index] += v;
483 Debug.Log(string.Concat(new string[]
484 {
485 this.vals[i + 1].ToString(),
486 ": ",
487 v.ToString(),
488 "/",
489 num.ToString()
490 }));
491 flag = true;
492 break;
493 }
494 else
495 {
496 i += 2;
497 }
498 }
499 if (v == 0)
500 {
501 return;
502 }
503 if (!flag)
504 {
505 this.vals.Add(id);
506 this.vals.Add(v);
507 }
508 this.cost += funcCost(num);
509 }
510
511 // Token: 0x060013F6 RID: 5110 RVA: 0x00083320 File Offset: 0x00081520
512 [CompilerGenerated]
513 private void <Generate>g__AddSkill|21_1(ref DNA.<>c__DisplayClass21_0 A_1)
514 {
515 Element element = A_1.listSkill[Mathf.Clamp(EClass.rnd(6), 0, A_1.listSkill.Count - 1)];
516 this.<Generate>g__AddVal|21_0(element.id, EClass.rndHalf(element.ValueWithoutLink / 2), true, (int v) => v / 5 + 1, ref A_1);
517 }
518
519 // Token: 0x060013F7 RID: 5111 RVA: 0x0008338C File Offset: 0x0008158C
520 [CompilerGenerated]
521 private void <Generate>g__AddAttribute|21_2(ref DNA.<>c__DisplayClass21_0 A_1)
522 {
523 Element element = A_1.listAttb[EClass.rnd(3)];
524 this.<Generate>g__AddVal|21_0(element.id, EClass.rndHalf(element.ValueWithoutLink / 2), true, (int v) => v / 5 + 1, ref A_1);
525 }
526
527 // Token: 0x060013F8 RID: 5112 RVA: 0x000833E8 File Offset: 0x000815E8
528 [CompilerGenerated]
529 private void <Generate>g__AddFeat|21_3(ref DNA.<>c__DisplayClass21_0 A_1)
530 {
531 if (A_1.listFeat.Count == 0)
532 {
533 return;
534 }
535 int feat = A_1.feat;
536 A_1.feat = feat + 1;
537 Element e = A_1.listFeat.RandomItem<Element>();
538 this.<Generate>g__AddVal|21_0(e.id, 1, false, (int v) => e.source.cost[0] * 5, ref A_1);
539 }
540
541 // Token: 0x060013F9 RID: 5113 RVA: 0x0008344C File Offset: 0x0008164C
542 [CompilerGenerated]
543 private void <Generate>g__AddBody|21_4(ref DNA.<>c__DisplayClass21_0 A_1)
544 {
545 if (A_1.body != 0)
546 {
547 return;
548 }
549 BodySlot bodySlot = null;
550 for (int i = 0; i < 100; i++)
551 {
552 BodySlot bodySlot2 = A_1.model.body.slots.RandomItem<BodySlot>();
553 if (bodySlot2 != null && bodySlot2.elementId != 40)
554 {
555 bodySlot = bodySlot2;
556 break;
557 }
558 }
559 if (bodySlot == null)
560 {
561 return;
562 }
563 this.<Generate>g__AddVal|21_0(bodySlot.elementId, 1, false, (int v) => 20, ref A_1);
564 int body = A_1.body;
565 A_1.body = body + 1;
566 }
567
568 // Token: 0x060013FA RID: 5114 RVA: 0x000834DC File Offset: 0x000816DC
569 [CompilerGenerated]
570 private void <Generate>g__AddAction|21_5(ref DNA.<>c__DisplayClass21_0 A_1)
571 {
572 if (A_1.model.ability.list.items.Count == 0)
573 {
574 return;
575 }
576 ActList.Item a = A_1.model.ability.list.items.RandomItem<ActList.Item>();
577 if (a.act.source.category != "ability")
578 {
579 return;
580 }
581 this.<Generate>g__AddVal|21_0(a.act.source.id, a.chance * (a.pt ? -1 : 1), false, (int v) => 8 + a.act.source.cost[0] / 10 * 2, ref A_1);
582 int action = A_1.action;
583 A_1.action = action + 1;
584 }
585
586 // Token: 0x060013FB RID: 5115 RVA: 0x000835A4 File Offset: 0x000817A4
587 [CompilerGenerated]
588 private void <Generate>g__AddRandom|21_6(int n, ref DNA.<>c__DisplayClass21_0 A_2)
589 {
590 for (int i = 0; i < n; i++)
591 {
592 if (EClass.debug.enable && EClass.rnd(2) == 0)
593 {
594 this.<Generate>g__AddSpecial|21_7(ref A_2);
595 }
596 else if (EClass.rnd(2) == 0)
597 {
598 this.<Generate>g__AddSkill|21_1(ref A_2);
599 }
600 else
601 {
602 this.<Generate>g__AddAttribute|21_2(ref A_2);
603 }
604 }
605 }
606
607 // Token: 0x060013FC RID: 5116 RVA: 0x000835F4 File Offset: 0x000817F4
608 [CompilerGenerated]
609 private void <Generate>g__AddSpecial|21_7(ref DNA.<>c__DisplayClass21_0 A_1)
610 {
611 if (EClass.rnd(3) == 0)
612 {
613 this.<Generate>g__AddAction|21_5(ref A_1);
614 return;
615 }
616 if (EClass.rnd(5) == 0)
617 {
618 this.<Generate>g__AddBody|21_4(ref A_1);
619 return;
620 }
621 if (A_1.listFeat.Count > 0)
622 {
623 this.<Generate>g__AddFeat|21_3(ref A_1);
624 return;
625 }
626 if (EClass.rnd(2) == 0)
627 {
628 this.<Generate>g__AddSkill|21_1(ref A_1);
629 return;
630 }
631 this.<Generate>g__AddAttribute|21_2(ref A_1);
632 }
633
634 // Token: 0x04000FB2 RID: 4018
635 [JsonProperty]
636 public string id;
637
638 // Token: 0x04000FB3 RID: 4019
639 [JsonProperty]
640 public int[] ints = new int[4];
641
642 // Token: 0x04000FB4 RID: 4020
643 [JsonProperty]
644 public List<int> vals = new List<int>();
645
646 // Token: 0x02000955 RID: 2389
647 public enum Type
648 {
649 // Token: 0x04002755 RID: 10069
650 Inferior,
651 // Token: 0x04002756 RID: 10070
652 Default = 3,
653 // Token: 0x04002757 RID: 10071
654 Superior = 5,
655 // Token: 0x04002758 RID: 10072
656 Brain = 8
657 }
658}
Definition Card.cs:13
Definition Chara.cs:12
Definition DNA.cs:9
Definition Thing.cs:10