From 7c89ab3fec2a4824a489696419645e8fb545b62f Mon Sep 17 00:00:00 2001 From: "Michael Cook (mackal)" Date: Sun, 5 Jul 2015 01:15:46 -0400 Subject: [PATCH] Pull Mob mainhand/offhand attack rounds into their own functions --- zone/attack.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ zone/mob.h | 2 ++ zone/mob_ai.cpp | 56 ++--------------------------------------------- 3 files changed, 62 insertions(+), 54 deletions(-) diff --git a/zone/attack.cpp b/zone/attack.cpp index 86f8b8d65..a702f0efe 100644 --- a/zone/attack.cpp +++ b/zone/attack.cpp @@ -5103,3 +5103,61 @@ bool Client::CheckDualWield() return zone->random.Int(1, 375) <= chance; } + +void Mob::DoMainHandAttackRounds(Mob *target, ExtraAttackOptions *opts) +{ + if (IsNPC()) { + int16 n_atk = CastToNPC()->GetNumberOfAttacks(); + if (n_atk <= 1) { + Attack(target, MainPrimary, false, false, false, opts); + } else { + for (int i = 0; i < n_atk; ++i) { + Attack(target, MainPrimary, false, false, false, opts); + } + } + } else { + Attack(target, MainPrimary, false, false, false, opts); + } + + if (target) { + // we use this random value in three comparisons with different + // thresholds, and if its truely random, then this should work + // out reasonably and will save us compute resources. + int32 RandRoll = zone->random.Int(0, 99); + if ((CanThisClassDoubleAttack() || GetSpecialAbility(SPECATK_TRIPLE) || GetSpecialAbility(SPECATK_QUAD)) + // check double attack, this is NOT the same rules that clients use... + && + RandRoll < (GetLevel() + NPCDualAttackModifier)) { + Attack(target, MainPrimary, false, false, false, opts); + // lets see if we can do a triple attack with the main hand + // pets are excluded from triple and quads... + if ((GetSpecialAbility(SPECATK_TRIPLE) || GetSpecialAbility(SPECATK_QUAD)) && !IsPet() && + RandRoll < (GetLevel() + NPCTripleAttackModifier)) { + Attack(target, MainPrimary, false, false, false, opts); + // now lets check the quad attack + if (GetSpecialAbility(SPECATK_QUAD) && + RandRoll < (GetLevel() + NPCQuadAttackModifier)) { + Attack(target, MainPrimary, false, false, false, opts); + } + } + } + } +} + +void Mob::DoOffHandAttackRounds(Mob *target, ExtraAttackOptions *opts) +{ + if (!target) + return; + // Mobs will only dual wield w/ the flag or have a secondary weapon + if (GetSpecialAbility(SPECATK_INNATE_DW) || GetEquipment(MaterialSecondary) != 0) { + if (CheckDualWield()) { + Attack(target, MainSecondary, false, false, false, opts); + if (CanThisClassDoubleAttack()) { + // This isn't correct yet + if (zone->random.Roll(GetLevel() + 20)) { + Attack(target, MainSecondary, false, false, false, opts); + } + } + } + } +} diff --git a/zone/mob.h b/zone/mob.h index e329128a9..84aa46595 100644 --- a/zone/mob.h +++ b/zone/mob.h @@ -167,6 +167,8 @@ public: void CommonBreakInvisible(); bool HasDied(); virtual bool CheckDualWield(); + void DoMainHandAttackRounds(Mob *target, ExtraAttackOptions *opts = nullptr); + void DoOffHandAttackRounds(Mob *target, ExtraAttackOptions *opts = nullptr); //Appearance void SendLevelAppearance(); diff --git a/zone/mob_ai.cpp b/zone/mob_ai.cpp index f171d72e3..f4a511b7b 100644 --- a/zone/mob_ai.cpp +++ b/zone/mob_ai.cpp @@ -1101,42 +1101,7 @@ void Mob::AI_Process() { //try main hand first if(attack_timer.Check()) { - if(IsNPC()) { - int16 n_atk = CastToNPC()->GetNumberOfAttacks(); - if(n_atk <= 1) { - Attack(target, MainPrimary); - } else { - for(int i = 0; i < n_atk; ++i) { - Attack(target, MainPrimary); - } - } - } else { - Attack(target, MainPrimary); - } - - if (target) { - //we use this random value in three comparisons with different - //thresholds, and if its truely random, then this should work - //out reasonably and will save us compute resources. - int32 RandRoll = zone->random.Int(0, 99); - if ((CanThisClassDoubleAttack() || GetSpecialAbility(SPECATK_TRIPLE) - || GetSpecialAbility(SPECATK_QUAD)) - //check double attack, this is NOT the same rules that clients use... - && RandRoll < (GetLevel() + NPCDualAttackModifier)) { - Attack(target, MainPrimary); - // lets see if we can do a triple attack with the main hand - //pets are excluded from triple and quads... - if ((GetSpecialAbility(SPECATK_TRIPLE) || GetSpecialAbility(SPECATK_QUAD)) - && !IsPet() && RandRoll < (GetLevel() + NPCTripleAttackModifier)) { - Attack(target, MainPrimary); - // now lets check the quad attack - if (GetSpecialAbility(SPECATK_QUAD) - && RandRoll < (GetLevel() + NPCQuadAttackModifier)) { - Attack(target, MainPrimary); - } - } - } - } + DoMainHandAttackRounds(target); if (GetSpecialAbility(SPECATK_FLURRY)) { int flurry_chance = GetSpecialAbilityParam(SPECATK_FLURRY, 0); @@ -1271,24 +1236,7 @@ void Mob::AI_Process() { //now off hand if (attack_dw_timer.Check() && CanThisClassDualWield()) - { - int myclass = GetClass(); - //can only dual wield without a weapon if your a monk - if(GetSpecialAbility(SPECATK_INNATE_DW) || (GetEquipment(MaterialSecondary) != 0 && GetLevel() > 29) || myclass == MONK || myclass == MONKGM) { - float DualWieldProbability = (GetSkill(SkillDualWield) + GetLevel()) / 400.0f; - if(zone->random.Roll(DualWieldProbability)) - { - Attack(target, MainSecondary); - if (CanThisClassDoubleAttack()) - { - if (zone->random.Roll(GetLevel() + 20)) - { - Attack(target, MainSecondary); - } - } - } - } - } + DoOffHandAttackRounds(target); //now special attacks (kick, etc) if(IsNPC())