Core/Movement: Fix issues where creatures cancel spell casts chasing target and Implement SPELL_ATTR5_CAN_CHANNEL_WHEN_MOVING
(cherry picked from commit bf2cee8cce39e64590dc68bc35e5d3d2dd19cbaf)
This commit is contained in:
@@ -2983,6 +2983,15 @@ int32 Unit::GetCurrentSpellCastTime(uint32 spell_id) const
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Unit::CanMoveDuringChannel() const
|
||||
{
|
||||
if (Spell* spell = m_currentSpells[CURRENT_CHANNELED_SPELL])
|
||||
if (spell->getState() != SPELL_STATE_FINISHED)
|
||||
return spell->GetSpellInfo()->HasAttribute(SPELL_ATTR5_CAN_CHANNEL_WHEN_MOVING) && spell->IsChannelActive();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Unit::isInFrontInMap(Unit const* target, float distance, float arc) const
|
||||
{
|
||||
return IsWithinDistInMap(target, distance) && HasInArc(arc, target);
|
||||
|
||||
@@ -1957,6 +1957,9 @@ class TC_GAME_API Unit : public WorldObject
|
||||
virtual SpellInfo const* GetCastSpellInfo(SpellInfo const* spellInfo) const;
|
||||
uint32 GetCastSpellXSpellVisualId(SpellInfo const* spellInfo) const;
|
||||
|
||||
// Check if our current channel spell has attribute SPELL_ATTR5_CAN_CHANNEL_WHEN_MOVING
|
||||
bool CanMoveDuringChannel() const;
|
||||
|
||||
SpellHistory* GetSpellHistory() { return _spellHistory; }
|
||||
SpellHistory const* GetSpellHistory() const { return _spellHistory; }
|
||||
|
||||
|
||||
@@ -540,7 +540,7 @@ enum SpellAttr4
|
||||
|
||||
enum SpellAttr5
|
||||
{
|
||||
SPELL_ATTR5_UNK0 = 0x00000001, // 0
|
||||
SPELL_ATTR5_CAN_CHANNEL_WHEN_MOVING = 0x00000001, // 0 available casting channel spell when moving
|
||||
SPELL_ATTR5_NO_REAGENT_WHILE_PREP = 0x00000002, // 1 not need reagents if UNIT_FLAG_PREPARATION
|
||||
SPELL_ATTR5_UNK2 = 0x00000004, // 2
|
||||
SPELL_ATTR5_USABLE_WHILE_STUNNED = 0x00000008, // 3 usable while stunned
|
||||
|
||||
@@ -36,6 +36,9 @@ void TargetedMovementGeneratorMedium<T, D>::_setTargetLocation(T* owner, bool up
|
||||
if (owner->HasUnitState(UNIT_STATE_NOT_MOVE))
|
||||
return;
|
||||
|
||||
if (owner->HasUnitState(UNIT_STATE_CASTING) && !owner->CanMoveDuringChannel())
|
||||
return;
|
||||
|
||||
if (owner->GetTypeId() == TYPEID_UNIT && !i_target->isInAccessiblePlaceFor(owner->ToCreature()))
|
||||
{
|
||||
owner->ToCreature()->SetCannotReachTarget(true);
|
||||
@@ -146,7 +149,7 @@ bool TargetedMovementGeneratorMedium<T, D>::DoUpdate(T* owner, uint32 time_diff)
|
||||
}
|
||||
|
||||
// prevent movement while casting spells with cast time or channel time
|
||||
if (owner->HasUnitState(UNIT_STATE_CASTING))
|
||||
if (owner->HasUnitState(UNIT_STATE_CASTING) && !owner->CanMoveDuringChannel())
|
||||
{
|
||||
if (!owner->IsStopped())
|
||||
owner->StopMoving();
|
||||
|
||||
@@ -3036,14 +3036,19 @@ void Spell::prepare(SpellCastTargets const* targets, AuraEffect const* triggered
|
||||
}
|
||||
|
||||
// don't allow channeled spells / spells with cast time to be cast while moving
|
||||
// exception are only channeled spells that have no casttime and SPELL_ATTR5_CAN_CHANNEL_WHEN_MOVING
|
||||
// (even if they are interrupted on moving, spells with almost immediate effect get to have their effect processed before movement interrupter kicks in)
|
||||
// don't cancel spells which are affected by a SPELL_AURA_CAST_WHILE_WALKING effect
|
||||
if (((m_spellInfo->IsChanneled() || m_casttime) && m_caster->GetTypeId() == TYPEID_PLAYER && m_caster->isMoving() &&
|
||||
m_spellInfo->InterruptFlags & SPELL_INTERRUPT_FLAG_MOVEMENT) && !m_caster->HasAuraTypeWithAffectMask(SPELL_AURA_CAST_WHILE_WALKING, m_spellInfo))
|
||||
{
|
||||
SendCastResult(SPELL_FAILED_MOVING);
|
||||
finish(false);
|
||||
return;
|
||||
// 1. Is a channel spell, 2. Has no casttime, 3. And has flag to allow movement during channel
|
||||
if (!(m_spellInfo->IsChanneled() && !m_casttime && m_spellInfo->HasAttribute(SPELL_ATTR5_CAN_CHANNEL_WHEN_MOVING)))
|
||||
{
|
||||
SendCastResult(SPELL_FAILED_MOVING);
|
||||
finish(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// set timer base at cast time
|
||||
@@ -3589,7 +3594,7 @@ void Spell::update(uint32 difftime)
|
||||
!m_caster->HasAuraTypeWithAffectMask(SPELL_AURA_CAST_WHILE_WALKING, m_spellInfo))
|
||||
{
|
||||
// don't cancel for melee, autorepeat, triggered and instant spells
|
||||
if (!IsNextMeleeSwingSpell() && !IsAutoRepeat() && !IsTriggered())
|
||||
if (!IsNextMeleeSwingSpell() && !IsAutoRepeat() && !IsTriggered() && !(IsChannelActive() && m_spellInfo->HasAttribute(SPELL_ATTR5_CAN_CHANNEL_WHEN_MOVING)))
|
||||
cancel();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user