mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-25 19:31:59 +01:00
Core/PetAI: apply some movement related corrections
Unit::StopMoving() is evil, and so is MotionMaster::Clear()
the first can really mess up existing movement generators
the second can interrupt "controlled" movements... can do it literally mid-air
(cherry picked from commit 74678b247e)
This commit is contained in:
@@ -447,7 +447,10 @@ void PetAI::HandleReturnMovement()
|
||||
me->GetCharmInfo()->GetStayPosition(x, y, z);
|
||||
ClearCharmInfoFlags();
|
||||
me->GetCharmInfo()->SetIsReturning(true);
|
||||
me->GetMotionMaster()->Clear();
|
||||
|
||||
if (me->HasUnitState(UNIT_STATE_CHASE))
|
||||
me->GetMotionMaster()->Remove(CHASE_MOTION_TYPE);
|
||||
|
||||
me->GetMotionMaster()->MovePoint(me->GetGUID().GetCounter(), x, y, z);
|
||||
}
|
||||
}
|
||||
@@ -457,7 +460,10 @@ void PetAI::HandleReturnMovement()
|
||||
{
|
||||
ClearCharmInfoFlags();
|
||||
me->GetCharmInfo()->SetIsReturning(true);
|
||||
me->GetMotionMaster()->Clear();
|
||||
|
||||
if (me->HasUnitState(UNIT_STATE_CHASE))
|
||||
me->GetMotionMaster()->Remove(CHASE_MOTION_TYPE);
|
||||
|
||||
me->GetMotionMaster()->MoveFollow(me->GetCharmerOrOwner(), PET_FOLLOW_DIST, me->GetFollowAngle());
|
||||
}
|
||||
}
|
||||
@@ -481,29 +487,35 @@ void PetAI::DoAttack(Unit* target, bool chase)
|
||||
bool oldCmdAttack = me->GetCharmInfo()->IsCommandAttack(); // This needs to be reset after other flags are cleared
|
||||
ClearCharmInfoFlags();
|
||||
me->GetCharmInfo()->SetIsCommandAttack(oldCmdAttack); // For passive pets commanded to attack so they will use spells
|
||||
me->GetMotionMaster()->Clear();
|
||||
me->GetMotionMaster()->MoveChase(target, me->GetPetChaseDistance(), (float)M_PI);
|
||||
|
||||
if (me->HasUnitState(UNIT_STATE_FOLLOW))
|
||||
me->GetMotionMaster()->Remove(FOLLOW_MOTION_TYPE);
|
||||
|
||||
me->GetMotionMaster()->MoveChase(target, me->GetPetChaseDistance(), float(M_PI));
|
||||
}
|
||||
else // (Stay && ((Aggressive || Defensive) && In Melee Range)))
|
||||
{
|
||||
ClearCharmInfoFlags();
|
||||
me->GetCharmInfo()->SetIsAtStay(true);
|
||||
me->GetMotionMaster()->Clear();
|
||||
|
||||
if (me->HasUnitState(UNIT_STATE_FOLLOW))
|
||||
me->GetMotionMaster()->Remove(FOLLOW_MOTION_TYPE);
|
||||
|
||||
me->GetMotionMaster()->MoveIdle();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PetAI::MovementInform(uint32 moveType, uint32 data)
|
||||
void PetAI::MovementInform(uint32 type, uint32 id)
|
||||
{
|
||||
// Receives notification when pet reaches stay or follow owner
|
||||
switch (moveType)
|
||||
switch (type)
|
||||
{
|
||||
case POINT_MOTION_TYPE:
|
||||
{
|
||||
// Pet is returning to where stay was clicked. data should be
|
||||
// pet's GUIDLow since we set that as the waypoint ID
|
||||
if (data == me->GetGUID().GetCounter() && me->GetCharmInfo()->IsReturning())
|
||||
if (id == me->GetGUID().GetCounter() && me->GetCharmInfo()->IsReturning())
|
||||
{
|
||||
ClearCharmInfoFlags();
|
||||
me->GetCharmInfo()->SetIsAtStay(true);
|
||||
@@ -516,7 +528,7 @@ void PetAI::MovementInform(uint32 moveType, uint32 data)
|
||||
{
|
||||
// If data is owner's GUIDLow then we've reached follow point,
|
||||
// otherwise we're probably chasing a creature
|
||||
if (me->GetCharmerOrOwner() && me->GetCharmInfo() && data == me->GetCharmerOrOwner()->GetGUID().GetCounter() && me->GetCharmInfo()->IsReturning())
|
||||
if (me->GetCharmerOrOwner() && me->GetCharmInfo() && id == me->GetCharmerOrOwner()->GetGUID().GetCounter() && me->GetCharmInfo()->IsReturning())
|
||||
{
|
||||
ClearCharmInfoFlags();
|
||||
me->GetCharmInfo()->SetIsFollowing(true);
|
||||
|
||||
@@ -39,7 +39,7 @@ class TC_GAME_API PetAI : public CreatureAI
|
||||
void AttackStart(Unit* target) override;
|
||||
// always start attacking if possible
|
||||
void _AttackStart(Unit* target);
|
||||
void MovementInform(uint32 moveType, uint32 data) override;
|
||||
void MovementInform(uint32 type, uint32 id) override;
|
||||
void OwnerAttackedBy(Unit* attacker) override;
|
||||
void OwnerAttacked(Unit* target) override;
|
||||
void DamageTaken(Unit* attacker, uint32& /*damage*/) override { AttackStart(attacker); }
|
||||
@@ -67,4 +67,5 @@ class TC_GAME_API PetAI : public CreatureAI
|
||||
GuidSet _allySet;
|
||||
uint32 _updateAlliesTimer;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user