-
Notifications
You must be signed in to change notification settings - Fork 416
/
attack.cpp
5465 lines (4738 loc) · 171 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/skills.h"
#include "../common/spdat.h"
#include "../common/string_util.h"
#include "../common/data_verification.h"
#include "../common/misc_functions.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 <assert.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef BOTS
#include "bot.h"
#endif
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;
EQEmu::skills::SkillType Mob::AttackAnimation(int Hand, const EQEmu::ItemInstance* weapon, EQEmu::skills::SkillType skillinuse)
{
// Determine animation
int type = 0;
if (weapon && weapon->IsClassCommon()) {
const EQEmu::ItemData* item = weapon->GetItem();
Log(Logs::Detail, Logs::Attack, "Weapon skill : %i", item->ItemType);
switch (item->ItemType) {
case EQEmu::item::ItemType1HSlash: // 1H Slashing
skillinuse = EQEmu::skills::Skill1HSlashing;
type = anim1HWeapon;
break;
case EQEmu::item::ItemType2HSlash: // 2H Slashing
skillinuse = EQEmu::skills::Skill2HSlashing;
type = anim2HSlashing;
break;
case EQEmu::item::ItemType1HPiercing: // Piercing
skillinuse = EQEmu::skills::Skill1HPiercing;
type = anim1HPiercing;
break;
case EQEmu::item::ItemType1HBlunt: // 1H Blunt
skillinuse = EQEmu::skills::Skill1HBlunt;
type = anim1HWeapon;
break;
case EQEmu::item::ItemType2HBlunt: // 2H Blunt
skillinuse = EQEmu::skills::Skill2HBlunt;
type = anim2HSlashing; //anim2HWeapon
break;
case EQEmu::item::ItemType2HPiercing: // 2H Piercing
if (IsClient() && CastToClient()->ClientVersion() < EQEmu::versions::ClientVersion::RoF2)
skillinuse = EQEmu::skills::Skill1HPiercing;
else
skillinuse = EQEmu::skills::Skill2HPiercing;
type = anim2HWeapon;
break;
case EQEmu::item::ItemTypeMartial:
skillinuse = EQEmu::skills::SkillHandtoHand;
type = animHand2Hand;
break;
default:
skillinuse = EQEmu::skills::SkillHandtoHand;
type = animHand2Hand;
break;
}// switch
}
else if (IsNPC()) {
switch (skillinuse) {
case EQEmu::skills::Skill1HSlashing: // 1H Slashing
type = anim1HWeapon;
break;
case EQEmu::skills::Skill2HSlashing: // 2H Slashing
type = anim2HSlashing;
break;
case EQEmu::skills::Skill1HPiercing: // Piercing
type = anim1HPiercing;
break;
case EQEmu::skills::Skill1HBlunt: // 1H Blunt
type = anim1HWeapon;
break;
case EQEmu::skills::Skill2HBlunt: // 2H Blunt
type = anim2HSlashing; //anim2HWeapon
break;
case EQEmu::skills::Skill2HPiercing: // 2H Piercing
type = anim2HWeapon;
break;
case EQEmu::skills::SkillHandtoHand:
type = animHand2Hand;
break;
default:
type = animHand2Hand;
break;
}// switch
}
else {
skillinuse = EQEmu::skills::SkillHandtoHand;
type = animHand2Hand;
}
// If we're attacking with the secondary hand, play the dual wield anim
if (Hand == EQEmu::invslot::slotSecondary) // DW anim
type = animDualWield;
DoAnim(type, 0, false);
return skillinuse;
}
int Mob::compute_tohit(EQEmu::skills::SkillType skillinuse)
{
int tohit = GetSkill(EQEmu::skills::SkillOffense) + 7;
tohit += GetSkill(skillinuse);
if (IsNPC())
tohit += CastToNPC()->GetAccuracyRating();
if (IsClient()) {
double reduction = CastToClient()->m_pp.intoxication / 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
int Mob::GetTotalToHit(EQEmu::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 != EQEmu::skills::SkillArchery && skill != EQEmu::skills::SkillThrowing)
accuracy += itembonuses.HitChance;
// 216 Melee Accuracy Amt aka SE_Accuracy -- flat bonus
accuracy += itembonuses.Accuracy[EQEmu::skills::HIGHEST_SKILL + 1] +
aabonuses.Accuracy[EQEmu::skills::HIGHEST_SKILL + 1] +
spellbonuses.Accuracy[EQEmu::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[EQEmu::skills::HIGHEST_SKILL + 1] >= 10000)
return -1;
// 184 Accuracy % aka SE_HitChance -- percentage increase
auto hit_bonus = itembonuses.HitChanceEffect[EQEmu::skills::HIGHEST_SKILL + 1] +
aabonuses.HitChanceEffect[EQEmu::skills::HIGHEST_SKILL + 1] +
spellbonuses.HitChanceEffect[EQEmu::skills::HIGHEST_SKILL + 1] +
itembonuses.HitChanceEffect[skill] +
aabonuses.HitChanceEffect[skill] +
spellbonuses.HitChanceEffect[skill];
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
int Mob::compute_defense()
{
int defense = GetSkill(EQEmu::skills::SkillDefense) * 400 / 225;
defense += (8000 * (GetAGI() - 40)) / 36000;
if (IsClient())
defense += CastToClient()->GetHeroicAGI() / 10;
defense += itembonuses.AvoidMeleeChance; // item mod2
if (IsNPC())
defense += CastToNPC()->GetAvoidanceRating();
if (IsClient()) {
double reduction = CastToClient()->m_pp.intoxication / 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
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;
//
// 172 Evasion aka SE_AvoidMeleeChance
evasion_bonus += itembonuses.AvoidMeleeChanceEffect + aabonuses.AvoidMeleeChanceEffect; // item bonus here isn't mod2 avoidance
Mob *owner = nullptr;
if (IsPet())
owner = GetOwner();
else if (IsNPC() && CastToNPC()->GetSwarmOwner())
owner = entity_list.GetMobID(CastToNPC()->GetSwarmOwner());
if (owner) // 215 Pet Avoidance % aka SE_PetAvoidance
evasion_bonus += owner->aabonuses.PetAvoidance + owner->spellbonuses.PetAvoidance + owner->itembonuses.PetAvoidance;
// 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.
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->IsClient() && defender->CastToClient()->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([hDex / 25], hStrikethrough)].
* 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. At present
time this is the only way to fine tune counter these mods on players. 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(COUNTER_AVOID_DAMAGE)) {
counter_all = attacker->GetSpecialAbilityParam(COUNTER_AVOID_DAMAGE, 0);
counter_riposte = attacker->GetSpecialAbilityParam(COUNTER_AVOID_DAMAGE, 1);
counter_block = attacker->GetSpecialAbilityParam(COUNTER_AVOID_DAMAGE, 2);
counter_parry = attacker->GetSpecialAbilityParam(COUNTER_AVOID_DAMAGE, 3);
counter_dodge = attacker->GetSpecialAbilityParam(COUNTER_AVOID_DAMAGE, 4);
}
// riposte -- it may seem crazy, but if the attacker has SPA 173 on them, they are immune to Ripo
bool ImmuneRipo = attacker->aabonuses.RiposteChance || attacker->spellbonuses.RiposteChance || attacker->itembonuses.RiposteChance || attacker->IsEnraged();
// Need to check if we have something in MainHand to actually attack with (or fists)
if (hit.hand != EQEmu::invslot::slotRange && (CanThisClassRiposte() || IsEnraged()) && InFront && !ImmuneRipo) {
if (IsEnraged()) {
hit.damage_done = DMG_RIPOSTED;
Log(Logs::Detail, Logs::Combat, "I am enraged, riposting frontal attack.");
return true;
}
if (IsClient())
CastToClient()->CheckIncreaseSkill(EQEmu::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(EQEmu::skills::SkillRiposte) + 100;
chance += (chance * (aabonuses.RiposteChance + spellbonuses.RiposteChance + itembonuses.RiposteChance)) / 100;
chance /= 50;
chance += itembonuses.HeroicDEX / 25; // live has "heroic strickthrough" here to counter
if (counter_riposte || counter_all) {
float counter = (counter_riposte + counter_all) / 100.0f;
chance -= chance * counter;
}
// AA Slippery Attacks
if (hit.hand == EQEmu::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(EQEmu::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(EQEmu::skills::SkillBlock) + 100;
chance += (chance * (aabonuses.IncreaseBlockChance + spellbonuses.IncreaseBlockChance + itembonuses.IncreaseBlockChance)) / 100;
chance /= 25;
chance += itembonuses.HeroicDEX / 25; // live has "heroic strickthrough" here to counter
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;
}
}
// parry
if (CanThisClassParry() && InFront && hit.hand != EQEmu::invslot::slotRange) {
if (IsClient())
CastToClient()->CheckIncreaseSkill(EQEmu::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(EQEmu::skills::SkillParry) + 100;
chance += (chance * (aabonuses.ParryChance + spellbonuses.ParryChance + itembonuses.ParryChance)) / 100;
chance /= 45;
chance += itembonuses.HeroicDEX / 25; // live has "heroic strickthrough" here to counter
if (counter_parry || counter_all) {
float counter = (counter_parry + counter_all) / 100.0f;
chance -= chance * counter;
}
if (zone->random.Roll(chance)) {
hit.damage_done = DMG_PARRIED;
return true;
}
}
// dodge
if (CanThisClassDodge() && (InFront || GetClass() == MONK)) {
if (IsClient())
CastToClient()->CheckIncreaseSkill(EQEmu::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(EQEmu::skills::SkillDodge) + 100;
chance += (chance * (aabonuses.DodgeChance + spellbonuses.DodgeChance + itembonuses.DodgeChance)) / 100;
chance /= 45;
chance += itembonuses.HeroicAGI / 25; // live has "heroic strickthrough" here to counter
if (counter_dodge || counter_all) {
float counter = (counter_dodge + counter_all) / 100.0f;
chance -= chance * counter;
}
if (zone->random.Roll(chance)) {
hit.damage_done = DMG_DODGED;
return true;
}
}
// Try Shield Block OR TwoHandBluntBlockCheck
if (HasShieldEquiped() && (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 (HasTwoHandBluntEquiped() && (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 WARRIOR:
return war_softcaps[level];
case CLERIC:
case BARD:
case MONK:
return clrbrdmnk_softcaps[level];
case PALADIN:
case SHADOWKNIGHT:
return palshd_softcaps[level];
case RANGER:
return rng_softcaps[level];
case DRUID:
return dru_softcaps[level];
case ROGUE:
case SHAMAN:
case BEASTLORD:
case BERSERKER:
return rogshmbstber_softcaps[level];
case NECROMANCER:
case WIZARD:
case MAGICIAN:
case 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 WARRIOR:
return 0.35;
case CLERIC:
case BARD:
case MONK:
return 0.3;
case PALADIN:
case SHADOWKNIGHT:
return 0.33;
case RANGER:
return 0.315;
case DRUID:
return 0.265;
case ROGUE:
case SHAMAN:
case BEASTLORD:
case BERSERKER:
return 0.28;
case NECROMANCER:
case WIZARD:
case MAGICIAN:
case ENCHANTER:
return 0.25;
default:
return 0.3;
}
}
int Mob::GetClassRaceACBonus()
{
int ac_bonus = 0;
auto level = GetLevel();
if (GetClass() == 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() : 0;
if (weight < hardcap - 1) {
int temp = level + 5;
if (weight > softcap) {
double redux = (weight - softcap) * 6.66667;
redux = (100.0 - std::min(100.0, redux)) * 0.01;
temp = std::max(0, static_cast<int>(temp * redux));
}
ac_bonus = (4 * temp) / 3;
}
else if (weight > hardcap + 1) {
int temp = level + 5;
double multiplier = std::min(1.0, (weight - (hardcap - 10.0)) / 100.0);
temp = (4 * temp) / 3;
ac_bonus -= static_cast<int>(temp * multiplier);
}
}
if (GetClass() == 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() == 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 += EQEmu::Clamp(static_cast<int>(level), 10, 35);
return ac_bonus;
}
int Mob::ACSum()
{
int ac = 0; // this should be base AC whenever shrouds come around
ac += itembonuses.AC; // items + food + tribute
int shield_ac = 0;
if (HasShieldEquiped() && IsClient()) {
auto client = CastToClient();
auto inst = client->GetInv().GetItem(EQEmu::invslot::slotSecondary);
if (inst) {
if (inst->GetItemRecommendedLevel(true) <= GetLevel())
shield_ac = inst->GetItemArmorClass(true);
else
shield_ac = client->CalcRecommendedLevelBonus(GetLevel(), inst->GetItemRecommendedLevel(true), inst->GetItemArmorClass(true));
}
shield_ac += client->GetHeroicSTR() / 10;
}
// EQ math
ac = (ac * 4) / 3;
// anti-twink
if (IsClient() && GetLevel() < 50)
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();
Mob *owner = nullptr;
if (IsPet())
owner = GetOwner();
else if (CastToNPC()->GetSwarmOwner())
owner = entity_list.GetMobID(CastToNPC()->GetSwarmOwner());
if (owner)
ac += owner->aabonuses.PetAvoidance + owner->spellbonuses.PetAvoidance + owner->itembonuses.PetAvoidance;
auto spell_aa_ac = aabonuses.AC + spellbonuses.AC;
ac += GetSkill(EQEmu::skills::SkillDefense) / 5;
if (EQEmu::ValueWithin(static_cast<int>(GetClass()), NECROMANCER, 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 (EQEmu::ValueWithin(static_cast<int>(GetClass()), NECROMANCER, ENCHANTER))
ac += GetSkill(EQEmu::skills::SkillDefense) / 2 + spell_aa_ac / 3;
else
ac += GetSkill(EQEmu::skills::SkillDefense) / 3 + spell_aa_ac / 4;
}
if (GetAGI() > 70)
ac += GetAGI() / 20;
if (ac < 0)
ac = 0;
if (IsClient()
#ifdef BOTS
|| IsBot()
#endif
) {
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);
}
Log(Logs::Detail, Logs::Combat, "ACSum ac %d softcap %d returns %f", ac, softcap, returns);
}
else {
Log(Logs::Detail, Logs::Combat, "ACSum ac %d", ac);
}
return ac;
}
int Mob::GetBestMeleeSkill()
{
int bestSkill=0;
EQEmu::skills::SkillType meleeSkills[]=
{ EQEmu::skills::Skill1HBlunt,
EQEmu::skills::Skill1HSlashing,
EQEmu::skills::Skill2HBlunt,
EQEmu::skills::Skill2HSlashing,
EQEmu::skills::SkillHandtoHand,
EQEmu::skills::Skill1HPiercing,
EQEmu::skills::Skill2HPiercing,
EQEmu::skills::SkillCount
};
int i;
for (i=0; meleeSkills[i] != EQEmu::skills::SkillCount; ++i) {
int value;
value = GetSkill(meleeSkills[i]);
bestSkill = std::max(value, bestSkill);
}
return bestSkill;
}
int Mob::offense(EQEmu::skills::SkillType skill)
{
int offense = GetSkill(skill);
int stat_bonus = GetSTR();
switch (skill) {
case EQEmu::skills::SkillArchery:
case EQEmu::skills::SkillThrowing:
stat_bonus = GetDEX();
break;
// Mobs with no weapons default to H2H.
// Since H2H is capped at 100 for many many classes,
// lets not handicap mobs based on not spawning with a
// weapon.
//
// Maybe we tweak this if Disarm is actually implemented.
case EQEmu::skills::SkillHandtoHand:
offense = GetBestMeleeSkill();
break;
}
if (stat_bonus >= 75)
offense += (2 * stat_bonus - 150) / 3;
offense += GetATK();
return offense;
}
// this assumes "this" is the defender
// this returns between 0.1 to 2.0
double Mob::RollD20(int offense, int mitigation)
{
static double mods[] = {
0.1, 0.2, 0.3, 0.4, 0.5,
0.6, 0.7, 0.8, 0.9, 1.0,
1.1, 1.2, 1.3, 1.4, 1.5,
1.6, 1.7, 1.8, 1.9, 2.0
};
if (IsClient() && CastToClient()->IsSitting())
return mods[19];
auto atk_roll = zone->random.Roll0(offense + 5);
auto def_roll = zone->random.Roll0(mitigation + 5);
int avg = (offense + mitigation + 10) / 2;
int index = std::max(0, (atk_roll - def_roll) + (avg / 2));
index = EQEmu::Clamp((index * 20) / avg, 0, 19);
return mods[index];
}
void Mob::MeleeMitigation(Mob *attacker, DamageHitInfo &hit, ExtraAttackOptions *opts)
{
#ifdef LUA_EQEMU
bool ignoreDefault = false;
LuaParser::Instance()->MeleeMitigation(this, attacker, hit, opts, ignoreDefault);
if (ignoreDefault) {
return;
}
#endif
if (hit.damage_done < 0 || hit.base_damage == 0)
return;
Mob* defender = this;
auto mitigation = defender->GetMitigationAC();
if (IsClient() && attacker->IsClient())
mitigation = mitigation * 80 / 100; // 2004 PvP changes
if (opts) {
mitigation *= (1.0f - opts->armor_pen_percent);
mitigation -= opts->armor_pen_flat;
}
auto roll = RollD20(hit.offense, mitigation);
// +0.5 for rounding, min to 1 dmg
hit.damage_done = std::max(static_cast<int>(roll * static_cast<double>(hit.base_damage) + 0.5), 1);
Log(Logs::Detail, Logs::Attack, "mitigation %d vs offense %d. base %d rolled %f damage %d", mitigation, hit.offense, hit.base_damage, roll, hit.damage_done);
}
//Returns the weapon damage against the input mob
//if we cannot hit the mob with the current weapon we will get a value less than or equal to zero
//Else we know we can hit.
//GetWeaponDamage(mob*, const EQEmu::ItemData*) is intended to be used for mobs or any other situation where we do not have a client inventory item
//GetWeaponDamage(mob*, const EQEmu::ItemInstance*) is intended to be used for situations where we have a client inventory item
int Mob::GetWeaponDamage(Mob *against, const EQEmu::ItemData *weapon_item) {
int dmg = 0;
int banedmg = 0;
//can't hit invulnerable stuff with weapons.
if (against->GetInvul() || against->GetSpecialAbility(IMMUNE_MELEE)) {
return 0;
}
//check to see if our weapons or fists are magical.
if (against->GetSpecialAbility(IMMUNE_MELEE_NONMAGICAL)) {
if (weapon_item) {
if (weapon_item->Magic) {
dmg = weapon_item->Damage;
//this is more for non weapon items, ex: boots for kick
//they don't have a dmg but we should be able to hit magical
dmg = dmg <= 0 ? 1 : dmg;
}
else
return 0;
}
else {
if ((GetClass() == MONK || GetClass() == BEASTLORD) && GetLevel() >= 30) {
dmg = GetHandToHandDamage();
}
else if (GetOwner() && GetLevel() >= RuleI(Combat, PetAttackMagicLevel)) {
//pets wouldn't actually use this but...