From 57658d821dca6c59dba94b3e04b36e31606dc49a Mon Sep 17 00:00:00 2001 From: Axel Cocat Date: Tue, 12 Oct 2021 12:23:52 +0200 Subject: [PATCH] fix(Core/Unit): perform melee attack when unit has not enough power for melee spell (#7996) --- src/server/game/Entities/Unit/Unit.cpp | 29 ++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 0dc75108c..f0bd0ba2f 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -2269,10 +2269,35 @@ void Unit::AttackerStateUpdate(Unit* victim, WeaponAttackType attType, bool extr if (attType != BASE_ATTACK && attType != OFF_ATTACK) return; // ignore ranged case + bool meleeAttack = true; + // melee attack spell casted at main hand attack only - no normal melee dmg dealt if (attType == BASE_ATTACK && m_currentSpells[CURRENT_MELEE_SPELL] && !extra) - m_currentSpells[CURRENT_MELEE_SPELL]->cast(); - else + { + meleeAttack = false; // The melee attack is replaced by the melee spell + + Spell* meleeSpell = m_currentSpells[CURRENT_MELEE_SPELL]; + SpellCastResult castResult = meleeSpell->CheckCast(false); + if (castResult != SPELL_CAST_OK) + { + meleeSpell->SendCastResult(castResult); + meleeSpell->SendInterrupted(0); + + meleeSpell->finish(false); + meleeSpell->SetExecutedCurrently(false); + + if (castResult == SPELL_FAILED_NO_POWER) + { + // Not enough rage, do a regular melee attack instead + meleeAttack = true; + } + } + else + { + meleeSpell->cast(true); + } + } + if (meleeAttack) { // attack can be redirected to another target victim = GetMeleeHitRedirectTarget(victim);