From 2f4f15df5afbbcd4f0386b88b7d2a557c7c0aed6 Mon Sep 17 00:00:00 2001 From: ratkosrb Date: Sun, 26 Nov 2023 18:50:33 +0200 Subject: [PATCH] Use virtual function for the hit chance. --- src/game/Objects/Creature.h | 1 + src/game/Objects/Player.h | 1 + src/game/Objects/Unit.cpp | 33 -------------------------- src/game/Objects/Unit.h | 2 +- src/game/StatSystem.cpp | 46 +++++++++++++++++++++++++++++++++++++ 5 files changed, 49 insertions(+), 34 deletions(-) diff --git a/src/game/Objects/Creature.h b/src/game/Objects/Creature.h index 5511327fa..cb5f4bea6 100644 --- a/src/game/Objects/Creature.h +++ b/src/game/Objects/Creature.h @@ -548,6 +548,7 @@ class Creature : public Unit } bool HasWeapon() const; + float GetBonusHitChanceFromAuras(WeaponAttackType attType) const final; void SetCallForHelpDist(float dist) { diff --git a/src/game/Objects/Player.h b/src/game/Objects/Player.h index 27eb9ddee..8817b7837 100644 --- a/src/game/Objects/Player.h +++ b/src/game/Objects/Player.h @@ -1678,6 +1678,7 @@ class Player final: public Unit void UpdateAllSpellCritChances(); void UpdateSpellCritChance(uint32 school); void CalculateMinMaxDamage(WeaponAttackType attType, bool normalized, float& min_damage, float& max_damage, uint8 index = 0) const; + float GetBonusHitChanceFromAuras(WeaponAttackType attType) const final; uint32 GetShieldBlockValue() const override; // overwrite Unit version (virtual) bool CanParry() const { return m_canParry; } diff --git a/src/game/Objects/Unit.cpp b/src/game/Objects/Unit.cpp index 0319a0e90..5605cce7a 100644 --- a/src/game/Objects/Unit.cpp +++ b/src/game/Objects/Unit.cpp @@ -2543,39 +2543,6 @@ bool Unit::IsEffectResist(SpellEntry const* spell, int eff) const return false; } -float Unit::GetBonusHitChanceFromAuras(WeaponAttackType attType) const -{ - float chance = 0.0f; - AuraList const& mTotalAuraList = GetAurasByType(SPELL_AURA_MOD_HIT_CHANCE); - for (auto const& i : mTotalAuraList) - { - SpellEntry const* pSpellEntry = i->GetSpellProto(); - if (pSpellEntry->EquippedItemClass >= 0) - { - if (Player const* pPlayer = ToPlayer()) - { - Item* pWeapon = pPlayer->GetWeaponForAttack(attType); - if (!pWeapon) - continue; - - if (!pWeapon->IsFitToSpellRequirements(pSpellEntry)) - continue; - } - else if (Creature const* pCreature = ToCreature()) - { - if (!pCreature->GetVirtualItemDisplayId(attType)) - continue; - - if (!Item::IsFitToSpellRequirements(pSpellEntry, pCreature->GetVirtualItemClass(attType), pCreature->GetVirtualItemSubclass(attType), pCreature->GetVirtualItemInventoryType(attType))) - continue; - } - } - - chance += i->GetModifier()->m_amount; - } - return chance; -} - float Unit::MeleeMissChanceCalc(Unit const* pVictim, WeaponAttackType attType) const { if (!pVictim || !pVictim->IsStandingUp()) diff --git a/src/game/Objects/Unit.h b/src/game/Objects/Unit.h index 1b983ceef..d0cc3f2a7 100644 --- a/src/game/Objects/Unit.h +++ b/src/game/Objects/Unit.h @@ -998,7 +998,7 @@ class Unit : public SpellCaster ObjectGuid const& GetReactiveTarget(ReactiveType reactive) const { return m_reactiveTarget[reactive]; } void UpdateReactives(uint32 p_time); - float GetBonusHitChanceFromAuras(WeaponAttackType attType) const; + virtual float GetBonusHitChanceFromAuras(WeaponAttackType attType) const = 0; float MeleeMissChanceCalc(Unit const* pVictim, WeaponAttackType attType) const; void CalculateMeleeDamage(Unit* pVictim, uint32 damage, CalcDamageInfo* damageInfo, WeaponAttackType attackType = BASE_ATTACK); void UnitDamaged(ObjectGuid from, uint32 damage) { m_damageTakenHistory[from] += damage; m_lastDamageTaken = 0; } diff --git a/src/game/StatSystem.cpp b/src/game/StatSystem.cpp index 8478714d6..d69ac2660 100644 --- a/src/game/StatSystem.cpp +++ b/src/game/StatSystem.cpp @@ -469,6 +469,31 @@ void Player::UpdateDamagePhysical(WeaponAttackType attType) } } +float Player::GetBonusHitChanceFromAuras(WeaponAttackType attType) const +{ + float chance = 0.0f; + AuraList const& hitAurasList = GetAurasByType(SPELL_AURA_MOD_HIT_CHANCE); + if (hitAurasList.empty()) + return chance; + + Item* pWeapon = GetWeaponForAttack(attType); + for (auto const& i : hitAurasList) + { + SpellEntry const* pSpellEntry = i->GetSpellProto(); + if (pSpellEntry->EquippedItemClass >= 0) + { + if (!pWeapon) + continue; + + if (!pWeapon->IsFitToSpellRequirements(pSpellEntry)) + continue; + } + + chance += i->GetModifier()->m_amount; + } + return chance; +} + void Player::UpdateDefenseBonusesMod() { UpdateBlockPercentage(); @@ -936,6 +961,27 @@ void Creature::UpdateDamagePhysical(WeaponAttackType attType) SetStatFloatValue(fieldmax, maxdamage); } +float Creature::GetBonusHitChanceFromAuras(WeaponAttackType attType) const +{ + float chance = 0.0f; + AuraList const& mTotalAuraList = GetAurasByType(SPELL_AURA_MOD_HIT_CHANCE); + for (auto const& i : mTotalAuraList) + { + SpellEntry const* pSpellEntry = i->GetSpellProto(); + if (pSpellEntry->EquippedItemClass >= 0) + { + if (!GetVirtualItemDisplayId(attType)) + continue; + + if (!Item::IsFitToSpellRequirements(pSpellEntry, GetVirtualItemClass(attType), GetVirtualItemSubclass(attType), GetVirtualItemInventoryType(attType))) + continue; + } + + chance += i->GetModifier()->m_amount; + } + return chance; +} + /*####################################### ######## ######## ######## PETS STAT SYSTEM ########