Elin Decompiled Documentation EA 23.359.1 Nightly
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, bool permanent = false)
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)
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 if (element.vPotential < 0)
181 {
182 element.vPotential = 0;
183 }
184 if (element.vPotential <= 0 && permanent)
185 {
186 element.vPotential = 1;
187 }
188 }
189 }
190 Refresh();
191 if (owner.IsPC)
192 {
194 }
195 }
196
197 public void AddRandom()
198 {
199 if (owner._listAbility == null)
200 {
201 owner._listAbility = new List<int>();
202 }
203 owner._listAbility.Add(GetRandomAbilityList().RandomItemWeighted((SourceElement.Row e) => e.chance).id);
204 Refresh();
205 }
206
207 public void Remove(int id, bool permanent = false)
208 {
209 owner._listAbility.Remove(id);
210 if (owner.IsPC && owner.HasElement(id) && owner._listAbility.IndexOf(id) == -1)
211 {
212 Element element = EClass.pc.elements.GetElement(id);
213 if (!(element is Spell) && (permanent || element.vPotential <= 0))
214 {
215 element.vPotential = -1;
216 }
217 }
218 if (owner._listAbility.Count == 0)
219 {
220 owner._listAbility = null;
221 }
222 Refresh();
223 if (owner.IsPC)
224 {
226 }
227 }
228
229 public bool Has(int id)
230 {
231 foreach (ActList.Item item in list.items)
232 {
233 if (item.act.id == id)
234 {
235 return true;
236 }
237 }
238 if (owner.IsPC && owner.faithElements != null && owner.faithElements.Has(id))
239 {
240 return true;
241 }
242 return false;
243 }
244}
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:6383
static List< SourceElement.Row > randomAbilities
Definition: CharaAbility.cs:7
void Refresh()
Definition: CharaAbility.cs:79
List< SourceElement.Row > GetRandomAbilityList()
Definition: CharaAbility.cs:56
void Remove(int id, bool permanent=false)
ActList list
Definition: CharaAbility.cs:13
static List< SourceElement.Row > randomAbilitiesAdv
Definition: CharaAbility.cs:9
CharaAbility(Chara _owner)
Definition: CharaAbility.cs:73
void AddRandom()
void Add(int id, int chance, bool pt, bool permanent=false)
static List< SourceElement.Row > BuildRandomAbilityList(bool adv)
Definition: CharaAbility.cs:15
bool Has(int id)
Definition: Chara.cs:10
Element MainElement
Definition: Chara.cs:737
new TraitChara trait
Definition: Chara.cs:511
override bool IsPC
Definition: Chara.cs:632
SourceChara.Row source
Definition: Chara.cs:164
ElementContainer faithElements
Definition: Chara.cs:40
List< int > _listAbility
Definition: Chara.cs:63
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
bool Has(int ele)
Element ModBase(int ele, int v)
Element GetElement(string alias)
SourceElement.Row source
Definition: ELEMENT.cs:282
int vPotential
Definition: ELEMENT.cs:265
static Element Void
Definition: ELEMENT.cs:247
static void Redraw()
Dictionary< string, string > fuzzyAlias
SourceElement elements
Definition: SPELL.cs:710
virtual int MaxRandomAbility
Definition: TraitChara.cs:100