Elin Decompiled Documentation EA 23.327 Nightly
Loading...
Searching...
No Matches
AttackProcess.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using UnityEngine;
5
6public class AttackProcess : EClass
7{
8 public static AttackProcess Current = new AttackProcess();
9
10 public long toHit;
11
12 public long toHitBase;
13
14 public long evasion;
15
16 public int dNum;
17
18 public int dDim;
19
20 public int dBonus;
21
22 public int toHitFix;
23
24 public int penetration;
25
26 public int distMod;
27
28 public int attackIndex;
29
30 public int dNumAmmo;
31
32 public int dDimAmmo;
33
34 public int dBonusAmmo;
35
36 public int numFire;
37
39
40 public float dMulti;
41
42 public bool crit;
43
44 public bool critFury;
45
46 public bool hit;
47
48 public bool evadePlus;
49
50 public bool isThrow;
51
52 public bool ignoreAnime;
53
54 public bool ignoreAttackSound;
55
56 public Chara CC;
57
58 public Card TC;
59
60 public Point TP;
61
63
65
66 public Thing weapon;
67
68 public Thing ammo;
69
71
73
75
76 public bool IsMartial => weapon == null;
77
78 public bool IsMartialWeapon
79 {
80 get
81 {
82 if (weapon != null)
83 {
84 return weapon.category.skill == 100;
85 }
86 return false;
87 }
88 }
89
90 public bool IsRanged
91 {
92 get
93 {
94 if (toolRange != null && !isThrow)
95 {
97 }
98 return false;
99 }
100 }
101
102 public bool IsCane
103 {
104 get
105 {
106 if (IsRanged)
107 {
109 }
110 return false;
111 }
112 }
113
114 public static int GetWeaponEnc(Chara CC, Thing w, int ele, bool addSelfEnc = false)
115 {
116 int num = w?.Evalue(ele) ?? 0;
118 {
119 num += EClass.pc.faction.charaElements.Value(ele);
120 }
121 num = num * (100 + GetTwoHandEncBonus(CC, w)) / 100;
122 if (addSelfEnc)
123 {
124 num += CC.Evalue(ele);
125 }
126 return num;
127 }
128
129 public static int GetTwoHandEncBonus(Chara CC, Thing w)
130 {
131 if (CC == null || CC.body.GetAttackStyle() != AttackStyle.TwoHand || w == null || !w.IsWeapon)
132 {
133 return 0;
134 }
135 return Mathf.Clamp(CC.Evalue(130) / 15, 0, 2) * 25;
136 }
137
138 public string GetText()
139 {
140 string text = dNum + "d" + dDim;
141 text = text + ((dBonus >= 0) ? "+" : "") + dBonus;
142 string @ref = (IsMartial ? "evalHand".lang() : "evalWeapon".lang((attackIndex + 1).ToString() ?? ""));
143 return "attackEval".lang(@ref, text, dMulti.ToString("F2") ?? "", toHit.ToString() ?? "", penetration.ToString() ?? "");
144 }
145
146 public void Prepare(Chara _CC, Thing _weapon, Card _TC = null, Point _TP = null, int _attackIndex = 0, bool _isThrow = false)
147 {
148 CC = _CC;
149 TC = _TC;
150 TP = _TP;
151 isThrow = _isThrow;
152 weapon = _weapon;
153 ammo = _weapon?.ammoData;
154 hit = (crit = (critFury = (evadePlus = false)));
156 attackType = AttackType.Slash;
157 attackStyle = AttackStyle.Default;
158 evasion = 0L;
159 penetration = 0;
160 distMod = 100;
161 attackIndex = _attackIndex;
163 ignoreAnime = (ignoreAttackSound = false);
164 if (!isThrow)
165 {
166 if (!IsRanged)
167 {
169 }
170 else if (TP != null)
171 {
172 int num = CC.pos.Distance(TP);
173 distMod = Mathf.Max(115 - 10 * Mathf.Abs(num - toolRange.BestDist) * 100 / (100 + weapon.Evalue(605) * 10), 80);
174 }
175 }
176 if (isThrow)
177 {
178 bool flag = weapon.HasTag(CTAG.throwWeapon) || weapon.HasTag(CTAG.throwWeaponEnemy);
179 int num2 = (int)Mathf.Clamp(Mathf.Sqrt(weapon.SelfWeight + weapon.ChildrenWeight) * 3f + 25f + (float)(flag ? 75 : 0), 10f, 400f + Mathf.Sqrt(CC.STR) * 50f);
180 int num3 = Mathf.Clamp(weapon.material.hardness, flag ? 40 : 20, 200);
182 attackType = AttackType.Blunt;
183 dBonus = CC.DMG + (CC.IsPCParty ? 3 : 7) + Math.Min(weapon.encLV, 99);
184 dNum = 2;
185 dDim = (((!CC.IsPCParty) ? CC.LV : 0) + CC.STR + CC.Evalue(108)) * num2 / 100 * num3 / 100 / 2;
186 dMulti = 1f + (float)CC.Evalue(132) / 500f;
187 toHitBase = EClass.curve(CC.DEX / 4 + CC.STR / 2 + weaponSkill.Value, 50, 25) + (CC.IsPCFaction ? 75 : 250);
188 toHitFix = CC.HIT + weapon.HIT;
189 penetration = 25;
190 }
191 else if (IsMartial || IsMartialWeapon)
192 {
194 bool flag2 = weapon != null && weapon.Evalue(482) > 0;
195 if (flag2)
196 {
198 }
199 attackType = ((!CC.race.meleeStyle.IsEmpty()) ? CC.race.meleeStyle.ToEnum<AttackType>() : ((EClass.rnd(2) == 0) ? AttackType.Kick : AttackType.Punch));
200 dBonus = CC.DMG + CC.encLV + (int)Mathf.Sqrt(Mathf.Max(0, weaponSkill.GetParent(CC).Value / 5 + weaponSkill.Value / 4));
201 dNum = 2 + Mathf.Min(weaponSkill.Value / 10, 4);
202 dDim = 5 + (int)Mathf.Sqrt(Mathf.Max(0, weaponSkill.Value / 3));
203 dMulti = 0.6f + (float)(weaponSkill.GetParent(CC).Value / 2 + weaponSkill.Value / 2 + CC.Evalue(flag2 ? 304 : 132) / 2) / 50f;
204 dMulti += 0.05f * (float)CC.Evalue(1400);
206 toHitFix = CC.HIT;
207 if (attackStyle == AttackStyle.Shield)
208 {
209 toHitBase = toHitBase * 75 / 100;
210 }
211 penetration = Mathf.Clamp(weaponSkill.Value / 10 + 5, 5, 20) + CC.Evalue(92);
212 if (CC.HasElement(1246))
213 {
214 penetration += 25;
215 }
216 if (IsMartialWeapon)
217 {
218 dBonus += weapon.DMG;
219 dNum += weapon.source.offense[0];
220 dDim = Mathf.Max(dDim / 2 + weapon.c_diceDim, 1);
223 if (!weapon.source.attackType.IsEmpty())
224 {
225 attackType = weapon.source.attackType.ToEnum<AttackType>();
226 }
227 }
228 }
229 else
230 {
231 if (IsRanged)
232 {
234 }
235 else
236 {
238 }
239 if (!weapon.source.attackType.IsEmpty())
240 {
241 attackType = weapon.source.attackType.ToEnum<AttackType>();
242 }
243 bool flag3 = IsCane || weapon.Evalue(482) > 0;
244 if (flag3)
245 {
247 }
248 dBonus = CC.DMG + CC.encLV + weapon.DMG;
249 dNum = weapon.source.offense[0];
251 dMulti = 0.6f + (float)(weaponSkill.GetParent(CC).Value + weaponSkill.Value / 2 + CC.Evalue(flag3 ? 304 : (IsRanged ? 133 : 132))) / 50f;
252 dMulti += 0.05f * (float)CC.Evalue(IsRanged ? 1404 : 1400);
253 toHitBase = EClass.curve((IsCane ? CC.WIL : CC.DEX) / 4 + weaponSkill.GetParent(CC).Value / 3 + weaponSkill.Value, 50, 25) + 50;
254 if (CC.HasElement(1208) && weaponSkill.id == 101)
255 {
256 toHitBase = toHitBase * 115 / 100;
257 }
258 toHitFix = CC.HIT + weapon.HIT;
259 penetration = weapon.Penetration + CC.Evalue(92);
260 if (IsRanged)
261 {
262 if (CC.HasElement(1244))
263 {
264 penetration += 25;
265 }
266 }
267 else if (CC.HasElement(1247))
268 {
269 penetration += 25;
270 }
271 if (IsCane)
272 {
273 toHitBase += 50L;
274 }
275 }
276 if (ammo != null && !(ammo.trait is TraitAmmoTalisman))
277 {
278 dNumAmmo = ((ammo.source.offense.Length != 0) ? ammo.source.offense[0] : 0);
280 dBonusAmmo = ammo.DMG + ammo.encLV;
281 if (dNumAmmo < 1)
282 {
283 dNumAmmo = 1;
284 }
285 if (dDimAmmo < 1)
286 {
287 dDimAmmo = 1;
288 }
289 toHitFix += ammo.HIT;
290 }
291 else
292 {
293 dNumAmmo = 0;
294 dDimAmmo = 0;
295 dBonusAmmo = 0;
296 }
297 if (dNum < 1)
298 {
299 dNum = 1;
300 }
301 if (dDim < 1)
302 {
303 dDim = 1;
304 }
305 if (penetration > 100)
306 {
307 penetration = 100;
308 }
309 if (attackStyle == AttackStyle.TwoHand)
310 {
311 dMulti = dMulti * 1.5f + 0.1f * Mathf.Sqrt(Mathf.Max(0, CC.Evalue(130)));
312 }
313 dMulti = dMulti * (float)distMod / 100f;
314 toHit = (toHitBase + toHitFix) * (100 + CC.Evalue(414)) / 100;
315 toHit = toHit * distMod / 100;
316 if (CC.HasCondition<ConBane>())
317 {
318 toHit = toHit * 75 / 100;
319 }
320 if (TC != null && CC.HasHigherGround(TC))
321 {
322 toHit = toHit * 120 / 100;
323 }
324 if (CC.ride != null)
325 {
326 toHit = toHit * 100 / (100 + 500 / Mathf.Max(5, 10 + CC.EvalueRiding()));
327 }
328 if (CC.parasite != null)
329 {
330 toHit = toHit * 100 / (100 + 1000 / Mathf.Max(5, 10 + CC.Evalue(227)));
331 }
332 if (CC.host != null)
333 {
334 if (CC.host.ride == CC)
335 {
336 toHit = toHit * 100 / (100 + 1000 / Mathf.Max(5, 10 + CC.STR));
337 }
338 if (CC.host.parasite == CC)
339 {
340 toHit = toHit * 100 / (100 + 2000 / Mathf.Max(5, 10 + CC.DEX));
341 }
342 }
343 if (attackStyle == AttackStyle.TwoHand)
344 {
345 toHit += 25 + (int)Mathf.Sqrt(Mathf.Max(0, CC.Evalue(130)) * 2);
346 }
347 else if (attackStyle == AttackStyle.TwoWield)
348 {
349 int num4 = CC.EvalueMax(131, -10);
350 int num5 = ((num4 >= 50) ? 10 : ((num4 >= 25) ? 12 : 15));
351 if (toHit > 0)
352 {
353 toHit = toHit * 100 / (100 + (attackIndex + 1) * num5 + attackIndex * Mathf.Clamp(2000 / (20 + num4), 0, 100));
354 }
355 }
356 if (CC.isBlind)
357 {
358 toHit /= ((IsRanged || isThrow) ? 10 : 3);
359 }
361 {
362 toHit /= 2L;
363 }
364 if (TC != null)
365 {
366 evasion = EClass.curve(TC.PER / 3 + TC.Evalue(150), 50, 10) + TC.DV + 25;
367 if (TC.isChara && TC.Chara.isBlind)
368 {
369 evasion /= 2L;
370 }
371 if (TC.HasCondition<ConDim>())
372 {
373 evasion /= 2L;
374 }
375 if (TC.isChara && TC.Chara.HasHigherGround(CC))
376 {
377 evasion = evasion * 120 / 100;
378 }
379 }
380 }
381
382 public void PlayRangedAnime(int numFire, float delay = 0f)
383 {
384 if (weapon == null)
385 {
386 return;
387 }
388 bool isGun = toolRange is TraitToolRangeGun;
389 bool isCane = toolRange is TraitToolRangeCane;
390 GameSetting.EffectData data = EClass.setting.effect.guns.TryGetValue(weapon.id) ?? EClass.setting.effect.guns[isCane ? "cane" : (isGun ? "gun" : "bow")];
391 CustomGunEffectData customData = data as CustomGunEffectData;
392 bool isPCC = CC.IsPCC && CC.renderer.hasActor;
393 Vector2 firePos = (isPCC ? new Vector2(data.firePos.x * (float)((CC.renderer.actor.currentDir != 0 && CC.renderer.actor.currentDir != 1) ? 1 : (-1)), data.firePos.y) : Vector2.zero);
394 Chara _CC = CC;
395 Point _TP = posRangedAnime.Copy();
396 Thing _weapon = weapon;
397 bool ignoreSound = ignoreAttackSound;
399 Color effColor = Color.white;
400 if (isCane)
401 {
402 Element element = toolRange.owner.elements.dict.Values.Where((Element e) => e.source.categorySub == "eleAttack").RandomItem();
403 if (element != null)
404 {
405 effColor = EClass.Colors.elementColors.TryGetValue(element.source.alias, "eleFire");
406 }
407 if (!string.IsNullOrEmpty(customData?.caneColor))
408 {
409 Color color = customData.caneColor.ToColor();
410 effColor = (customData.caneColorBlend ? Color.Lerp(effColor, color, 0.5f) : color);
411 }
412 }
413 bool isLaser = toolRange is TraitToolRangeGunEnergy || (customData?.forceLaser ?? false);
414 bool isRail = isLaser && (weapon.id == "gun_rail" || (customData?.forceRail ?? false));
415 for (int i = 0; i < numFire; i++)
416 {
417 TweenUtil.Delay((float)i * data.delay + delay, delegate
418 {
419 if (EClass.core.IsGameStarted && _CC.IsAliveInCurrentZone && _zone == _CC.currentZone)
420 {
421 Vector3 fromV = (_CC.isSynced ? _CC.renderer.position : _CC.pos.Position());
422 switch (_weapon.id)
423 {
424 case "gun_rail":
425 _CC.PlayEffect("laser_rail").GetComponent<SpriteBasedLaser>().Play(_TP.PositionCenter());
426 break;
427 case "gun_laser":
428 _CC.PlayEffect("laser").GetComponent<SpriteBasedLaser>().Play(_TP.PositionCenter());
429 break;
430 case "gun_laser_assault":
431 Effect.Get("ranged_laser")._Play(_CC.pos, fromV, 0f, _TP, data.sprite);
432 break;
433 default:
434 if (isLaser)
435 {
436 string id = (isRail ? "laser_rail" : "laser");
437 _CC.PlayEffect(id).GetComponent<SpriteBasedLaser>().Play(_TP.PositionCenter());
438 }
439 else
440 {
441 Effect effect = Effect.Get("ranged_arrow")._Play(_CC.pos, fromV, 0f, _TP, data.sprite);
442 if (isCane)
443 {
444 effect.sr.color = effColor;
445 }
446 }
447 break;
448 }
449 if (data.eject)
450 {
451 if (!ignoreSound)
452 {
453 _CC.PlaySound(customData?.idSoundEject.IsEmpty("bullet_drop"));
454 }
455 _CC.PlayEffect("bullet").Emit(1);
456 }
457 if (isGun)
458 {
459 if (isPCC)
460 {
461 _weapon.PlayEffect(data.idEffect.IsEmpty("gunfire"), useRenderPos: true, 0f, firePos);
462 }
463 else
464 {
465 _CC.PlayEffect(data.idEffect.IsEmpty("gunfire"));
466 }
467 }
468 if (!ignoreSound)
469 {
470 _CC.PlaySound(data.idSound.IsEmpty("attack_gun"));
471 }
472 }
473 });
474 }
475 }
476
477 public int GetRocketPower()
478 {
479 return (30 + (dNum * dDim + dBonus) + (dNumAmmo * dDimAmmo + dBonusAmmo)) * (100 + (int)Mathf.Sqrt(weaponSkill.Value) * 8) / 100;
480 }
481
482 public long GetRawDamage(float dmgMulti, bool crit, bool maxRoll)
483 {
484 bool flag = CC.HasCondition<ConReload>();
485 long num = Dice.Roll(dNum, dDim, dBonus, CC);
486 if (ammo != null && !flag)
487 {
488 num += Dice.Roll(dNumAmmo, dDimAmmo, dBonusAmmo, CC);
489 }
490 if (crit || maxRoll)
491 {
492 num = Dice.RollMax(dNum, dDim, dBonus);
493 if (ammo != null && !flag)
494 {
495 num += Dice.RollMax(dNumAmmo, dDimAmmo, dBonusAmmo);
496 }
497 if (crit && (IsMartial || IsMartialWeapon))
498 {
499 dMulti *= 1.25f;
500 }
501 }
502 if (CC.Evalue(1355) > 0)
503 {
504 num++;
505 }
506 num = (long)(dMulti * (float)num * dmgMulti);
507 long num2 = 99999999L;
508 ConStrife condition = CC.GetCondition<ConStrife>();
509 if (condition != null)
510 {
511 num = num * (100 + condition.lv * 10) / 100;
512 num2 = num2 * (100 + condition.lv * 5) / 100;
513 }
514 return (long)Mathf.Clamp(num, 0f, num2);
515 }
516
517 public static void ProcShieldEncs(Chara CC, Card TC, int mtpChance = 100)
518 {
519 foreach (BodySlot slot in CC.body.slots)
520 {
521 if (slot.elementId == 35 && slot.thing != null && (slot.thing.category.IsChildOf("shield") || slot.thing.category.IsChildOf("martial")))
522 {
523 ProcAbility(slot.thing.elements.dict.Values.ToList(), CC, TC, CC.Evalue((slot.thing.category.skill == 0) ? 123 : slot.thing.category.skill), subAttack: false, mtpChance);
524 }
525 }
526 }
527
528 public static void ProcAbility(List<Element> list, Chara CC, Card TC, int bonus, bool subAttack = false, int mtpChance = 100)
529 {
530 if (list == null)
531 {
532 return;
533 }
534 foreach (Element item in list)
535 {
536 ProcAbility(item, CC, TC, bonus, subAttack, mtpChance);
537 }
538 }
539
540 public static void ProcAbility(Element e, Chara CC, Card TC, int bonus, bool subAttack = false, int mtpChance = 100)
541 {
542 if (!(e is Ability))
543 {
544 return;
545 }
546 int num = (10 + e.Value / 5) * mtpChance / 100;
547 int power = EClass.curve((100 + e.Value * 10) * (100 + bonus) / 100, 400, 100);
548 if (e.id == 6602)
549 {
550 num = 100;
551 }
552 if (num <= EClass.rnd(100))
553 {
554 return;
555 }
556 Act obj = e as Act;
557 Card card = (obj.TargetType.CanSelectSelf ? CC : TC);
558 string text = ((e.source.proc.Length >= 2) ? e.source.proc[1] : "");
559 string text2 = obj.source.abilityType.TryGet(0);
560 switch (text2)
561 {
562 case "buff":
563 if (CC.HasCondition(text))
564 {
565 return;
566 }
567 card = CC;
568 break;
569 case "debuff":
570 case "attack":
571 case "dot":
572 card = TC;
573 break;
574 }
575 if (subAttack)
576 {
577 if (card == CC)
578 {
579 return;
580 }
581 switch (text2)
582 {
583 case "summon":
584 return;
585 case "teleport":
586 return;
587 case "suicide":
588 return;
589 }
590 }
591 if (card.IsAliveInCurrentZone)
592 {
593 Card tC = Act.TC;
594 ActEffect.ProcAt(e.source.proc[0].ToEnum<EffectId>(), power, BlessedState.Normal, CC, card, card.pos, isNeg: false, new ActRef
595 {
596 n1 = text,
597 aliasEle = e.source.aliasRef,
598 noFriendlyFire = true
599 });
600 Act.TC = tC;
601 }
602 }
603
604 public bool Perform(int count, bool hasHit, float dmgMulti = 1f, bool maxRoll = false, bool subAttack = false)
605 {
606 bool flag = CC.HasCondition<ConReload>();
607 bool flag2 = CC.HasElement(486) && CC.IsPCFactionOrMinion;
608 hit = CalcHit();
609 if (CC.id == "tsunami")
610 {
611 hit = true;
612 }
613 long num = GetRawDamage(dmgMulti, crit, maxRoll);
614 if (IsRanged && count >= numFireWithoutDamageLoss)
615 {
616 num = num * 100 / (100 + (count - numFireWithoutDamageLoss + 1) * 30);
617 }
618 if (CC.isRestrained)
619 {
620 num /= 2;
621 }
622 List<Element> list = new List<Element>();
623 int num2 = CC.Evalue(91);
624 string id = CC.id;
625 if ((id == "stalker" || id == "stalker_shadow") && TC.isChara && TC.Chara.CanSee(CC))
626 {
627 num2 = 0;
628 }
629 int num3 = 0;
630 if (weapon != null)
631 {
632 list = weapon.elements.dict.Values.ToList();
633 if (ammo != null && !flag)
634 {
635 list = list.Concat(ammo.elements.dict.Values).ToList();
636 }
637 num2 += weapon.Evalue(91, ignoreGlobalElement: true);
638 num3 += weapon.Evalue(603, ignoreGlobalElement: true);
639 }
640 foreach (Element value in CC.elements.dict.Values)
641 {
642 if (!value.IsGlobalElement && value.source.categorySub == "eleAttack")
643 {
644 list.Add(value);
645 }
646 }
647 if (!IsRanged && !isThrow && CC.HasElement(1426))
648 {
649 list.Add(Element.Create(6650, 100));
650 }
651 int bane;
652 if (TC?.Chara != null)
653 {
654 bane = 0;
655 AddBane(valid: true, 468, 50);
656 AddBane(TC.Chara.IsUndead, 461, 100);
657 AddBane(TC.Chara.IsAnimal, 463, 100);
658 AddBane(TC.Chara.IsHuman, 464, 100);
659 AddBane(TC.Chara.IsDragon, 460, 100);
660 AddBane(TC.Chara.IsGod, 466, 100);
661 AddBane(TC.Chara.IsMachine, 465, 100);
662 AddBane(TC.Chara.IsFish, 467, 100);
663 AddBane(TC.Chara.IsFairy, 462, 100);
664 if (bane != 0)
665 {
666 num = num * (100 + bane * 3) / 100;
667 }
668 }
669 if (CC.IsPCFaction)
670 {
671 foreach (Element value2 in EClass.pc.faction.charaElements.dict.Values)
672 {
673 if (value2.Value > 0)
674 {
675 list.Add(value2);
676 }
677 }
678 }
679 if (hit && num2 > EClass.rnd(100))
680 {
681 CC.Say("vopal");
682 penetration = 100;
683 }
684 if (crit)
685 {
686 CC.Say((critFury ? "fury_" : "") + (CC.IsHostile() ? "critical_enemy" : "critical"));
687 if (CC.IsPC)
688 {
689 CC.PlaySound("critical");
690 }
691 }
692 if (CC.isSynced || (TC != null && TC.isSynced))
693 {
694 if (toolRange != null && (!IsRanged || count == 0) && !flag && !ignoreAnime)
695 {
696 PlayRangedAnime((!IsRanged) ? 1 : numFire);
697 }
698 if (hit && TC != null && !hasHit)
699 {
700 PlayHitEffect();
701 }
702 }
703 if (TC == null)
704 {
705 if (weapon == null || !(weapon.trait is TraitToolRangeGunRocket))
706 {
707 CC.Say(IsRanged ? "attack_air_range" : "attack_air", CC);
708 }
709 return true;
710 }
711 if (!hit)
712 {
713 if (TC != null)
714 {
715 if (CC.IsPCParty)
716 {
717 CC.Say(evadePlus ? "evadePlus2" : "evade2", CC, TC);
718 }
719 else
720 {
721 TC.Say(evadePlus ? "evadePlus" : "evade", TC, CC);
722 }
723 ModExpDef(150, 90);
724 ModExpDef(151, 90);
725 }
726 ProcAbility(list, CC, TC, weaponSkill.Value * (100 + GetTwoHandEncBonus(CC, weapon)) / 100, subAttack);
727 return false;
728 }
729 if (TC.IsPC)
730 {
731 Msg.SetColor("attack_pc");
732 EClass.pc.Say("attackMeleeToPC", CC, TC, GetAttackText(attackType, 3));
733 }
734 else
735 {
736 CC.Say("attackMelee", CC, TC, GetAttackText(attackType, 0));
737 }
738 bool showEffect = true;
739 int num4 = 0;
740 int num5 = 0;
741 int num6 = 0;
742 ConWeapon conWeapon = null;
743 if (weapon != null)
744 {
745 foreach (Element value3 in weapon.elements.dict.Values)
746 {
747 if (value3.source.categorySub == "eleConvert")
748 {
749 num4 = EClass.sources.elements.alias[value3.source.aliasRef].id;
750 num5 = 50 + value3.Value * 2;
751 num6 = Mathf.Min(value3.Value, 100);
752 break;
753 }
754 }
755 }
756 if (num4 == 0)
757 {
758 if (CC.HasCondition<ConWeapon>())
759 {
760 conWeapon = CC.GetCondition<ConWeapon>();
761 num4 = conWeapon.sourceElement.id;
762 num5 = conWeapon.power / 2;
763 num6 = (int)Mathf.Min(40f + MathF.Sqrt(conWeapon.power), 80f);
764 }
765 if (conWeapon == null && (weapon == null || IsMartialWeapon) && (CC.MainElement != Element.Void || CC.HasElement(1565)))
766 {
767 num4 = (CC.HasElement(1565) ? 915 : CC.MainElement.id);
768 num5 = CC.Power / 3 + EClass.rnd(CC.Power / 2);
769 if (CC.MainElement != Element.Void)
770 {
771 num5 += CC.MainElement.Value;
772 }
773 showEffect = false;
774 num6 = 50;
775 }
776 if (conWeapon == null && weapon != null && weapon.trait is TraitToolRangeCane)
777 {
778 IEnumerable<Element> enumerable = weapon.elements.dict.Values.Where((Element e) => e.source.categorySub == "eleAttack");
779 if (enumerable.Count() > 0)
780 {
781 num4 = enumerable.RandomItem().id;
782 num5 = num4 switch
783 {
784 920 => 30,
785 914 => 50,
786 918 => 50,
787 _ => 100,
788 };
789 }
790 num6 = 50;
791 }
792 }
793 long num7 = num;
794 long num8 = num * num6 / 100;
795 num -= num8;
796 long num9 = num * penetration / 100;
797 num -= num9;
798 num = TC.ApplyProtection(num) + num9 + num8;
799 int weaponEnc = GetWeaponEnc(CC, weapon, 609, addSelfEnc: true);
800 TC.DamageHP(num, num4, num5, (!IsRanged && !isThrow) ? AttackSource.Melee : AttackSource.Range, CC, showEffect, weapon);
801 if (conWeapon != null && (weaponEnc <= 0 || !(Mathf.Min(10f + Mathf.Sqrt(weaponEnc) * 5f, 90f) > (float)EClass.rnd(100))))
802 {
803 conWeapon.Mod(-1);
804 }
805 bool flag3 = IsCane || (weapon != null && weapon.Evalue(482) > 0);
806 int attackStyleElement = CC.body.GetAttackStyleElement(attackStyle);
807 if (!subAttack)
808 {
809 int mod2 = 100 / (count + 1);
810 if (!IsRanged || count == 0)
811 {
812 ModExpAtk(weaponSkill.id, mod2);
813 ModExpAtk(flag3 ? 304 : (IsRanged ? 133 : 132), mod2);
814 }
815 if (crit)
816 {
817 ModExpAtk(134, 50);
818 }
819 if (count == 0 && attackStyleElement != 0)
820 {
821 ModExpAtk(attackStyleElement, 100);
822 }
823 }
824 if (!CC.IsAliveInCurrentZone || !TC.IsAliveInCurrentZone)
825 {
826 return true;
827 }
828 if (EClass.rnd(8) == 0 && TC.isChara && CC.HasElement(1219))
829 {
830 CC.Say("abCrab", CC, TC);
831 TC.Chara.AddCondition<ConParalyze>(30 + EClass.rnd(30));
832 TC.Chara.AddCondition<ConGravity>();
833 }
834 if (list.Count > 0 && !flag2)
835 {
836 foreach (Element item in list)
837 {
838 if (!TC.IsAliveInCurrentZone)
839 {
840 break;
841 }
842 if (!item.IsActive(weapon) || !(item.source.categorySub == "eleAttack"))
843 {
844 continue;
845 }
846 int num10 = 25;
847 long num11 = EClass.rnd(num * (100 + item.Value * 10) / 500 + 5);
848 num11 = num11 * (100 + GetTwoHandEncBonus(CC, weapon)) / 100;
849 if (num11 >= 0)
850 {
851 if (conWeapon == null && weapon != null && weapon.trait is TraitToolRangeCane)
852 {
853 num10 = 0;
854 }
855 if (num10 > EClass.rnd(100))
856 {
857 TC.DamageHP(num11, item.id, isThrow ? (100 + item.Value * 5) : (30 + item.Value), AttackSource.WeaponEnchant, CC);
858 }
859 }
860 }
861 ProcAbility(list, CC, TC, weaponSkill.Value * (100 + GetTwoHandEncBonus(CC, weapon)) / 100, subAttack);
862 }
863 if (!CC.IsAliveInCurrentZone || !TC.IsAliveInCurrentZone)
864 {
865 return true;
866 }
867 if (!IsRanged && !flag2 && attackStyle == AttackStyle.Shield)
868 {
869 int num12 = CC.Evalue(123);
870 int num13 = CC.Evalue(381);
871 if (CC.elements.ValueWithoutLink(123) >= 10 && Mathf.Clamp(Mathf.Sqrt(num12) - 2f, 8f, 15f) + Mathf.Min(Mathf.Sqrt(num13), 25f) > (float)EClass.rnd(100))
872 {
873 num = num7 * (Mathf.Min(50 + num12 + num13, 200) + (int)Mathf.Min(Mathf.Sqrt(num13), 100f)) / 100;
874 penetration = (int)Mathf.Sqrt(num13) + ((num13 != 0) ? 20 : 0);
875 if (penetration > 100)
876 {
877 penetration = 100;
878 }
879 num9 = num * penetration / 100;
880 num -= num9;
881 num = TC.ApplyProtection(num) + num9;
882 Debug.Log("Bash:" + num + "/" + num7);
883 CC.PlaySound("shield_bash");
884 CC.Say("shield_bash", CC, TC);
885 TC.DamageHP(num, AttackSource.None, CC);
886 if (TC.IsAliveInCurrentZone && TC.isChara)
887 {
888 if (EClass.rnd(2) == 0)
889 {
890 TC.Chara.AddCondition<ConDim>(50 + (int)Mathf.Sqrt(num12) * 10);
891 }
892 TC.Chara.AddCondition<ConParalyze>(EClass.rnd(2), force: true);
893 }
894 if (!TC.isRestrained)
895 {
896 ProcShieldEncs(CC, TC, 500 + num13);
897 }
898 if (CC.IsAliveInCurrentZone)
899 {
900 CC.ModExp(123, 50);
901 }
902 }
903 }
904 if (!CC.IsAliveInCurrentZone || !TC.IsAliveInCurrentZone)
905 {
906 return true;
907 }
908 if (CC.HasElement(1253))
909 {
910 TC.DamageHP(num7 / 10, 916, 100, AttackSource.None, CC);
911 }
912 if (!CC.IsAliveInCurrentZone || !TC.IsAliveInCurrentZone)
913 {
914 return true;
915 }
916 if (TC.isChara && !TC.HasCondition<ConGravity>() && num3 > 0 && num3 * 2 + 15 > EClass.rnd(100) && !TC.isRestrained && TC.Chara.TryMoveFrom(CC.pos) == Card.MoveResult.Success)
917 {
918 TC.pos.PlayEffect("vanish");
919 TC.PlaySound("push", 1.5f);
920 }
921 return true;
922 void AddBane(bool valid, int idEle, int mod)
923 {
924 if (valid)
925 {
926 bane += (CC.Evalue(idEle) + ((weapon != null) ? weapon.Evalue(idEle, ignoreGlobalElement: true) : 0) + ((ammo != null) ? ammo.Evalue(idEle, ignoreGlobalElement: true) : 0)) * mod / 100;
927 }
928 }
929 bool IgnoreExp()
930 {
931 if (!CC.HasEditorTag(EditorTag.Invulnerable) && !CC.HasEditorTag(EditorTag.InvulnerableToMobs) && !TC.HasEditorTag(EditorTag.Invulnerable))
932 {
933 return TC.HasEditorTag(EditorTag.InvulnerableToMobs);
934 }
935 return true;
936 }
937 void ModExpAtk(int ele, int mod)
938 {
939 if (!IgnoreExp() && (!TC.isCopy || EClass.rnd(10) == 0))
940 {
941 int a = (Mathf.Clamp((TC.LV + 10 - CC.elements.ValueWithoutLink(ele)) / 2, 1, 10) + Mathf.Min(TC.LV / 10, 10)) * mod / 100;
942 a = Mathf.Min(a, 200);
943 if (TC == CC)
944 {
945 a /= 2;
946 }
947 if (a > 0)
948 {
949 CC.ModExp(ele, a + EClass.rnd(a / 2 + 1));
950 }
951 }
952 }
953 void ModExpDef(int ele, int mod)
954 {
955 if (!IgnoreExp() && (!CC.isCopy || EClass.rnd(10) == 0))
956 {
957 int a2 = (Mathf.Clamp((CC.LV + 10 - TC.elements.ValueWithoutLink(ele)) / 2, 1, 10) + Mathf.Min(CC.LV / 10, 10)) * mod / 100;
958 a2 = Mathf.Min(a2, TC.isRestrained ? 10 : 200);
959 if (TC == CC)
960 {
961 a2 /= 2;
962 }
963 if (!TC.IsPC && !TC.isRestrained && !TC.HasHost)
964 {
965 a2 *= 3;
966 }
967 if (a2 > 0)
968 {
969 TC.ModExp(ele, a2 + EClass.rnd(a2 / 2 + 1));
970 }
971 }
972 }
973 void PlayHitEffect()
974 {
975 string id2 = "hit_default";
976 string id3 = "hit_default";
977 switch (attackType)
978 {
979 case AttackType.Slash:
980 id3 = "hit_slash";
981 id2 = "hit_slash";
982 break;
983 case AttackType.Spore:
984 id3 = "hit_spore";
985 id2 = "hit_spore";
986 break;
987 case AttackType.Claw:
988 case AttackType.Bite:
989 id3 = "hit_claw";
990 id2 = "hit_claw";
991 break;
992 case AttackType.Blunt:
993 case AttackType.Punch:
994 case AttackType.Kick:
995 case AttackType.Bow:
996 case AttackType.Gun:
997 case AttackType.Cane:
998 id3 = "hit_blunt";
999 id2 = "hit_blunt";
1000 break;
1001 }
1002 if (TC != null)
1003 {
1004 TC.PlayEffect(id3).SetScale(crit ? 1.25f : 0.75f);
1005 }
1006 CC.PlaySound(id2);
1007 }
1008 }
1009
1010 private bool Crit()
1011 {
1012 crit = true;
1013 return true;
1014 }
1015
1016 private bool EvadePlus()
1017 {
1018 evadePlus = true;
1019 return false;
1020 }
1021
1022 public bool CalcHit()
1023 {
1024 if (CC.HasCondition<ConAmbush>())
1025 {
1026 return Crit();
1027 }
1028 if (critFury)
1029 {
1030 return Crit();
1031 }
1032 if (CC.HasCondition<ConSevenSense>() && (CC.HasElement(1244) || CC.HasElement(1246) || CC.HasElement(1247) || CC.HasElement(1253)))
1033 {
1034 return true;
1035 }
1036 if (TC != null)
1037 {
1038 if (TC.HasCondition<ConDim>() && EClass.rnd(4) == 0)
1039 {
1040 return Crit();
1041 }
1042 if (TC.IsDeadOrSleeping)
1043 {
1044 return Crit();
1045 }
1046 int num = TC.Evalue(151);
1047 if (num != 0 && toHit < num * 10)
1048 {
1049 float num2 = (float)(evasion * 100) / Mathf.Clamp(toHit, 1f, toHit);
1050 if (num2 > 300f && EClass.rnd(num + 250) > 100)
1051 {
1052 return EvadePlus();
1053 }
1054 if (num2 > 200f && EClass.rnd(num + 250) > 150)
1055 {
1056 return EvadePlus();
1057 }
1058 if (num2 > 150f && EClass.rnd(num + 250) > 200)
1059 {
1060 return EvadePlus();
1061 }
1062 }
1063 int num3 = TC.Evalue(57);
1064 if (num3 > 0)
1065 {
1066 if (num3 > EClass.rnd(100))
1067 {
1068 return EvadePlus();
1069 }
1070 }
1071 else if (num3 < 0 && num3 * -1 > EClass.rnd(100))
1072 {
1073 return true;
1074 }
1075 }
1076 if (EClass.rnd(20) == 0)
1077 {
1078 return true;
1079 }
1080 if (EClass.rnd(20) == 0)
1081 {
1082 return false;
1083 }
1084 if (toHit < 1)
1085 {
1086 return false;
1087 }
1088 if (evasion < 1)
1089 {
1090 return true;
1091 }
1092 if (EClass.rnd(toHit) < EClass.rnd(evasion * (IsRanged ? 150 : 125) / 100))
1093 {
1094 return false;
1095 }
1096 if (EClass.rnd(5000) < CC.Evalue(73) + 50)
1097 {
1098 return Crit();
1099 }
1100 if ((float)(CC.Evalue(90) + ((weapon != null) ? weapon.Evalue(90, ignoreGlobalElement: true) : 0)) + Mathf.Sqrt(CC.Evalue(134)) > (float)EClass.rnd(200))
1101 {
1102 return Crit();
1103 }
1104 if (CC.Evalue(1420) > 0)
1105 {
1106 int num4 = Mathf.Min(100, 100 - CC.hp * 100 / CC.MaxHP) * (50 + CC.Evalue(1420) * 50) / 100;
1107 if (num4 >= 50 && num4 * num4 * num4 * num4 / 3 > EClass.rnd(100000000))
1108 {
1109 return Crit();
1110 }
1111 }
1112 return true;
1113 }
1114
1115 public string GetAttackText(AttackType type, int id)
1116 {
1117 return Lang.GetList("attack" + type)[id];
1118 }
1119}
AttackSource
Definition: AttackSource.cs:2
AttackStyle
Definition: AttackStyle.cs:2
AttackType
Definition: AttackType.cs:2
BlessedState
Definition: BlessedState.cs:2
CTAG
Definition: CTAG.cs:2
if(!match.Success)
EditorTag
Definition: EditorTag.cs:2
EffectId
Definition: EffectId.cs:2
static void ProcAt(EffectId id, int power, BlessedState state, Card cc, Card tc, Point tp, bool isNeg, ActRef actRef=default(ActRef))
Definition: ActEffect.cs:470
Definition: ACT.cs:62
static Card TC
Definition: ACT.cs:79
TraitToolRange toolRange
AttackType attackType
void Prepare(Chara _CC, Thing _weapon, Card _TC=null, Point _TP=null, int _attackIndex=0, bool _isThrow=false)
bool Perform(int count, bool hasHit, float dmgMulti=1f, bool maxRoll=false, bool subAttack=false)
string GetAttackText(AttackType type, int id)
static void ProcAbility(List< Element > list, Chara CC, Card TC, int bonus, bool subAttack=false, int mtpChance=100)
static AttackProcess Current
Definition: AttackProcess.cs:8
long GetRawDamage(float dmgMulti, bool crit, bool maxRoll)
int GetRocketPower()
static void ProcAbility(Element e, Chara CC, Card TC, int bonus, bool subAttack=false, int mtpChance=100)
static int GetTwoHandEncBonus(Chara CC, Thing w)
string GetText()
bool ignoreAttackSound
int numFireWithoutDamageLoss
bool IsMartialWeapon
Point posRangedAnime
Element weaponSkill
void PlayRangedAnime(int numFire, float delay=0f)
static int GetWeaponEnc(Chara CC, Thing w, int ele, bool addSelfEnc=false)
AttackStyle attackStyle
static void ProcShieldEncs(Chara CC, Card TC, int mtpChance=100)
void Mod(int a, bool force=false)
SourceElement.Row sourceElement
int elementId
Definition: BodySlot.cs:6
Thing thing
Definition: BodySlot.cs:8
virtual int currentDir
Definition: CardActor.cs:41
CardActor actor
Definition: CardRenderer.cs:11
Definition: Card.cs:11
int DMG
Definition: Card.cs:2401
bool IsPCFactionOrMinion
Definition: Card.cs:2342
int EvalueMax(int ele, int min=0)
Definition: Card.cs:2718
ElementContainerCard elements
Definition: Card.cs:42
string id
Definition: Card.cs:36
int ChildrenWeight
Definition: Card.cs:2065
SourceMaterial.Row material
Definition: Card.cs:2103
int HIT
Definition: Card.cs:2399
Thing ammoData
Definition: Card.cs:1825
int WIL
Definition: Card.cs:2413
int STR
Definition: Card.cs:2403
bool HasTag(CTAG tag)
Definition: Card.cs:2728
Point pos
Definition: Card.cs:60
int DEX
Definition: Card.cs:2405
Trait trait
Definition: Card.cs:54
int encLV
Definition: Card.cs:329
int c_diceDim
Definition: Card.cs:1429
MoveResult
Definition: Card.cs:13
virtual Thing Thing
Definition: Card.cs:2110
int Evalue(int ele)
Definition: Card.cs:2704
SourceCategory.Row category
Definition: Card.cs:2101
bool IsWeapon
Definition: Card.cs:2260
CardRenderer renderer
Definition: Card.cs:64
bool HasElement(int ele, bool includeNagative=false)
Definition: Card.cs:6344
int LV
Definition: Card.cs:389
void Say(string lang, string ref1=null, string ref2=null)
Definition: Card.cs:7284
AttackStyle GetAttackStyle()
Definition: CharaBody.cs:479
Definition: Chara.cs:10
CharaBody body
Definition: Chara.cs:94
Faction faction
Definition: Chara.cs:431
Chara host
Definition: Chara.cs:33
override bool IsPCParty
Definition: Chara.cs:633
int EvalueRiding()
Definition: Chara.cs:6435
bool HasCondition(string alias)
Definition: Chara.cs:9934
Zone currentZone
Definition: Chara.cs:259
bool HasHigherGround(Card c)
Definition: Chara.cs:1249
Chara parasite
Definition: Chara.cs:30
Chara ride
Definition: Chara.cs:27
bool isBlind
Definition: Chara.cs:132
bool isConfused
Definition: Chara.cs:128
SourceRace.Row race
Definition: Chara.cs:468
UD_String_Color elementColors
Definition: ConDim.cs:2
Definition: Dice.cs:5
static int RollMax(int num, int sides, int bonus=0)
Definition: Dice.cs:70
static int Roll(int num, int sides, int bonus=0, Card card=null)
Definition: Dice.cs:48
Definition: EClass.cs:6
static int curve(long _a, int start, int step, int rate=75)
Definition: EClass.cs:69
static ColorProfile Colors
Definition: EClass.cs:39
static Zone _zone
Definition: EClass.cs:21
static int rnd(long a)
Definition: EClass.cs:59
static SourceManager sources
Definition: EClass.cs:43
static Chara pc
Definition: EClass.cs:15
static GameSetting setting
Definition: EClass.cs:35
Dictionary< int, Element > dict
int Value(int ele)
Element GetOrCreateElement(Element ele)
int id
Definition: ELEMENT.cs:259
SourceElement.Row source
Definition: ELEMENT.cs:282
int Value
Definition: ELEMENT.cs:301
static Element Create(int id, int v=0)
Definition: ELEMENT.cs:1123
static Element Void
Definition: ELEMENT.cs:247
bool IsGlobalElement
Definition: ELEMENT.cs:354
Element GetParent(Card c)
Definition: ELEMENT.cs:531
ElementContainerFaction charaElements
Definition: FACTION.cs:146
UD_String_EffectData guns
Definition: GameSetting.cs:278
EffectSetting effect
Definition: GameSetting.cs:301
Definition: Lang.cs:7
static string[] GetList(string id)
Definition: Lang.cs:113
Definition: Msg.cs:5
static void SetColor()
Definition: Msg.cs:22
Definition: Point.cs:9
Point Copy()
Definition: Point.cs:491
int Distance(Point p)
Definition: Point.cs:995
SourceElement elements
Definition: TC.cs:4
Definition: Thing.cs:8
SourceThing.Row source
Definition: Thing.cs:11
bool isEquipped
Definition: Thing.cs:17
override int SelfWeight
Definition: Thing.cs:64
int Penetration
Definition: Thing.cs:34
virtual Element WeaponSkill
Card owner
Definition: Trait.cs:28
bool TryGetValue(TKey key, out TValue value)
Definition: UDictionary.cs:178
Definition: Zone.cs:12
Definition: ActRef.cs:2