Elin Decompiled Documentation EA 23.343 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 (thing.c_DNA != null)
84 {
85 thing.c_DNA.Apply(owner, reverse: true);
86 owner.feat += thing.c_DNA.cost;
87 }
89 {
90 if (slot.elementId == 45 || thing.HasElement(490))
91 {
93 }
94 if (refresh && owner.isCreated)
95 {
96 owner.Refresh();
97 if (slot.elementId == 37 && owner.HasElement(1209) && !thing.HasElement(419))
98 {
99 owner.Say("tail_free", owner);
100 }
101 }
102 }
103 if (owner.IsPC)
104 {
105 if (refresh)
106 {
108 }
110 }
112 }
113
114 public bool IsEquippable(Thing thing, BodySlot slot, bool text = true)
115 {
116 if (slot == null)
117 {
118 return false;
119 }
120 switch (slot.elementId)
121 {
122 case 31:
123 if (owner.HasElement(1555))
124 {
125 return CannotEquip("cannnotEquip");
126 }
127 break;
128 case 33:
129 if (owner.HasElement(1554))
130 {
131 return CannotEquip("cannnotEquip");
132 }
133 break;
134 case 39:
135 if (owner.HasElement(1552))
136 {
137 return CannotEquip("cannnotEquip");
138 }
139 break;
140 }
141 if (slot.thing != null)
142 {
143 if (slot.thing.blessedState <= BlessedState.Cursed)
144 {
145 return CannotEquip("cannnotEquip");
146 }
147 if (slot.thing.c_DNA != null && slot.thing.GetBool(135))
148 {
149 return CannotEquip("isSleepLock");
150 }
151 }
152 if (thing.c_uidAttune != 0 && thing.c_uidAttune != owner.uid)
153 {
154 if (text)
155 {
156 Msg.Say("unequipCursed", thing);
157 }
158 return false;
159 }
160 if (thing.c_DNA != null && thing.c_DNA.cost > EClass.pc.feat)
161 {
162 if (text)
163 {
164 Msg.Say("notEnoughFeatPoint");
165 }
166 return false;
167 }
168 if (IsTooHeavyToEquip(thing))
169 {
170 if (EClass.core.IsGameStarted && owner.IsPC && text)
171 {
172 Msg.Say("tooHeavyToEquip", thing);
173 }
174 return false;
175 }
176 return true;
177 bool CannotEquip(string idLang)
178 {
179 if (text)
180 {
181 Msg.Say(idLang, slot.element.GetName().ToLower());
182 }
183 return false;
184 }
185 }
186
187 public bool IsTooHeavyToEquip(Thing thing)
188 {
189 if (owner.HasElement(1204) && thing.ChildrenAndSelfWeight > 1000)
190 {
191 return thing.category.slot != 44;
192 }
193 return false;
194 }
195
197 {
198 if (t.isEquipped)
199 {
200 _ = slots[t.c_equippedSlot - 1];
201 if (IsTooHeavyToEquip(t))
202 {
203 owner.Say("tooHeavyToEquip", t);
204 Unequip(t);
205 }
206 }
207 if (!owner.IsPC && !t.isEquipped)
208 {
209 owner.TryEquip(t);
210 }
211 }
212
213 public bool Equip(Thing thing, BodySlot slot = null, bool msg = true)
214 {
215 slot = slot ?? GetSlot(thing.category.slot) ?? GetSlot(thing.category.slot, onlyEmpty: false);
216 if (slot == slotMainHand || slot == slotOffHand)
217 {
218 owner.combatCount = 10;
219 }
220 if (slot == null || slot.elementId != thing.category.slot)
221 {
222 Debug.LogWarning("could not equip:" + thing?.ToString() + "/" + slot?.ToString() + "/" + owner);
223 return false;
224 }
225 if (!IsEquippable(thing, slot))
226 {
227 return false;
228 }
229 if (slot.thing != null)
230 {
231 if (slot.thing == thing)
232 {
233 Unequip(slot);
234 return false;
235 }
236 Unequip(slot, refresh: false);
237 }
238 Unequip(thing, refresh: false);
239 if (thing.c_uidAttune != 0)
240 {
241 foreach (Thing item in owner.things.List((Thing a) => a.isEquipped && a.c_uidAttune != 0 && (a.id == "amulet_engagement" || a.id == "ring_engagement")))
242 {
243 Unequip(item);
244 }
245 }
246 if (thing.parent != owner)
247 {
248 if (msg && owner.IsPC && thing.parent is Thing)
249 {
250 Msg.Say("movedToEquip", thing, thing.parent as Thing);
251 }
252 owner.AddCard(thing);
253 }
254 slot.thing = thing;
255 thing.c_equippedSlot = slot.index + 1;
256 thing.elements.SetParent(owner);
257 thing.trait.OnEquip(owner, onSetOwner: false);
258 if (EClass.pc != null)
259 {
261 }
263 if (thing.c_DNA != null)
264 {
265 thing.c_DNA.Apply(owner, reverse: false);
266 Msg.Say("equip_relic");
267 owner.feat -= thing.c_DNA.cost;
268 if (!EClass.debug.godMode)
269 {
270 thing.SetBool(135, enable: true);
271 }
272 }
273 if (owner.IsPC)
274 {
275 if (msg)
276 {
278 }
281 }
283 {
284 if (slot.elementId == 45 || thing.HasElement(490))
285 {
287 }
288 if (owner.isCreated)
289 {
290 owner.Refresh();
291 }
292 }
293 if (owner.isCreated)
294 {
295 if (thing.Evalue(656) > 0)
296 {
297 thing.SetBlessedState(BlessedState.Cursed);
298 }
299 if (thing.blessedState <= BlessedState.Cursed)
300 {
301 owner.Say("equipCursed", owner);
302 owner.PlaySound("curse3");
303 }
304 }
305 if (slot.elementId == 37 && owner.HasElement(1209) && !thing.HasElement(419))
306 {
307 owner.Say("tail_covered", owner);
308 }
309 return true;
310 }
311
312 public void AddBodyPart(int ele, Thing thing = null)
313 {
315 {
316 elementId = ele,
317 thing = thing,
318 index = slots.Count
319 };
320 if (ele == 35)
321 {
322 if (slotMainHand == null)
323 {
325 }
326 else if (slotOffHand == null)
327 {
329 }
330 }
331 if (ele == 41)
332 {
333 slotRange = item;
334 }
335 slots.Add(item);
336 }
337
338 public void RefreshBodyParts()
339 {
340 for (int i = 0; i < slots.Count; i++)
341 {
342 BodySlot bodySlot = slots[i];
343 bodySlot.index = i;
344 int elementId = bodySlot.elementId;
345 if (elementId == 35)
346 {
347 if (slotMainHand == null || slotMainHand == bodySlot)
348 {
349 slotMainHand = bodySlot;
350 }
351 else if (slotOffHand == null)
352 {
353 slotOffHand = bodySlot;
354 }
355 }
356 if (elementId == 41)
357 {
358 slotRange = bodySlot;
359 }
360 if (bodySlot.thing != null)
361 {
362 bodySlot.thing.c_equippedSlot = i + 1;
363 }
364 }
365 }
366
367 public void RemoveBodyPart(int ele)
368 {
369 int idx = slots.FindIndex((BodySlot a) => a.elementId == ele);
370 RemoveBodyPartAt(idx);
371 }
372
373 public void RemoveBodyPartAt(int idx)
374 {
375 if (idx != -1)
376 {
377 BodySlot bodySlot = slots[idx];
378 if (bodySlot.thing != null)
379 {
380 Unequip(bodySlot);
381 }
382 if (slotMainHand == bodySlot)
383 {
384 slotMainHand = null;
385 }
386 if (slotOffHand == bodySlot)
387 {
388 slotOffHand = null;
389 }
390 if (slotRange == bodySlot)
391 {
392 slotRange = null;
393 }
394 slots.RemoveAt(idx);
395 }
396 }
397
398 public BodySlot GetSlot(Thing t, bool onlyEmpty = false, bool secondSlot = false)
399 {
400 BodySlot slot = GetSlot(t.category.slot, onlyEmpty: true, secondSlot);
401 if (slot != null)
402 {
403 return slot;
404 }
405 if (!onlyEmpty)
406 {
407 return GetSlot(t.category.slot, onlyEmpty: false, secondSlot);
408 }
409 return null;
410 }
411
412 public BodySlot GetSlot(int elementId, bool onlyEmpty = true, bool getSecondSlot = false)
413 {
414 bool flag = true;
415 foreach (BodySlot slot in slots)
416 {
417 if (elementId == slot.elementId && (!onlyEmpty || slot.thing == null))
418 {
419 if (!(getSecondSlot && flag))
420 {
421 return slot;
422 }
423 flag = false;
424 }
425 }
426 return null;
427 }
428
429 public bool HasWeapon()
430 {
431 foreach (BodySlot slot in slots)
432 {
433 if (slot.thing != null && slot.thing.IsWeapon)
434 {
435 return true;
436 }
437 }
438 return false;
439 }
440
441 public bool HasElement(int idEle)
442 {
443 foreach (BodySlot slot in slots)
444 {
445 if (slot.thing != null && slot.thing.elements.Has(idEle))
446 {
447 return true;
448 }
449 }
450 return false;
451 }
452
453 public Thing GetEquippedThing(int elementId)
454 {
455 foreach (BodySlot slot in slots)
456 {
457 if (slot.elementId == elementId && slot.thing != null)
458 {
459 return slot.thing;
460 }
461 }
462 return null;
463 }
464
465 public int GetWeight(bool armorOnly = false)
466 {
467 int num = 0;
468 foreach (BodySlot slot in slots)
469 {
470 if (slot.thing != null && (!armorOnly || (slot.elementId != 44 && slot.elementId != 45)))
471 {
472 num += slot.thing.ChildrenAndSelfWeight;
473 }
474 }
475 return num;
476 }
477
478 public int GetAttackIndex(Thing t)
479 {
480 int num = 0;
481 foreach (BodySlot slot in slots)
482 {
483 if (slot.thing != null && slot.elementId == 35 && slot.thing.source.offense.Length >= 2)
484 {
485 if (slot.thing == t)
486 {
487 return num;
488 }
489 num++;
490 }
491 }
492 return -1;
493 }
494
495 public int GetMeleeDistance()
496 {
497 int num = owner.Evalue(666);
498 foreach (BodySlot slot in slots)
499 {
500 if (slot.elementId == 35 && slot.thing != null && slot.thing.Evalue(666) > num)
501 {
502 num = slot.thing.Evalue(666);
503 }
504 }
505 return 1 + num;
506 }
507
509 {
510 bool flag = false;
511 int num = 0;
512 foreach (BodySlot slot in slots)
513 {
514 if (slot.elementId == 35 && slot.thing != null)
515 {
516 if (slot.thing.IsMeleeWeapon)
517 {
518 num++;
519 }
520 else
521 {
522 flag = true;
523 }
524 }
525 }
526 if (num > 1)
527 {
528 return AttackStyle.TwoWield;
529 }
530 if (flag)
531 {
532 return AttackStyle.Shield;
533 }
534 if (num == 1)
535 {
536 return AttackStyle.TwoHand;
537 }
538 return AttackStyle.Default;
539 }
540
542 {
543 return style switch
544 {
545 AttackStyle.TwoHand => 130,
546 AttackStyle.TwoWield => 131,
547 _ => 0,
548 };
549 }
550
551 public int GetSortVal(BodySlot slot)
552 {
553 return -(slot.element.sort * 100 + owner.body.slots.IndexOf(slot));
554 }
555
557 {
558 if (!t)
559 {
560 return;
561 }
562 if (b.indexPart == 0)
563 {
564 int num = 0;
565 foreach (BodySlot slot in slots)
566 {
567 if (slot.elementId == b.element.id)
568 {
569 num++;
570 }
571 if (b == slot)
572 {
573 break;
574 }
575 }
576 b.indexPart = num;
577 }
578 if (b.elementId == 35)
579 {
580 t.SetText(b.indexPart.ToString() ?? "");
581 t.SetActive(enable: true);
582 }
583 else
584 {
585 t.SetActive(enable: false);
586 }
587 }
588
589 public int CountWeapons()
590 {
591 int num = 0;
592 foreach (BodySlot slot in slots)
593 {
594 if (slot.thing != null && slot.thing.IsMeleeWeapon)
595 {
596 num++;
597 }
598 }
599 return num;
600 }
601}
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:42
string id
Definition: Card.cs:36
int c_equippedSlot
Definition: Card.cs:979
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:6641
Card AddCard(Card c)
Definition: Card.cs:3266
ICardParent parent
Definition: Card.cs:56
virtual void SetBlessedState(BlessedState s)
Definition: Card.cs:4076
void RecalculateFOV()
Definition: Card.cs:6857
int uid
Definition: Card.cs:125
Trait trait
Definition: Card.cs:54
int feat
Definition: Card.cs:377
ThingContainer things
Definition: Card.cs:39
bool IsMeleeWeapon
Definition: Card.cs:2295
int Evalue(int ele)
Definition: Card.cs:2704
bool GetBool(string id)
Definition: Card.cs:2557
BlessedState blessedState
Definition: Card.cs:281
DNA c_DNA
Definition: Card.cs:1933
int ChildrenAndSelfWeight
Definition: Card.cs:2093
SourceCategory.Row category
Definition: Card.cs:2101
void SetBool(string id, bool enable)
Definition: Card.cs:2562
bool IsWeapon
Definition: Card.cs:2260
bool HasElement(int ele, bool includeNagative=false)
Definition: Card.cs:6379
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:7319
int c_uidAttune
Definition: Card.cs:1212
bool HasWeapon()
Definition: CharaBody.cs:429
void RemoveBodyPartAt(int idx)
Definition: CharaBody.cs:373
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:312
bool HasElement(int idEle)
Definition: CharaBody.cs:441
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:196
void Unequip(Thing thing, bool refresh=true)
Definition: CharaBody.cs:49
int GetMeleeDistance()
Definition: CharaBody.cs:495
List< BodySlot > slots
Definition: CharaBody.cs:8
int GetAttackIndex(Thing t)
Definition: CharaBody.cs:478
BodySlot GetSlot(int elementId, bool onlyEmpty=true, bool getSecondSlot=false)
Definition: CharaBody.cs:412
BodySlot slotMainHand
Definition: CharaBody.cs:10
void Unequip(BodySlot slot, bool refresh=true)
Definition: CharaBody.cs:68
bool IsTooHeavyToEquip(Thing thing)
Definition: CharaBody.cs:187
void SetBodyIndexText(BodySlot b, UIText t)
Definition: CharaBody.cs:556
AttackStyle GetAttackStyle()
Definition: CharaBody.cs:508
int GetAttackStyleElement(AttackStyle style)
Definition: CharaBody.cs:541
int GetSortVal(BodySlot slot)
Definition: CharaBody.cs:551
bool IsEquippable(Thing thing, BodySlot slot, bool text=true)
Definition: CharaBody.cs:114
BodySlot slotRange
Definition: CharaBody.cs:14
int CountWeapons()
Definition: CharaBody.cs:589
int GetWeight(bool armorOnly=false)
Definition: CharaBody.cs:465
Thing GetEquippedThing(int elementId)
Definition: CharaBody.cs:453
bool Equip(Thing thing, BodySlot slot=null, bool msg=true)
Definition: CharaBody.cs:213
BodySlot GetSlot(Thing t, bool onlyEmpty=false, bool secondSlot=false)
Definition: CharaBody.cs:398
void RefreshBodyParts()
Definition: CharaBody.cs:338
void RemoveBodyPart(int ele)
Definition: CharaBody.cs:367
Definition: Chara.cs:10
void Refresh(bool calledRecursive=false)
Definition: Chara.cs:1796
CharaBody body
Definition: Chara.cs:94
Faction faction
Definition: Chara.cs:431
override bool IsPC
Definition: Chara.cs:630
bool isCreated
Definition: Chara.cs:138
void SetTempHand(int right=0, int left=0)
Definition: Chara.cs:7110
int[] rawSlots
Definition: Chara.cs:73
bool TryEquip(Thing t, bool useFav=false)
Definition: Chara.cs:8189
bool godMode
Definition: CoreDebug.cs:189
bool IsGameStarted
Definition: Core.cs:87
int cost
Definition: DNA.cs:41
void Apply(Chara c)
Definition: DNA.cs:178
Definition: EClass.cs:6
static Core core
Definition: EClass.cs:7
static Chara pc
Definition: EClass.cs:15
static CoreDebug debug
Definition: EClass.cs:49
void OnUnequip(Chara c, Thing t)
void OnEquip(Chara c, Thing t)
void SetParent(Card c)
bool Has(int ele)
ElementContainerFaction charaElements
Definition: FACTION.cs:146
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
List< Thing > List(Func< Thing, bool > func, bool onlyAccessible=false)
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:704
virtual void OnUnequip(Chara c)
Definition: Trait.cs:708
Definition: UIText.cs:6
void SetText(string s)
Definition: UIText.cs:163
static void SetDirty()
Definition: WidgetEquip.cs:34