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