Skip to content

Commit

Permalink
Core/Movement: Pet follow movement code improvements. (jasongdove#43)
Browse files Browse the repository at this point in the history
* added some missing methods from TrinityCore

Co-authored-by: 3nei <[email protected]>
  • Loading branch information
3nei and 3nei authored Oct 4, 2024
1 parent 3e7443c commit 1feeb35
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 27 deletions.
16 changes: 16 additions & 0 deletions src/server/game/Entities/Unit/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4283,6 +4283,22 @@ int32 Unit::GetCurrentSpellCastTime(uint32 spell_id) const
return 0;
}

bool Unit::IsMovementPreventedByCasting() const
{
// can always move when not casting
if (!HasUnitState(UNIT_STATE_CASTING))
return false;

// channeled spells during channel stage (after the initial cast timer) allow movement with a specific spell attribute
if (Spell* spell = m_currentSpells[CURRENT_CHANNELED_SPELL])
if (spell->getState() != SPELL_STATE_FINISHED && spell->IsChannelActive())
if (spell->GetSpellInfo()->IsMoveAllowedChannel())
return false;

// prohibit movement for all other spell casts
return true;
}

bool Unit::isInFrontInMap(Unit const* target, float distance, float arc) const
{
return IsWithinDistInMap(target, distance) && HasInArc(arc, target);
Expand Down
2 changes: 2 additions & 0 deletions src/server/game/Entities/Unit/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1551,6 +1551,7 @@ class Unit : public WorldObject

bool IsLevitating() const { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_DISABLE_GRAVITY);}
bool IsWalking() const { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_WALKING);}
bool IsHovering() const { return m_movementInfo.HasMovementFlag(MOVEMENTFLAG_HOVER);}
bool SetWalk(bool enable);
bool SetDisableGravity(bool disable, bool isPlayer = false);
bool SetFall(bool enable, bool isPlayer = false);
Expand Down Expand Up @@ -1894,6 +1895,7 @@ class Unit : public WorldObject
Spell* GetCurrentSpell(uint32 spellType) const { return m_currentSpells[spellType]; }
Spell* FindCurrentSpellBySpellId(uint32 spell_id) const;
int32 GetCurrentSpellCastTime(uint32 spell_id) const;
bool IsMovementPreventedByCasting() const;
SpellInfo const* GetCastSpellInfo(SpellInfo const* spellInfo) const;
void SendSpellCreateVisual(SpellInfo const* spellInfo, Position const* position = nullptr, Unit* target = nullptr, uint32 type = 0, uint32 visualId = 0);
void CancelSpellVisualKit(int32 spellVisualKitID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,30 +569,6 @@ static Position const PredictPosition(Unit* target)
return pos;
}

bool IsMovementPreventedByCasting(Creature* owner)
{
Spell* spell = owner->GetCurrentSpell(CURRENT_CHANNELED_SPELL);
// first check if currently a movement allowed channel is active and we're not casting
if (spell && spell->getState() != SPELL_STATE_FINISHED && spell->IsChannelActive() &&
(spell->GetSpellInfo() && spell->GetSpellInfo()->IsChanneled() && spell->GetSpellInfo()->HasAttribute(SPELL_ATTR5_USABLE_WHILE_MOVING))
)
{
return false;
}

/*if (owner->HasSpellFocus())
{
return true;
}*/

if (owner->HasUnitState(UNIT_STATE_CASTING))
{
return true;
}

return false;
}

template<class T>
bool FollowMovementGenerator<T>::DoUpdate(T& owner, uint32 time_diff)
{
Expand All @@ -606,7 +582,7 @@ bool FollowMovementGenerator<T>::DoUpdate(T& owner, uint32 time_diff)
Unit* target = this->i_target.getTarget();

// the owner might be unable to move (rooted or casting), or we have lost the target, pause movement
if (owner.HasUnitState(UNIT_STATE_NOT_MOVE) || (cOwner && IsMovementPreventedByCasting(owner.ToCreature())))
if (owner.HasUnitState(UNIT_STATE_NOT_MOVE) || (cOwner && owner.IsMovementPreventedByCasting()))
{
i_path = nullptr;
owner.StopMoving();
Expand Down Expand Up @@ -676,8 +652,7 @@ bool FollowMovementGenerator<T>::DoUpdate(T& owner, uint32 time_diff)
float x, y, z;
targetPosition.GetPosition(x, y, z);

//if (owner->IsHovering())
if (owner.m_movementInfo.HasMovementFlag(MOVEMENTFLAG_HOVER)) // alt: owner.isHover()
if (owner.IsHovering())
owner.UpdateAllowedPositionZ(x, y, z);

bool success = i_path->CalculatePath(x, y, z, forceDest);
Expand Down
5 changes: 5 additions & 0 deletions src/server/game/Spells/SpellInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1854,6 +1854,11 @@ bool SpellInfo::IsChanneled() const
return (GetMisc()->MiscData.Attributes[1] & (SPELL_ATTR1_CHANNELED_1 | SPELL_ATTR1_CHANNELED_2)) != 0;
}

bool SpellInfo::IsMoveAllowedChannel() const
{
return IsChanneled() && HasAttribute(SPELL_ATTR5_USABLE_WHILE_MOVING);
}

bool SpellInfo::IsBreakingStealth() const
{
return !HasAttribute(SPELL_ATTR1_NOT_BREAK_STEALTH);
Expand Down
1 change: 1 addition & 0 deletions src/server/game/Spells/SpellInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,7 @@ class SpellInfo
bool IsPositive() const;
bool IsPositiveEffect(uint8 effIndex, bool caster = false) const;
bool IsChanneled() const;
bool IsMoveAllowedChannel() const;
bool IsBreakingStealth() const;
bool IsRangedWeaponSpell() const;
bool IsRangedSpell() const;
Expand Down

0 comments on commit 1feeb35

Please sign in to comment.