diff --git a/Source/Game/AI/ScriptedAI/ScriptedEscortAI.cs b/Source/Game/AI/ScriptedAI/ScriptedEscortAI.cs index 8b0ed12e2..d5a9d664d 100644 --- a/Source/Game/AI/ScriptedAI/ScriptedEscortAI.cs +++ b/Source/Game/AI/ScriptedAI/ScriptedEscortAI.cs @@ -283,7 +283,7 @@ namespace Game.AI { Log.outDebug(LogFilter.ScriptsAi, $"EscortAI::MovementInform has returned to original position before combat ({me.GetGUID()})"); - me.SetWalk(!_running); + me.SetWalk(false); RemoveEscortState(EscortState.Returning); } @@ -310,7 +310,12 @@ namespace Game.AI } } - public void AddWaypoint(uint id, float x, float y, float z, float orientation, TimeSpan waitTime) + void AddWaypoint(uint id, float x, float y, float z, bool run) + { + AddWaypoint(id, x, y, z, 0.0f, TimeSpan.Zero, run); + } + + public void AddWaypoint(uint id, float x, float y, float z, float orientation = 0, TimeSpan waitTime = default, bool run = false) { GridDefines.NormalizeMapCoord(ref x); GridDefines.NormalizeMapCoord(ref y); @@ -321,48 +326,38 @@ namespace Game.AI waypoint.y = y; waypoint.z = z; waypoint.orientation = orientation; - waypoint.moveType = _running ? WaypointMoveType.Run : WaypointMoveType.Walk; + waypoint.moveType = run ? WaypointMoveType.Run : WaypointMoveType.Walk; waypoint.delay = (uint)waitTime.TotalMilliseconds; waypoint.eventId = 0; waypoint.eventChance = 100; _path.nodes.Add(waypoint); - - _manualPath = true; } - void FillPointMovementListForCreature() + void ResetPath() { - WaypointPath path = Global.WaypointMgr.GetPath(me.GetEntry()); + _path.nodes.Clear(); + } + + public void LoadPath(uint pathId) + { + WaypointPath path = Global.WaypointMgr.GetPath(pathId); if (path == null) - return; - - foreach (WaypointNode value in path.nodes) { - WaypointNode node = value; - GridDefines.NormalizeMapCoord(ref node.x); - GridDefines.NormalizeMapCoord(ref node.y); - node.moveType = _running ? WaypointMoveType.Run : WaypointMoveType.Walk; - - _path.nodes.Add(node); - } - } - - public void SetRun(bool on = true) - { - if (on == _running) + Log.outError(LogFilter.ScriptsAi, $"EscortAI::LoadPath: (script: {me.GetScriptName()}) path {pathId} is invalid ({me.GetGUID()})"); return; - - foreach (var node in _path.nodes) - node.moveType = on ? WaypointMoveType.Run : WaypointMoveType.Walk; - - me.SetWalk(!on); - - _running = on; + } + _path = path; } /// todo get rid of this many variables passed in function. - public void Start(bool isActiveAttacker = true, bool run = false, ObjectGuid playerGUID = default, Quest quest = null, bool instantRespawn = false, bool canLoopPath = false, bool resetWaypoints = true) + public void Start(bool isActiveAttacker = true, ObjectGuid playerGUID = default, Quest quest = null, bool instantRespawn = false, bool canLoopPath = false) { + if (_path.nodes.Empty()) + { + Log.outError(LogFilter.ScriptsAi, $"EscortAI::Start: (script: {me.GetScriptName()}) path is empty ({me.GetGUID()})"); + return; + } + // Queue respawn from the point it starts CreatureData cdata = me.GetCreatureData(); if (cdata != null) @@ -383,11 +378,6 @@ namespace Game.AI return; } - _running = run; - - if (!_manualPath && resetWaypoints) - FillPointMovementListForCreature(); - 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()})"); @@ -416,10 +406,7 @@ namespace Game.AI me.SetImmuneToNPC(false); } - Log.outDebug(LogFilter.ScriptsAi, $"EscortAI::Start: (script: {me.GetScriptName()}, started with {_path.nodes.Count} waypoints. ActiveAttacker = {_activeAttacker}, Run = {_running}, Player = {_playerGUID} ({me.GetGUID()})"); - - // set initial speed - me.SetWalk(!_running); + 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); @@ -474,12 +461,10 @@ namespace Game.AI WaypointPath _path; bool _activeAttacker; // obsolete, determined by faction. - bool _running; // all creatures are walking by default (has flag MOVEMENTFLAG_WALK) bool _instantRespawn; // if creature should respawn instantly after escort over (if not, database respawntime are used) bool _returnToStart; // if creature can walk same path (loop) without despawn. Not for regular escort quests. bool _despawnAtEnd; bool _despawnAtFar; - bool _manualPath; bool _hasImmuneToNPCFlags; bool _started; bool _ended; diff --git a/Source/Game/Scripting/ScriptManager.cs b/Source/Game/Scripting/ScriptManager.cs index e8db7e682..8c9f0ec91 100644 --- a/Source/Game/Scripting/ScriptManager.cs +++ b/Source/Game/Scripting/ScriptManager.cs @@ -180,71 +180,9 @@ namespace Game.Scripting public void LoadDatabase() { - LoadScriptWaypoints(); LoadScriptSplineChains(); } - void LoadScriptWaypoints() - { - uint oldMSTime = Time.GetMSTime(); - - // Drop Existing Waypoint list - _waypointStore.Clear(); - - ulong entryCount = 0; - - // Load Waypoints - SQLResult result = DB.World.Query("SELECT COUNT(entry) FROM script_waypoint GROUP BY entry"); - if (!result.IsEmpty()) - entryCount = result.Read(0); - - Log.outInfo(LogFilter.ServerLoading, $"Loading Script Waypoints for {entryCount} creature(s)..."); - - // 0 1 2 3 4 5 - result = DB.World.Query("SELECT entry, pointid, location_x, location_y, location_z, waittime FROM script_waypoint ORDER BY pointid"); - - if (result.IsEmpty()) - { - Log.outInfo(LogFilter.ServerLoading, "Loaded 0 Script Waypoints. DB table `script_waypoint` is empty."); - return; - } - - uint count = 0; - - 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); - uint waitTime = result.Read(5); - - CreatureTemplate info = Global.ObjectMgr.GetCreatureTemplate(entry); - if (info == null) - { - Log.outError(LogFilter.Sql, $"SystemMgr: DB table script_waypoint has waypoint for non-existant creature entry {entry}"); - continue; - } - - if (info.ScriptID == 0) - Log.outError(LogFilter.Sql, $"SystemMgr: DB table script_waypoint has waypoint for creature entry {entry}, but creature does not have ScriptName defined and then useless."); - - if (!_waypointStore.ContainsKey(entry)) - _waypointStore[entry] = new WaypointPath(); - - WaypointPath path = _waypointStore[entry]; - path.id = entry; - path.nodes.Add(new WaypointNode(id, x, y, z, null, waitTime)); - - ++count; - } - while (result.NextRow()); - - Log.outInfo(LogFilter.ServerLoading, "Loaded {0} Script Waypoint nodes in {1} ms", count, Time.GetMSTimeDiffToNow(oldMSTime)); - - } - void LoadScriptSplineChains() { uint oldMSTime = Time.GetMSTime(); @@ -328,11 +266,6 @@ namespace Game.Scripting { UnitAI.FillAISpellInfo(); } - - public WaypointPath GetPath(uint creatureEntry) - { - return _waypointStore.LookupByKey(creatureEntry); - } public List GetSplineChain(Creature who, ushort chainId) { @@ -1220,8 +1153,6 @@ namespace Game.Scripting uint _ScriptCount; public Dictionary spellSummaryStorage = new(); Hashtable ScriptStorage = new(); - - Dictionary _waypointStore = new(); // creature entry + chain ID MultiMap, SplineChainLink> m_mSplineChainsMap = new(); // spline chains diff --git a/Source/Scripts/World/NpcSpecial.cs b/Source/Scripts/World/NpcSpecial.cs index e6d95a1a3..d0ac632f4 100644 --- a/Source/Scripts/World/NpcSpecial.cs +++ b/Source/Scripts/World/NpcSpecial.cs @@ -1179,7 +1179,8 @@ namespace Scripts.World.NpcSpecial break; } - Start(false, true); + LoadPath((me.GetEntry() << 3) | 2); + Start(false); } else EnterEvadeMode(); //something went wrong