forked from EQMacEmu/Server
-
Notifications
You must be signed in to change notification settings - Fork 49
/
attack.cpp
5389 lines (4649 loc) · 149 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/eqemu_logsys.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/strings.h"
#include "../common/fastmath.h"
#include "quest_parser_collection.h"
#include "string_ids.h"
#include "water_map.h"
#include "queryserv.h"
#include "worldserver.h"
#include "zone.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
extern WorldServer worldserver;
extern QueryServ* QServ;
extern FastMath g_Math;
#ifdef _WINDOWS
#define snprintf _snprintf
#define strncasecmp _strnicmp
#define strcasecmp _stricmp
#endif
extern EntityList entity_list;
extern Zone* zone;
bool Mob::AttackAnimation(EQ::skills::SkillType &skillinuse, int Hand, const EQ::ItemInstance* weapon)
{
// Determine animation
DoAnimation type = DoAnimation::None;
if (weapon && weapon->IsType(EQ::item::ItemClassCommon)) {
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 = DoAnimation::Weapon1H;
break;
}
case EQ::item::ItemType2HSlash: // 2H Slashing
{
skillinuse = EQ::skills::Skill2HSlashing;
type = DoAnimation::Slashing2H;
break;
}
case EQ::item::ItemType1HPiercing: // Piercing
{
skillinuse = EQ::skills::Skill1HPiercing;
type = DoAnimation::Piercing;
break;
}
case EQ::item::ItemType1HBlunt: // 1H Blunt
{
skillinuse = EQ::skills::Skill1HBlunt;
type = DoAnimation::Weapon1H;
break;
}
case EQ::item::ItemType2HBlunt: // 2H Blunt
{
skillinuse = EQ::skills::Skill2HBlunt;
type = DoAnimation::Weapon2H; //anim2HWeapon
break;
}
case EQ::item::ItemType2HPiercing: // 2H Piercing
{
skillinuse = EQ::skills::Skill1HPiercing; // change to Skill2HPiercing once activated
type = DoAnimation::Weapon2H;
break;
}
case EQ::item::ItemTypeMartial:
{
skillinuse = EQ::skills::SkillHandtoHand;
type = DoAnimation::Hand2Hand;
break;
}
default:
{
skillinuse = EQ::skills::SkillHandtoHand;
type = DoAnimation::Hand2Hand;
break;
}
}// switch
}
else if(IsNPC()) {
switch (skillinuse)
{
case EQ::skills::Skill1HSlashing: // 1H Slashing
{
type = DoAnimation::Weapon1H;
break;
}
case EQ::skills::Skill2HSlashing: // 2H Slashing
{
type = DoAnimation::Slashing2H;
break;
}
case EQ::skills::Skill1HPiercing: // Piercing
{
type = DoAnimation::Piercing;
break;
}
case EQ::skills::Skill1HBlunt: // 1H Blunt
{
type = DoAnimation::Weapon1H;
break;
}
case EQ::skills::Skill2HBlunt: // 2H Blunt
{
type = DoAnimation::Weapon2H;
break;
}
case EQ::skills::SkillHandtoHand:
{
type = DoAnimation::Hand2Hand;
break;
}
default:
{
type = DoAnimation::Hand2Hand;
break;
}
}// switch
}
else {
skillinuse = EQ::skills::SkillHandtoHand;
type = DoAnimation::Hand2Hand;
}
// If we're attacking with the secondary hand, play the dual wield anim
if (Hand == EQ::invslot::slotSecondary) // DW anim
type = DoAnimation::DualWield;
DoAnim(type, 0, false);
return true;
}
// returns true on hit
bool Mob::AvoidanceCheck(Mob* attacker, EQ::skills::SkillType skillinuse)
{
Mob *defender = this;
if (IsClient() && CastToClient()->IsSitting())
{
return true;
}
int toHit = attacker->GetToHit(skillinuse);
int avoidance = defender->GetAvoidance();
int percentMod = 0;
Log(Logs::Detail, Logs::Attack, "AvoidanceCheck: %s attacked by %s; Avoidance: %i To-Hit: %i", defender->GetName(), attacker->GetName(), avoidance, toHit);
// Hit Chance percent modifier
// Disciplines: Evasive, Precision, Deadeye, Trueshot, Charge
percentMod = attacker->itembonuses.HitChanceEffect[skillinuse] +
attacker->spellbonuses.HitChanceEffect[skillinuse] +
attacker->aabonuses.HitChanceEffect[skillinuse] +
attacker->itembonuses.HitChanceEffect[EQ::skills::HIGHEST_SKILL + 1] +
attacker->spellbonuses.HitChanceEffect[EQ::skills::HIGHEST_SKILL + 1] +
attacker->aabonuses.HitChanceEffect[EQ::skills::HIGHEST_SKILL + 1];
// Avoidance chance percent modifier
// Disciplines: Evasive, Precision, Voiddance, Fortitude
percentMod -= (defender->spellbonuses.AvoidMeleeChanceEffect + defender->itembonuses.AvoidMeleeChanceEffect);
if (percentMod != 0)
{
if (skillinuse == EQ::skills::SkillArchery && percentMod > 0)
percentMod -= static_cast<int>(static_cast<float>(percentMod) * RuleR(Combat, ArcheryHitPenalty));
Log(Logs::Detail, Logs::Attack, "Modified chance to hit: %i%%", percentMod);
if (percentMod > 0)
{
if (zone->random.Roll(percentMod))
{
Log(Logs::Detail, Logs::Attack, "Modified Hit");
return true;
}
}
else
{
if (zone->random.Roll(-percentMod))
{
Log(Logs::Detail, Logs::Attack, "Modified Miss");
return false;
}
}
}
// This produces precise output. Don't change this unless you have Sony's actual code
double hitChance;
toHit += 10;
avoidance += 10;
if (toHit * 1.21 > avoidance)
{
hitChance = 1.0 - avoidance / (toHit * 1.21 * 2.0);
}
else
{
hitChance = toHit * 1.21 / (avoidance * 2.0);
}
if (zone->random.Real(0.0, 1.0) < hitChance)
{
Log(Logs::Detail, Logs::Attack, "Hit; Hit chance was %0.1f%%", hitChance*100);
return true;
}
if (IsClient() && attacker->IsNPC())
CastToClient()->CheckIncreaseSkill(EQ::skills::SkillDefense, attacker, zone->skill_difficulty[EQ::skills::SkillDefense].difficulty);
Log(Logs::Detail, Logs::Attack, "Miss; Hit chance was %0.1f%%", hitChance * 100);
return false;
}
bool Mob::AvoidDamage(Mob* attacker, int32 &damage, bool noRiposte, bool isRangedAttack)
{
/* solar: 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
*
*/
Mob *defender = this;
bool InFront = attacker->InFrontMob(this, attacker->GetX(), attacker->GetY());
// block
if (GetSkill(EQ::skills::SkillBlock))
{
if (IsClient())
CastToClient()->CheckIncreaseSkill(EQ::skills::SkillBlock, attacker, zone->skill_difficulty[EQ::skills::SkillBlock].difficulty);
// check auto discs ... I guess aa/items too :P
if (spellbonuses.IncreaseBlockChance == 10000 || aabonuses.IncreaseBlockChance == 10000 ||
itembonuses.IncreaseBlockChance == 10000) {
damage = DMG_BLOCK;
return true;
}
int chance = GetSkill(EQ::skills::SkillBlock) + 100;
chance += (chance * (aabonuses.IncreaseBlockChance + spellbonuses.IncreaseBlockChance + itembonuses.IncreaseBlockChance)) / 100;
chance /= 25;
if (zone->random.Roll(chance)) {
damage = DMG_BLOCK;
return true;
}
}
// parry
if (GetSkill(EQ::skills::SkillParry) && InFront && !isRangedAttack)
{
if (IsClient())
CastToClient()->CheckIncreaseSkill(EQ::skills::SkillParry, attacker, zone->skill_difficulty[EQ::skills::SkillParry].difficulty);
// check auto discs ... I guess aa/items too :P
if (spellbonuses.ParryChance == 10000 || aabonuses.ParryChance == 10000 || itembonuses.ParryChance == 10000) {
damage = DMG_PARRY;
return true;
}
int chance = GetSkill(EQ::skills::SkillParry) + 100;
chance += (chance * (aabonuses.ParryChance + spellbonuses.ParryChance + itembonuses.ParryChance)) / 100;
chance /= 50; // this is 45 in modern EQ. Old EQ logs parsed to a lower parry rate, so raising this
if (zone->random.Roll(chance)) {
damage = DMG_PARRY;
return true;
}
}
// riposte
if (!noRiposte && !isRangedAttack && GetSkill(EQ::skills::SkillRiposte) && InFront)
{
bool cannotRiposte = false;
if (IsClient())
{
EQ::ItemInstance* weapon = nullptr;
weapon = CastToClient()->GetInv().GetItem(EQ::invslot::slotPrimary);
if (weapon != nullptr && !weapon->IsWeapon())
{
cannotRiposte = true;
}
else
{
CastToClient()->CheckIncreaseSkill(EQ::skills::SkillRiposte, attacker, zone->skill_difficulty[EQ::skills::SkillRiposte].difficulty);
}
}
// riposting ripostes is possible, but client attacks become unripable while under a rip disc
if (attacker->IsEnraged() ||
(attacker->IsClient() && (attacker->aabonuses.RiposteChance + attacker->spellbonuses.RiposteChance + attacker->itembonuses.RiposteChance) >= 10000)
)
cannotRiposte = true;
if (!cannotRiposte)
{
if (IsEnraged() || spellbonuses.RiposteChance == 10000 || aabonuses.RiposteChance == 10000 || itembonuses.RiposteChance == 10000)
{
damage = DMG_RIPOSTE;
return true;
}
int chance = GetSkill(EQ::skills::SkillRiposte) + 100;
chance += (chance * (aabonuses.RiposteChance + spellbonuses.RiposteChance + itembonuses.RiposteChance)) / 100;
chance /= 55; // this is 50 in modern EQ. Old EQ logs parsed to a lower rate, so raising this
if (chance > 0 && zone->random.Roll(chance)) // could be <0 from offhand stuff
{
// March 19 2002 patch made pets not take non-enrage ripostes from NPCs. it said 'more likely to avoid' but player comments say zero and logs confirm
if (IsNPC() && attacker->IsPet())
{
damage = DMG_MISS; // converting ripostes to misses. don't know what Sony did but erring on conservative
return true;
}
damage = DMG_RIPOSTE;
return true;
}
}
}
// dodge
if (GetSkill(EQ::skills::SkillDodge) && InFront)
{
if (IsClient())
CastToClient()->CheckIncreaseSkill(EQ::skills::SkillDodge, attacker, zone->skill_difficulty[EQ::skills::SkillDodge].difficulty);
// check auto discs ... I guess aa/items too :P
if (spellbonuses.DodgeChance == 10000 || aabonuses.DodgeChance == 10000 || itembonuses.DodgeChance == 10000) {
damage = DMG_DODGE;
return true;
}
int chance = GetSkill(EQ::skills::SkillDodge) + 100;
chance += (chance * (aabonuses.DodgeChance + spellbonuses.DodgeChance + itembonuses.DodgeChance)) / 100;
chance /= 45;
if (zone->random.Roll(chance)) {
damage = DMG_DODGE;
return true;
}
}
return false;
}
int Mob::RollD20(double offense, double mitigation)
{
int atkRoll = zone->random.Roll0(offense + 5);
int defRoll = zone->random.Roll0(mitigation + 5);
int avg = (offense + mitigation + 10) / 2;
int index = std::max(0, (atkRoll - defRoll) + (avg / 2));
index = (index * 20) / avg;
index = std::max(0, index);
index = std::min(19, index);
return index + 1;
}
// Our database uses a min hit and max hit system, instead of Sony's DB + baseDmg * 0.1-2.0
// This calcs a DB (which is minHit - DI) from min and max hits
int NPC::GetDamageBonus()
{
if (min_dmg > max_dmg)
return min_dmg;
int di1k = ((max_dmg - min_dmg) * 1000) / 19; // multiply damage interval by 1000 to avoid using floats
di1k = (di1k + 50) / 100 * 100; // round DI to nearest tenth of a point
int db = max_dmg * 1000 - di1k * 20;
return db / 1000;
}
// Our database uses a min hit and max hit system, instead of Sony's DB + baseDmg * 0.1-2.0
// This calcs a baseDamage value (which is DI*10) from min and max hits
// baseDamage is the equivalent to weapon damage for clients
int NPC::GetBaseDamage(Mob* defender, int slot)
{
if (slot != EQ::invslot::slotSecondary && slot != EQ::invslot::slotRange)
slot = EQ::invslot::slotPrimary;
int baseDamage = 1;
if (max_dmg > min_dmg)
{
int di1k = (max_dmg - min_dmg) * 1000 / 19; // multiply damage interval by 1000 to avoid using floats
di1k = (di1k + 50) / 100 * 100; // round DI to nearest tenth of a point
baseDamage = di1k / 100;
}
const EQ::ItemData* weapon = nullptr;
if (equipment[slot] > 0)
weapon = database.GetItem(equipment[slot]);
if (weapon)
{
int weaponDmg = weapon->Damage;
if (weapon->ElemDmgAmt)
{
weaponDmg += CalcEleWeaponResist(weapon->ElemDmgAmt, weapon->ElemDmgType, defender);
}
if (weapon->BaneDmgBody == defender->GetBodyType() || weapon->BaneDmgRace == defender->GetRace())
{
weaponDmg += weapon->BaneDmgAmt;
}
if (slot == EQ::invslot::slotRange)
{
weapon = database.GetItem(equipment[EQ::invslot::slotAmmo]);
if (weapon)
{
if (weapon->ElemDmgAmt)
{
weaponDmg += CalcEleWeaponResist(weapon->ElemDmgAmt, weapon->ElemDmgType, defender);
}
}
}
if (weaponDmg > baseDamage)
baseDamage = weaponDmg;
}
return baseDamage;
}
// returns the client's weapon (or hand to hand) damage
// slot parameter should be one of: SlotPrimary, SlotSecondary, SlotRange, SlotAmmo
// does not check for immunities
// calling this with SlotRange will also add the arrow damage
int Client::GetBaseDamage(Mob *defender, int slot)
{
if (slot != EQ::invslot::slotSecondary && slot != EQ::invslot::slotRange && slot != EQ::invslot::slotAmmo)
slot = EQ::invslot::slotPrimary;
int dmg = 0;
EQ::ItemInstance* weaponInst = GetInv().GetItem(slot);
const EQ::ItemData* weapon = nullptr;
if (weaponInst)
weapon = weaponInst->GetItem();
if (weapon)
{
// cheaters or GMs doing stuff
if (weapon->ReqLevel > GetLevel())
return dmg;
if (!weaponInst->IsEquipable(GetBaseRace(), GetClass()))
return dmg;
if (GetLevel() < weapon->RecLevel)
dmg = CastToClient()->CalcRecommendedLevelBonus(GetLevel(), weapon->RecLevel, weapon->Damage);
else
dmg = weapon->Damage;
if (weapon->ElemDmgAmt && !defender->GetSpecialAbility(IMMUNE_MAGIC))
{
int eledmg = 0;
if (GetLevel() < weapon->RecLevel)
eledmg = CastToClient()->CalcRecommendedLevelBonus(GetLevel(), weapon->RecLevel, weapon->ElemDmgAmt);
else
eledmg = weapon->ElemDmgAmt;
if (eledmg)
{
eledmg = CalcEleWeaponResist(eledmg, weapon->ElemDmgType, defender);
dmg += eledmg;
}
}
if (weapon->BaneDmgBody == defender->GetBodyType() || weapon->BaneDmgRace == defender->GetRace())
{
if (GetLevel() < weapon->RecLevel)
dmg += CastToClient()->CalcRecommendedLevelBonus(GetLevel(), weapon->RecLevel, weapon->BaneDmgAmt);
else
dmg += weapon->BaneDmgAmt;
}
if (slot == EQ::invslot::slotRange && GetInv().GetItem(EQ::invslot::slotAmmo))
{
dmg += GetBaseDamage(defender, EQ::invslot::slotAmmo);
}
}
else if (slot == EQ::invslot::slotPrimary || slot == EQ::invslot::slotSecondary)
dmg = GetHandToHandDamage();
return dmg;
}
// For both Clients and NPCs. Sony calls client weapon damage and innate NPC damage 'base damage'
// NPC base damage is essentially DI * 10. Special skills have their own base damage
// All melee, archery and throwing damage should pass through here
// For reference, NPC damage is: minHit = DB + DI*1; maxHit = DB + DI*20. Clients do the same, but get a multiplier after it
int Mob::CalcMeleeDamage(Mob* defender, int baseDamage, EQ::skills::SkillType skill)
{
if (!defender || !baseDamage)
return 0;
// ranged physical damage does half that of melee
if ((skill == EQ::skills::SkillArchery || skill == EQ::skills::SkillThrowing) && baseDamage > 1)
baseDamage /= 2;
int offense = GetOffense(skill);
// mitigation roll
int roll = RollD20(offense, defender->GetMitigation());
if (defender->IsClient() && defender->CastToClient()->IsSitting())
roll = 20;
// SE_MinDamageModifier[186] for disciplines: Fellstrike, Innerflame, Duelist, Bestial Rage
// min hit becomes 4 x weapon damage + 1 x damage bonus
int minHit = baseDamage * GetMeleeMinDamageMod_SE(skill) / 100;
// SE_DamageModifier[185] for disciplines: Aggressive, Ashenhand, Bestial Rage, Defensive, Duelist,
// Fellstrike, Innerflame, Silentfist, Thunderkick
baseDamage += baseDamage * GetMeleeDamageMod_SE(skill) / 100;
// SE_MeleeMitigation[168] for disciplines: Defensive (-50), Stonestance & Protective Spirit (-90)
// Aggressive (+50)
baseDamage += baseDamage * defender->GetSpellBonuses().MeleeMitigationEffect / 100;
if (defender->IsClient() && IsPet() && GetOwner()->IsClient()) {
// pets do reduced damage to clients in pvp
baseDamage /= 2;
}
int damage = (roll * baseDamage + 5) / 10;
if (damage < minHit) damage = minHit;
if (damage < 1)
damage = 1;
if (IsClient())
CastToClient()->RollDamageMultiplier(offense, damage, skill);
return damage;
}
// the output of this function is precise and is based on the code from:
// https://forums.daybreakgames.com/eq/index.php?threads/progression-monks-we-have-work-to-do.229581/
uint32 Client::RollDamageMultiplier(uint32 offense, int& damage, EQ::skills::SkillType skill)
{
int rollChance = 51;
int maxExtra = 210;
int minusFactor = 105;
if (GetClass() == MONK && level >= 65)
{
rollChance = 83;
maxExtra = 300;
minusFactor = 50;
}
else if (level >= 65 || (GetClass() == MONK && level >= 63))
{
rollChance = 81;
maxExtra = 295;
minusFactor = 55;
}
else if (level >= 63 || (GetClass() == MONK && level >= 60))
{
rollChance = 79;
maxExtra = 290;
minusFactor = 60;
}
else if (level >= 60 || (GetClass() == MONK && level >= 56))
{
rollChance = 77;
maxExtra = 285;
minusFactor = 65;
}
else if (level >= 56)
{
rollChance = 72;
maxExtra = 265;
minusFactor = 70;
}
else if (level >= 51 || GetClass() == MONK)
{
rollChance = 65;
maxExtra = 245;
minusFactor = 80;
}
int baseBonus = (static_cast<int>(offense) - minusFactor) / 2;
if (baseBonus < 10)
baseBonus = 10;
if (zone->random.Roll(rollChance))
{
uint32 roll;
roll = zone->random.Int(0, baseBonus) + 100;
if (roll > maxExtra)
roll = maxExtra;
damage = damage * roll / 100;
if (level >= 55 && damage > 1 && skill != EQ::skills::SkillArchery && IsWarriorClass())
damage++;
return roll;
}
else
{
return 100;
}
}
// decompile shows that weapon elemental damage resist uses a special function
// credit to demonstar
int Mob::CalcEleWeaponResist(int weaponDamage, int resistType, Mob *target)
{
int resistValue = 0;
switch (resistType)
{
case RESIST_FIRE:
resistValue = target->GetFR();
break;
case RESIST_COLD:
resistValue = target->GetCR();
break;
case RESIST_MAGIC:
resistValue = target->GetMR();
break;
case RESIST_DISEASE:
resistValue = target->GetDR();
break;
case RESIST_POISON:
resistValue = target->GetPR();
break;
}
if (resistValue > 200)
return 0;
int roll = zone->random.Int(1, 201) - resistValue;
if (roll < 1)
return 0;
if (roll <= 99)
return weaponDamage * roll / 100;
else
return weaponDamage;
}
// Checks for weapon (including ranged) immunity, and magic flagged armor (kicks, punches, bashes)
// slot argument should be one of the following: SlotPrimary, SlotSecondary, SlotRange, SlotAmmo, SlotFeet, SlotHands
bool Mob::IsImmuneToMelee(Mob* attacker, int slot)
{
if (!attacker || GetInvul() || GetSpecialAbility(IMMUNE_MELEE))
return true;
if (slot != EQ::invslot::slotSecondary && slot != EQ::invslot::slotRange && slot != EQ::invslot::slotAmmo && slot != EQ::invslot::slotFeet && slot != EQ::invslot::slotHands)
slot = EQ::invslot::slotPrimary;
if (attacker->IsNPC() && slot != EQ::invslot::slotPrimary && slot != EQ::invslot::slotSecondary)
slot = EQ::invslot::slotPrimary;
EQ::ItemInstance* weaponInst = nullptr;
const EQ::ItemData* weapon = nullptr;
if (attacker->IsClient())
{
weaponInst = attacker->CastToClient()->GetInv().GetItem(slot);
if (weaponInst)
weapon = weaponInst->GetItem();
}
else if (attacker->IsNPC())
{
uint32 weaponID = attacker->CastToNPC()->GetEquipment(slot == EQ::invslot::slotSecondary ? EQ::textures::weaponSecondary : EQ::textures::weaponPrimary);
if (weaponID > 0)
weapon = database.GetItem(weaponID);
}
bool magicWeapon = false;
if (weapon)
{
if (weapon->Magic || attacker->spellbonuses.MagicWeapon || attacker->itembonuses.MagicWeapon)
magicWeapon = true;
}
else if ((attacker->GetClass() == MONK || attacker->GetClass() == BEASTLORD) && attacker->GetLevel() > 29
&& (slot == EQ::invslot::slotPrimary || slot == EQ::invslot::slotSecondary || slot == EQ::invslot::slotHands)
)
magicWeapon = true;
if (!magicWeapon && GetSpecialAbility(IMMUNE_MELEE_NONMAGICAL))
{
if (attacker->IsNPC() && !attacker->GetSpecialAbility(SPECATK_MAGICAL) && attacker->GetLevel() < MAGIC_ATTACK_LEVEL)
{
return true;
}
else if (attacker->IsClient())
{
// grant magic attack to fists but not to held weapons if gloves are magic to these three classes
if ( (attacker->GetClass() == MONK || attacker->GetClass() == BEASTLORD || attacker->GetClass() == BARD)
&& ((!weapon && (slot == EQ::invslot::slotPrimary || slot == EQ::invslot::slotSecondary)) || slot == EQ::invslot::slotHands)
)
{
EQ::ItemInstance *gloves = attacker->CastToClient()->GetInv().GetItem(EQ::invslot::slotHands);
if (!gloves || !gloves->GetItem()->Magic)
return true;
}
else
return true;
}
}
// don't think there are weapons that are pure elemental damage, but handling them anyway
if (weapon && !weapon->Damage && weapon->ElemDmgAmt && GetSpecialAbility(IMMUNE_MAGIC))
return true;
if (GetSpecialAbility(IMMUNE_MELEE_EXCEPT_BANE))
{
if (attacker->IsClient())
{
// Use primary hand weapon to check for bane immunity on special attacks
if (slot != EQ::invslot::slotPrimary && slot != EQ::invslot::slotSecondary && slot != EQ::invslot::slotRange)
{
weapon = nullptr;
weaponInst = attacker->CastToClient()->GetInv().GetItem(EQ::invslot::slotPrimary);
if (weaponInst)
weapon = weaponInst->GetItem();
}
if (!weapon || (weapon->BaneDmgBody != GetBodyType() && weapon->BaneDmgRace != GetRace()))
return true;
}
else
{
if (!attacker->GetSpecialAbility(SPECATK_BANE)
&& (!weapon || (weapon->BaneDmgBody != GetBodyType() && weapon->BaneDmgRace != GetRace()))
)
return true;
}
}
return false;
}
//note: throughout this method, setting `damage` to a negative is a way to
//stop the attack calculations
bool Client::Attack(Mob* other, int hand, int damagePct)
{
if (!other) {
SetTarget(nullptr);
Log(Logs::General, Logs::Error, "A null Mob object was passed to Client::Attack() for evaluation!");
return false;
}
if (hand != EQ::invslot::slotSecondary)
hand = EQ::invslot::slotPrimary;
Log(Logs::Detail, Logs::Combat, "Attacking %s with hand %d", other?other->GetName():"(nullptr)", hand);
//SetAttackTimer();
if (
(IsCasting() && GetClass() != BARD)
|| other == nullptr
|| ((IsClient() && CastToClient()->dead) || (other->IsClient() && other->CastToClient()->dead))
|| (GetHP() < 0)
|| (!IsAttackAllowed(other))
) {
Log(Logs::Detail, Logs::Combat, "Attack canceled, invalid circumstances.");
return false; // Only bards can attack while casting
}
if(DivineAura() && !GetGM()) {//cant attack while invulnerable unless your a gm
Log(Logs::Detail, Logs::Combat, "Attack canceled, Divine Aura is in effect.");
Message_StringID(Chat::DefaultText, DIVINE_AURA_NO_ATK); //You can't attack while invulnerable!
return false;
}
if (IsFeigned() || other->HasDied())
return false;
if (!GetTarget())
SetTarget(other);
EQ::ItemInstance* weapon = GetInv().GetItem(hand);
if(weapon != nullptr) {
if (!weapon->IsWeapon()) {
Log(Logs::Detail, Logs::Combat, "Attack canceled, Item %s (%d) is not a weapon.", weapon->GetItem()->Name, weapon->GetID());
return(false);
}
Log(Logs::Detail, Logs::Combat, "Attacking with weapon: %s (%d)", weapon->GetItem()->Name, weapon->GetID());
} else {
Log(Logs::Detail, Logs::Combat, "Attacking without a weapon.");
}
// calculate attack_skill and skillinuse depending on hand and weapon
// also send Packet to near clients
EQ::skills::SkillType skillinuse;
AttackAnimation(skillinuse, hand, weapon);
Log(Logs::Detail, Logs::Combat, "Attacking with %s in slot %d using skill %d", weapon?weapon->GetItem()->Name:"Fist", hand, skillinuse);
AddWeaponAttackFatigue(weapon);
// Now figure out damage
int damage = 1;
uint8 mylevel = GetLevel();
int baseDamage = GetBaseDamage(other, hand);
// anti-twink damage caps. Taken from decompiles
if (mylevel < 10)
{
switch (GetClass())
{
case DRUID:
case CLERIC:
case SHAMAN:
if (baseDamage > 9)
baseDamage = 9;
break;
case WIZARD:
case MAGICIAN:
case NECROMANCER:
case ENCHANTER:
if (baseDamage > 6)
baseDamage = 6;
break;
default:
if (baseDamage > 10)
baseDamage = 10;
}
}
else if (mylevel < 20)
{
switch (GetClass())
{
case DRUID:
case CLERIC:
case SHAMAN:
if (baseDamage > 12)
baseDamage = 12;
break;
case WIZARD:
case MAGICIAN:
case NECROMANCER:
case ENCHANTER:
if (baseDamage > 10)
baseDamage = 10;
break;
default:
if (baseDamage > 14)
baseDamage = 14;
}
}
else if (mylevel < 30)
{
switch (GetClass())
{
case DRUID:
case CLERIC:
case SHAMAN:
if (baseDamage > 20)
baseDamage = 20;
break;
case WIZARD:
case MAGICIAN:
case NECROMANCER:
case ENCHANTER:
if (baseDamage > 12)
baseDamage = 12;
break;
default:
if (baseDamage > 30)
baseDamage = 30;
}
}
else if (mylevel < 40)
{
switch (GetClass())
{
case DRUID:
case CLERIC:
case SHAMAN:
if (baseDamage > 26)
baseDamage = 26;
break;
case WIZARD:
case MAGICIAN:
case NECROMANCER:
case ENCHANTER:
if (baseDamage > 18)
baseDamage = 18;
break;
default:
if (baseDamage > 60)
baseDamage = 60;
}
}
/*
// these are in the decompile but so unrealistic, commenting them out for cycles
// also caps GM weapons
else
{
switch (GetClass())
{
case DRUID:
case CLERIC:
case SHAMAN:
if (baseDamage > 80)
baseDamage = 80;
break;
case WIZARD:
case MAGICIAN:
case NECROMANCER:
case ENCHANTER:
if (baseDamage > 40)
baseDamage = 40;
break;
default:
if (baseDamage > 200)
baseDamage = 200;
}
}*/
int damageBonus = 0;
if (hand == EQ::invslot::slotPrimary)
damageBonus = GetDamageBonus();
int hate = baseDamage + damageBonus;
if (other->IsImmuneToMelee(this, hand))
{
damage = DMG_INVUL;
}
else
{
// check avoidance skills
other->AvoidDamage(this, damage);
if (damage < 0 && (damage == DMG_DODGE || damage == DMG_PARRY || damage == DMG_RIPOSTE || damage == DMG_BLOCK)
&& aabonuses.StrikeThrough && zone->random.Roll(aabonuses.StrikeThrough))
{
damage = 1; // Warrior Tactical Mastery AA
}
//riposte
if (damage == DMG_RIPOSTE)
{
DoRiposte(other);
if (IsDead()) return false;
}
if (damage > 0)
{
// swing not avoided by skills; do avoidance AC check
if (!other->AvoidanceCheck(this, skillinuse))
{
Log(Logs::Detail, Logs::Combat, "Attack missed. Damage set to 0.");
damage = DMG_MISS;
}
}
if (damage > 0)