Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
CharaBody.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using UnityEngine;
3
4public class CharaBody : EClass
5{
6 public Chara owner;
7
8 public List<BodySlot> slots = new List<BodySlot>();
9
11
13
15
16 public int[] rawSlots => owner.rawSlots;
17
18 public void SetOwner(Chara chara, bool deserialized = false)
19 {
20 owner = chara;
21 if (!deserialized)
22 {
23 return;
24 }
25 if (rawSlots != null)
26 {
27 for (int i = 0; i < rawSlots.Length; i++)
28 {
30 }
31 }
32 foreach (Thing thing in owner.things)
33 {
34 if (thing.isEquipped)
35 {
36 int num = thing.c_equippedSlot - 1;
37 if (num < 0 || num >= slots.Count)
38 {
39 thing.c_equippedSlot = 0;
40 continue;
41 }
42 slots[num].thing = thing;
44 thing.trait.OnEquip(owner, onSetOwner: true);
45 }
46 }
47 }
48
49 public void Unequip(Thing thing, bool refresh = true)
50 {
51 if (thing.isEquipped)
52 {
53 Unequip(slots[thing.c_equippedSlot - 1], refresh);
54 }
55 }
56
57 public void UnequipAll(int idSlot)
58 {
59 foreach (BodySlot slot in slots)
60 {
61 if (slot.elementId == idSlot)
62 {
63 Unequip(slot);
64 }
65 }
66 }
67
68 public void Unequip(BodySlot slot, bool refresh = true)
69 {
70 if (slot.thing == null)
71 {
72 return;
73 }
74 Thing thing = slot.thing;
75 if (EClass.pc != null)
76 {
78 }
79 thing.elements.SetParent();
80 thing.trait.OnUnequip(owner);
81 thing.c_equippedSlot = 0;
82 slot.thing = null;
83 if (owner.IsPC)
84 {
85 if (refresh)
86 {
88 }
90 }
92 if (slot.elementId == 45 && EClass.core.IsGameStarted)
93 {
95 }
96 if (refresh && owner.isCreated && EClass.core.IsGameStarted)
97 {
98 owner.Refresh();
99 if (slot.elementId == 37 && owner.HasElement(1209))
100 {
101 owner.Say("tail_free", owner);
102 }
103 }
104 }
105
106 public bool IsEquippable(Thing thing, BodySlot slot, bool text = true)
107 {
108 if (slot == null)
109 {
110 return false;
111 }
112 switch (slot.elementId)
113 {
114 case 31:
115 if (owner.HasElement(1555))
116 {
117 return CannotEquip();
118 }
119 break;
120 case 33:
121 if (owner.HasElement(1554))
122 {
123 return CannotEquip();
124 }
125 break;
126 case 39:
127 if (owner.HasElement(1552))
128 {
129 return CannotEquip();
130 }
131 break;
132 }
133 if (slot.thing != null && slot.thing.blessedState <= BlessedState.Cursed)
134 {
135 return CannotEquip();
136 }
137 if (IsTooHeavyToEquip(thing))
138 {
139 if (EClass.core.IsGameStarted && owner.IsPC && text)
140 {
141 Msg.Say("tooHeavyToEquip", thing);
142 }
143 return false;
144 }
145 return true;
146 bool CannotEquip()
147 {
148 if (text)
149 {
150 Msg.Say("cannnotEquip", slot.element.GetName().ToLower());
151 }
152 return false;
153 }
154 }
155
156 public bool IsTooHeavyToEquip(Thing thing)
157 {
158 if (owner.HasElement(1204) && thing.ChildrenAndSelfWeight > 1000)
159 {
160 return thing.category.slot != 44;
161 }
162 return false;
163 }
164
166 {
167 if (t.isEquipped)
168 {
169 _ = slots[t.c_equippedSlot - 1];
170 if (IsTooHeavyToEquip(t))
171 {
172 owner.Say("tooHeavyToEquip", t);
173 Unequip(t);
174 }
175 }
176 if (!owner.IsPC && !t.isEquipped)
177 {
178 owner.TryEquip(t);
179 }
180 }
181
182 public bool Equip(Thing thing, BodySlot slot = null, bool msg = true)
183 {
184 slot = slot ?? GetSlot(thing.category.slot) ?? GetSlot(thing.category.slot, onlyEmpty: false);
185 if (slot == slotMainHand || slot == slotOffHand)
186 {
187 owner.combatCount = 10;
188 }
189 if (slot == null || slot.elementId != thing.category.slot)
190 {
191 Debug.LogWarning("could not equip:" + thing?.ToString() + "/" + slot?.ToString() + "/" + owner);
192 return false;
193 }
194 if (!IsEquippable(thing, slot))
195 {
196 return false;
197 }
198 if (slot.thing != null)
199 {
200 if (slot.thing == thing)
201 {
202 Unequip(slot);
203 return false;
204 }
205 Unequip(slot, refresh: false);
206 }
207 Unequip(thing, refresh: false);
208 if (thing.parent != owner)
209 {
210 if (msg && owner.IsPC && thing.parent is Thing)
211 {
212 Msg.Say("movedToEquip", thing, thing.parent as Thing);
213 }
214 owner.AddCard(thing);
215 }
216 slot.thing = thing;
217 thing.c_equippedSlot = slot.index + 1;
218 thing.elements.SetParent(owner);
219 thing.trait.OnEquip(owner, onSetOwner: false);
220 if (EClass.pc != null)
221 {
223 }
225 if (owner.IsPC)
226 {
227 if (msg)
228 {
230 }
233 }
234 if (slot.elementId == 45 && EClass.core.IsGameStarted)
235 {
237 }
239 {
240 owner.Refresh();
241 }
242 if (owner.isCreated)
243 {
244 if (thing.Evalue(656) > 0)
245 {
246 thing.blessedState = BlessedState.Cursed;
247 }
248 if (thing.blessedState <= BlessedState.Cursed)
249 {
250 owner.Say("equipCursed", owner);
251 owner.PlaySound("curse3");
252 }
253 }
254 if (slot.elementId == 37 && owner.HasElement(1209))
255 {
256 owner.Say("tail_covered", owner);
257 }
258 return true;
259 }
260
261 public void AddBodyPart(int ele, Thing thing = null)
262 {
264 {
265 elementId = ele,
266 thing = thing,
267 index = slots.Count
268 };
269 if (ele == 35)
270 {
271 if (slotMainHand == null)
272 {
274 }
275 else if (slotOffHand == null)
276 {
278 }
279 }
280 if (ele == 41)
281 {
282 slotRange = item;
283 }
284 slots.Add(item);
285 }
286
287 public void RefreshBodyParts()
288 {
289 foreach (BodySlot slot in slots)
290 {
291 int elementId = slot.elementId;
292 if (elementId == 35)
293 {
294 if (slotMainHand == null)
295 {
296 slotMainHand = slot;
297 }
298 else if (slotOffHand == null)
299 {
300 slotOffHand = slot;
301 }
302 }
303 if (elementId == 41)
304 {
305 slotRange = slot;
306 }
307 }
308 }
309
310 public void RemoveBodyPart(int ele)
311 {
312 int idx = slots.FindIndex((BodySlot a) => a.elementId == ele);
313 RemoveBodyPartAt(idx);
314 }
315
316 public void RemoveBodyPartAt(int idx)
317 {
318 if (idx != -1)
319 {
320 BodySlot bodySlot = slots[idx];
321 if (bodySlot.thing != null)
322 {
323 Unequip(bodySlot);
324 }
325 if (slotMainHand == bodySlot)
326 {
327 slotMainHand = null;
328 }
329 if (slotOffHand == bodySlot)
330 {
331 slotOffHand = null;
332 }
333 if (slotRange == bodySlot)
334 {
335 slotRange = null;
336 }
337 slots.RemoveAt(idx);
338 }
339 }
340
341 public BodySlot GetSlot(Thing t, bool onlyEmpty = false, bool secondSlot = false)
342 {
343 BodySlot slot = GetSlot(t.category.slot, onlyEmpty: true, secondSlot);
344 if (slot != null)
345 {
346 return slot;
347 }
348 if (!onlyEmpty)
349 {
350 return GetSlot(t.category.slot, onlyEmpty: false, secondSlot);
351 }
352 return null;
353 }
354
355 public BodySlot GetSlot(int elementId, bool onlyEmpty = true, bool secondSlot = false)
356 {
357 bool flag = true;
358 foreach (BodySlot slot in slots)
359 {
360 if (elementId == slot.elementId && (!onlyEmpty || slot.thing == null))
361 {
362 if (!(secondSlot && flag))
363 {
364 return slot;
365 }
366 flag = false;
367 }
368 }
369 return null;
370 }
371
372 public Thing GetEquippedThing(int elementId)
373 {
374 foreach (BodySlot slot in slots)
375 {
376 if (slot.elementId == elementId && slot.thing != null)
377 {
378 return slot.thing;
379 }
380 }
381 return null;
382 }
383
384 public int GetWeight(bool armorOnly = false)
385 {
386 int num = 0;
387 foreach (BodySlot slot in slots)
388 {
389 if (slot.thing != null && (!armorOnly || (slot.elementId != 44 && slot.elementId != 45)))
390 {
391 num += slot.thing.ChildrenAndSelfWeight;
392 }
393 }
394 return num;
395 }
396
397 public int GetAttackIndex(Thing t)
398 {
399 int num = 0;
400 foreach (BodySlot slot in slots)
401 {
402 if (slot.thing != null && slot.elementId == 35 && slot.thing.source.offense.Length >= 2)
403 {
404 if (slot.thing == t)
405 {
406 return num;
407 }
408 num++;
409 }
410 }
411 return -1;
412 }
413
414 public int GetMeleeDistance()
415 {
416 int num = owner.Evalue(666);
417 foreach (BodySlot slot in slots)
418 {
419 if (slot.elementId == 35 && slot.thing != null && slot.thing.Evalue(666) > num)
420 {
421 num = slot.thing.Evalue(666);
422 }
423 }
424 return 1 + num;
425 }
426
428 {
429 bool flag = false;
430 int num = 0;
431 foreach (BodySlot slot in slots)
432 {
433 if (slot.elementId == 35 && slot.thing != null)
434 {
435 if (slot.thing.IsMeleeWeapon)
436 {
437 num++;
438 }
439 else
440 {
441 flag = true;
442 }
443 }
444 }
445 if (num > 1)
446 {
447 return AttackStyle.TwoWield;
448 }
449 if (flag)
450 {
451 return AttackStyle.Shield;
452 }
453 if (num == 1)
454 {
455 return AttackStyle.TwoHand;
456 }
457 return AttackStyle.Default;
458 }
459
461 {
462 return style switch
463 {
464 AttackStyle.TwoHand => 130,
465 AttackStyle.TwoWield => 131,
466 _ => 0,
467 };
468 }
469
470 public int GetSortVal(BodySlot slot)
471 {
472 return -(slot.element.sort * 100 + owner.body.slots.IndexOf(slot));
473 }
474
476 {
477 if (!t)
478 {
479 return;
480 }
481 if (b.indexPart == 0)
482 {
483 int num = 0;
484 foreach (BodySlot slot in slots)
485 {
486 if (slot.elementId == b.element.id)
487 {
488 num++;
489 }
490 if (b == slot)
491 {
492 break;
493 }
494 }
495 b.indexPart = num;
496 }
497 if (b.elementId == 35)
498 {
499 t.SetText(b.indexPart.ToString() ?? "");
500 t.SetActive(enable: true);
501 }
502 else
503 {
504 t.SetActive(enable: false);
505 }
506 }
507}
AttackStyle
Definition: AttackStyle.cs:2
BlessedState
Definition: BlessedState.cs:2
int elementId
Definition: BodySlot.cs:6
int indexPart
Definition: BodySlot.cs:12
Thing thing
Definition: BodySlot.cs:8
SourceElement.Row element
Definition: BodySlot.cs:16
ElementContainerCard elements
Definition: Card.cs:37
int c_equippedSlot
Definition: Card.cs:912
bool HasElement(int ele, int req=1)
Definition: Card.cs:5214
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:5404
Card AddCard(Card c)
Definition: Card.cs:2887
ICardParent parent
Definition: Card.cs:51
void RecalculateFOV()
Definition: Card.cs:5616
Trait trait
Definition: Card.cs:49
ThingContainer things
Definition: Card.cs:34
bool IsMeleeWeapon
Definition: Card.cs:2101
int Evalue(int ele)
Definition: Card.cs:2431
BlessedState blessedState
Definition: Card.cs:262
int ChildrenAndSelfWeight
Definition: Card.cs:1917
SourceCategory.Row category
Definition: Card.cs:1925
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:6046
void RemoveBodyPartAt(int idx)
Definition: CharaBody.cs:316
BodySlot GetSlot(int elementId, bool onlyEmpty=true, bool secondSlot=false)
Definition: CharaBody.cs:355
void SetOwner(Chara chara, bool deserialized=false)
Definition: CharaBody.cs:18
BodySlot slotOffHand
Definition: CharaBody.cs:12
void AddBodyPart(int ele, Thing thing=null)
Definition: CharaBody.cs:261
Chara owner
Definition: CharaBody.cs:6
int[] rawSlots
Definition: CharaBody.cs:16
void UnequipAll(int idSlot)
Definition: CharaBody.cs:57
void UnqeuipIfTooHeavy(Thing t)
Definition: CharaBody.cs:165
void Unequip(Thing thing, bool refresh=true)
Definition: CharaBody.cs:49
int GetMeleeDistance()
Definition: CharaBody.cs:414
List< BodySlot > slots
Definition: CharaBody.cs:8
int GetAttackIndex(Thing t)
Definition: CharaBody.cs:397
BodySlot slotMainHand
Definition: CharaBody.cs:10
void Unequip(BodySlot slot, bool refresh=true)
Definition: CharaBody.cs:68
bool IsTooHeavyToEquip(Thing thing)
Definition: CharaBody.cs:156
void SetBodyIndexText(BodySlot b, UIText t)
Definition: CharaBody.cs:475
AttackStyle GetAttackStyle()
Definition: CharaBody.cs:427
int GetAttackStyleElement(AttackStyle style)
Definition: CharaBody.cs:460
int GetSortVal(BodySlot slot)
Definition: CharaBody.cs:470
bool IsEquippable(Thing thing, BodySlot slot, bool text=true)
Definition: CharaBody.cs:106
BodySlot slotRange
Definition: CharaBody.cs:14
int GetWeight(bool armorOnly=false)
Definition: CharaBody.cs:384
Thing GetEquippedThing(int elementId)
Definition: CharaBody.cs:372
bool Equip(Thing thing, BodySlot slot=null, bool msg=true)
Definition: CharaBody.cs:182
BodySlot GetSlot(Thing t, bool onlyEmpty=false, bool secondSlot=false)
Definition: CharaBody.cs:341
void RefreshBodyParts()
Definition: CharaBody.cs:287
void RemoveBodyPart(int ele)
Definition: CharaBody.cs:310
Definition: Chara.cs:10
void Refresh(bool calledRecursive=false)
Definition: Chara.cs:1504
CharaBody body
Definition: Chara.cs:91
Faction faction
Definition: Chara.cs:412
override bool IsPC
Definition: Chara.cs:597
bool isCreated
Definition: Chara.cs:131
void SetTempHand(int right=0, int left=0)
Definition: Chara.cs:6057
int[] rawSlots
Definition: Chara.cs:70
bool TryEquip(Thing t, bool useFav=false)
Definition: Chara.cs:6961
bool IsGameStarted
Definition: Core.cs:84
Definition: EClass.cs:5
static Core core
Definition: EClass.cs:6
static Chara pc
Definition: EClass.cs:14
void OnUnequip(Chara c, Thing t)
void OnEquip(Chara c, Thing t)
void SetParent(Card c)
ElementContainerFaction charaElements
Definition: FACTION.cs:144
static void Refresh()
Definition: LayerChara.cs:16
static void SetDirty(Thing t)
Definition: Msg.cs:5
static string Say(string idLang, string ref1, string ref2=null, string ref3=null, string ref4=null)
Definition: Msg.cs:58
Definition: Thing.cs:8
SourceThing.Row source
Definition: Thing.cs:11
bool isEquipped
Definition: Thing.cs:17
virtual void OnEquip(Chara c, bool onSetOwner)
Definition: Trait.cs:622
virtual void OnUnequip(Chara c)
Definition: Trait.cs:626
Definition: UIText.cs:6
void SetText(string s)
Definition: UIText.cs:159
static void SetDirty()
Definition: WidgetEquip.cs:34