Core/SAI: Drop waypoints table and move existing rows to waypoint_data table
Port From (https://github.com/TrinityCore/TrinityCore/commit/356c98579babd1aef12e2b5ef28baba2403368d0)
This commit is contained in:
@@ -33,7 +33,6 @@ namespace Game.AI
|
||||
SmartEscortState _escortState;
|
||||
uint _escortNPCFlags;
|
||||
uint _escortInvokerCheckTimer;
|
||||
WaypointPath _path = new();
|
||||
uint _currentWaypointNode;
|
||||
bool _waypointReached;
|
||||
uint _waypointPauseTimer;
|
||||
@@ -71,20 +70,16 @@ namespace Game.AI
|
||||
return !_isCharmed;
|
||||
}
|
||||
|
||||
public void StartPath(bool run = false, uint pathId = 0, bool repeat = false, Unit invoker = null, uint nodeId = 1)
|
||||
public void StartPath(uint pathId = 0, bool repeat = false, Unit invoker = null, uint nodeId = 1)
|
||||
{
|
||||
if (HasEscortState(SmartEscortState.Escorting))
|
||||
StopPath();
|
||||
|
||||
SetRun(run);
|
||||
if (pathId == 0)
|
||||
return;
|
||||
|
||||
if (pathId != 0)
|
||||
{
|
||||
if (!LoadPath(pathId))
|
||||
return;
|
||||
}
|
||||
|
||||
if (_path.nodes.Empty())
|
||||
WaypointPath path = LoadPath(pathId);
|
||||
if (path == null)
|
||||
return;
|
||||
|
||||
_currentWaypointNode = nodeId;
|
||||
@@ -101,32 +96,23 @@ namespace Game.AI
|
||||
me.ReplaceAllNpcFlags(NPCFlags.None);
|
||||
}
|
||||
|
||||
me.GetMotionMaster().MovePath(_path, _repeatWaypointPath);
|
||||
me.GetMotionMaster().MovePath(path, _repeatWaypointPath);
|
||||
}
|
||||
|
||||
bool LoadPath(uint entry)
|
||||
WaypointPath LoadPath(uint entry)
|
||||
{
|
||||
if (HasEscortState(SmartEscortState.Escorting))
|
||||
return false;
|
||||
return null;
|
||||
|
||||
WaypointPath path = Global.SmartAIMgr.GetPath(entry);
|
||||
WaypointPath path = Global.WaypointMgr.GetPath(entry);
|
||||
if (path == null || path.nodes.Empty())
|
||||
{
|
||||
GetScript().SetPathId(0);
|
||||
return false;
|
||||
}
|
||||
|
||||
_path.id = path.id;
|
||||
_path.nodes.AddRange(path.nodes);
|
||||
foreach (WaypointNode waypoint in _path.nodes)
|
||||
{
|
||||
GridDefines.NormalizeMapCoord(ref waypoint.x);
|
||||
GridDefines.NormalizeMapCoord(ref waypoint.y);
|
||||
waypoint.moveType = _run ? WaypointMoveType.Run : WaypointMoveType.Walk;
|
||||
return null;
|
||||
}
|
||||
|
||||
GetScript().SetPathId(entry);
|
||||
return true;
|
||||
return path;
|
||||
}
|
||||
|
||||
public void PausePath(uint delay, bool forced)
|
||||
@@ -217,7 +203,7 @@ namespace Game.AI
|
||||
public void EndPath(bool fail = false)
|
||||
{
|
||||
RemoveEscortState(SmartEscortState.Escorting | SmartEscortState.Paused | SmartEscortState.Returning);
|
||||
_path.nodes.Clear();
|
||||
|
||||
_waypointPauseTimer = 0;
|
||||
|
||||
if (_escortNPCFlags != 0)
|
||||
@@ -280,7 +266,7 @@ namespace Game.AI
|
||||
if (_repeatWaypointPath)
|
||||
{
|
||||
if (IsAIControlled())
|
||||
StartPath(_run, GetScript().GetPathId(), _repeatWaypointPath);
|
||||
StartPath(GetScript().GetPathId(), _repeatWaypointPath);
|
||||
}
|
||||
else if (pathid == GetScript().GetPathId()) // if it's not the same pathid, our script wants to start another path; don't override it
|
||||
GetScript().SetPathId(0);
|
||||
@@ -403,7 +389,8 @@ namespace Game.AI
|
||||
}
|
||||
else if (HasEscortState(SmartEscortState.Escorting) && me.GetMotionMaster().GetCurrentMovementGeneratorType() == MovementGeneratorType.Waypoint)
|
||||
{
|
||||
if (_currentWaypointNode == _path.nodes.Count)
|
||||
WaypointPath path = Global.WaypointMgr.GetPath(pathId);
|
||||
if (path != null && _currentWaypointNode == path.nodes.Count)
|
||||
_waypointPathEnded = true;
|
||||
else
|
||||
SetRun(_run);
|
||||
@@ -736,7 +723,7 @@ namespace Game.AI
|
||||
if (!charmed && !me.IsInEvadeMode())
|
||||
{
|
||||
if (_repeatWaypointPath)
|
||||
StartPath(_run, GetScript().GetPathId(), true);
|
||||
StartPath(GetScript().GetPathId(), true);
|
||||
else
|
||||
me.SetWalk(!_run);
|
||||
|
||||
@@ -789,9 +776,6 @@ namespace Game.AI
|
||||
{
|
||||
me.SetWalk(!run);
|
||||
_run = run;
|
||||
|
||||
foreach (var node in _path.nodes)
|
||||
node.moveType = run ? WaypointMoveType.Run : WaypointMoveType.Walk;
|
||||
}
|
||||
|
||||
public void SetDisableGravity(bool disable = true)
|
||||
|
||||
@@ -18,7 +18,6 @@ namespace Game.AI
|
||||
public class SmartAIManager : Singleton<SmartAIManager>
|
||||
{
|
||||
MultiMap<int, SmartScriptHolder>[] _eventMap = new MultiMap<int, SmartScriptHolder>[(int)SmartScriptType.Max];
|
||||
Dictionary<uint, WaypointPath> _waypointStore = new();
|
||||
|
||||
SmartAIManager()
|
||||
{
|
||||
@@ -312,65 +311,6 @@ namespace Game.AI
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loaded {0} SmartAI scripts in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime));
|
||||
}
|
||||
|
||||
public void LoadWaypointFromDB()
|
||||
{
|
||||
uint oldMSTime = Time.GetMSTime();
|
||||
|
||||
_waypointStore.Clear();
|
||||
|
||||
PreparedStatement stmt = WorldDatabase.GetPreparedStatement(WorldStatements.SEL_SMARTAI_WP);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
Log.outInfo(LogFilter.ServerLoading, "Loaded 0 SmartAI Waypoint Paths. DB table `waypoints` is empty.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
uint count = 0;
|
||||
uint total = 0;
|
||||
uint lastEntry = 0;
|
||||
uint lastId = 1;
|
||||
|
||||
do
|
||||
{
|
||||
uint entry = result.Read<uint>(0);
|
||||
uint id = result.Read<uint>(1);
|
||||
float x = result.Read<float>(2);
|
||||
float y = result.Read<float>(3);
|
||||
float z = result.Read<float>(4);
|
||||
float? o = null;
|
||||
if (!result.IsNull(5))
|
||||
o = result.Read<float>(5);
|
||||
uint delay = result.Read<uint>(6);
|
||||
|
||||
if (lastEntry != entry)
|
||||
{
|
||||
lastId = 1;
|
||||
++count;
|
||||
}
|
||||
|
||||
if (lastId != id)
|
||||
Log.outError(LogFilter.Sql, $"SmartWaypointMgr.LoadFromDB: Path entry {entry}, unexpected point id {id}, expected {lastId}.");
|
||||
|
||||
++lastId;
|
||||
|
||||
if (!_waypointStore.ContainsKey(entry))
|
||||
_waypointStore[entry] = new WaypointPath();
|
||||
|
||||
WaypointPath path = _waypointStore[entry];
|
||||
path.id = entry;
|
||||
path.nodes.Add(new WaypointNode(id, x, y, z, o, delay));
|
||||
|
||||
lastEntry = entry;
|
||||
++total;
|
||||
}
|
||||
while (result.NextRow());
|
||||
|
||||
Log.outInfo(LogFilter.ServerLoading, $"Loaded {count} SmartAI waypoint paths (total {total} waypoints) in {Time.GetMSTimeDiffToNow(oldMSTime)} ms");
|
||||
}
|
||||
|
||||
static bool EventHasInvoker(SmartEvents smartEvent)
|
||||
{
|
||||
switch (smartEvent)
|
||||
@@ -1662,7 +1602,7 @@ namespace Game.AI
|
||||
break;
|
||||
case SmartActions.WpStart:
|
||||
{
|
||||
WaypointPath path = GetPath(e.Action.wpStart.pathID);
|
||||
WaypointPath path = Global.WaypointMgr.GetPath(e.Action.wpStart.pathID);
|
||||
if (path == null || path.nodes.Empty())
|
||||
{
|
||||
Log.outError(LogFilter.ScriptsAi, $"SmartAIMgr: {e} uses non-existent WaypointPath id {e.Action.wpStart.pathID}, skipped.");
|
||||
@@ -2336,11 +2276,6 @@ namespace Game.AI
|
||||
return temp;
|
||||
}
|
||||
|
||||
public WaypointPath GetPath(uint id)
|
||||
{
|
||||
return _waypointStore.LookupByKey(id);
|
||||
}
|
||||
|
||||
public static SmartScriptHolder FindLinkedSourceEvent(List<SmartScriptHolder> list, uint eventId)
|
||||
{
|
||||
var sch = list.Find(p => p.Link == eventId);
|
||||
|
||||
@@ -1289,7 +1289,6 @@ namespace Game.AI
|
||||
if (!IsSmart())
|
||||
break;
|
||||
|
||||
bool run = e.Action.wpStart.run != 0;
|
||||
uint entry = e.Action.wpStart.pathID;
|
||||
bool repeat = e.Action.wpStart.repeat != 0;
|
||||
|
||||
@@ -1302,7 +1301,7 @@ namespace Game.AI
|
||||
}
|
||||
}
|
||||
|
||||
_me.GetAI<SmartAI>().StartPath(run, entry, repeat, unit);
|
||||
_me.GetAI<SmartAI>().StartPath(entry, repeat, unit);
|
||||
|
||||
uint quest = e.Action.wpStart.quest;
|
||||
uint DespawnTime = e.Action.wpStart.despawnTime;
|
||||
@@ -2026,7 +2025,7 @@ namespace Game.AI
|
||||
{
|
||||
foreach (uint pathId in waypoints)
|
||||
{
|
||||
WaypointPath path = Global.SmartAIMgr.GetPath(pathId);
|
||||
WaypointPath path = Global.WaypointMgr.GetPath(pathId);
|
||||
if (path == null || path.nodes.Empty())
|
||||
continue;
|
||||
|
||||
@@ -2043,7 +2042,7 @@ namespace Game.AI
|
||||
}
|
||||
|
||||
if (closestPathId != 0)
|
||||
((SmartAI)creature.GetAI()).StartPath(false, closestPathId, true, null, closestWaypointId);
|
||||
((SmartAI)creature.GetAI()).StartPath(closestPathId, true, null, closestWaypointId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user