-
Notifications
You must be signed in to change notification settings - Fork 416
/
attack.cpp
7088 lines (6115 loc) · 221 KB
/
attack.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* EQEMu: Everquest Server Emulator
Copyright (C) 2001-2002 EQEMu Development Team (http://eqemulator.net)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY except by those people which sell it, which
are required to give you total support for your newly bought product;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "../common/global_define.h"
#include "../common/eq_constants.h"
#include "../common/eq_packet_structs.h"
#include "../common/rulesys.h"
#include "../common/spdat.h"
#include "../common/strings.h"
#include "../common/data_verification.h"
#include "../common/misc_functions.h"
#include "../common/events/player_event_logs.h"
#include "queryserv.h"
#include "quest_parser_collection.h"
#include "string_ids.h"
#include "water_map.h"
#include "worldserver.h"
#include "zone.h"
#include "lua_parser.h"
#include "fastmath.h"
#include "mob.h"
#include "npc.h"
#include "bot.h"
extern QueryServ* QServ;
extern WorldServer worldserver;
extern FastMath g_Math;
#ifdef _WINDOWS
#define snprintf _snprintf
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#endif
extern EntityList entity_list;
extern Zone* zone;
//SYNC WITH: tune.cpp, mob.h TuneAttackAnimation
EQ::skills::SkillType Mob::AttackAnimation(int Hand, const EQ::ItemInstance* weapon, EQ::skills::SkillType skillinuse)
{
// Determine animation
int type = 0;
if (weapon && weapon->IsClassCommon()) {
const EQ::ItemData* item = weapon->GetItem();
Log(Logs::Detail, Logs::Attack, "Weapon skill : %i", item->ItemType);
switch (item->ItemType) {
case EQ::item::ItemType1HSlash: // 1H Slashing
skillinuse = EQ::skills::Skill1HSlashing;
type = anim1HWeapon;
break;
case EQ::item::ItemType2HSlash: // 2H Slashing
skillinuse = EQ::skills::Skill2HSlashing;
type = anim2HSlashing;
break;
case EQ::item::ItemType1HPiercing: // Piercing
skillinuse = EQ::skills::Skill1HPiercing;
type = anim1HPiercing;
break;
case EQ::item::ItemType1HBlunt: // 1H Blunt
skillinuse = EQ::skills::Skill1HBlunt;
type = anim1HWeapon;
break;
case EQ::item::ItemType2HBlunt: // 2H Blunt
skillinuse = EQ::skills::Skill2HBlunt;
type = RuleB(Combat, Classic2HBAnimation) ? anim2HWeapon : anim2HSlashing;
break;
case EQ::item::ItemType2HPiercing: // 2H Piercing
if (IsClient() && CastToClient()->ClientVersion() < EQ::versions::ClientVersion::RoF2)
skillinuse = EQ::skills::Skill1HPiercing;
else
skillinuse = EQ::skills::Skill2HPiercing;
type = anim2HWeapon;
break;
case EQ::item::ItemTypeMartial:
skillinuse = EQ::skills::SkillHandtoHand;
type = animHand2Hand;
break;
default:
skillinuse = EQ::skills::SkillHandtoHand;
type = animHand2Hand;
break;
}// switch
}
else if (IsNPC()) {
switch (skillinuse) {
case EQ::skills::Skill1HBlunt: // 1H Blunt
case EQ::skills::Skill1HSlashing: // 1H Slashing
type = anim1HWeapon;
break;
case EQ::skills::Skill2HBlunt: // 2H Blunt
case EQ::skills::Skill2HSlashing: // 2H Slashing
type = anim2HSlashing;
break;
case EQ::skills::Skill1HPiercing: // Piercing
type = anim1HPiercing;
break;
case EQ::skills::Skill2HPiercing: // 2H Piercing
type = anim2HWeapon;
break;
case EQ::skills::SkillHandtoHand:
type = animHand2Hand;
break;
default:
type = animHand2Hand;
break;
}// switch
}
else {
skillinuse = EQ::skills::SkillHandtoHand;
type = animHand2Hand;
}
// If we're attacking with the secondary hand, play the dual wield anim
if (Hand == EQ::invslot::slotSecondary) {// DW anim
type = animDualWield;
//allow animation chance to fire to be similar to your dw chance
if (GetDualWieldingSameDelayWeapons() == 2) {
SetDualWieldingSameDelayWeapons(3);
}
}
//If both weapons have same delay this allows a chance for DW animation
if (GetDualWieldingSameDelayWeapons() && Hand == EQ::invslot::slotPrimary) {
if (GetDualWieldingSameDelayWeapons() == 3 && zone->random.Roll(50)) {
type = animDualWield;
SetDualWieldingSameDelayWeapons(2);//Don't roll again till you do another dw attack.
}
SetDualWieldingSameDelayWeapons(2);//Ensures first attack is always primary.
}
DoAnim(type, 0, false);
return skillinuse;
}
//SYNC WITH: tune.cpp, mob.h Tunecompute_tohit
int Mob::compute_tohit(EQ::skills::SkillType skillinuse)
{
int tohit = GetSkill(EQ::skills::SkillOffense) + 7;
tohit += GetSkill(skillinuse);
if (IsNPC()) {
if (RuleB(Combat, UseMobStaticOffenseSkill)) {
tohit = GetMobFixedWeaponSkill() + GetMobFixedOffenseSkill() + 7;
}
tohit += CastToNPC()->GetAccuracyRating();
} else if (IsClient()) {
double reduction = CastToClient()->GetIntoxication() / 2.0;
if (reduction > 20.0) {
reduction = std::min((110 - reduction) / 100.0, 1.0);
tohit = reduction * static_cast<double>(tohit);
} else if (IsBerserk()) {
tohit += (GetLevel() * 2) / 5;
}
}
return std::max(tohit, 1);
}
// return -1 in cases that always hit
//SYNC WITH: tune.cpp, mob.h TuneGetTotalToHit
int Mob::GetTotalToHit(EQ::skills::SkillType skill, int chance_mod)
{
if (chance_mod >= 10000) // override for stuff like SE_SkillAttack
return -1;
// calculate attacker's accuracy
auto accuracy = compute_tohit(skill) + 10; // add 10 in case the NPC's stats are fucked
if (chance_mod > 0) // multiplier
accuracy *= chance_mod;
// Torven parsed an apparent constant of 1.2 somewhere in here * 6 / 5 looks eqmathy to me!
// new test clients have 121 / 100
accuracy = (accuracy * 121) / 100;
// unsure on the stacking order of these effects, rather hard to parse
// item mod2 accuracy isn't applied to range? Theory crafting and parses back it up I guess
// mod2 accuracy -- flat bonus
if (skill != EQ::skills::SkillArchery && skill != EQ::skills::SkillThrowing) {
accuracy += itembonuses.HitChance;
} else {
// Applying a scale factor as sources suggest Accuracy should reduce number of missing by 0.1% per point, so 150 = 15% reduction in misses.
// Based on my calculator 150 Accuracy was reducing misses by too much (closer to 20%)
// NOTE: This doesn't mean if you have a 30% miss chance you now miss 15%. It means if you have a 30% miss chance you now have a 30% * (100% - 15%) = 30% * 85% = 25.5% miss chance
// Using same scale factor for Avoidance and Accuracy since they impact the formula about the same.
accuracy += itembonuses.HitChance * RuleI(Combat, PCAccuracyAvoidanceMod2Scale) / 100;
}
//518 Increase ATK accuracy by percentage, stackable
auto atkhit_bonus = itembonuses.Attack_Accuracy_Max_Percent + aabonuses.Attack_Accuracy_Max_Percent + spellbonuses.Attack_Accuracy_Max_Percent;
if (atkhit_bonus)
accuracy += round(static_cast<double>(accuracy) * static_cast<double>(atkhit_bonus) * 0.0001);
// 216 Melee Accuracy Amt aka SE_Accuracy -- flat bonus
accuracy += itembonuses.Accuracy[EQ::skills::HIGHEST_SKILL + 1] +
aabonuses.Accuracy[EQ::skills::HIGHEST_SKILL + 1] +
spellbonuses.Accuracy[EQ::skills::HIGHEST_SKILL + 1] +
itembonuses.Accuracy[skill] +
aabonuses.Accuracy[skill] +
spellbonuses.Accuracy[skill];
// auto hit discs (and looks like there are some autohit AAs)
if (spellbonuses.HitChanceEffect[skill] >= 10000 || aabonuses.HitChanceEffect[skill] >= 10000)
return -1;
if (spellbonuses.HitChanceEffect[EQ::skills::HIGHEST_SKILL + 1] >= 10000)
return -1;
// 184 Accuracy % aka SE_HitChance -- percentage increase
auto hit_bonus = itembonuses.HitChanceEffect[EQ::skills::HIGHEST_SKILL + 1] +
aabonuses.HitChanceEffect[EQ::skills::HIGHEST_SKILL + 1] +
spellbonuses.HitChanceEffect[EQ::skills::HIGHEST_SKILL + 1] +
itembonuses.HitChanceEffect[skill] +
aabonuses.HitChanceEffect[skill] +
spellbonuses.HitChanceEffect[skill];
if (skill == EQ::skills::SkillArchery) {
hit_bonus += spellbonuses.increase_archery + aabonuses.increase_archery + itembonuses.increase_archery;
hit_bonus -= hit_bonus * RuleR(Combat, ArcheryHitPenalty);
}
accuracy = (accuracy * (100 + hit_bonus)) / 100;
// TODO: April 2003 added an archery/throwing PVP accuracy penalty while moving, should be in here some where,
// but PVP is less important so I haven't tried parsing it at all
// There is also 110 Ranger Archery Accuracy % which should probably be in here some where, but it's not in any spells/aas
// Name implies it's a percentage increase, if one wishes to implement, do it like the hit_bonus above but limited to ranger archery
// There is also 183 UNUSED - Skill Increase Chance which devs say isn't used at all in code, but some spells reference it
// I do not recommend implementing this once since there are spells that use it which would make this not live-like with default spell files
return accuracy;
}
// based on dev quotes
// the AGI bonus has actually drastically changed from classic
//SYNC WITH: tune.cpp, mob.h Tunecompute_defense
int Mob::compute_defense()
{
int defense = GetSkill(EQ::skills::SkillDefense) * 400 / 225;
// In new code, AGI becomes a large contributor to avoidance at low levels, since AGI isn't capped by Level but Defense is
// A scale factor is implemented for PCs to reduce the effect of AGI at low levels. This isn't applied to NPCs since they can be
// easily controlled via the Database.
if (RuleB(Combat, LegacyComputeDefense)) {
int agi_scale_factor = 1000;
if (IsOfClientBot()) {
agi_scale_factor = std::min(1000, static_cast<int>(GetLevel()) * 1000 / 70); // Scales Agi Contribution for PC's Level, max Contribution at Level 70
}
defense += agi_scale_factor * (800 * (GetAGI() - 40)) / 3600 / 1000;
if (IsOfClientBot()) {
defense += GetHeroicAGI() / 10;
}
defense += itembonuses.AvoidMeleeChance * RuleI(Combat, PCAccuracyAvoidanceMod2Scale) / 100; // item mod2
} else {
defense += (8000 * (GetAGI() - 40)) / 36000;
if (IsOfClientBot()) {
defense += itembonuses.heroic_agi_avoidance;
}
defense += itembonuses.AvoidMeleeChance; // item mod2
}
//516 SE_AC_Mitigation_Max_Percent
auto ac_bonus = itembonuses.AC_Mitigation_Max_Percent + aabonuses.AC_Mitigation_Max_Percent + spellbonuses.AC_Mitigation_Max_Percent;
if (ac_bonus) {
defense += round(static_cast<double>(defense) * static_cast<double>(ac_bonus) * 0.0001);
}
if (IsNPC()) {
defense += CastToNPC()->GetAvoidanceRating();
}
if (IsClient()) {
double reduction = CastToClient()->GetIntoxication() / 2.0;
if (reduction > 20.0) {
reduction = std::min((110 - reduction) / 100.0, 1.0);
defense = reduction * static_cast<double>(defense);
}
}
return std::max(1, defense);
}
// return -1 in cases that always miss
// SYNC WITH : tune.cpp, mob.h TuneGetTotalDefense()
int Mob::GetTotalDefense()
{
auto avoidance = compute_defense() + 10; // add 10 in case the NPC's stats are fucked
auto evasion_bonus = spellbonuses.AvoidMeleeChanceEffect; // we check this first since it has a special case
if (evasion_bonus >= 10000)
return -1;
// 515 SE_AC_Avoidance_Max_Percent
auto ac_aviodance_bonus = itembonuses.AC_Avoidance_Max_Percent + aabonuses.AC_Avoidance_Max_Percent + spellbonuses.AC_Avoidance_Max_Percent;
if (ac_aviodance_bonus)
avoidance += round(static_cast<double>(avoidance) * static_cast<double>(ac_aviodance_bonus) * 0.0001);
// 172 Evasion aka SE_AvoidMeleeChance
evasion_bonus += itembonuses.AvoidMeleeChanceEffect + aabonuses.AvoidMeleeChanceEffect; // item bonus here isn't mod2 avoidance
// 215 Pet Avoidance % aka SE_PetAvoidance
evasion_bonus += GetPetAvoidanceBonusFromOwner();
// Evasion is a percentage bonus according to AA descriptions
if (evasion_bonus)
avoidance = (avoidance * (100 + evasion_bonus)) / 100;
return avoidance;
}
// called when a mob is attacked, does the checks to see if it's a hit
// and does other mitigation checks. 'this' is the mob being attacked.
// SYNC WITH : tune.cpp, mob.h TuneCheckHitChance()
bool Mob::CheckHitChance(Mob* other, DamageHitInfo &hit)
{
#ifdef LUA_EQEMU
bool lua_ret = false;
bool ignoreDefault = false;
lua_ret = LuaParser::Instance()->CheckHitChance(this, other, hit, ignoreDefault);
if(ignoreDefault) {
return lua_ret;
}
#endif
Mob *attacker = other;
Mob *defender = this;
Log(Logs::Detail, Logs::Attack, "CheckHitChance(%s) attacked by %s", defender->GetName(), attacker->GetName());
if (defender->IsOfClientBotMerc() && defender->IsSitting()) {
return true;
}
auto avoidance = defender->GetTotalDefense();
if (avoidance == -1) // some sort of auto avoid disc
return false;
auto accuracy = hit.tohit;
if (accuracy == -1)
return true;
// so now we roll!
// relevant dev quote:
// Then your chance to simply avoid the attack is checked (defender's avoidance roll beat the attacker's accuracy roll.)
int tohit_roll = zone->random.Roll0(accuracy);
int avoid_roll = zone->random.Roll0(avoidance);
Log(Logs::Detail, Logs::Attack, "CheckHitChance accuracy(%d => %d) avoidance(%d => %d)", accuracy, tohit_roll, avoidance, avoid_roll);
// tie breaker? Don't want to be biased any one way
if (tohit_roll == avoid_roll)
return zone->random.Roll(50);
return tohit_roll > avoid_roll;
}
bool Mob::AvoidDamage(Mob *other, DamageHitInfo &hit)
{
#ifdef LUA_EQEMU
bool lua_ret = false;
bool ignoreDefault = false;
lua_ret = LuaParser::Instance()->AvoidDamage(this, other, hit, ignoreDefault);
if (ignoreDefault) {
return lua_ret;
}
#endif
/* called when a mob is attacked, does the checks to see if it's a hit
* and does other mitigation checks. 'this' is the mob being attacked.
*
* special return values:
* -1 - block
* -2 - parry
* -3 - riposte
* -4 - dodge
*
*/
/* Order according to current (SoF+?) dev quotes:
* https://forums.daybreakgames.com/eq/index.php?threads/test-update-06-10-15.223510/page-2#post-3261772
* https://forums.daybreakgames.com/eq/index.php?threads/test-update-06-10-15.223510/page-2#post-3268227
* Riposte 50, hDEX, must have weapon/fists, doesn't work on archery/throwing
* Block 25, hDEX, works on archery/throwing, behind block done here if back to attacker base1 is chance
* Parry 45, hDEX, doesn't work on throwing/archery, must be facing target
* Dodge 45, hAGI, works on archery/throwing, monks can dodge attacks from behind
* Shield Block, rand base1
* Staff Block, rand base1
* regular strike through
* avoiding the attack (CheckHitChance)
* As soon as one succeeds, none of the rest are checked
*
* Formula (all int math)
* (posted for parry, assume rest at the same)
* Chance = (((SKILL + 100) + [((SKILL+100) * SPA(175).Base1) / 100]) / 45) + [(hDex / 25) - min([hStrikethrough, hDex / 25])].
* hStrikethrough is a mob stat that was added to counter the bonuses of heroic stats
* Number rolled against 100, if the chance is greater than 100 it happens 100% of time
*
* Things with 10k accuracy mods can be avoided with these skills qq
*/
Mob *attacker = other;
Mob *defender = this;
bool InFront = !attacker->BehindMob(this, attacker->GetX(), attacker->GetY());
/*
This special ability adds a negative modifer to the defenders riposte/block/parry/chance
therefore reducing the defenders chance to successfully avoid the melee attack. Works in tandem with Heroic Strikethrough. This may
ultimately end up being more useful as fields in npc_types.
*/
int counter_all = 0;
int counter_riposte = 0;
int counter_block = 0;
int counter_parry = 0;
int counter_dodge = 0;
if (attacker->GetSpecialAbility(SpecialAbility::CounterAvoidDamage)) {
counter_all = attacker->GetSpecialAbilityParam(SpecialAbility::CounterAvoidDamage, 0);
counter_riposte = attacker->GetSpecialAbilityParam(SpecialAbility::CounterAvoidDamage, 1);
counter_block = attacker->GetSpecialAbilityParam(SpecialAbility::CounterAvoidDamage, 2);
counter_parry = attacker->GetSpecialAbilityParam(SpecialAbility::CounterAvoidDamage, 3);
counter_dodge = attacker->GetSpecialAbilityParam(SpecialAbility::CounterAvoidDamage, 4);
}
int modify_all = 0;
int modify_riposte = 0;
int modify_block = 0;
int modify_parry = 0;
int modify_dodge = 0;
if (GetSpecialAbility(SpecialAbility::ModifyAvoidDamage)) {
modify_all = GetSpecialAbilityParam(SpecialAbility::ModifyAvoidDamage, 0);
modify_riposte = GetSpecialAbilityParam(SpecialAbility::ModifyAvoidDamage, 1);
modify_block = GetSpecialAbilityParam(SpecialAbility::ModifyAvoidDamage, 2);
modify_parry = GetSpecialAbilityParam(SpecialAbility::ModifyAvoidDamage, 3);
modify_dodge = GetSpecialAbilityParam(SpecialAbility::ModifyAvoidDamage, 4);
}
/* Heroic Strikethrough Implementation per Dev Quotes (2018):
* https://forums.daybreakgames.com/eq/index.php?threads/illusions-benefit-neza-10-dodge.246757/#post-3622670
* Step1 = HeroicStrikethrough(NPC)
* Step2 = HeroicAgility / 25
* Step3 = MIN( Step1, Step2 )
* Step4 = DodgeSkill + 100
* Step5 = Step4 + ( DodgeSkill * DodgeSPA ) / 100
* Step6 = Step5 / 45
* DodgeChance = Step6 + ( Step2 - Step3 )
* Formula (all int math)
* (posted for parry, dodge appears to be the same as confirmed per Dev, assuming Riposte/Block are the same)
* Chance = (((SKILL + 100) + [((SKILL+100) * SPA(175).Base1) / 100]) / 45) + [(hDex / 25) - min([hStrikethrough, hDex / 25])].
If an NPC's Heroic Strikethrough is higher than your character's Heroic Agility bonus, you are disqualified from the "bonus" you would have gotten at the end.
*/
int hstrikethrough = attacker->GetHeroicStrikethrough();
// riposte -- it may seem crazy, but if the attacker has SPA 173 on them, they are immune to Ripo
bool ImmuneRipo = false;
if (!RuleB(Combat, UseLiveRiposteMechanics)) {
ImmuneRipo = attacker->aabonuses.RiposteChance || attacker->spellbonuses.RiposteChance || attacker->itembonuses.RiposteChance || attacker->IsEnraged();
}
/*
Live Riposte Mechanics (~Kayen updated 1/22)
-Ripostes can not trigger another riposte. (Ie. Riposte from defender can't then trigger the attacker to riposte)
-Ripostes can not be 'avoided', only hit or miss.
-Attacker with SPA 173 is not immune to riposte. The defender can riposte against the attackers melee hits.
Legacy Riposte Mechanics
-Ripostes can trigger another riposte
-Attacker with SPA 173 is immune to riposte
-Attacker that is enraged is immune to riposte
*/
// Need to check if we have something in MainHand to actually attack with (or fists)
if (hit.hand != EQ::invslot::slotRange && (CanThisClassRiposte() || IsEnraged()) && InFront && !ImmuneRipo) {
if (IsEnraged()) {
hit.damage_done = DMG_RIPOSTED;
LogCombat("I am enraged, riposting frontal attack");
return true;
}
if (IsClient())
CastToClient()->CheckIncreaseSkill(EQ::skills::SkillRiposte, other, -10);
// check auto discs ... I guess aa/items too :P
if (spellbonuses.RiposteChance == 10000 || aabonuses.RiposteChance == 10000 || itembonuses.RiposteChance == 10000) {
hit.damage_done = DMG_RIPOSTED;
return true;
}
int chance = GetSkill(EQ::skills::SkillRiposte) + 100;
chance += (chance * (aabonuses.RiposteChance + spellbonuses.RiposteChance + itembonuses.RiposteChance)) / 100;
chance /= 50;
chance += (itembonuses.HeroicDEX / 25) - std::min(hstrikethrough,(itembonuses.HeroicDEX / 25)); // "Heroic Strikethrough" subtracted here to counter HeroicDEX
if (counter_riposte || counter_all) {
float counter = (counter_riposte + counter_all) / 100.0f;
chance -= chance * counter;
}
if (modify_riposte || modify_all) {
float npc_modifier = (modify_riposte + modify_all) / 100.0f;
chance += chance * npc_modifier;
}
// AA Slippery Attacks
if (hit.hand == EQ::invslot::slotSecondary) {
int slip = aabonuses.OffhandRiposteFail + itembonuses.OffhandRiposteFail + spellbonuses.OffhandRiposteFail;
chance += chance * slip / 100;
}
if (chance > 0 && zone->random.Roll(chance)) { // could be <0 from offhand stuff
hit.damage_done = DMG_RIPOSTED;
return true;
}
}
// block
bool bBlockFromRear = false;
// a successful roll on this does not mean a successful block is forthcoming. only that a chance to block
// from a direction other than the rear is granted.
int BlockBehindChance = aabonuses.BlockBehind + spellbonuses.BlockBehind + itembonuses.BlockBehind;
if (BlockBehindChance && zone->random.Roll(BlockBehindChance))
bBlockFromRear = true;
if (CanThisClassBlock() && (InFront || bBlockFromRear)) {
if (IsClient())
CastToClient()->CheckIncreaseSkill(EQ::skills::SkillBlock, other, -10);
// check auto discs ... I guess aa/items too :P
if (spellbonuses.IncreaseBlockChance == 10000 || aabonuses.IncreaseBlockChance == 10000 ||
itembonuses.IncreaseBlockChance == 10000) {
hit.damage_done = DMG_BLOCKED;
return true;
}
int chance = GetSkill(EQ::skills::SkillBlock) + 100;
chance += (chance * (aabonuses.IncreaseBlockChance + spellbonuses.IncreaseBlockChance + itembonuses.IncreaseBlockChance)) / 100;
chance /= 25;
chance += (itembonuses.HeroicDEX / 25) - std::min(hstrikethrough,(itembonuses.HeroicDEX / 25)); // "Heroic Strikethrough" subtracted here to counter HeroicDEX
if (counter_block || counter_all) {
float counter = (counter_block + counter_all) / 100.0f;
chance -= chance * counter;
}
if (modify_block || modify_all) {
float npc_modifier = (modify_block + modify_all) / 100.0f;
chance += chance * npc_modifier;
}
if (zone->random.Roll(chance)) {
hit.damage_done = DMG_BLOCKED;
return true;
}
}
// parry
if (CanThisClassParry() && InFront && hit.hand != EQ::invslot::slotRange) {
if (IsClient())
CastToClient()->CheckIncreaseSkill(EQ::skills::SkillParry, other, -10);
// check auto discs ... I guess aa/items too :P
if (spellbonuses.ParryChance == 10000 || aabonuses.ParryChance == 10000 || itembonuses.ParryChance == 10000) {
hit.damage_done = DMG_PARRIED;
return true;
}
int chance = GetSkill(EQ::skills::SkillParry) + 100;
chance += (chance * (aabonuses.ParryChance + spellbonuses.ParryChance + itembonuses.ParryChance)) / 100;
chance /= 45;
chance += (itembonuses.HeroicDEX / 25) - std::min(hstrikethrough,(itembonuses.HeroicDEX / 25)); // "Heroic Strikethrough" subtracted here to counter HeroicDEX
if (counter_parry || counter_all) {
float counter = (counter_parry + counter_all) / 100.0f;
chance -= chance * counter;
}
if (modify_parry || modify_all) {
float npc_modifier = (modify_parry + modify_all) / 100.0f;
chance += chance * npc_modifier;
}
if (zone->random.Roll(chance)) {
hit.damage_done = DMG_PARRIED;
return true;
}
}
// dodge
if (CanThisClassDodge() && (InFront || GetClass() == Class::Monk)) {
if (IsClient())
CastToClient()->CheckIncreaseSkill(EQ::skills::SkillDodge, other, -10);
// check auto discs ... I guess aa/items too :P
if (spellbonuses.DodgeChance == 10000 || aabonuses.DodgeChance == 10000 || itembonuses.DodgeChance == 10000) {
hit.damage_done = DMG_DODGED;
return true;
}
int chance = GetSkill(EQ::skills::SkillDodge) + 100;
chance += (chance * (aabonuses.DodgeChance + spellbonuses.DodgeChance + itembonuses.DodgeChance)) / 100;
chance /= 45;
chance += (itembonuses.HeroicAGI / 25) - std::min(hstrikethrough,(itembonuses.HeroicAGI / 25)); // "Heroic Strikethrough" subtracted here to counter HeroicAGI
if (counter_dodge || counter_all) {
float counter = (counter_dodge + counter_all) / 100.0f;
chance -= chance * counter;
}
if (modify_dodge || modify_all) {
float npc_modifier = (modify_dodge + modify_all) / 100.0f;
chance += chance * npc_modifier;
}
if (zone->random.Roll(chance)) {
hit.damage_done = DMG_DODGED;
return true;
}
}
// Try Shield Block OR TwoHandBluntBlockCheck
if (HasShieldEquipped() && (aabonuses.ShieldBlock || spellbonuses.ShieldBlock || itembonuses.ShieldBlock) && (InFront || bBlockFromRear)) {
int chance = aabonuses.ShieldBlock + spellbonuses.ShieldBlock + itembonuses.ShieldBlock;
if (counter_block || counter_all) {
float counter = (counter_block + counter_all) / 100.0f;
chance -= chance * counter;
}
if (zone->random.Roll(chance)) {
hit.damage_done = DMG_BLOCKED;
return true;
}
}
if (HasTwoHandBluntEquipped() && (aabonuses.TwoHandBluntBlock || spellbonuses.TwoHandBluntBlock || itembonuses.TwoHandBluntBlock) && (InFront || bBlockFromRear)) {
int chance = aabonuses.TwoHandBluntBlock + itembonuses.TwoHandBluntBlock + spellbonuses.TwoHandBluntBlock;
if (counter_block || counter_all) {
float counter = (counter_block + counter_all) / 100.0f;
chance -= chance * counter;
}
if (zone->random.Roll(chance)) {
hit.damage_done = DMG_BLOCKED;
return true;
}
}
return false;
}
int Mob::GetACSoftcap()
{
// from test server Resources/ACMitigation.txt
static int war_softcaps[] = {
312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 338, 340, 342, 344, 346, 348, 350, 352,
354, 356, 358, 360, 362, 364, 366, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 388, 390, 392, 394,
396, 398, 400, 402, 404, 406, 408, 410, 412, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436,
438, 440, 442, 444, 446, 448, 450, 452, 454, 456, 458, 460, 462, 464, 466, 468, 470, 472, 474, 476, 478,
480, 482, 484, 486, 488, 490, 492, 494, 496, 498, 500, 502, 504, 506, 508, 510, 512, 514, 516, 518, 520
};
static int clrbrdmnk_softcaps[] = {
274, 276, 278, 278, 280, 282, 284, 286, 288, 290, 292, 292, 294, 296, 298, 300, 302, 304, 306, 308, 308,
310, 312, 314, 316, 318, 320, 322, 322, 324, 326, 328, 330, 332, 334, 336, 336, 338, 340, 342, 344, 346,
348, 350, 352, 352, 354, 356, 358, 360, 362, 364, 366, 366, 368, 370, 372, 374, 376, 378, 380, 380, 382,
384, 386, 388, 390, 392, 394, 396, 396, 398, 400, 402, 404, 406, 408, 410, 410, 412, 414, 416, 418, 420,
422, 424, 424, 426, 428, 430, 432, 434, 436, 438, 440, 440, 442, 444, 446, 448, 450, 452, 454, 454, 456
};
static int palshd_softcaps[] = {
298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 324, 326, 328, 330, 332, 334, 336, 336,
338, 340, 342, 344, 346, 348, 350, 352, 354, 356, 358, 360, 362, 364, 366, 368, 370, 372, 374, 376, 378,
380, 382, 384, 384, 386, 388, 390, 392, 394, 396, 398, 400, 402, 404, 406, 408, 410, 412, 414, 416, 418,
420, 422, 424, 426, 428, 430, 432, 432, 434, 436, 438, 440, 442, 444, 446, 448, 450, 452, 454, 456, 458,
460, 462, 464, 466, 468, 470, 472, 474, 476, 478, 480, 480, 482, 484, 486, 488, 490, 492, 494, 496, 498
};
static int rng_softcaps[] = {
286, 288, 290, 292, 294, 296, 298, 298, 300, 302, 304, 306, 308, 310, 312, 314, 316, 318, 320, 322, 322,
324, 326, 328, 330, 332, 334, 336, 338, 340, 342, 344, 344, 346, 348, 350, 352, 354, 356, 358, 360, 362,
364, 366, 368, 368, 370, 372, 374, 376, 378, 380, 382, 384, 386, 388, 390, 390, 392, 394, 396, 398, 400,
402, 404, 406, 408, 410, 412, 414, 414, 416, 418, 420, 422, 424, 426, 428, 430, 432, 434, 436, 436, 438,
440, 442, 444, 446, 448, 450, 452, 454, 456, 458, 460, 460, 462, 464, 466, 468, 470, 472, 474, 476, 478
};
static int dru_softcaps[] = {
254, 256, 258, 260, 262, 264, 264, 266, 268, 270, 272, 272, 274, 276, 278, 280, 282, 282, 284, 286, 288,
290, 290, 292, 294, 296, 298, 300, 300, 302, 304, 306, 308, 308, 310, 312, 314, 316, 318, 318, 320, 322,
324, 326, 328, 328, 330, 332, 334, 336, 336, 338, 340, 342, 344, 346, 346, 348, 350, 352, 354, 354, 356,
358, 360, 362, 364, 364, 366, 368, 370, 372, 372, 374, 376, 378, 380, 382, 382, 384, 386, 388, 390, 390,
392, 394, 396, 398, 400, 400, 402, 404, 406, 408, 410, 410, 412, 414, 416, 418, 418, 420, 422, 424, 426
};
static int rogshmbstber_softcaps[] = {
264, 266, 268, 270, 272, 272, 274, 276, 278, 280, 282, 282, 284, 286, 288, 290, 292, 294, 294, 296, 298,
300, 302, 304, 306, 306, 308, 310, 312, 314, 316, 316, 318, 320, 322, 324, 326, 328, 328, 330, 332, 334,
336, 338, 340, 340, 342, 344, 346, 348, 350, 350, 352, 354, 356, 358, 360, 362, 362, 364, 366, 368, 370,
372, 374, 374, 376, 378, 380, 382, 384, 384, 386, 388, 390, 392, 394, 396, 396, 398, 400, 402, 404, 406,
408, 408, 410, 412, 414, 416, 418, 418, 420, 422, 424, 426, 428, 430, 430, 432, 434, 436, 438, 440, 442
};
static int necwizmagenc_softcaps[] = {
248, 250, 252, 254, 256, 256, 258, 260, 262, 264, 264, 266, 268, 270, 272, 272, 274, 276, 278, 280, 280,
282, 284, 286, 288, 288, 290, 292, 294, 296, 296, 298, 300, 302, 304, 304, 306, 308, 310, 312, 312, 314,
316, 318, 320, 320, 322, 324, 326, 328, 328, 330, 332, 334, 336, 336, 338, 340, 342, 344, 344, 346, 348,
350, 352, 352, 354, 356, 358, 360, 360, 362, 364, 366, 368, 368, 370, 372, 374, 376, 376, 378, 380, 382,
384, 384, 386, 388, 390, 392, 392, 394, 396, 398, 400, 400, 402, 404, 406, 408, 408, 410, 412, 414, 416
};
int level = std::min(105, static_cast<int>(GetLevel())) - 1;
switch (GetClass()) {
case Class::Warrior:
return war_softcaps[level];
case Class::Cleric:
case Class::Bard:
case Class::Monk:
return clrbrdmnk_softcaps[level];
case Class::Paladin:
case Class::ShadowKnight:
return palshd_softcaps[level];
case Class::Ranger:
return rng_softcaps[level];
case Class::Druid:
return dru_softcaps[level];
case Class::Rogue:
case Class::Shaman:
case Class::Beastlord:
case Class::Berserker:
return rogshmbstber_softcaps[level];
case Class::Necromancer:
case Class::Wizard:
case Class::Magician:
case Class::Enchanter:
return necwizmagenc_softcaps[level];
default:
return 350;
}
}
double Mob::GetSoftcapReturns()
{
// These are based on the dev post, they seem to be correct for every level
// AKA no more hard caps
switch (GetClass()) {
case Class::Warrior:
return 0.35;
case Class::Cleric:
case Class::Bard:
case Class::Monk:
return 0.3;
case Class::Paladin:
case Class::ShadowKnight:
return 0.33;
case Class::Ranger:
return 0.315;
case Class::Druid:
return 0.265;
case Class::Rogue:
case Class::Shaman:
case Class::Beastlord:
case Class::Berserker:
return 0.28;
case Class::Necromancer:
case Class::Wizard:
case Class::Magician:
case Class::Enchanter:
return 0.25;
default:
return 0.3;
}
}
int Mob::GetClassRaceACBonus()
{
int ac_bonus = 0;
auto level = GetLevel();
if (GetClass() == Class::Monk) {
int hardcap = 30;
int softcap = 14;
if (level > 99) {
hardcap = 58;
softcap = 35;
}
else if (level > 94) {
hardcap = 57;
softcap = 34;
}
else if (level > 89) {
hardcap = 56;
softcap = 33;
}
else if (level > 84) {
hardcap = 55;
softcap = 32;
}
else if (level > 79) {
hardcap = 54;
softcap = 31;
}
else if (level > 74) {
hardcap = 53;
softcap = 30;
}
else if (level > 69) {
hardcap = 53;
softcap = 28;
}
else if (level > 64) {
hardcap = 53;
softcap = 26;
}
else if (level > 63) {
hardcap = 50;
softcap = 24;
}
else if (level > 61) {
hardcap = 47;
softcap = 24;
}
else if (level > 59) {
hardcap = 45;
softcap = 24;
}
else if (level > 54) {
hardcap = 40;
softcap = 20;
}
else if (level > 50) {
hardcap = 38;
softcap = 18;
}
else if (level > 44) {
hardcap = 36;
softcap = 17;
}
else if (level > 29) {
hardcap = 34;
softcap = 16;
}
else if (level > 14) {
hardcap = 32;
softcap = 15;
}
int weight = IsClient() ? CastToClient()->CalcCurrentWeight()/10 : 0;
if (weight < hardcap - 1) {
double temp = level + 5;
if (weight > softcap) {
double redux = static_cast<double>(weight - softcap) * 6.66667;
redux = (100.0 - std::min(100.0, redux)) * 0.01;
temp = std::max(0.0, temp * redux);
}
ac_bonus = static_cast<int>((4.0 * temp) / 3.0);
}
else if (weight > hardcap + 1) {
double temp = level + 5;
double multiplier = std::min(1.0, (weight - (static_cast<double>(hardcap) - 10.0)) / 100.0);
temp = (4.0 * temp) / 3.0;
ac_bonus -= static_cast<int>(temp * multiplier);
}
}
if (GetClass() == Class::Rogue) {
int level_scaler = level - 26;
if (GetAGI() < 80)
ac_bonus = level_scaler / 4;
else if (GetAGI() < 85)
ac_bonus = (level_scaler * 2) / 4;
else if (GetAGI() < 90)
ac_bonus = (level_scaler * 3) / 4;
else if (GetAGI() < 100)
ac_bonus = (level_scaler * 4) / 4;
else if (GetAGI() >= 100)
ac_bonus = (level_scaler * 5) / 4;
if (ac_bonus > 12)
ac_bonus = 12;
}
if (GetClass() == Class::Beastlord) {
int level_scaler = level - 6;
if (GetAGI() < 80)
ac_bonus = level_scaler / 5;
else if (GetAGI() < 85)
ac_bonus = (level_scaler * 2) / 5;
else if (GetAGI() < 90)
ac_bonus = (level_scaler * 3) / 5;
else if (GetAGI() < 100)
ac_bonus = (level_scaler * 4) / 5;
else if (GetAGI() >= 100)
ac_bonus = (level_scaler * 5) / 5;
if (ac_bonus > 16)
ac_bonus = 16;
}
if (GetRace() == IKSAR)
ac_bonus += EQ::Clamp(static_cast<int>(level), 10, 35);
return ac_bonus;
}
//SYNC WITH: tune.cpp, mob.h TuneACSum
int Mob::ACSum(bool skip_caps)
{
int ac = 0; // this should be base AC whenever shrouds come around
ac += itembonuses.AC; // items + food + tribute
int shield_ac = 0;
if (HasShieldEquipped() && IsOfClientBot()) {
auto inst = (IsClient()) ? GetInv().GetItem(EQ::invslot::slotSecondary) : CastToBot()->GetBotItem(EQ::invslot::slotSecondary);
if (inst) {
if (inst->GetItemRecommendedLevel(true) <= GetLevel()) {
shield_ac = inst->GetItemArmorClass(true);
} else {
shield_ac = CalcRecommendedLevelBonus(GetLevel(), inst->GetItemRecommendedLevel(true), inst->GetItemArmorClass(true));
}
}
shield_ac += itembonuses.heroic_str_shield_ac;
}
// EQ math
ac = (ac * 4) / 3;
// anti-twink
if (!skip_caps && IsOfClientBot() && GetLevel() < RuleI(Combat, LevelToStopACTwinkControl)) {
ac = std::min(ac, 25 + 6 * GetLevel());
}
ac = std::max(0, ac + GetClassRaceACBonus());
if (IsNPC()) {
// This is the developer tweaked number
// for the VAST amount of NPCs in EQ this number didn't exceed 600 until recently (PoWar)
// According to the guild hall Combat Dummies, a level 50 classic EQ mob it should be ~115
// For a 60 PoP mob ~120, 70 OoW ~120
ac += GetAC();
ac += GetPetACBonusFromOwner();
auto spell_aa_ac = aabonuses.AC + spellbonuses.AC;
ac += GetSkill(EQ::skills::SkillDefense) / 5;
if (EQ::ValueWithin(static_cast<int>(GetClass()), Class::Necromancer, Class::Enchanter))
ac += spell_aa_ac / 3;
else
ac += spell_aa_ac / 4;
}
else { // TODO: so we can't set NPC skills ... so the skill bonus ends up being HUGE so lets nerf them a bit
auto spell_aa_ac = aabonuses.AC + spellbonuses.AC;
if (EQ::ValueWithin(static_cast<int>(GetClass()), Class::Necromancer, Class::Enchanter))
ac += GetSkill(EQ::skills::SkillDefense) / 2 + spell_aa_ac / 3;
else
ac += GetSkill(EQ::skills::SkillDefense) / 3 + spell_aa_ac / 4;
}
if (GetAGI() > 70)
ac += GetAGI() / 20;
if (ac < 0)
ac = 0;
if (!skip_caps && IsOfClientBot()) {
auto softcap = GetACSoftcap();
auto returns = GetSoftcapReturns();
int total_aclimitmod = aabonuses.CombatStability + itembonuses.CombatStability + spellbonuses.CombatStability;
if (total_aclimitmod)
softcap = (softcap * (100 + total_aclimitmod)) / 100;
softcap += shield_ac;
if (ac > softcap) {
auto over_cap = ac - softcap;
ac = softcap + (over_cap * returns);
}
LogCombatDetail("ACSum ac [{}] softcap [{}] returns [{}]", ac, softcap, returns);
}
else {
LogCombatDetail("ACSum ac [{}]", ac);
}
return ac;
}
int Mob::GetBestMeleeSkill()
{
int bestSkill=0;
EQ::skills::SkillType meleeSkills[]=
{ EQ::skills::Skill1HBlunt,
EQ::skills::Skill1HSlashing,
EQ::skills::Skill2HBlunt,
EQ::skills::Skill2HSlashing,
EQ::skills::SkillHandtoHand,
EQ::skills::Skill1HPiercing,
EQ::skills::Skill2HPiercing,
EQ::skills::SkillCount
};
int i;
for (i=0; meleeSkills[i] != EQ::skills::SkillCount; ++i) {
int value;
value = GetSkill(meleeSkills[i]);
bestSkill = std::max(value, bestSkill);
}
return bestSkill;
}
//SYNC WITH: tune.cpp, mob.h Tuneoffense
int Mob::offense(EQ::skills::SkillType skill)