fix(Core/SmartAI): despawn follow if player goes out of range / offline (#24450)

This commit is contained in:
sogladev
2026-03-22 21:45:31 +01:00
committed by GitHub
parent 795e59dbcf
commit 9c05983b2a
2 changed files with 42 additions and 17 deletions

View File

@@ -109,6 +109,45 @@ void SmartAI::UpdateDespawn(const uint32 diff)
mDespawnTime -= diff;
}
void SmartAI::UpdateFollow(const uint32 diff)
{
if (!mFollowGuid)
return;
if (mFollowArrivedTimer < diff)
{
if (me->FindNearestCreature(mFollowArrivedEntry, INTERACTION_DISTANCE, mFollowArrivedAlive))
StopFollow(true);
else
mFollowArrivedTimer = 1000;
}
else
mFollowArrivedTimer -= diff;
if (mFollowGuid.IsPlayer())
{
if (_followCheckTimer < diff)
{
bool shouldDespawn = false;
if (Player* player = ObjectAccessor::FindPlayer(mFollowGuid))
{
float checkDist = me->GetInstanceScript() ? SMART_ESCORT_MAX_PLAYER_DIST * 2 : SMART_ESCORT_MAX_PLAYER_DIST;
if (!me->IsWithinDistInMap(player, checkDist))
shouldDespawn = true;
}
else
shouldDespawn = true;
if (shouldDespawn)
me->DespawnOrUnsummon();
_followCheckTimer = 1000;
}
else
_followCheckTimer -= diff;
}
}
WaypointData const* SmartAI::GetNextWayPoint()
{
if (!mWayPoints || mWayPoints->empty())
@@ -536,23 +575,7 @@ void SmartAI::UpdateAI(uint32 diff)
GetScript()->OnUpdate(diff);
UpdatePath(diff);
UpdateDespawn(diff);
//TODO move to void
if (mFollowGuid)
{
if (mFollowArrivedTimer < diff)
{
if (me->FindNearestCreature(mFollowArrivedEntry, INTERACTION_DISTANCE, mFollowArrivedAlive))
{
StopFollow(true);
return;
}
mFollowArrivedTimer = 1000;
}
else
mFollowArrivedTimer -= diff;
}
UpdateFollow(diff);
if (!IsAIControlled())
{

View File

@@ -222,6 +222,7 @@ private:
bool mIsCharmed;
uint32 mFollowCreditType;
uint32 mFollowArrivedTimer;
uint32 _followCheckTimer;
uint32 mFollowCredit;
uint32 mFollowArrivedEntry;
bool mFollowArrivedAlive;
@@ -253,6 +254,7 @@ private:
uint32 mDespawnTime;
uint32 mDespawnState;
void UpdateDespawn(const uint32 diff);
void UpdateFollow(const uint32 diff);
uint32 mEscortInvokerCheckTimer;
bool mJustReset;