Core/AI: Drop script_waypoints and move data to waypoint_data
Port From (https://github.com/TrinityCore/TrinityCore/commit/89e09dc44ed15567f77f862d1936e8e0d9019456)
This commit is contained in:
@@ -283,7 +283,7 @@ namespace Game.AI
|
|||||||
{
|
{
|
||||||
Log.outDebug(LogFilter.ScriptsAi, $"EscortAI::MovementInform has returned to original position before combat ({me.GetGUID()})");
|
Log.outDebug(LogFilter.ScriptsAi, $"EscortAI::MovementInform has returned to original position before combat ({me.GetGUID()})");
|
||||||
|
|
||||||
me.SetWalk(!_running);
|
me.SetWalk(false);
|
||||||
RemoveEscortState(EscortState.Returning);
|
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 x);
|
||||||
GridDefines.NormalizeMapCoord(ref y);
|
GridDefines.NormalizeMapCoord(ref y);
|
||||||
@@ -321,48 +326,38 @@ namespace Game.AI
|
|||||||
waypoint.y = y;
|
waypoint.y = y;
|
||||||
waypoint.z = z;
|
waypoint.z = z;
|
||||||
waypoint.orientation = orientation;
|
waypoint.orientation = orientation;
|
||||||
waypoint.moveType = _running ? WaypointMoveType.Run : WaypointMoveType.Walk;
|
waypoint.moveType = run ? WaypointMoveType.Run : WaypointMoveType.Walk;
|
||||||
waypoint.delay = (uint)waitTime.TotalMilliseconds;
|
waypoint.delay = (uint)waitTime.TotalMilliseconds;
|
||||||
waypoint.eventId = 0;
|
waypoint.eventId = 0;
|
||||||
waypoint.eventChance = 100;
|
waypoint.eventChance = 100;
|
||||||
_path.nodes.Add(waypoint);
|
_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)
|
if (path == null)
|
||||||
return;
|
|
||||||
|
|
||||||
foreach (WaypointNode value in path.nodes)
|
|
||||||
{
|
{
|
||||||
WaypointNode node = value;
|
Log.outError(LogFilter.ScriptsAi, $"EscortAI::LoadPath: (script: {me.GetScriptName()}) path {pathId} is invalid ({me.GetGUID()})");
|
||||||
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)
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
foreach (var node in _path.nodes)
|
_path = path;
|
||||||
node.moveType = on ? WaypointMoveType.Run : WaypointMoveType.Walk;
|
|
||||||
|
|
||||||
me.SetWalk(!on);
|
|
||||||
|
|
||||||
_running = on;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// todo get rid of this many variables passed in function.
|
/// 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
|
// Queue respawn from the point it starts
|
||||||
CreatureData cdata = me.GetCreatureData();
|
CreatureData cdata = me.GetCreatureData();
|
||||||
if (cdata != null)
|
if (cdata != null)
|
||||||
@@ -383,11 +378,6 @@ namespace Game.AI
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
_running = run;
|
|
||||||
|
|
||||||
if (!_manualPath && resetWaypoints)
|
|
||||||
FillPointMovementListForCreature();
|
|
||||||
|
|
||||||
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()})");
|
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);
|
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()})");
|
Log.outDebug(LogFilter.ScriptsAi, $"EscortAI::Start: (script: {me.GetScriptName()}, started with {_path.nodes.Count} waypoints. ActiveAttacker = {_activeAttacker}, Player = {_playerGUID} ({me.GetGUID()})");
|
||||||
|
|
||||||
// set initial speed
|
|
||||||
me.SetWalk(!_running);
|
|
||||||
|
|
||||||
_started = false;
|
_started = false;
|
||||||
AddEscortState(EscortState.Escorting);
|
AddEscortState(EscortState.Escorting);
|
||||||
@@ -474,12 +461,10 @@ namespace Game.AI
|
|||||||
WaypointPath _path;
|
WaypointPath _path;
|
||||||
|
|
||||||
bool _activeAttacker; // obsolete, determined by faction.
|
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 _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 _returnToStart; // if creature can walk same path (loop) without despawn. Not for regular escort quests.
|
||||||
bool _despawnAtEnd;
|
bool _despawnAtEnd;
|
||||||
bool _despawnAtFar;
|
bool _despawnAtFar;
|
||||||
bool _manualPath;
|
|
||||||
bool _hasImmuneToNPCFlags;
|
bool _hasImmuneToNPCFlags;
|
||||||
bool _started;
|
bool _started;
|
||||||
bool _ended;
|
bool _ended;
|
||||||
|
|||||||
@@ -180,71 +180,9 @@ namespace Game.Scripting
|
|||||||
|
|
||||||
public void LoadDatabase()
|
public void LoadDatabase()
|
||||||
{
|
{
|
||||||
LoadScriptWaypoints();
|
|
||||||
LoadScriptSplineChains();
|
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<uint>(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<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);
|
|
||||||
uint waitTime = result.Read<uint>(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()
|
void LoadScriptSplineChains()
|
||||||
{
|
{
|
||||||
uint oldMSTime = Time.GetMSTime();
|
uint oldMSTime = Time.GetMSTime();
|
||||||
@@ -328,11 +266,6 @@ namespace Game.Scripting
|
|||||||
{
|
{
|
||||||
UnitAI.FillAISpellInfo();
|
UnitAI.FillAISpellInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
public WaypointPath GetPath(uint creatureEntry)
|
|
||||||
{
|
|
||||||
return _waypointStore.LookupByKey(creatureEntry);
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SplineChainLink> GetSplineChain(Creature who, ushort chainId)
|
public List<SplineChainLink> GetSplineChain(Creature who, ushort chainId)
|
||||||
{
|
{
|
||||||
@@ -1220,8 +1153,6 @@ namespace Game.Scripting
|
|||||||
uint _ScriptCount;
|
uint _ScriptCount;
|
||||||
public Dictionary<uint, SpellSummary> spellSummaryStorage = new();
|
public Dictionary<uint, SpellSummary> spellSummaryStorage = new();
|
||||||
Hashtable ScriptStorage = new();
|
Hashtable ScriptStorage = new();
|
||||||
|
|
||||||
Dictionary<uint, WaypointPath> _waypointStore = new();
|
|
||||||
|
|
||||||
// creature entry + chain ID
|
// creature entry + chain ID
|
||||||
MultiMap<Tuple<uint, ushort>, SplineChainLink> m_mSplineChainsMap = new(); // spline chains
|
MultiMap<Tuple<uint, ushort>, SplineChainLink> m_mSplineChainsMap = new(); // spline chains
|
||||||
|
|||||||
@@ -1179,7 +1179,8 @@ namespace Scripts.World.NpcSpecial
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
Start(false, true);
|
LoadPath((me.GetEntry() << 3) | 2);
|
||||||
|
Start(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
EnterEvadeMode(); //something went wrong
|
EnterEvadeMode(); //something went wrong
|
||||||
|
|||||||
Reference in New Issue
Block a user