diff options
author | Giacomo Pozzoni <giacomopoz@gmail.com> | 2020-08-09 19:24:15 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-09 21:24:15 +0200 |
commit | 63a6e1e0480df659e773a3df5e1acc2027ebcf15 (patch) | |
tree | 71ac0ef5a21c60f5815f68f249caf352c30ec17e /src | |
parent | dd28cecda36ed3912be39d0c3caefef910db707d (diff) |
Core/SAI: Fix creatures casting with flag SMARTCAST_COMBAT_MOVE not switching to melee when the school of the spell they are trying to cast gets silenced (and other cases of spell failure) (#25226)
* Core/SAI: Fix creatures casting with flag SMARTCAST_COMBAT_MOVE not switching to melee when the school of the spell they are trying to cast gets silenced (and other cases of spell failure)
* Core/SAI: Retry casting after 500ms if a cast failed
Fixes #24914
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/AI/SmartScripts/SmartScript.cpp | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/server/game/AI/SmartScripts/SmartScript.cpp b/src/server/game/AI/SmartScripts/SmartScript.cpp index dac03891e43..feb0cbd978e 100644 --- a/src/server/game/AI/SmartScripts/SmartScript.cpp +++ b/src/server/game/AI/SmartScripts/SmartScript.cpp @@ -552,23 +552,17 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u if (e.action.cast.castFlags & SMARTCAST_INTERRUPT_PREVIOUS) me->InterruptNonMeleeSpells(false); + SpellCastResult result = me->CastSpell(target->ToUnit(), e.action.cast.spell, triggerFlag); + bool spellCastFailed = (result != SPELL_CAST_OK && result != SPELL_FAILED_SPELL_IN_PROGRESS); + if (e.action.cast.castFlags & SMARTCAST_COMBAT_MOVE) { // If cast flag SMARTCAST_COMBAT_MOVE is set combat movement will not be allowed unless target is outside spell range, out of mana, or LOS. - bool allowMove = false; - SpellInfo const* spellInfo = sSpellMgr->AssertSpellInfo(e.action.cast.spell); - int32 mana = me->GetPower(POWER_MANA); - - if (me->GetDistance(target) > spellInfo->GetMaxRange(true) || me->GetDistance(target) < spellInfo->GetMinRange(true) || - !me->IsWithinLOSInMap(target) || - mana < spellInfo->CalcPowerCost(me, spellInfo->GetSchoolMask()) || - me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED)) - allowMove = true; - - ENSURE_AI(SmartAI, me->AI())->SetCombatMove(allowMove, true); + ENSURE_AI(SmartAI, me->AI())->SetCombatMove(spellCastFailed, true); } - me->CastSpell(target->ToUnit(), e.action.cast.spell, triggerFlag); + if (spellCastFailed) + RecalcTimer(e, 500, 500); } else if (go) go->CastSpell(target->ToUnit(), e.action.cast.spell, triggerFlag); |