fix(Core/Movement): Fire WaypointReached before PathEndReached (#25241)
Co-authored-by: blinkysc <blinkysc@users.noreply.github.com>
This commit is contained in:
@@ -143,18 +143,9 @@ void WaypointMovementGenerator<Creature>::ProcessWaypointArrival(Creature* creat
|
|||||||
_waypointDelay = waypoint.Delay;
|
_waypointDelay = waypoint.Delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the waypoint path has reached its end and may not repeat. Inform AI.
|
bool pathEnded = (i_currentNode == i_path->Nodes.size() - 1) && !_repeating && !_done;
|
||||||
if ((i_currentNode == i_path->Nodes.size() - 1) && !_repeating && !_done)
|
if (pathEnded)
|
||||||
{
|
|
||||||
_done = true;
|
_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);
|
UpdateHomePosition(creature, waypoint);
|
||||||
|
|
||||||
@@ -189,6 +180,20 @@ void WaypointMovementGenerator<Creature>::ProcessWaypointArrival(Creature* creat
|
|||||||
AI->SummonMovementInform(creature, WAYPOINT_MOTION_TYPE, waypoint.Id);
|
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
|
// 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.
|
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();
|
i_currentNode = (i_currentNode + 1) % i_path->Nodes.size();
|
||||||
@@ -422,11 +427,12 @@ bool WaypointMovementGenerator<Creature>::DoUpdate(Creature* creature, uint32 di
|
|||||||
_smoothSplineLaunched = false;
|
_smoothSplineLaunched = false;
|
||||||
creature->UpdateCurrentWaypointInfo(0, 0);
|
creature->UpdateCurrentWaypointInfo(0, 0);
|
||||||
if (CreatureAI* AI = creature->AI())
|
if (CreatureAI* AI = creature->AI())
|
||||||
{
|
|
||||||
AI->PathEndReached(i_path->Id);
|
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);
|
AI->WaypointPathEnded(i_path->Nodes.at(i_currentNode).Id, i_path->Id);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Repeating: rebuild spline
|
// Repeating: rebuild spline
|
||||||
|
|||||||
Reference in New Issue
Block a user