Elin Modding Docs Doc
Loading...
Searching...
No Matches
Dice.cs
1using System;
2using System.Runtime.CompilerServices;
3using UnityEngine;
4
5// Token: 0x02000060 RID: 96
6public class Dice
7{
8 // Token: 0x0600027F RID: 639 RVA: 0x0001389C File Offset: 0x00011A9C
9 public static int Roll(int num, int sides, int bonus = 0, Card card = null)
10 {
11 Dice.<>c__DisplayClass1_0 CS$<>8__locals1;
12 CS$<>8__locals1.sides = sides;
13 CS$<>8__locals1.num = num;
14 CS$<>8__locals1.bonus = bonus;
15 int num2 = 1;
16 bool flag = true;
17 int num3 = 0;
18 if (card != null)
19 {
20 int num4 = card.Evalue(78);
21 flag = (num4 >= 0);
22 num2 = 1 + Mathf.Abs(num4 / 100) + ((Mathf.Abs(num4 % 100) > Dice.rnd(100)) ? 1 : 0);
23 }
24 for (int i = 0; i < num2; i++)
25 {
26 int num5 = Dice.<Roll>g__Roll|1_0(ref CS$<>8__locals1);
27 if (i == 0 || (flag && num5 > num3) || (!flag && num5 < num3))
28 {
29 num3 = num5;
30 }
31 }
32 return num3;
33 }
34
35 // Token: 0x06000280 RID: 640 RVA: 0x00013933 File Offset: 0x00011B33
36 public static int RollMax(int num, int sides, int bonus = 0)
37 {
38 return num * sides + bonus;
39 }
40
41 // Token: 0x06000281 RID: 641 RVA: 0x0001393A File Offset: 0x00011B3A
42 public static int rnd(int a)
43 {
44 return Rand.Range(0, a);
45 }
46
47 // Token: 0x06000282 RID: 642 RVA: 0x00013943 File Offset: 0x00011B43
48 public Dice(int _num = 0, int _sides = 0, int _bonus = 0, Card _card = null)
49 {
50 this.num = _num;
51 this.sides = _sides;
52 this.bonus = _bonus;
53 this.card = _card;
54 }
55
56 // Token: 0x06000283 RID: 643 RVA: 0x00013968 File Offset: 0x00011B68
57 public static Dice Parse(string raw)
58 {
59 Dice dice = new Dice(0, 0, 0, null);
60 string[] array = raw.Split(',', StringSplitOptions.None);
61 if (array.Length != 0)
62 {
63 string[] array2 = array[0].Split('d', StringSplitOptions.None);
64 dice.num = int.Parse(array2[0]);
65 dice.sides = int.Parse(array2[1]);
66 }
67 if (array.Length > 1)
68 {
69 dice.bonus = int.Parse(array[1]);
70 }
71 return dice;
72 }
73
74 // Token: 0x06000284 RID: 644 RVA: 0x000139CA File Offset: 0x00011BCA
75 public int Roll()
76 {
77 return Dice.Roll(this.num, this.sides, this.bonus, this.card);
78 }
79
80 // Token: 0x06000285 RID: 645 RVA: 0x000139E9 File Offset: 0x00011BE9
81 public int RollMax()
82 {
83 return Dice.RollMax(this.num, this.sides, this.bonus);
84 }
85
86 // Token: 0x06000286 RID: 646 RVA: 0x00013A04 File Offset: 0x00011C04
87 public override string ToString()
88 {
89 return this.num.ToString() + "d" + this.sides.ToString() + ((this.bonus > 0) ? ("+" + this.bonus.ToString()) : ((this.bonus < 0) ? (this.bonus.ToString() ?? "") : ""));
90 }
91
92 // Token: 0x06000287 RID: 647 RVA: 0x00013A78 File Offset: 0x00011C78
93 public static Dice Create(Element ele, Card c)
94 {
95 string key = ele.source.alias;
96 if (!EClass.sources.calc.map.ContainsKey(key) && !ele.source.aliasRef.IsEmpty())
97 {
98 key = ele.source.alias.Split('_', StringSplitOptions.None)[0] + "_";
99 }
100 if (!EClass.sources.calc.map.ContainsKey(key))
101 {
102 return null;
103 }
104 SourceCalc.Row row = EClass.sources.calc.map[key];
105 int power = ele.GetPower(c);
106 int ele2 = ele.source.aliasParent.IsEmpty() ? 0 : c.Evalue(ele.source.aliasParent);
107 Dice result;
108 try
109 {
110 result = new Dice(Mathf.Max(1, row.num.Calc(power, ele2, 0)), Mathf.Max(1, row.sides.Calc(power, ele2, 0)), row.bonus.Calc(power, ele2, 0), c);
111 }
112 catch
113 {
114 Debug.Log(ele.id);
115 result = new Dice(0, 0, 0, null);
116 }
117 return result;
118 }
119
120 // Token: 0x06000288 RID: 648 RVA: 0x00013BA8 File Offset: 0x00011DA8
121 public static Dice Create(string id, int power, Card c = null, Act act = null)
122 {
123 if (!EClass.sources.calc.map.ContainsKey(id))
124 {
125 Debug.Log(id);
126 return null;
127 }
128 SourceCalc.Row row = EClass.sources.calc.map[id];
129 int power2 = power;
130 int ele = power / 10;
131 if (act != null)
132 {
133 Element orCreateElement = c.elements.GetOrCreateElement(act.source.id);
134 power2 = orCreateElement.GetPower(c);
135 ele = (orCreateElement.source.aliasParent.IsEmpty() ? 0 : c.Evalue(orCreateElement.source.aliasParent));
136 }
137 Dice result;
138 try
139 {
140 result = new Dice(Mathf.Max(1, row.num.Calc(power2, ele, 0)), Mathf.Max(1, row.sides.Calc(power2, ele, 0)), row.bonus.Calc(power2, ele, 0), c);
141 }
142 catch
143 {
144 result = new Dice(0, 0, 0, null);
145 }
146 return result;
147 }
148
149 // Token: 0x0600028A RID: 650 RVA: 0x00013CAC File Offset: 0x00011EAC
150 [CompilerGenerated]
151 internal static int <Roll>g__Roll|1_0(ref Dice.<>c__DisplayClass1_0 A_0)
152 {
153 int num = 0;
154 for (int i = 0; i < A_0.num; i++)
155 {
156 num += Dice.rnd(A_0.sides) + 1;
157 }
158 return num + A_0.bonus;
159 }
160
161 // Token: 0x04000519 RID: 1305
162 public static Dice Null = new Dice(0, 0, 0, null);
163
164 // Token: 0x0400051A RID: 1306
165 public int num;
166
167 // Token: 0x0400051B RID: 1307
168 public int sides;
169
170 // Token: 0x0400051C RID: 1308
171 public int bonus;
172
173 // Token: 0x0400051D RID: 1309
174 public Card card;
175}
Definition Act.2.cs:7
Definition Card.cs:13
Definition Dice.cs:7