Pets: Move To works like Stay at the clicked spot

After the pet bar's Move To a pet never fought again until it was dismissed
and called back: PetAI only knew Stay and Follow, so it sent the pet home on
the next update and refused every target, even an explicit Attack. Move To
now counts as Stay at the new spot everywhere the code checked for Stay (pet
AI attack, chase and return, catch-up and travel parking, resurrect, possess),
and the handler stores the clicked spot as the stay position (the spline had
not started yet, so it saved where the pet stood). Test: PetStayCommand.

From buildthehomelab/wow-trinitycore-everlake, commit 5ad51b11b, by Bob (GPL-2.0). Thank you!
This commit is contained in:
Karrz1
2026-11-14 09:36:57 +00:00
parent 477219538d
commit edcd627657
8 changed files with 68 additions and 9 deletions
+4 -4
View File
@@ -261,7 +261,7 @@ void PetAI::_AttackStart(Unit* target)
return;
// Only chase if not commanded to stay or if stay but commanded to attack
DoAttack(target, (!me->GetCharmInfo()->HasCommandState(COMMAND_STAY) || me->GetCharmInfo()->IsCommandAttack()));
DoAttack(target, (!me->GetCharmInfo()->HasStayCommand() || me->GetCharmInfo()->IsCommandAttack()));
}
void PetAI::OwnerAttackedBy(Unit* attacker)
@@ -364,7 +364,7 @@ void PetAI::HandleReturnMovement()
return;
}
if (me->GetCharmInfo()->HasCommandState(COMMAND_STAY))
if (me->GetCharmInfo()->HasStayCommand()) // Stay or Move To
{
if (!me->GetCharmInfo()->IsAtStay() && !me->GetCharmInfo()->IsReturning())
{
@@ -506,8 +506,8 @@ bool PetAI::CanAttack(Unit* target)
if (me->GetCharmInfo()->IsReturning())
return !me->GetCharmInfo()->IsCommandFollow();
// Stay - can attack if target is within range or commanded to
if (me->GetCharmInfo()->HasCommandState(COMMAND_STAY))
// Stay or Move To - can attack if target is within range or commanded to
if (me->GetCharmInfo()->HasStayCommand())
return (me->IsWithinMeleeRange(target) || me->GetCharmInfo()->IsCommandAttack());
// Pets attacking something (or chasing) should only switch targets if owner tells them to
+2 -2
View File
@@ -802,7 +802,7 @@ bool Pet::CatchUpWithOwner()
return false;
if (owner->IsInFlight() || owner->IsBeingTeleported() || owner->IsPetNeedBeTemporaryUnsummoned())
return false;
if (GetCharmInfo() && GetCharmInfo()->HasCommandState(COMMAND_STAY))
if (GetCharmInfo() && GetCharmInfo()->HasStayCommand())
return false; // told to stay there: dismissed as before
// A fight it was left at stays behind, or the pet would run straight back to it and drop out of sight again.
@@ -821,7 +821,7 @@ bool Pet::ParkForOwnerTravel()
Player* owner = GetOwner();
if (!owner || !owner->IsInWorld() || !owner->IsAlive() || !IsInWorld() || !IsAlive() || m_removed || isPossessed() || isTemporarySummoned())
return false;
if (GetCharmInfo() && GetCharmInfo()->HasCommandState(COMMAND_STAY))
if (GetCharmInfo() && GetCharmInfo()->HasStayCommand())
return false; // told to stay there: dismissed as before
if (owner->GetMap() != GetMap())
return false;
@@ -96,6 +96,7 @@ struct TC_GAME_API CharmInfo
void SetCommandState(CommandStates st) { _CommandState = st; }
CommandStates GetCommandState() const { return _CommandState; }
bool HasCommandState(CommandStates state) const { return (_CommandState == state); }
bool HasStayCommand() const { return IsPetStayCommand(_CommandState); }
void InitPossessCreateSpells();
void InitCharmCreateSpells();
@@ -129,6 +130,7 @@ struct TC_GAME_API CharmInfo
void SetIsReturning(bool val);
bool IsReturning();
void SaveStayPosition();
void SetStayPosition(float x, float y, float z) { _stayX = x; _stayY = y; _stayZ = z; }
void GetStayPosition(float &x, float &y, float &z);
private:
@@ -467,4 +467,11 @@ enum CommandStates : uint8
COMMAND_MOVE_TO = 4
};
// "Move To" parks the pet at the clicked spot, so it behaves like Stay there: it fights what comes into reach or what
// it is told to attack, and goes back to that spot afterwards.
constexpr bool IsPetStayCommand(CommandStates state)
{
return state == COMMAND_STAY || state == COMMAND_MOVE_TO;
}
#endif // UnitDefines_h__
+3 -1
View File
@@ -265,7 +265,9 @@ void WorldSession::HandlePetActionHelper(Unit* pet, ObjectGuid guid1, uint32 spe
charmInfo->SetIsAtStay(true);
charmInfo->SetIsFollowing(false);
charmInfo->SetIsReturning(false);
charmInfo->SaveStayPosition();
// The point movement above only starts on the next motion update, so the spline still ends where
// the pet stands now: store the clicked spot itself, which is where the pet returns after a fight.
charmInfo->SetStayPosition(pos.GetPositionX(), pos.GetPositionY(), pos.GetPositionZ());
break;
default:
TC_LOG_ERROR("entities.pet", "WORLD: unknown PET flag Action {} and spellid {}.", uint32(flag), spellid);
@@ -3327,7 +3327,7 @@ void AuraEffect::HandleModPossessPet(AuraApplication const* aurApp, uint8 mode,
caster->ToPlayer()->PetSpellInitialize();
// TODO: remove this
if (!pet->GetVictim() && !pet->GetCharmInfo()->HasCommandState(COMMAND_STAY))
if (!pet->GetVictim() && !pet->GetCharmInfo()->HasStayCommand())
pet->GetMotionMaster()->MoveFollow(caster, PET_FOLLOW_DIST, pet->GetFollowAngle());
}
}
+1 -1
View File
@@ -4465,7 +4465,7 @@ void Spell::EffectResurrectPet()
{
// In case the pet was at stay, we don't want it running back
ci->SaveStayPosition();
ci->SetIsAtStay(ci->HasCommandState(COMMAND_STAY));
ci->SetIsAtStay(ci->HasStayCommand());
ci->SetIsFollowing(false);
ci->SetIsCommandAttack(false);
+48
View File
@@ -0,0 +1,48 @@
#include "tc_catch2.h"
#include "CharmInfo.h"
#include "Creature.h"
// "Move To" must leave a pet in the same mode as "Stay" at the new spot. PetAI only knew COMMAND_STAY and
// COMMAND_FOLLOW, so after Move To the pet refused every target, even an explicit Attack, until it was re-summoned.
TEST_CASE("Stay and Move To are stay commands; Follow, Attack and Abandon are not", "[PetStayCommand]")
{
STATIC_CHECK(IsPetStayCommand(COMMAND_STAY));
STATIC_CHECK(IsPetStayCommand(COMMAND_MOVE_TO));
STATIC_CHECK_FALSE(IsPetStayCommand(COMMAND_FOLLOW));
STATIC_CHECK_FALSE(IsPetStayCommand(COMMAND_ATTACK));
STATIC_CHECK_FALSE(IsPetStayCommand(COMMAND_ABANDON));
}
TEST_CASE("A pet's charm info reports a stay command after Stay or Move To", "[PetStayCommand]")
{
Creature pet(false);
CharmInfo charmInfo(&pet);
// New pets start on Follow.
CHECK_FALSE(charmInfo.HasStayCommand());
charmInfo.SetCommandState(COMMAND_MOVE_TO);
CHECK(charmInfo.HasStayCommand());
CHECK_FALSE(charmInfo.HasCommandState(COMMAND_STAY));
charmInfo.SetCommandState(COMMAND_STAY);
CHECK(charmInfo.HasStayCommand());
charmInfo.SetCommandState(COMMAND_FOLLOW);
CHECK_FALSE(charmInfo.HasStayCommand());
}
TEST_CASE("Move To stores the clicked spot as the stay position", "[PetStayCommand]")
{
// The handler cannot read the spot from the spline: the point movement it just queued has not started yet.
Creature pet(false);
CharmInfo charmInfo(&pet);
charmInfo.SetStayPosition(-8913.5f, 554.25f, 93.75f);
float x = 0.0f, y = 0.0f, z = 0.0f;
charmInfo.GetStayPosition(x, y, z);
CHECK(x == -8913.5f);
CHECK(y == 554.25f);
CHECK(z == 93.75f);
}