diff options
author | Meji <alvaro.megias@outlook.com> | 2023-03-24 12:27:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-24 12:27:01 +0100 |
commit | cc57c9dad59a2eded2f7ea0471aa79c89b390559 (patch) | |
tree | 5eb6012786882808dab11f90ca93a5c619afa67c | |
parent | d6d5d94ebe88e71b6250678f114d900871fcf054 (diff) |
Core/Creatures: Improved movement interruption while casting spells (#28845)
-rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 17 | ||||
-rw-r--r-- | src/server/game/Entities/Unit/Unit.cpp | 3 | ||||
-rw-r--r-- | src/server/game/Spells/Spell.cpp | 6 |
3 files changed, 11 insertions, 15 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 6abc6af2c69..67bdf7a915e 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -3407,21 +3407,10 @@ void Creature::DoNotReacquireSpellFocusTarget() bool Creature::IsMovementPreventedByCasting() const { - // first check if currently a movement allowed channel is active and we're not casting - if (Spell* spell = m_currentSpells[CURRENT_CHANNELED_SPELL]) - { - if (spell->getState() != SPELL_STATE_FINISHED && spell->IsChannelActive()) - if (spell->CheckMovement() != SPELL_CAST_OK) - return true; - } - - if (HasSpellFocus()) - return true; - - if (HasUnitState(UNIT_STATE_CASTING)) - return true; + if (!Unit::IsMovementPreventedByCasting() && !HasSpellFocus()) + return false; - return false; + return true; } void Creature::StartPickPocketRefillTimer() diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 63839501aaa..51db897043a 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -3029,7 +3029,8 @@ bool Unit::IsMovementPreventedByCasting() const return false; if (Spell* spell = m_currentSpells[CURRENT_GENERIC_SPELL]) - if (CanCastSpellWhileMoving(spell->GetSpellInfo())) + if (CanCastSpellWhileMoving(spell->GetSpellInfo()) || spell->getState() == SPELL_STATE_FINISHED || + !spell->m_spellInfo->InterruptFlags.HasFlag(SpellInterruptFlags::Movement)) return false; // channeled spells during channel stage (after the initial cast timer) allow movement with a specific spell attribute diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 3fd216df5ae..6d6e5e7e44f 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -6875,6 +6875,12 @@ SpellCastResult Spell::CheckMovement() const if (IsTriggered()) return SPELL_CAST_OK; + // Creatures (not controlled) give priority to spell casting over movement. + // We assume that the casting is always valid and the current movement + // is stopped by Unit:IsmovementPreventedByCasting to prevent casting interruption. + if (m_caster->IsCreature() && !m_caster->ToCreature()->IsControlledByPlayer()) + return SPELL_CAST_OK; + if (Unit* unitCaster = m_caster->ToUnit()) { if (!unitCaster->CanCastSpellWhileMoving(m_spellInfo)) |