Elin Decompiled Documentation EA 23.233 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 }
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) && !thing.HasElement(419))
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.SetBlessedState(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) && !thing.HasElement(419))
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 for (int i = 0; i < slots.Count; i++)
290 {
291 BodySlot bodySlot = slots[i];
292 bodySlot.index = i;
293 int elementId = bodySlot.elementId;
294 if (elementId == 35)
295 {
296 if (slotMainHand == null)
297 {
298 slotMainHand = bodySlot;
299 }
300 else if (slotOffHand == null)
301 {
302 slotOffHand = bodySlot;
303 }
304 }
305 if (elementId == 41)
306 {
307 slotRange = bodySlot;
308 }
309 if (bodySlot.thing != null)
310 {
311 bodySlot.thing.c_equippedSlot = i + 1;
312 }
313 }
314 }
315
316 public void RemoveBodyPart(int ele)
317 {
318 int idx = slots.FindIndex((BodySlot a) => a.elementId == ele);
319 RemoveBodyPartAt(idx);
320 }
321
322 public void RemoveBodyPartAt(int idx)
323 {
324 if (idx != -1)
325 {
326 BodySlot bodySlot = slots[idx];
327 if (bodySlot.thing != null)
328 {
329 Unequip(bodySlot);
330 }
331 if (slotMainHand == bodySlot)
332 {
333 slotMainHand = null;
334 }
335 if (slotOffHand == bodySlot)
336 {
337 slotOffHand = null;
338 }
339 if (slotRange == bodySlot)
340 {
341 slotRange = null;
342 }
343 slots.RemoveAt(idx);
344 }
345 }
346
347 public BodySlot GetSlot(Thing t, bool onlyEmpty = false, bool secondSlot = false)
348 {
349 BodySlot slot = GetSlot(t.category.slot, onlyEmpty: true, secondSlot);
350 if (slot != null)
351 {
352 return slot;
353 }
354 if (!onlyEmpty)
355 {
356 return GetSlot(t.category.slot, onlyEmpty: false, secondSlot);
357 }
358 return null;
359 }
360
361 public BodySlot GetSlot(int elementId, bool onlyEmpty = true, bool secondSlot = false)
362 {
363 bool flag = true;
364 foreach (BodySlot slot in slots)
365 {
366 if (elementId == slot.elementId && (!onlyEmpty || slot.thing == null))
367 {
368 if (!(secondSlot && flag))
369 {
370 return slot;
371 }
372 flag = false;
373 }
374 }
375 return null;
376 }
377
378 public bool HasWeapon()
379 {
380 foreach (BodySlot slot in slots)
381 {
382 if (slot.thing != null && slot.thing.IsWeapon)
383 {
384 return true;
385 }
386 }
387 return false;
388 }
389
390 public Thing GetEquippedThing(int elementId)
391 {
392 foreach (BodySlot slot in slots)
393 {
394 if (slot.elementId == elementId && slot.thing != null)
395 {
396 return slot.thing;
397 }
398 }
399 return null;
400 }
401
402 public int GetWeight(bool armorOnly = false)
403 {
404 int num = 0;
405 foreach (BodySlot slot in slots)
406 {
407 if (slot.thing != null && (!armorOnly || (slot.elementId != 44 && slot.elementId != 45)))
408 {
409 num += slot.thing.ChildrenAndSelfWeight;
410 }
411 }
412 return num;
413 }
414
415 public int GetAttackIndex(Thing t)
416 {
417 int num = 0;
418 foreach (BodySlot slot in slots)
419 {
420 if (slot.thing != null && slot.elementId == 35 && slot.thing.source.offense.Length >= 2)
421 {
422 if (slot.thing == t)
423 {
424 return num;
425 }
426 num++;
427 }
428 }
429 return -1;
430 }
431
432 public int GetMeleeDistance()
433 {
434 int num = owner.Evalue(666);
435 foreach (BodySlot slot in slots)
436 {
437 if (slot.elementId == 35 && slot.thing != null && slot.thing.Evalue(666) > num)
438 {
439 num = slot.thing.Evalue(666);
440 }
441 }
442 return 1 + num;
443 }
444
446 {
447 bool flag = false;
448 int num = 0;
449 foreach (BodySlot slot in slots)
450 {
451 if (slot.elementId == 35 && slot.thing != null)
452 {
453 if (slot.thing.IsMeleeWeapon)
454 {
455 num++;
456 }
457 else
458 {
459 flag = true;
460 }
461 }
462 }
463 if (num > 1)
464 {
465 return AttackStyle.TwoWield;
466 }
467 if (flag)
468 {
469 return AttackStyle.Shield;
470 }
471 if (num == 1)
472 {
473 return AttackStyle.TwoHand;
474 }
475 return AttackStyle.Default;
476 }
477
479 {
480 return style switch
481 {
482 AttackStyle.TwoHand => 130,
483 AttackStyle.TwoWield => 131,
484 _ => 0,
485 };
486 }
487
488 public int GetSortVal(BodySlot slot)
489 {
490 return -(slot.element.sort * 100 + owner.body.slots.IndexOf(slot));
491 }
492
494 {
495 if (!t)
496 {
497 return;
498 }
499 if (b.indexPart == 0)
500 {
501 int num = 0;
502 foreach (BodySlot slot in slots)
503 {
504 if (slot.elementId == b.element.id)
505 {
506 num++;
507 }
508 if (b == slot)
509 {
510 break;
511 }
512 }
513 b.indexPart = num;
514 }
515 if (b.elementId == 35)
516 {
517 t.SetText(b.indexPart.ToString() ?? "");
518 t.SetActive(enable: true);
519 }
520 else
521 {
522 t.SetActive(enable: false);
523 }
524 }
525}
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
bool HasElement(int ele, int req=1)
Definition: Card.cs:5845
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:6077
Card AddCard(Card c)
Definition: Card.cs:3071
ICardParent parent
Definition: Card.cs:55
virtual void SetBlessedState(BlessedState s)
Definition: Card.cs:3844
void RecalculateFOV()
Definition: Card.cs:6289
Trait trait
Definition: Card.cs:53
ThingContainer things
Definition: Card.cs:38
bool IsMeleeWeapon
Definition: Card.cs:2229
int Evalue(int ele)
Definition: Card.cs:2559
BlessedState blessedState
Definition: Card.cs:278
int ChildrenAndSelfWeight
Definition: Card.cs:2029
SourceCategory.Row category
Definition: Card.cs:2037
bool IsWeapon
Definition: Card.cs:2194
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:6729
bool HasWeapon()
Definition: CharaBody.cs:378
void RemoveBodyPartAt(int idx)
Definition: CharaBody.cs:322
BodySlot GetSlot(int elementId, bool onlyEmpty=true, bool secondSlot=false)
Definition: CharaBody.cs:361
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:432
List< BodySlot > slots
Definition: CharaBody.cs:8
int GetAttackIndex(Thing t)
Definition: CharaBody.cs:415
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:493
AttackStyle GetAttackStyle()
Definition: CharaBody.cs:445
int GetAttackStyleElement(AttackStyle style)
Definition: CharaBody.cs:478
int GetSortVal(BodySlot slot)
Definition: CharaBody.cs:488
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:402
Thing GetEquippedThing(int elementId)
Definition: CharaBody.cs:390
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:347
void RefreshBodyParts()
Definition: CharaBody.cs:287
void RemoveBodyPart(int ele)
Definition: CharaBody.cs:316
Definition: Chara.cs:10
void Refresh(bool calledRecursive=false)
Definition: Chara.cs:1720
CharaBody body
Definition: Chara.cs:94
Faction faction
Definition: Chara.cs:425
override bool IsPC
Definition: Chara.cs:610
bool isCreated
Definition: Chara.cs:136
void SetTempHand(int right=0, int left=0)
Definition: Chara.cs:6610
int[] rawSlots
Definition: Chara.cs:73
bool TryEquip(Thing t, bool useFav=false)
Definition: Chara.cs:7599
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: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:671
virtual void OnUnequip(Chara c)
Definition: Trait.cs:675
Definition: UIText.cs:6
void SetText(string s)
Definition: UIText.cs:159
static void SetDirty()
Definition: WidgetEquip.cs:34