From 517473cc3ee000c75154a70f919b0037ee10527a Mon Sep 17 00:00:00 2001 From: killerwife Date: Sun, 26 Nov 2023 17:19:48 +0100 Subject: [PATCH] Aura: Adjust masked SPELL_AURA_MOD_HIT_CHANCE applying to wrong weapon types Only designation exists to melee vs ranged so not adding redundant main hand vs offhand granularity --- src/game/Entities/Player.cpp | 5 +++++ src/game/Entities/StatSystem.cpp | 30 ++++++++++++++++++++++++++++-- src/game/Spells/SpellAuras.cpp | 6 +++--- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/game/Entities/Player.cpp b/src/game/Entities/Player.cpp index dc28122d5a..5fae00d339 100644 --- a/src/game/Entities/Player.cpp +++ b/src/game/Entities/Player.cpp @@ -10484,9 +10484,14 @@ Item* Player::EquipItem(uint16 pos, Item* pItem, bool update) ApplyEquipCooldown(pItem); if (slot == EQUIPMENT_SLOT_MAINHAND) + { UpdateExpertise(BASE_ATTACK); + UpdateMeleeHitChances(); + } else if (slot == EQUIPMENT_SLOT_OFFHAND) UpdateExpertise(OFF_ATTACK); + else if (slot == EQUIPMENT_SLOT_RANGED) + UpdateRangedHitChances(); } else { diff --git a/src/game/Entities/StatSystem.cpp b/src/game/Entities/StatSystem.cpp index 08a11d5674..1892a33a68 100644 --- a/src/game/Entities/StatSystem.cpp +++ b/src/game/Entities/StatSystem.cpp @@ -572,13 +572,39 @@ void Player::UpdateSpellCritChance(uint32 school) void Player::UpdateMeleeHitChances() { - m_modMeleeHitChance = GetTotalAuraModifier(SPELL_AURA_MOD_HIT_CHANCE); + int32 meleeHitChance = 0; + Item* weapon = GetWeaponForAttack(BASE_ATTACK); + + AuraList const& hitAura = GetAurasByType(SPELL_AURA_MOD_HIT_CHANCE); + for (auto hitAura : hitAura) + { + // item neutral spell + if (hitAura->GetSpellProto()->EquippedItemClass == -1) + meleeHitChance += hitAura->GetModifier()->m_amount; + // item dependent spell + else if (weapon && weapon->IsFitToSpellRequirements(hitAura->GetSpellProto())) + meleeHitChance += hitAura->GetModifier()->m_amount; + } + m_modMeleeHitChance = meleeHitChance; m_modMeleeHitChance += GetRatingBonusValue(CR_HIT_MELEE); } void Player::UpdateRangedHitChances() { - m_modRangedHitChance = GetTotalAuraModifier(SPELL_AURA_MOD_HIT_CHANCE); + int32 rangedHitChance = 0; + Item* weapon = GetWeaponForAttack(RANGED_ATTACK); + + AuraList const& hitAura = GetAurasByType(SPELL_AURA_MOD_HIT_CHANCE); + for (auto hitAura : hitAura) + { + // item neutral spell + if (hitAura->GetSpellProto()->EquippedItemClass == -1) + rangedHitChance += hitAura->GetModifier()->m_amount; + // item dependent spell + else if (weapon && weapon->IsFitToSpellRequirements(hitAura->GetSpellProto())) + rangedHitChance += hitAura->GetModifier()->m_amount; + } + m_modMeleeHitChance = rangedHitChance; m_modRangedHitChance += GetRatingBonusValue(CR_HIT_RANGED); } diff --git a/src/game/Spells/SpellAuras.cpp b/src/game/Spells/SpellAuras.cpp index d67505515b..7e1ba93de5 100755 --- a/src/game/Spells/SpellAuras.cpp +++ b/src/game/Spells/SpellAuras.cpp @@ -5863,10 +5863,10 @@ void Aura::HandleModHitChance(bool apply, bool /*Real*/) { Unit* target = GetTarget(); - if (target->GetTypeId() == TYPEID_PLAYER) + if (target->IsPlayer()) { - ((Player*)target)->UpdateMeleeHitChances(); - ((Player*)target)->UpdateRangedHitChances(); + static_cast(target)->UpdateMeleeHitChances(); + static_cast(target)->UpdateRangedHitChances(); } else {