From 792a6ecd84660584c8b5f67538b179c2df8712f2 Mon Sep 17 00:00:00 2001 From: hondacrx Date: Tue, 25 Apr 2023 17:05:34 -0400 Subject: [PATCH] Core/SAI: Drop waypoints table and move existing rows to waypoint_data table Port From (https://github.com/TrinityCore/TrinityCore/commit/356c98579babd1aef12e2b5ef28baba2403368d0) --- .../Database/Databases/WorldDatabase.cs | 2 - Source/Game/AI/SmartScripts/SmartAI.cs | 48 +++++-------- Source/Game/AI/SmartScripts/SmartAIManager.cs | 67 +------------------ Source/Game/AI/SmartScripts/SmartScript.cs | 7 +- Source/Game/World/WorldManager.cs | 3 - .../BlackrockSpire/GizrulTheSlavener.cs | 2 +- .../BlackrockMountain/BlackrockSpire/Gyth.cs | 2 +- .../BlackrockSpire/RendBlackhand.cs | 10 +-- .../BlackwingLair/Nefarian.cs | 4 +- .../InstanceMagistersTerrace.cs | 2 +- Source/Scripts/World/AreaTrigger.cs | 4 +- 11 files changed, 32 insertions(+), 119 deletions(-) diff --git a/Source/Framework/Database/Databases/WorldDatabase.cs b/Source/Framework/Database/Databases/WorldDatabase.cs index fd8e20cc1..0e6af53f4 100644 --- a/Source/Framework/Database/Databases/WorldDatabase.cs +++ b/Source/Framework/Database/Databases/WorldDatabase.cs @@ -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, diff --git a/Source/Game/AI/SmartScripts/SmartAI.cs b/Source/Game/AI/SmartScripts/SmartAI.cs index 1bcf949a1..7e60ff267 100644 --- a/Source/Game/AI/SmartScripts/SmartAI.cs +++ b/Source/Game/AI/SmartScripts/SmartAI.cs @@ -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) diff --git a/Source/Game/AI/SmartScripts/SmartAIManager.cs b/Source/Game/AI/SmartScripts/SmartAIManager.cs index 79af13cde..a9d1cc0e1 100644 --- a/Source/Game/AI/SmartScripts/SmartAIManager.cs +++ b/Source/Game/AI/SmartScripts/SmartAIManager.cs @@ -18,7 +18,6 @@ namespace Game.AI public class SmartAIManager : Singleton { MultiMap[] _eventMap = new MultiMap[(int)SmartScriptType.Max]; - Dictionary _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(0); - uint id = result.Read(1); - float x = result.Read(2); - float y = result.Read(3); - float z = result.Read(4); - float? o = null; - if (!result.IsNull(5)) - o = result.Read(5); - uint delay = result.Read(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 list, uint eventId) { var sch = list.Find(p => p.Link == eventId); diff --git a/Source/Game/AI/SmartScripts/SmartScript.cs b/Source/Game/AI/SmartScripts/SmartScript.cs index d714cca6f..26112384f 100644 --- a/Source/Game/AI/SmartScripts/SmartScript.cs +++ b/Source/Game/AI/SmartScripts/SmartScript.cs @@ -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().StartPath(run, entry, repeat, unit); + _me.GetAI().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); } } } diff --git a/Source/Game/World/WorldManager.cs b/Source/Game/World/WorldManager.cs index 6b2172f33..e2d8249e3 100644 --- a/Source/Game/World/WorldManager.cs +++ b/Source/Game/World/WorldManager.cs @@ -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(); diff --git a/Source/Scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/GizrulTheSlavener.cs b/Source/Scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/GizrulTheSlavener.cs index d1addff87..10d57ce7d 100644 --- a/Source/Scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/GizrulTheSlavener.cs +++ b/Source/Scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/GizrulTheSlavener.cs @@ -17,7 +17,7 @@ namespace Scripts.EasternKingdoms.BlackrockMountain.BlackrockSpire.GizrulTheSlav struct PathIds { - public const uint Gizrul = 402450; + public const uint Gizrul = 3219600; } [Script] diff --git a/Source/Scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/Gyth.cs b/Source/Scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/Gyth.cs index e21be3621..74166b201 100644 --- a/Source/Scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/Gyth.cs +++ b/Source/Scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/Gyth.cs @@ -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] diff --git a/Source/Scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/RendBlackhand.cs b/Source/Scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/RendBlackhand.cs index a5102d9b6..40add4d3b 100644 --- a/Source/Scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/RendBlackhand.cs +++ b/Source/Scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/RendBlackhand.cs @@ -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 { diff --git a/Source/Scripts/EasternKingdoms/BlackrockMountain/BlackwingLair/Nefarian.cs b/Source/Scripts/EasternKingdoms/BlackrockMountain/BlackwingLair/Nefarian.cs index 1ab89f344..e52c9cd79 100644 --- a/Source/Scripts/EasternKingdoms/BlackrockMountain/BlackwingLair/Nefarian.cs +++ b/Source/Scripts/EasternKingdoms/BlackrockMountain/BlackwingLair/Nefarian.cs @@ -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 { diff --git a/Source/Scripts/EasternKingdoms/MagistersTerrace/InstanceMagistersTerrace.cs b/Source/Scripts/EasternKingdoms/MagistersTerrace/InstanceMagistersTerrace.cs index abd582c5e..02bc5bb32 100644 --- a/Source/Scripts/EasternKingdoms/MagistersTerrace/InstanceMagistersTerrace.cs +++ b/Source/Scripts/EasternKingdoms/MagistersTerrace/InstanceMagistersTerrace.cs @@ -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 = { diff --git a/Source/Scripts/World/AreaTrigger.cs b/Source/Scripts/World/AreaTrigger.cs index d03ac03b7..c3eb9ee00 100644 --- a/Source/Scripts/World/AreaTrigger.cs +++ b/Source/Scripts/World/AreaTrigger.cs @@ -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;