diff options
| author | ccrs <ccrs@users.noreply.github.com> | 2019-05-16 01:11:13 +0200 | 
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2021-12-05 18:37:57 +0100 | 
| commit | 97dddac75adab46d55d3d698e36c4403a93b4372 (patch) | |
| tree | 23a04706db5d647130b3d37a754ad524f796a22f /src/server | |
| parent | 6814b4d32b283c3a1b676d2f13953894a9f1ff7a (diff) | |
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 74678b247e04728562e78f6a624577964020a7f0)
Diffstat (limited to 'src/server')
| -rw-r--r-- | src/server/game/AI/CoreAI/PetAI.cpp | 30 | ||||
| -rw-r--r-- | src/server/game/AI/CoreAI/PetAI.h | 3 | 
2 files changed, 23 insertions, 10 deletions
| diff --git a/src/server/game/AI/CoreAI/PetAI.cpp b/src/server/game/AI/CoreAI/PetAI.cpp index e92db6063f4..006fad0acf3 100644 --- a/src/server/game/AI/CoreAI/PetAI.cpp +++ b/src/server/game/AI/CoreAI/PetAI.cpp @@ -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); diff --git a/src/server/game/AI/CoreAI/PetAI.h b/src/server/game/AI/CoreAI/PetAI.h index 5df11ad8282..4ce30b1f93f 100644 --- a/src/server/game/AI/CoreAI/PetAI.h +++ b/src/server/game/AI/CoreAI/PetAI.h @@ -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 | 
