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