Elin Decompiled Documentation EA 23.130 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 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 Thing GetEquippedThing(int elementId)
379 {
380 foreach (BodySlot slot in slots)
381 {
382 if (slot.elementId == elementId && slot.thing != null)
383 {
384 return slot.thing;
385 }
386 }
387 return null;
388 }
389
390 public int GetWeight(bool armorOnly = false)
391 {
392 int num = 0;
393 foreach (BodySlot slot in slots)
394 {
395 if (slot.thing != null && (!armorOnly || (slot.elementId != 44 && slot.elementId != 45)))
396 {
397 num += slot.thing.ChildrenAndSelfWeight;
398 }
399 }
400 return num;
401 }
402
403 public int GetAttackIndex(Thing t)
404 {
405 int num = 0;
406 foreach (BodySlot slot in slots)
407 {
408 if (slot.thing != null && slot.elementId == 35 && slot.thing.source.offense.Length >= 2)
409 {
410 if (slot.thing == t)
411 {
412 return num;
413 }
414 num++;
415 }
416 }
417 return -1;
418 }
419
420 public int GetMeleeDistance()
421 {
422 int num = owner.Evalue(666);
423 foreach (BodySlot slot in slots)
424 {
425 if (slot.elementId == 35 && slot.thing != null && slot.thing.Evalue(666) > num)
426 {
427 num = slot.thing.Evalue(666);
428 }
429 }
430 return 1 + num;
431 }
432
434 {
435 bool flag = false;
436 int num = 0;
437 foreach (BodySlot slot in slots)
438 {
439 if (slot.elementId == 35 && slot.thing != null)
440 {
441 if (slot.thing.IsMeleeWeapon)
442 {
443 num++;
444 }
445 else
446 {
447 flag = true;
448 }
449 }
450 }
451 if (num > 1)
452 {
453 return AttackStyle.TwoWield;
454 }
455 if (flag)
456 {
457 return AttackStyle.Shield;
458 }
459 if (num == 1)
460 {
461 return AttackStyle.TwoHand;
462 }
463 return AttackStyle.Default;
464 }
465
467 {
468 return style switch
469 {
470 AttackStyle.TwoHand => 130,
471 AttackStyle.TwoWield => 131,
472 _ => 0,
473 };
474 }
475
476 public int GetSortVal(BodySlot slot)
477 {
478 return -(slot.element.sort * 100 + owner.body.slots.IndexOf(slot));
479 }
480
482 {
483 if (!t)
484 {
485 return;
486 }
487 if (b.indexPart == 0)
488 {
489 int num = 0;
490 foreach (BodySlot slot in slots)
491 {
492 if (slot.elementId == b.element.id)
493 {
494 num++;
495 }
496 if (b == slot)
497 {
498 break;
499 }
500 }
501 b.indexPart = num;
502 }
503 if (b.elementId == 35)
504 {
505 t.SetText(b.indexPart.ToString() ?? "");
506 t.SetActive(enable: true);
507 }
508 else
509 {
510 t.SetActive(enable: false);
511 }
512 }
513}
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:5395
SoundSource PlaySound(string id, float v=1f, bool spatial=true)
Definition: Card.cs:5585
Card AddCard(Card c)
Definition: Card.cs:2936
ICardParent parent
Definition: Card.cs:51
void RecalculateFOV()
Definition: Card.cs:5797
Trait trait
Definition: Card.cs:49
ThingContainer things
Definition: Card.cs:34
bool IsMeleeWeapon
Definition: Card.cs:2141
int Evalue(int ele)
Definition: Card.cs:2471
BlessedState blessedState
Definition: Card.cs:262
int ChildrenAndSelfWeight
Definition: Card.cs:1941
SourceCategory.Row category
Definition: Card.cs:1949
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:6232
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:420
List< BodySlot > slots
Definition: CharaBody.cs:8
int GetAttackIndex(Thing t)
Definition: CharaBody.cs:403
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:481
AttackStyle GetAttackStyle()
Definition: CharaBody.cs:433
int GetAttackStyleElement(AttackStyle style)
Definition: CharaBody.cs:466
int GetSortVal(BodySlot slot)
Definition: CharaBody.cs:476
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:390
Thing GetEquippedThing(int elementId)
Definition: CharaBody.cs:378
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:1518
CharaBody body
Definition: Chara.cs:94
Faction faction
Definition: Chara.cs:417
override bool IsPC
Definition: Chara.cs:602
bool isCreated
Definition: Chara.cs:134
void SetTempHand(int right=0, int left=0)
Definition: Chara.cs:6115
int[] rawSlots
Definition: Chara.cs:73
bool TryEquip(Thing t, bool useFav=false)
Definition: Chara.cs:7058
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:660
virtual void OnUnequip(Chara c)
Definition: Trait.cs:664
Definition: UIText.cs:6
void SetText(string s)
Definition: UIText.cs:159
static void SetDirty()
Definition: WidgetEquip.cs:34