Core/Waypoints: Refactor to split data into path and node related info in db
Port From (https://github.com/TrinityCore/TrinityCore/commit/12186ef8573f60abeff4747da58767ee71092600)
This commit is contained in:
@@ -295,13 +295,13 @@ namespace Game.AI
|
||||
}
|
||||
else if (moveType == MovementGeneratorType.Waypoint)
|
||||
{
|
||||
Cypher.Assert(Id < _path.nodes.Count, $"EscortAI::MovementInform: referenced movement id ({Id}) points to non-existing node in loaded path ({me.GetGUID()})");
|
||||
WaypointNode waypoint = _path.nodes[(int)Id];
|
||||
Cypher.Assert(Id < _path.Nodes.Count, $"EscortAI::MovementInform: referenced movement id ({Id}) points to non-existing node in loaded path ({me.GetGUID()})");
|
||||
WaypointNode waypoint = _path.Nodes[(int)Id];
|
||||
|
||||
Log.outDebug(LogFilter.ScriptsAi, $"EscortAI::MovementInform: waypoint node {waypoint.id} reached ({me.GetGUID()})");
|
||||
Log.outDebug(LogFilter.ScriptsAi, $"EscortAI::MovementInform: waypoint node {waypoint.Id} reached ({me.GetGUID()})");
|
||||
|
||||
// last point
|
||||
if (Id == _path.nodes.Count - 1)
|
||||
if (Id == _path.Nodes.Count - 1)
|
||||
{
|
||||
_started = false;
|
||||
_ended = true;
|
||||
@@ -310,7 +310,7 @@ namespace Game.AI
|
||||
}
|
||||
}
|
||||
|
||||
void AddWaypoint(uint id, float x, float y, float z, bool run)
|
||||
public void AddWaypoint(uint id, float x, float y, float z, bool run)
|
||||
{
|
||||
AddWaypoint(id, x, y, z, 0.0f, TimeSpan.Zero, run);
|
||||
}
|
||||
@@ -320,20 +320,14 @@ namespace Game.AI
|
||||
GridDefines.NormalizeMapCoord(ref x);
|
||||
GridDefines.NormalizeMapCoord(ref y);
|
||||
|
||||
WaypointNode waypoint = new();
|
||||
waypoint.id = id;
|
||||
waypoint.x = x;
|
||||
waypoint.y = y;
|
||||
waypoint.z = z;
|
||||
waypoint.orientation = orientation;
|
||||
waypoint.moveType = run ? WaypointMoveType.Run : WaypointMoveType.Walk;
|
||||
waypoint.delay = (uint)waitTime.TotalMilliseconds;
|
||||
_path.nodes.Add(waypoint);
|
||||
WaypointNode waypoint = new(id, x, y, z, orientation, (uint)waitTime.TotalMilliseconds);
|
||||
waypoint.MoveType = run ? WaypointMoveType.Run : WaypointMoveType.Walk;
|
||||
_path.Nodes.Add(waypoint);
|
||||
}
|
||||
|
||||
void ResetPath()
|
||||
{
|
||||
_path.nodes.Clear();
|
||||
_path.Nodes.Clear();
|
||||
}
|
||||
|
||||
public void LoadPath(uint pathId)
|
||||
@@ -350,7 +344,7 @@ namespace Game.AI
|
||||
/// todo get rid of this many variables passed in function.
|
||||
public void Start(bool isActiveAttacker = true, ObjectGuid playerGUID = default, Quest quest = null, bool instantRespawn = false, bool canLoopPath = false)
|
||||
{
|
||||
if (_path.nodes.Empty())
|
||||
if (_path.Nodes.Empty())
|
||||
{
|
||||
Log.outError(LogFilter.ScriptsAi, $"EscortAI::Start: (script: {me.GetScriptName()}) path is empty ({me.GetGUID()})");
|
||||
return;
|
||||
@@ -376,7 +370,7 @@ namespace Game.AI
|
||||
return;
|
||||
}
|
||||
|
||||
if (_path.nodes.Empty())
|
||||
if (_path.Nodes.Empty())
|
||||
{
|
||||
Log.outError(LogFilter.ScriptsAi, $"EscortAI::Start: (script: {me.GetScriptName()} starts with 0 waypoints (possible missing entry in script_waypoint. Quest: {(quest != null ? quest.Id : 0)} ({me.GetGUID()})");
|
||||
return;
|
||||
@@ -404,7 +398,7 @@ namespace Game.AI
|
||||
me.SetImmuneToNPC(false);
|
||||
}
|
||||
|
||||
Log.outDebug(LogFilter.ScriptsAi, $"EscortAI::Start: (script: {me.GetScriptName()}, started with {_path.nodes.Count} waypoints. ActiveAttacker = {_activeAttacker}, Player = {_playerGUID} ({me.GetGUID()})");
|
||||
Log.outDebug(LogFilter.ScriptsAi, $"EscortAI::Start: (script: {me.GetScriptName()}, started with {_path.Nodes.Count} waypoints. ActiveAttacker = {_activeAttacker}, Player = {_playerGUID} ({me.GetGUID()})");
|
||||
|
||||
_started = false;
|
||||
AddEscortState(EscortState.Escorting);
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Game.AI
|
||||
SmartEscortState _escortState;
|
||||
uint _escortNPCFlags;
|
||||
uint _escortInvokerCheckTimer;
|
||||
uint _currentWaypointNode;
|
||||
uint _currentWaypointNodeId;
|
||||
bool _waypointReached;
|
||||
uint _waypointPauseTimer;
|
||||
bool _waypointPauseForced;
|
||||
@@ -82,7 +82,7 @@ namespace Game.AI
|
||||
if (path == null)
|
||||
return;
|
||||
|
||||
_currentWaypointNode = nodeId;
|
||||
_currentWaypointNodeId = nodeId;
|
||||
_waypointPathEnded = false;
|
||||
|
||||
_repeatWaypointPath = repeat;
|
||||
@@ -105,7 +105,7 @@ namespace Game.AI
|
||||
return null;
|
||||
|
||||
WaypointPath path = Global.WaypointMgr.GetPath(entry);
|
||||
if (path == null || path.nodes.Empty())
|
||||
if (path == null || path.Nodes.Empty())
|
||||
{
|
||||
GetScript().SetPathId(0);
|
||||
return null;
|
||||
@@ -147,7 +147,7 @@ namespace Game.AI
|
||||
_waypointReached = false;
|
||||
|
||||
AddEscortState(SmartEscortState.Paused);
|
||||
GetScript().ProcessEventsFor(SmartEvents.WaypointPaused, null, _currentWaypointNode, GetScript().GetPathId());
|
||||
GetScript().ProcessEventsFor(SmartEvents.WaypointPaused, null, _currentWaypointNodeId, GetScript().GetPathId());
|
||||
}
|
||||
|
||||
public bool CanResumePath()
|
||||
@@ -196,7 +196,7 @@ namespace Game.AI
|
||||
|
||||
me.GetMotionMaster().MoveIdle();
|
||||
|
||||
GetScript().ProcessEventsFor(SmartEvents.WaypointStopped, null, _currentWaypointNode, GetScript().GetPathId());
|
||||
GetScript().ProcessEventsFor(SmartEvents.WaypointStopped, null, _currentWaypointNodeId, GetScript().GetPathId());
|
||||
|
||||
EndPath(fail);
|
||||
}
|
||||
@@ -262,7 +262,7 @@ namespace Game.AI
|
||||
return;
|
||||
|
||||
uint pathid = GetScript().GetPathId();
|
||||
GetScript().ProcessEventsFor(SmartEvents.WaypointEnded, null, _currentWaypointNode, pathid);
|
||||
GetScript().ProcessEventsFor(SmartEvents.WaypointEnded, null, _currentWaypointNodeId, pathid);
|
||||
|
||||
if (_repeatWaypointPath)
|
||||
{
|
||||
@@ -278,7 +278,7 @@ namespace Game.AI
|
||||
|
||||
public void ResumePath()
|
||||
{
|
||||
GetScript().ProcessEventsFor(SmartEvents.WaypointResumed, null, _currentWaypointNode, GetScript().GetPathId());
|
||||
GetScript().ProcessEventsFor(SmartEvents.WaypointResumed, null, _currentWaypointNodeId, GetScript().GetPathId());
|
||||
|
||||
RemoveEscortState(SmartEscortState.Paused);
|
||||
|
||||
@@ -378,9 +378,9 @@ namespace Game.AI
|
||||
return;
|
||||
}
|
||||
|
||||
_currentWaypointNode = nodeId;
|
||||
_currentWaypointNodeId = nodeId;
|
||||
|
||||
GetScript().ProcessEventsFor(SmartEvents.WaypointReached, null, _currentWaypointNode, pathId);
|
||||
GetScript().ProcessEventsFor(SmartEvents.WaypointReached, null, _currentWaypointNodeId, pathId);
|
||||
|
||||
if (_waypointPauseTimer != 0 && !_waypointPauseForced)
|
||||
{
|
||||
@@ -391,7 +391,7 @@ namespace Game.AI
|
||||
else if (HasEscortState(SmartEscortState.Escorting) && me.GetMotionMaster().GetCurrentMovementGeneratorType() == MovementGeneratorType.Waypoint)
|
||||
{
|
||||
WaypointPath path = Global.WaypointMgr.GetPath(pathId);
|
||||
if (path != null && _currentWaypointNode == path.nodes.Last()?.id)
|
||||
if (path != null && _currentWaypointNodeId == path.Nodes.Last()?.Id)
|
||||
_waypointPathEnded = true;
|
||||
else
|
||||
SetRun(_run);
|
||||
@@ -568,8 +568,8 @@ namespace Game.AI
|
||||
if (formation == null || formation.GetLeader() == me || !formation.IsFormed())
|
||||
{
|
||||
if (me.GetMotionMaster().GetCurrentMovementGeneratorType(MovementSlot.Default) != MovementGeneratorType.Waypoint)
|
||||
if (me.GetWaypointPath() != 0)
|
||||
me.GetMotionMaster().MovePath(me.GetWaypointPath(), true);
|
||||
if (me.GetWaypointPathId() != 0)
|
||||
me.GetMotionMaster().MovePath(me.GetWaypointPathId(), true);
|
||||
|
||||
me.ResumeMovement();
|
||||
}
|
||||
|
||||
@@ -1645,7 +1645,7 @@ namespace Game.AI
|
||||
case SmartActions.WpStart:
|
||||
{
|
||||
WaypointPath path = Global.WaypointMgr.GetPath(e.Action.wpStart.pathID);
|
||||
if (path == null || path.nodes.Empty())
|
||||
if (path == null || path.Nodes.Empty())
|
||||
{
|
||||
Log.outError(LogFilter.ScriptsAi, $"SmartAIMgr: {e} uses non-existent WaypointPath id {e.Action.wpStart.pathID}, skipped.");
|
||||
return false;
|
||||
|
||||
@@ -2027,17 +2027,17 @@ namespace Game.AI
|
||||
foreach (uint pathId in waypoints)
|
||||
{
|
||||
WaypointPath path = Global.WaypointMgr.GetPath(pathId);
|
||||
if (path == null || path.nodes.Empty())
|
||||
if (path == null || path.Nodes.Empty())
|
||||
continue;
|
||||
|
||||
foreach (var waypoint in path.nodes)
|
||||
foreach (var waypoint in path.Nodes)
|
||||
{
|
||||
float distToThisPath = creature.GetDistance(waypoint.x, waypoint.y, waypoint.z);
|
||||
if (distToThisPath < distanceToClosest)
|
||||
float distanceToThisNode = creature.GetDistance(waypoint.X, waypoint.Y, waypoint.Z);
|
||||
if (distanceToThisNode < distanceToClosest)
|
||||
{
|
||||
distanceToClosest = distToThisPath;
|
||||
distanceToClosest = distanceToThisNode;
|
||||
closestPathId = pathId;
|
||||
closestWaypointId = waypoint.id;
|
||||
closestWaypointId = waypoint.Id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user