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:
hondacrx
2023-04-25 17:05:34 -04:00
parent 097346aad5
commit 792a6ecd84
11 changed files with 32 additions and 119 deletions
@@ -12,7 +12,6 @@ namespace Framework.Database
PrepareStatement(WorldStatements.REP_LINKED_RESPAWN, "REPLACE INTO linked_respawn (guid, linkedGuid, linkType) VALUES (?, ?, ?)");
PrepareStatement(WorldStatements.SEL_CREATURE_TEXT, "SELECT CreatureID, GroupID, ID, Text, Type, Language, Probability, Emote, Duration, Sound, SoundPlayType, BroadcastTextId, TextRange FROM creature_text");
PrepareStatement(WorldStatements.SEL_SMART_SCRIPTS, "SELECT entryorguid, source_type, id, link, event_type, event_phase_mask, event_chance, event_flags, event_param1, event_param2, event_param3, event_param4, event_param5, event_param_string, action_type, action_param1, action_param2, action_param3, action_param4, action_param5, action_param6, action_param7, target_type, target_param1, target_param2, target_param3, target_param4, target_x, target_y, target_z, target_o FROM smart_scripts ORDER BY entryorguid, source_type, id, link");
PrepareStatement(WorldStatements.SEL_SMARTAI_WP, "SELECT entry, pointid, position_x, position_y, position_z, orientation, delay FROM waypoints ORDER BY entry, pointid");
PrepareStatement(WorldStatements.DEL_GAMEOBJECT, "DELETE FROM gameobject WHERE guid = ?");
PrepareStatement(WorldStatements.DEL_EVENT_GAMEOBJECT, "DELETE FROM game_event_gameobject WHERE guid = ?");
PrepareStatement(WorldStatements.INS_GRAVEYARD_ZONE, "INSERT INTO graveyard_zone (ID, GhostZone, faction) VALUES (?, ?, ?)");
@@ -88,7 +87,6 @@ namespace Framework.Database
REP_LINKED_RESPAWN,
SEL_CREATURE_TEXT,
SEL_SMART_SCRIPTS,
SEL_SMARTAI_WP,
DEL_GAMEOBJECT,
DEL_EVENT_GAMEOBJECT,
INS_GRAVEYARD_ZONE,
+16 -32
View File
@@ -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)
+1 -66
View File
@@ -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);
+3 -4
View File
@@ -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);
}
}
}
-3
View File
@@ -899,9 +899,6 @@ namespace Game
Log.outInfo(LogFilter.ServerLoading, "Loading Waypoints...");
Global.WaypointMgr.Load();
Log.outInfo(LogFilter.ServerLoading, "Loading SmartAI Waypoints...");
Global.SmartAIMgr.LoadWaypointFromDB();
Log.outInfo(LogFilter.ServerLoading, "Loading Creature Formations...");
FormationMgr.LoadCreatureFormations();
@@ -17,7 +17,7 @@ namespace Scripts.EasternKingdoms.BlackrockMountain.BlackrockSpire.GizrulTheSlav
struct PathIds
{
public const uint Gizrul = 402450;
public const uint Gizrul = 3219600;
}
[Script]
@@ -23,7 +23,7 @@ namespace Scripts.EasternKingdoms.BlackrockMountain.BlackrockSpire.Gyth
{
public const uint NefariusPath2 = 1379671;
public const uint NefariusPath3 = 1379672;
public const uint GythPath1 = 1379681;
public const uint GythPath1 = 11037448;
}
[Script]
@@ -46,11 +46,11 @@ namespace Scripts.EasternKingdoms.BlackrockMountain.BlackrockSpire.RendBlackhand
struct MiscConst
{
public const uint NefariusPath1 = 1379670;
public const uint NefariusPath2 = 1379671;
public const uint NefariusPath3 = 1379672;
public const uint RendPath1 = 1379680;
public const uint RendPath2 = 1379681;
public const uint NefariusPath1 = 11037360;
public const uint NefariusPath2 = 11037368;
public const uint NefariusPath3 = 11037376;
public const uint RendPath1 = 11037440;
public const uint RendPath2 = 11037448;
public static Wave[] Wave2 = // 22 sec
{
@@ -103,8 +103,8 @@ namespace Scripts.EasternKingdoms.BlackrockMountain.BlackwingLair.VictorNefarius
struct MiscConst
{
public const uint NefariusPath2 = 1379671;
public const uint NefariusPath3 = 1379672;
public const uint NefariusPath2 = 11037368;
public const uint NefariusPath3 = 11037376;
public static Position[] DrakeSpawnLoc = // drakonid
{
@@ -72,7 +72,7 @@ namespace Scripts.EasternKingdoms.MagistersTerrace
public const uint SayKalecgosSpawn = 0;
public const uint PathKalecgosFlight = 248440;
public const uint PathKalecgosFlight = 1987520;
public static ObjectData[] creatureData =
{
+2 -2
View File
@@ -367,14 +367,14 @@ namespace Scripts.World.Areatriggers
stormforgedMonitor.SetWalk(false);
/// The npc would search an alternative way to get to the last waypoint without this unit state.
stormforgedMonitor.AddUnitState(UnitState.IgnorePathfinding);
stormforgedMonitor.GetMotionMaster().MovePath(CreatureIds.StormforgedMonitor * 100, false);
stormforgedMonitor.GetMotionMaster().MovePath((CreatureIds.StormforgedMonitor * 100) << 3, false);
}
stormforgedEradictor = player.SummonCreature(CreatureIds.StormforgedEradictor, Misc.StormforgedEradictorPosition, TempSummonType.TimedDespawnOutOfCombat, TimeSpan.FromSeconds(60));
if (stormforgedEradictor)
{
stormforgedEradictorGUID = stormforgedEradictor.GetGUID();
stormforgedEradictor.GetMotionMaster().MovePath(CreatureIds.StormforgedEradictor * 100, false);
stormforgedEradictor.GetMotionMaster().MovePath((CreatureIds.StormforgedEradictor * 100) << 3, false);
}
return true;