fix(Core/Movement): Fire WaypointReached before PathEndReached (#25241)

Co-authored-by: blinkysc <blinkysc@users.noreply.github.com>
This commit is contained in:
blinkysc 2026-03-26 20:07:49 -05:00 committed by GitHub
parent db5cc7c4f3
commit 43769b9099
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -143,18 +143,9 @@ void WaypointMovementGenerator<Creature>::ProcessWaypointArrival(Creature* creat
_waypointDelay = waypoint.Delay;
}
// Check if the waypoint path has reached its end and may not repeat. Inform AI.
if ((i_currentNode == i_path->Nodes.size() - 1) && !_repeating && !_done)
{
bool pathEnded = (i_currentNode == i_path->Nodes.size() - 1) && !_repeating && !_done;
if (pathEnded)
_done = true;
creature->UpdateCurrentWaypointInfo(0, 0);
if (CreatureAI* AI = creature->AI())
{
AI->PathEndReached(i_path->Id);
AI->WaypointPathEnded(waypoint.Id, i_path->Id);
}
}
UpdateHomePosition(creature, waypoint);
@ -189,6 +180,20 @@ void WaypointMovementGenerator<Creature>::ProcessWaypointArrival(Creature* creat
AI->SummonMovementInform(creature, WAYPOINT_MOTION_TYPE, waypoint.Id);
}
// Path end notifications fire after WaypointReached so that m_path_id
// is still valid when SmartAI checks it for SMART_EVENT_WAYPOINT_REACHED.
if (pathEnded)
{
creature->UpdateCurrentWaypointInfo(0, 0);
if (CreatureAI* AI = creature->AI())
AI->PathEndReached(i_path->Id);
// Re-fetch AI — PathEndReached may have despawned the creature or swapped its AI
if (CreatureAI* AI = creature->AI())
AI->WaypointPathEnded(waypoint.Id, i_path->Id);
}
// All hooks called and infos updated. Time to increment the waypoint node id
if (i_path && !i_path->Nodes.empty()) // ensure that the path has not been changed in one of the hooks.
i_currentNode = (i_currentNode + 1) % i_path->Nodes.size();
@ -422,10 +427,11 @@ bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* creature, uint32 di
_smoothSplineLaunched = false;
creature->UpdateCurrentWaypointInfo(0, 0);
if (CreatureAI* AI = creature->AI())
{
AI->PathEndReached(i_path->Id);
// Re-fetch AI — PathEndReached may have despawned the creature or swapped its AI
if (CreatureAI* AI = creature->AI())
AI->WaypointPathEnded(i_path->Nodes.at(i_currentNode).Id, i_path->Id);
}
}
else
{