Elin Decompiled Documentation EA 23.321 Nightly Patch 1
Loading...
Searching...
No Matches
CharaAbility.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Linq;
3using UnityEngine;
4
5public class CharaAbility : EClass
6{
7 public static List<SourceElement.Row> randomAbilities = new List<SourceElement.Row>();
8
9 public static List<SourceElement.Row> randomAbilitiesAdv = new List<SourceElement.Row>();
10
11 public Chara owner;
12
13 public ActList list = new ActList();
14
15 public static List<SourceElement.Row> BuildRandomAbilityList(bool adv)
16 {
17 List<SourceElement.Row> list = new List<SourceElement.Row>();
18 foreach (SourceElement.Row row in EClass.sources.elements.rows)
19 {
20 if (row.abilityType.Length == 0 || row.aliasRef == "mold")
21 {
22 continue;
23 }
24 switch (row.id)
25 {
26 case 5000:
27 case 5001:
28 case 5005:
29 case 5040:
30 case 5048:
31 case 6400:
32 case 6410:
33 case 6800:
34 case 8200:
35 continue;
36 }
37 if (row.idMold != 0 && !adv)
38 {
39 switch (row.aliasRef)
40 {
41 case "eleEther":
42 case "eleAcid":
43 case "eleCut":
44 case "eleImpact":
45 continue;
46 }
47 }
48 if (!row.tag.Contains("noRandomAbility"))
49 {
50 list.Add(row);
51 }
52 }
53 return list;
54 }
55
57 {
58 if (randomAbilities.Count == 0)
59 {
61 }
62 if (randomAbilitiesAdv.Count == 0)
63 {
65 }
66 if (!(owner.trait is TraitAdventurer))
67 {
68 return randomAbilities;
69 }
70 return randomAbilitiesAdv;
71 }
72
73 public CharaAbility(Chara _owner)
74 {
75 owner = _owner;
76 Refresh();
77 }
78
79 public void Refresh()
80 {
81 this.list.items.Clear();
82 List<string> list = owner.source.actCombat.ToList();
83 bool flag = true;
84 for (int num = list.Count - 1; num >= 0; num--)
85 {
86 string text = list[num];
87 string text2 = text.Split('/')[0];
88 if (text2.IsEmpty())
89 {
90 list.RemoveAt(num);
91 flag = false;
92 }
93 else if (!EClass.sources.elements.alias.ContainsKey(text2) || !ACT.dict.ContainsKey(text2))
94 {
95 if (EClass.sources.elements.fuzzyAlias.TryGetValue(text2.Trim(), out var value) && ACT.dict.ContainsKey(value))
96 {
97 list[num] = text.Replace(text2, value);
98 }
99 else
100 {
101 list.RemoveAt(num);
102 ModUtil.LogModError("source chara row '" + owner.id + "' has invalid actCombat '" + text + "'", owner.source);
103 }
104 flag = false;
105 }
106 }
107 if (!flag)
108 {
109 owner.source.actCombat = list.ToArray();
110 }
111 foreach (string item in list)
112 {
113 string[] array = item.Split('/');
114 this.list.items.Add(new ActList.Item
115 {
116 act = ACT.dict[ConvertID(array[0])],
117 chance = ((array.Length > 1) ? array[1].ToInt() : 100),
118 pt = (array.Length > 2)
119 });
120 }
121 if (owner.trait.MaxRandomAbility > 0 && owner._listAbility == null)
122 {
123 int num2 = owner.trait.MaxRandomAbility + EClass.rnd(2) - this.list.items.Count;
124 if (num2 > 1)
125 {
126 owner._listAbility = new List<int>();
127 for (int i = 0; i < num2; i++)
128 {
129 owner._listAbility.Add(GetRandomAbilityList().RandomItemWeighted((SourceElement.Row e) => e.chance).id);
130 }
131 }
132 }
133 if (owner._listAbility == null)
134 {
135 return;
136 }
137 foreach (int item2 in owner._listAbility)
138 {
139 string text3 = EClass.sources.elements.map.TryGetValue(Mathf.Abs(item2))?.alias;
140 if (!text3.IsEmpty())
141 {
142 this.list.items.Add(new ActList.Item
143 {
144 act = ACT.dict[text3],
145 chance = 50,
146 pt = (item2 < 0)
147 });
148 }
149 }
150 string ConvertID(string s)
151 {
153 {
154 return s;
155 }
156 if (EClass.sources.elements.alias[s].aliasRef == "mold")
157 {
158 return s + owner.MainElement.source.alias.Replace("ele", "");
159 }
160 return s;
161 }
162 }
163
164 public void Add(int id, int chance, bool pt)
165 {
166 if (owner._listAbility == null)
167 {
168 owner._listAbility = new List<int>();
169 }
170 owner._listAbility.Add(id * ((!pt) ? 1 : (-1)));
171 if (owner.IsPC && owner.HasElement(1274))
172 {
173 Element element = owner.elements.GetElement(id);
174 if (element == null)
175 {
176 owner.elements.ModBase(id, 1);
177 }
178 else if (!(element is Spell))
179 {
180 element.vPotential = 0;
181 }
182 }
183 Refresh();
184 if (owner.IsPC)
185 {
187 }
188 }
189
190 public void AddRandom()
191 {
192 if (owner._listAbility == null)
193 {
194 owner._listAbility = new List<int>();
195 }
196 owner._listAbility.Add(GetRandomAbilityList().RandomItemWeighted((SourceElement.Row e) => e.chance).id);
197 Refresh();
198 }
199
200 public void Remove(int id)
201 {
202 owner._listAbility.Remove(id);
203 if (owner.IsPC && owner.HasElement(1274) && owner.HasElement(id) && owner._listAbility.IndexOf(id) == -1)
204 {
205 Element element = EClass.pc.elements.GetElement(id);
206 if (!(element is Spell))
207 {
208 element.vPotential = -1;
209 }
210 }
211 if (owner._listAbility.Count == 0)
212 {
213 owner._listAbility = null;
214 }
215 Refresh();
216 if (owner.IsPC)
217 {
219 }
220 }
221
222 public bool Has(int id)
223 {
224 foreach (ActList.Item item in list.items)
225 {
226 if (item.act.id == id)
227 {
228 return true;
229 }
230 }
231 return false;
232 }
233}
Definition: ACT.cs:6
static Dictionary< string, Act > dict
Definition: ACT.cs:23
List< Item > items
Definition: ActList.cs:14
ElementContainerCard elements
Definition: Card.cs:42
string id
Definition: Card.cs:36
bool HasElement(int ele, bool includeNagative=false)
Definition: Card.cs:6320
static List< SourceElement.Row > randomAbilities
Definition: CharaAbility.cs:7
void Refresh()
Definition: CharaAbility.cs:79
List< SourceElement.Row > GetRandomAbilityList()
Definition: CharaAbility.cs:56
ActList list
Definition: CharaAbility.cs:13
static List< SourceElement.Row > randomAbilitiesAdv
Definition: CharaAbility.cs:9
void Add(int id, int chance, bool pt)
void Remove(int id)
CharaAbility(Chara _owner)
Definition: CharaAbility.cs:73
void AddRandom()
static List< SourceElement.Row > BuildRandomAbilityList(bool adv)
Definition: CharaAbility.cs:15
bool Has(int id)
Definition: Chara.cs:10
Element MainElement
Definition: Chara.cs:735
new TraitChara trait
Definition: Chara.cs:509
override bool IsPC
Definition: Chara.cs:630
SourceChara.Row source
Definition: Chara.cs:162
List< int > _listAbility
Definition: Chara.cs:61
Definition: EClass.cs:6
static int rnd(long a)
Definition: EClass.cs:59
static SourceManager sources
Definition: EClass.cs:43
static Chara pc
Definition: EClass.cs:15
Element ModBase(int ele, int v)
Element GetElement(string alias)
SourceElement.Row source
Definition: ELEMENT.cs:280
static Element Void
Definition: ELEMENT.cs:245
static void Redraw()
Dictionary< string, string > fuzzyAlias
SourceElement elements
Definition: SPELL.cs:630
virtual int MaxRandomAbility
Definition: TraitChara.cs:98