Skip to content

Commit

Permalink
Clean up pet stay functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Phatcat committed Aug 3, 2016
1 parent a05643b commit 8837c45
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 34 deletions.
20 changes: 20 additions & 0 deletions src/game/Pet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2096,3 +2096,23 @@ void Pet::SetModeFlags(PetModeFlags mode)
data << uint32(m_petModeFlags);
((Player*)owner)->GetSession()->SendPacket(&data);
}

void Pet::SetStayPosition(bool stay)
{
if (stay)
{
m_stayPosX = GetPositionX();
m_stayPosY = GetPositionY();
m_stayPosZ = GetPositionZ();
m_stayPosO = GetOrientation();
}
else
{
m_stayPosX = 0;
m_stayPosY = 0;
m_stayPosZ = 0;
m_stayPosO = 0;
}

m_stayPosSet = stay;
}
25 changes: 2 additions & 23 deletions src/game/Pet.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,44 +236,23 @@ class MANGOS_DLL_SPEC Pet : public Creature

bool m_retreating;

void SetIsRetreating(bool retreating = false) { m_retreating = retreating; }
bool GetIsRetreating() { return m_retreating; }
void SetIsRetreating(bool retreating = false)
{
m_retreating = retreating;
((Unit*)this)->InterruptNonMeleeSpells(false);
}

bool m_stayPosSet;
float m_stayPosX;
float m_stayPosY;
float m_stayPosZ;
float m_stayPosO;

void SetStayPosition(bool stay = false);
bool IsStayPosSet() { return m_stayPosSet; }

float GetStayPosX() { return m_stayPosX; }
float GetStayPosY() { return m_stayPosY; }
float GetStayPosZ() { return m_stayPosZ; }
float GetStayPosO() { return m_stayPosO; }

void SetStayPosition()
{
m_stayPosX = GetPositionX();
m_stayPosY = GetPositionY();
m_stayPosZ = GetPositionZ();
m_stayPosO = GetOrientation();
m_stayPosSet = true;
}

void ClearStayPosition()
{
m_stayPosSet = false;
m_stayPosX = 0;
m_stayPosY = 0;
m_stayPosZ = 0;
m_stayPosO = 0;
}

PetSpellMap m_spells;
AutoSpellList m_autospells;

Expand Down
25 changes: 17 additions & 8 deletions src/game/PetAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,21 +337,30 @@ void PetAI::UpdateAI(const uint32 diff)
{
if (Pet* pet = (Pet*)m_creature)
{
//if stay command is already set but we dont have stay pos set then we need to establish current pos as stay position
//if stay command is set but we dont have stay pos set then we need to establish current pos as stay position
if (!pet->IsStayPosSet())
pet->SetStayPosition();
pet->SetStayPosition(true);

float stayPosX = pet->GetStayPosX();
float stayPosY = pet->GetStayPosY();
float stayPosZ = pet->GetStayPosZ();

if (!(m_creature->hasUnitState(UNIT_STAT_MOVING)
|| (m_creature->GetPositionX() == stayPosX
if (m_creature->GetPositionX() == stayPosX
&& m_creature->GetPositionY() == stayPosY
&& m_creature->GetPositionZ() == stayPosZ)))
pet->GetMotionMaster()->MovePoint(0, stayPosX, stayPosY, stayPosZ, false);

return;
&& m_creature->GetPositionZ() == stayPosZ)
{
float StayPosO = pet->GetStayPosO();

if (m_creature->hasUnitState(UNIT_STAT_MOVING))
{
m_creature->GetMotionMaster()->Clear(false);
m_creature->GetMotionMaster()->MoveIdle();
}
else if (m_creature->GetOrientation() != StayPosO)
m_creature->SetOrientation(StayPosO);
}
else
pet->GetMotionMaster()->MovePoint(0, stayPosX, stayPosY, stayPosZ, false);
}
}
else if (m_creature->hasUnitState(UNIT_STAT_FOLLOW))
Expand Down
6 changes: 3 additions & 3 deletions src/game/PetHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ void WorldSession::HandlePetAction(WorldPacket& recv_data)
pet->AttackStop(true, true);
pet->GetMotionMaster()->Clear(false);
pet->GetMotionMaster()->MoveIdle();
((Pet*)pet)->SetStayPosition();
((Pet*)pet)->SetStayPosition(true);
((Pet*)pet)->SetIsRetreating();
((Pet*)pet)->SetSpellOpener();
charmInfo->SetCommandState(COMMAND_STAY);
break;
}
case COMMAND_FOLLOW: // spellid=1792 // FOLLOW
{
((Pet*)pet)->ClearStayPosition();
((Pet*)pet)->SetStayPosition();
pet->AttackStop(true, true);
pet->GetMotionMaster()->MoveFollow(_player, PET_FOLLOW_DIST, PET_FOLLOW_ANGLE);
((Pet*)pet)->SetIsRetreating(true);
Expand Down Expand Up @@ -163,8 +163,8 @@ void WorldSession::HandlePetAction(WorldPacket& recv_data)
petC->ForcedDespawn();
return;
}
((Pet*)pet)->ClearStayPosition();

((Pet*)pet)->SetStayPosition();
break;
}
default:
Expand Down

0 comments on commit 8837c45

Please sign in to comment.