Elin Modding Docs Doc
Loading...
Searching...
No Matches
CharaBody.cs
1using System;
2using System.Collections.Generic;
3using System.Runtime.CompilerServices;
4using UnityEngine;
5
6// Token: 0x020002A6 RID: 678
7public class CharaBody : EClass
8{
9 // Token: 0x17000622 RID: 1570
10 // (get) Token: 0x060015FC RID: 5628 RVA: 0x00094AB6 File Offset: 0x00092CB6
11 public int[] rawSlots
12 {
13 get
14 {
15 return this.owner.rawSlots;
16 }
17 }
18
19 // Token: 0x060015FD RID: 5629 RVA: 0x00094AC4 File Offset: 0x00092CC4
20 public void SetOwner(Chara chara, bool deserialized = false)
21 {
22 this.owner = chara;
23 if (deserialized)
24 {
25 if (this.rawSlots != null)
26 {
27 for (int i = 0; i < this.rawSlots.Length; i++)
28 {
29 this.AddBodyPart(this.rawSlots[i], null);
30 }
31 }
32 foreach (Thing thing in this.owner.things)
33 {
34 if (thing.isEquipped)
35 {
36 int num = thing.c_equippedSlot - 1;
37 if (num < 0 || num >= this.slots.Count)
38 {
39 thing.c_equippedSlot = 0;
40 }
41 else
42 {
43 this.slots[num].thing = thing;
44 thing.elements.SetParent(this.owner);
45 }
46 }
47 }
48 }
49 }
50
51 // Token: 0x060015FE RID: 5630 RVA: 0x00094B9C File Offset: 0x00092D9C
52 public void Unequip(Thing thing, bool refresh = true)
53 {
54 if (!thing.isEquipped)
55 {
56 return;
57 }
58 this.Unequip(this.slots[thing.c_equippedSlot - 1], refresh);
59 }
60
61 // Token: 0x060015FF RID: 5631 RVA: 0x00094BC4 File Offset: 0x00092DC4
62 public void UnequipAll(int idSlot)
63 {
64 foreach (BodySlot bodySlot in this.slots)
65 {
66 if (bodySlot.elementId == idSlot)
67 {
68 this.Unequip(bodySlot, true);
69 }
70 }
71 }
72
73 // Token: 0x06001600 RID: 5632 RVA: 0x00094C24 File Offset: 0x00092E24
74 public void Unequip(BodySlot slot, bool refresh = true)
75 {
76 if (slot.thing == null)
77 {
78 return;
79 }
80 Thing thing = slot.thing;
81 if (EClass.pc != null)
82 {
83 EClass.pc.faction.charaElements.OnUnequip(this.owner, thing);
84 }
85 thing.elements.SetParent(null);
86 thing.c_equippedSlot = 0;
87 slot.thing = null;
88 if (this.owner.IsPC)
89 {
90 LayerChara.Refresh();
91 LayerInventory.SetDirty(thing);
92 WidgetEquip.SetDirty();
93 }
94 if (slot.elementId == 45 && EClass.core.IsGameStarted)
95 {
96 this.owner.RecalculateFOV();
97 }
98 if (refresh && this.owner.isCreated && EClass.core.IsGameStarted)
99 {
100 this.owner.Refresh(false);
101 if (slot.elementId == 37 && this.owner.HasElement(1209, 1))
102 {
103 this.owner.Say("tail_free", this.owner, null, null);
104 }
105 }
106 }
107
108 // Token: 0x06001601 RID: 5633 RVA: 0x00094D18 File Offset: 0x00092F18
109 public bool IsEquippable(Thing thing, BodySlot slot, bool text = true)
110 {
111 CharaBody.<>c__DisplayClass11_0 CS$<>8__locals1;
112 CS$<>8__locals1.text = text;
113 CS$<>8__locals1.slot = slot;
114 if (CS$<>8__locals1.slot == null)
115 {
116 return false;
117 }
118 int elementId = CS$<>8__locals1.slot.elementId;
119 if (elementId != 31)
120 {
121 if (elementId != 33)
122 {
123 if (elementId == 39)
124 {
125 if (this.owner.HasElement(1552, 1))
126 {
127 return CharaBody.<IsEquippable>g__CannotEquip|11_0(ref CS$<>8__locals1);
128 }
129 }
130 }
131 else if (this.owner.HasElement(1554, 1))
132 {
133 return CharaBody.<IsEquippable>g__CannotEquip|11_0(ref CS$<>8__locals1);
134 }
135 }
136 else if (this.owner.HasElement(1555, 1))
137 {
138 return CharaBody.<IsEquippable>g__CannotEquip|11_0(ref CS$<>8__locals1);
139 }
140 if (this.IsTooHeavyToEquip(thing))
141 {
142 if (EClass.core.IsGameStarted && this.owner.IsPC && CS$<>8__locals1.text)
143 {
144 Msg.Say("tooHeavyToEquip", thing, null, null, null);
145 }
146 return false;
147 }
148 return true;
149 }
150
151 // Token: 0x06001602 RID: 5634 RVA: 0x00094DE9 File Offset: 0x00092FE9
152 public bool IsTooHeavyToEquip(Thing thing)
153 {
154 return this.owner.HasElement(1204, 1) && thing.ChildrenAndSelfWeight > 1000 && thing.category.slot != 44;
155 }
156
157 // Token: 0x06001603 RID: 5635 RVA: 0x00094E20 File Offset: 0x00093020
158 public void UnqeuipIfTooHeavy(Thing t)
159 {
160 if (t.isEquipped)
161 {
162 BodySlot bodySlot = this.slots[t.c_equippedSlot - 1];
163 if (this.IsTooHeavyToEquip(t))
164 {
165 this.owner.Say("tooHeavyToEquip", t, null, null);
166 this.Unequip(t, true);
167 }
168 }
169 if (!this.owner.IsPC && !t.isEquipped)
170 {
171 this.owner.TryEquip(t, false);
172 }
173 }
174
175 // Token: 0x06001604 RID: 5636 RVA: 0x00094E90 File Offset: 0x00093090
176 public bool Equip(Thing thing, BodySlot slot = null, bool msg = true)
177 {
178 BodySlot bodySlot;
179 if ((bodySlot = slot) == null)
180 {
181 bodySlot = (this.GetSlot(thing.category.slot, true, false) ?? this.GetSlot(thing.category.slot, false, false));
182 }
183 slot = bodySlot;
184 if (slot == this.slotMainHand || slot == this.slotOffHand)
185 {
186 this.owner.combatCount = 10;
187 }
188 if (slot == null || slot.elementId != thing.category.slot)
189 {
190 string[] array = new string[6];
191 array[0] = "could not equip:";
192 array[1] = ((thing != null) ? thing.ToString() : null);
193 array[2] = "/";
194 int num = 3;
195 BodySlot bodySlot2 = slot;
196 array[num] = ((bodySlot2 != null) ? bodySlot2.ToString() : null);
197 array[4] = "/";
198 int num2 = 5;
199 Chara chara = this.owner;
200 array[num2] = ((chara != null) ? chara.ToString() : null);
201 Debug.LogWarning(string.Concat(array));
202 return false;
203 }
204 if (!this.IsEquippable(thing, slot, true))
205 {
206 return false;
207 }
208 if (slot.thing != null)
209 {
210 if (slot.thing == thing)
211 {
212 this.Unequip(slot, true);
213 return false;
214 }
215 this.Unequip(slot, false);
216 }
217 this.Unequip(thing, false);
218 if (thing.parent != this.owner)
219 {
220 if (msg && this.owner.IsPC && thing.parent is Thing)
221 {
222 Msg.Say("movedToEquip", thing, thing.parent as Thing, null, null);
223 }
224 this.owner.AddCard(thing);
225 }
226 slot.thing = thing;
227 thing.c_equippedSlot = slot.index + 1;
228 thing.elements.SetParent(this.owner);
229 if (EClass.pc != null)
230 {
231 EClass.pc.faction.charaElements.OnEquip(this.owner, thing);
232 }
233 this.owner.SetTempHand(0, 0);
234 if (this.owner.IsPC)
235 {
236 LayerChara.Refresh();
237 LayerInventory.SetDirty(thing);
238 WidgetEquip.SetDirty();
239 }
240 if (slot.elementId == 45 && EClass.core.IsGameStarted)
241 {
242 this.owner.RecalculateFOV();
243 }
244 if (this.owner.isCreated && EClass.core.IsGameStarted)
245 {
246 this.owner.Refresh(false);
247 }
248 if (this.owner.isCreated)
249 {
250 if (thing.Evalue(656) > 0)
251 {
252 thing.blessedState = BlessedState.Cursed;
253 }
254 if (thing.blessedState <= BlessedState.Cursed)
255 {
256 this.owner.Say("equipCursed", this.owner, null, null);
257 this.owner.PlaySound("curse3", 1f, true);
258 }
259 }
260 if (slot.elementId == 37 && this.owner.HasElement(1209, 1))
261 {
262 this.owner.Say("tail_covered", this.owner, null, null);
263 }
264 return true;
265 }
266
267 // Token: 0x06001605 RID: 5637 RVA: 0x00095134 File Offset: 0x00093334
268 public void AddBodyPart(int ele, Thing thing = null)
269 {
270 BodySlot item = new BodySlot
271 {
272 elementId = ele,
273 thing = thing,
274 index = this.slots.Count
275 };
276 if (ele == 35)
277 {
278 if (this.slotMainHand == null)
279 {
280 this.slotMainHand = item;
281 }
282 else if (this.slotOffHand == null)
283 {
284 this.slotOffHand = item;
285 }
286 }
287 if (ele == 41)
288 {
289 this.slotRange = item;
290 }
291 this.slots.Add(item);
292 }
293
294 // Token: 0x06001606 RID: 5638 RVA: 0x000951A4 File Offset: 0x000933A4
295 public void RefreshBodyParts()
296 {
297 foreach (BodySlot bodySlot in this.slots)
298 {
299 int elementId = bodySlot.elementId;
300 if (elementId == 35)
301 {
302 if (this.slotMainHand == null)
303 {
304 this.slotMainHand = bodySlot;
305 }
306 else if (this.slotOffHand == null)
307 {
308 this.slotOffHand = bodySlot;
309 }
310 }
311 if (elementId == 41)
312 {
313 this.slotRange = bodySlot;
314 }
315 }
316 }
317
318 // Token: 0x06001607 RID: 5639 RVA: 0x00095228 File Offset: 0x00093428
319 public void RemoveBodyPart(int ele)
320 {
321 int num = this.slots.FindIndex((BodySlot a) => a.elementId == ele);
322 if (num != -1)
323 {
324 BodySlot bodySlot = this.slots[num];
325 if (bodySlot.thing != null)
326 {
327 this.Unequip(bodySlot, true);
328 }
329 if (this.slotMainHand == bodySlot)
330 {
331 this.slotMainHand = null;
332 }
333 if (this.slotOffHand == bodySlot)
334 {
335 this.slotOffHand = null;
336 }
337 if (this.slotRange == bodySlot)
338 {
339 this.slotRange = null;
340 }
341 this.slots.RemoveAt(num);
342 }
343 }
344
345 // Token: 0x06001608 RID: 5640 RVA: 0x000952B8 File Offset: 0x000934B8
346 public BodySlot GetSlot(Thing t, bool onlyEmpty = false, bool secondSlot = false)
347 {
348 BodySlot slot = this.GetSlot(t.category.slot, true, secondSlot);
349 if (slot != null)
350 {
351 return slot;
352 }
353 if (!onlyEmpty)
354 {
355 return this.GetSlot(t.category.slot, false, secondSlot);
356 }
357 return null;
358 }
359
360 // Token: 0x06001609 RID: 5641 RVA: 0x000952F8 File Offset: 0x000934F8
361 public BodySlot GetSlot(int elementId, bool onlyEmpty = true, bool secondSlot = false)
362 {
363 bool flag = true;
364 foreach (BodySlot bodySlot in this.slots)
365 {
366 if (elementId == bodySlot.elementId && (!onlyEmpty || bodySlot.thing == null))
367 {
368 if (!secondSlot || !flag)
369 {
370 return bodySlot;
371 }
372 flag = false;
373 }
374 }
375 return null;
376 }
377
378 // Token: 0x0600160A RID: 5642 RVA: 0x0009536C File Offset: 0x0009356C
379 public Thing GetEquippedThing(int elementId)
380 {
381 foreach (BodySlot bodySlot in this.slots)
382 {
383 if (bodySlot.elementId == elementId && bodySlot.thing != null)
384 {
385 return bodySlot.thing;
386 }
387 }
388 return null;
389 }
390
391 // Token: 0x0600160B RID: 5643 RVA: 0x000953D8 File Offset: 0x000935D8
392 public int GetWeight(bool armorOnly = false)
393 {
394 int num = 0;
395 foreach (BodySlot bodySlot in this.slots)
396 {
397 if (bodySlot.thing != null && (!armorOnly || (bodySlot.elementId != 44 && bodySlot.elementId != 45)))
398 {
399 num += bodySlot.thing.ChildrenAndSelfWeight;
400 }
401 }
402 return num;
403 }
404
405 // Token: 0x0600160C RID: 5644 RVA: 0x00095454 File Offset: 0x00093654
406 public int GetAttackIndex(Thing t)
407 {
408 int num = 0;
409 foreach (BodySlot bodySlot in this.slots)
410 {
411 if (bodySlot.thing != null && bodySlot.elementId == 35 && bodySlot.thing.source.offense.Length >= 2)
412 {
413 if (bodySlot.thing == t)
414 {
415 return num;
416 }
417 num++;
418 }
419 }
420 return -1;
421 }
422
423 // Token: 0x0600160D RID: 5645 RVA: 0x000954E0 File Offset: 0x000936E0
424 public int GetMeleeDistance()
425 {
426 int num = this.owner.Evalue(666);
427 if (num == 0)
428 {
429 return 1;
430 }
431 num = 0;
432 foreach (BodySlot bodySlot in this.slots)
433 {
434 if (bodySlot.elementId == 35 && bodySlot.thing != null && bodySlot.thing.Evalue(666) > num)
435 {
436 num = bodySlot.thing.Evalue(666);
437 }
438 }
439 return 1 + num;
440 }
441
442 // Token: 0x0600160E RID: 5646 RVA: 0x00095580 File Offset: 0x00093780
443 public AttackStyle GetAttackStyle()
444 {
445 bool flag = false;
446 int num = 0;
447 foreach (BodySlot bodySlot in this.slots)
448 {
449 if (bodySlot.elementId == 35 && bodySlot.thing != null)
450 {
451 if (bodySlot.thing.IsMeleeWeapon)
452 {
453 num++;
454 }
455 else
456 {
457 flag = true;
458 }
459 }
460 }
461 if (num > 1)
462 {
463 return AttackStyle.TwoWield;
464 }
465 if (flag)
466 {
467 return AttackStyle.Shield;
468 }
469 if (num == 1)
470 {
471 return AttackStyle.TwoHand;
472 }
473 return AttackStyle.Default;
474 }
475
476 // Token: 0x0600160F RID: 5647 RVA: 0x0009560C File Offset: 0x0009380C
477 public int GetAttackStyleElement(AttackStyle style)
478 {
479 if (style == AttackStyle.TwoHand)
480 {
481 return 130;
482 }
483 if (style != AttackStyle.TwoWield)
484 {
485 return 0;
486 }
487 return 131;
488 }
489
490 // Token: 0x06001611 RID: 5649 RVA: 0x00095638 File Offset: 0x00093838
491 [CompilerGenerated]
492 internal static bool <IsEquippable>g__CannotEquip|11_0(ref CharaBody.<>c__DisplayClass11_0 A_0)
493 {
494 if (A_0.text)
495 {
496 Msg.Say("cannnotEquip", A_0.slot.element.GetName().ToLower(), null, null, null);
497 }
498 return false;
499 }
500
501 // Token: 0x04001028 RID: 4136
502 public Chara owner;
503
504 // Token: 0x04001029 RID: 4137
505 public List<BodySlot> slots = new List<BodySlot>();
506
507 // Token: 0x0400102A RID: 4138
508 public BodySlot slotMainHand;
509
510 // Token: 0x0400102B RID: 4139
511 public BodySlot slotOffHand;
512
513 // Token: 0x0400102C RID: 4140
514 public BodySlot slotRange;
515}
Definition Chara.cs:12
Definition Msg.cs:7
Definition Thing.cs:10