Core/Waypoints: Refactor to split data into path and node related info in db
Port From (https://github.com/TrinityCore/TrinityCore/commit/12186ef8573f60abeff4747da58767ee71092600)
This commit is contained in:
@@ -915,16 +915,16 @@ namespace Game.Chat
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("waypoint_data", RBACPermissions.CommandReloadWaypointData, true)]
|
||||
[Command("waypoint_path", RBACPermissions.CommandReloadWaypointPath, true)]
|
||||
static bool HandleReloadWpCommand(CommandHandler handler, StringArguments args)
|
||||
{
|
||||
if (args != null)
|
||||
Log.outInfo(LogFilter.Server, "Re-Loading Waypoints data from 'waypoints_data'");
|
||||
Log.outInfo(LogFilter.Server, "Re-Loading Waypoints data from 'waypoint_path' and 'waypoint_path_node'");
|
||||
|
||||
Global.WaypointMgr.Load();
|
||||
Global.WaypointMgr.LoadPaths();
|
||||
|
||||
if (args != null)
|
||||
handler.SendGlobalGMSysMessage("DB Table 'waypoint_data' reloaded.");
|
||||
handler.SendGlobalGMSysMessage("DB Tables 'waypoint_path' and 'waypoint_path_node' reloaded.");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using Game.Entities;
|
||||
using Game.Maps;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace Game.Chat.Commands
|
||||
{
|
||||
@@ -15,32 +16,31 @@ namespace Game.Chat.Commands
|
||||
class WPCommands
|
||||
{
|
||||
[Command("add", RBACPermissions.CommandWpAdd)]
|
||||
static bool HandleWpAddCommand(CommandHandler handler, uint? optionalPathId)
|
||||
static bool HandleWpAddCommand(CommandHandler handler, uint? optionalpathId)
|
||||
{
|
||||
uint point = 0;
|
||||
Creature target = handler.GetSelectedCreature();
|
||||
|
||||
PreparedStatement stmt;
|
||||
uint pathId;
|
||||
|
||||
if (!optionalPathId.HasValue)
|
||||
if (!optionalpathId.HasValue)
|
||||
{
|
||||
if (target != null)
|
||||
pathId = target.GetWaypointPath();
|
||||
pathId = target.GetWaypointPathId();
|
||||
else
|
||||
{
|
||||
stmt = WorldDatabase.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_MAX_ID);
|
||||
stmt = WorldDatabase.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_PATH_NODE_MAX_PATHID);
|
||||
SQLResult result1 = DB.World.Query(stmt);
|
||||
|
||||
uint maxpathid = result1.Read<uint>(0);
|
||||
pathId = maxpathid + 1;
|
||||
uint maxpathId = result1.Read<uint>(0);
|
||||
pathId = maxpathId + 1;
|
||||
handler.SendSysMessage("|cff00ff00New path started.|r");
|
||||
}
|
||||
}
|
||||
else
|
||||
pathId = optionalPathId.Value;
|
||||
pathId = optionalpathId.Value;
|
||||
|
||||
// path_id . ID of the Path
|
||||
// pathId . ID of the Path
|
||||
// point . number of the waypoint (if not 0)
|
||||
|
||||
if (pathId == 0)
|
||||
@@ -49,39 +49,52 @@ namespace Game.Chat.Commands
|
||||
return true;
|
||||
}
|
||||
|
||||
stmt = WorldDatabase.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_MAX_POINT);
|
||||
stmt = WorldDatabase.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_PATH_NODE_MAX_NODEID);
|
||||
stmt.AddValue(0, pathId);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
uint nodeId = 0;
|
||||
if (result.IsEmpty())
|
||||
point = result.Read<uint>(0);
|
||||
nodeId = result.Read<uint>(0);
|
||||
|
||||
Player player = handler.GetSession().GetPlayer();
|
||||
Player player = handler.GetPlayer();
|
||||
|
||||
stmt = WorldDatabase.GetPreparedStatement(WorldStatements.INS_WAYPOINT_DATA);
|
||||
stmt = WorldDatabase.GetPreparedStatement(WorldStatements.INS_WAYPOINT_PATH_NODE);
|
||||
stmt.AddValue(0, pathId);
|
||||
stmt.AddValue(1, point + 1);
|
||||
stmt.AddValue(1, nodeId);
|
||||
stmt.AddValue(2, player.GetPositionX());
|
||||
stmt.AddValue(3, player.GetPositionY());
|
||||
stmt.AddValue(4, player.GetPositionZ());
|
||||
stmt.AddValue(5, player.GetOrientation());
|
||||
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
handler.SendSysMessage("|cff00ff00PathID: |r|cff00ffff{0} |r|cff00ff00: Waypoint |r|cff00ffff{1}|r|cff00ff00 created.|r", pathId, point + 1);
|
||||
if (target != null)
|
||||
{
|
||||
uint displayId = target.GetDisplayId();
|
||||
|
||||
WaypointPath path = Global.WaypointMgr.GetPath(pathId);
|
||||
if (path == null)
|
||||
return true;
|
||||
|
||||
Global.WaypointMgr.DevisualizePath(player, path);
|
||||
Global.WaypointMgr.ReloadPath(pathId);
|
||||
Global.WaypointMgr.VisualizePath(player, path, displayId);
|
||||
}
|
||||
|
||||
handler.SendSysMessage("|cff00ff00pathId: |r|cff00ffff{pathId}|r|cff00ff00: Waypoint |r|cff00ffff{nodeId}|r|cff00ff00 created. ");
|
||||
return true;
|
||||
}
|
||||
|
||||
[Command("load", RBACPermissions.CommandWpLoad)]
|
||||
static bool HandleWpLoadCommand(CommandHandler handler, uint? optionalPathId)
|
||||
static bool HandleWpLoadCommand(CommandHandler handler, uint? optionalpathId)
|
||||
{
|
||||
Creature target = handler.GetSelectedCreature();
|
||||
|
||||
// Did player provide a path_id?
|
||||
if (!optionalPathId.HasValue)
|
||||
// Did player provide a pathId?
|
||||
if (!optionalpathId.HasValue)
|
||||
return false;
|
||||
|
||||
uint pathId = optionalPathId.Value;
|
||||
uint pathId = optionalpathId.Value;
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
@@ -143,19 +156,9 @@ namespace Game.Chat.Commands
|
||||
if (subCommand.IsEmpty())
|
||||
return false;
|
||||
|
||||
// Check
|
||||
// Remember: "show" must also be the name of a column!
|
||||
if ((subCommand != "delay") && (subCommand != "action") && (subCommand != "action_chance")
|
||||
&& (subCommand != "move_flag") && (subCommand != "del") && (subCommand != "move"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Did user provide a GUID
|
||||
// or did the user select a creature?
|
||||
// . variable lowguid is filled with the GUID of the NPC
|
||||
uint pathid;
|
||||
uint point;
|
||||
Creature target = handler.GetSelectedCreature();
|
||||
|
||||
// User did select a visual waypoint?
|
||||
@@ -165,148 +168,50 @@ namespace Game.Chat.Commands
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check the creature
|
||||
PreparedStatement stmt = WorldDatabase.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_BY_WPGUID);
|
||||
stmt.AddValue(0, target.GetSpawnId());
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
WaypointPath path = Global.WaypointMgr.GetPathByVisualGUID(target.GetGUID());
|
||||
if (path == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotfoundsearch, target.GetGUID().ToString());
|
||||
// Select waypoint number from database
|
||||
// Since we compare float values, we have to deal with
|
||||
// some difficulties.
|
||||
// Here we search for all waypoints that only differ in one from 1 thousand
|
||||
// See also: http://dev.mysql.com/doc/refman/5.0/en/problems-with-float.html
|
||||
string maxDiff = "0.01";
|
||||
|
||||
stmt = WorldDatabase.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_BY_POS);
|
||||
stmt.AddValue(0, target.GetPositionX());
|
||||
stmt.AddValue(1, maxDiff);
|
||||
stmt.AddValue(2, target.GetPositionY());
|
||||
stmt.AddValue(3, maxDiff);
|
||||
stmt.AddValue(4, target.GetPositionZ());
|
||||
stmt.AddValue(5, maxDiff);
|
||||
result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotfounddbproblem, target.GetGUID().ToString());
|
||||
return true;
|
||||
}
|
||||
handler.SendSysMessage("|cff00ff00Path does not exist or target has no path|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
do
|
||||
WaypointNode node = Global.WaypointMgr.GetNodeByVisualGUID(target.GetGUID());
|
||||
if (node == null)
|
||||
{
|
||||
pathid = result.Read<uint>(0);
|
||||
point = result.Read<uint>(1);
|
||||
}
|
||||
while (result.NextRow());
|
||||
|
||||
// We have the waypoint number and the GUID of the "master npc"
|
||||
// Text is enclosed in "<>", all other arguments not
|
||||
|
||||
// Check for argument
|
||||
if (subCommand != "del" && subCommand != "move")
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointArgumentreq, subCommand);
|
||||
return false;
|
||||
handler.SendSysMessage("|cff00ff00Path does not exist or target has no path|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (subCommand == "del")
|
||||
{
|
||||
handler.SendSysMessage("|cff00ff00DEBUG: wp modify del, PathID: |r|cff00ffff{0}|r", pathid);
|
||||
handler.SendSysMessage($"|cff00ff00DEBUG: .wp modify del, pathId: |r|cff00ffff{path.Id}|r, NodeId: |r|cff00ffff{node.Id}|r");
|
||||
|
||||
if (Creature.DeleteFromDB(target.GetSpawnId()))
|
||||
{
|
||||
uint displayId = target.GetDisplayId();
|
||||
|
||||
stmt = WorldDatabase.GetPreparedStatement(WorldStatements.DEL_WAYPOINT_DATA);
|
||||
stmt.AddValue(0, pathid);
|
||||
stmt.AddValue(1, point);
|
||||
DB.World.Execute(stmt);
|
||||
Global.WaypointMgr.DevisualizePath(handler.GetPlayer(), path);
|
||||
Global.WaypointMgr.DeleteNode(path, node);
|
||||
Global.WaypointMgr.ReloadPath(path.Id);
|
||||
Global.WaypointMgr.VisualizePath(handler.GetPlayer(), path, displayId);
|
||||
|
||||
stmt = WorldDatabase.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_DATA_POINT);
|
||||
stmt.AddValue(0, pathid);
|
||||
stmt.AddValue(1, point);
|
||||
DB.World.Execute(stmt);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.WaypointRemoved);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotremoved);
|
||||
return false;
|
||||
}
|
||||
} // del
|
||||
|
||||
if (subCommand == "move")
|
||||
handler.SendSysMessage(CypherStrings.WaypointRemoved);
|
||||
return true;
|
||||
}
|
||||
else if (subCommand == "move")
|
||||
{
|
||||
handler.SendSysMessage("|cff00ff00DEBUG: wp move, PathID: |r|cff00ffff{0}|r", pathid);
|
||||
handler.SendSysMessage("|cff00ff00DEBUG: .wp move, pathId: |r|cff00ffff%u|r, NodeId: |r|cff00ffff%u|r", path.Id, node.Id);
|
||||
|
||||
Player chr = handler.GetSession().GetPlayer();
|
||||
Map map = chr.GetMap();
|
||||
// What to do:
|
||||
// Move the visual spawnpoint
|
||||
// Respawn the owner of the waypoints
|
||||
if (Creature.DeleteFromDB(target.GetSpawnId()))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, 1);
|
||||
return false;
|
||||
}
|
||||
uint displayId = target.GetDisplayId();
|
||||
|
||||
// re-create
|
||||
Creature creature = Creature.CreateCreature(1, map, chr.GetPosition());
|
||||
if (creature == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
PhasingHandler.InheritPhaseShift(creature, chr);
|
||||
creature.SaveToDB(map.GetId(), new List<Difficulty>() { map.GetDifficultyID() });
|
||||
|
||||
ulong dbGuid = creature.GetSpawnId();
|
||||
|
||||
// current "wpCreature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
|
||||
creature.CleanupsBeforeDelete();
|
||||
creature.Dispose();
|
||||
|
||||
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
|
||||
creature = Creature.CreateCreatureFromDB(dbGuid, map, true, true);
|
||||
if (creature == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
stmt = WorldDatabase.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_DATA_POSITION);
|
||||
stmt.AddValue(0, chr.GetPositionX());
|
||||
stmt.AddValue(1, chr.GetPositionY());
|
||||
stmt.AddValue(2, chr.GetPositionZ());
|
||||
stmt.AddValue(3, chr.GetOrientation());
|
||||
stmt.AddValue(4, pathid);
|
||||
stmt.AddValue(5, point);
|
||||
DB.World.Execute(stmt);
|
||||
Global.WaypointMgr.DevisualizePath(handler.GetPlayer(), path);
|
||||
Global.WaypointMgr.MoveNode(path, node, handler.GetPlayer().GetPosition());
|
||||
Global.WaypointMgr.ReloadPath(path.Id);
|
||||
Global.WaypointMgr.VisualizePath(handler.GetPlayer(), path, displayId);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.WaypointChanged);
|
||||
|
||||
return true;
|
||||
} // move
|
||||
|
||||
if (arg.IsEmpty())
|
||||
{
|
||||
// show_str check for present in list of correct values, no sql injection possible
|
||||
DB.World.Execute("UPDATE waypoint_data SET {0}=null WHERE id='{1}' AND point='{2}'", subCommand, pathid, point); // Query can't be a prepared statement
|
||||
}
|
||||
else
|
||||
{
|
||||
// show_str check for present in list of correct values, no sql injection possible
|
||||
DB.World.Execute("UPDATE waypoint_data SET {0}='{1}' WHERE id='{2}' AND point='{3}'", subCommand, arg, pathid, point); // Query can't be a prepared statement
|
||||
}
|
||||
|
||||
handler.SendSysMessage(CypherStrings.WaypointChangedNo, subCommand);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
[Command("reload", RBACPermissions.CommandWpReload)]
|
||||
@@ -321,328 +226,122 @@ namespace Game.Chat.Commands
|
||||
}
|
||||
|
||||
[Command("show", RBACPermissions.CommandWpShow)]
|
||||
static bool HandleWpShowCommand(CommandHandler handler, string subCommand, uint? optionalPathId)
|
||||
static bool HandleWpShowCommand(CommandHandler handler, string subCommand, uint? optionalpathId)
|
||||
{
|
||||
// first arg: on, off, first, last
|
||||
if (subCommand.IsEmpty())
|
||||
return false;
|
||||
|
||||
uint pathId;
|
||||
Creature target = handler.GetSelectedCreature();
|
||||
|
||||
// Did player provide a PathID?
|
||||
uint pathId;
|
||||
|
||||
if (!optionalPathId.HasValue)
|
||||
// Did player provide a pathId?
|
||||
if (!optionalpathId.HasValue)
|
||||
{
|
||||
// No PathID provided
|
||||
// No pathId provided
|
||||
// . Player must have selected a creature
|
||||
|
||||
if (target == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.SelectCreature);
|
||||
handler.SendSysMessage(CypherStrings.SelectCreature);
|
||||
return false;
|
||||
}
|
||||
|
||||
pathId = target.GetWaypointPath();
|
||||
pathId = target.GetWaypointPathId();
|
||||
}
|
||||
else
|
||||
{
|
||||
// PathID provided
|
||||
// pathId provided
|
||||
// Warn if player also selected a creature
|
||||
// . Creature selection is ignored <-
|
||||
if (target != null)
|
||||
handler.SendSysMessage(CypherStrings.WaypointCreatselected);
|
||||
|
||||
pathId = optionalPathId.Value;
|
||||
pathId = optionalpathId.Value;
|
||||
}
|
||||
|
||||
// Show info for the selected waypoint
|
||||
if (subCommand == "info")
|
||||
{
|
||||
// Check if the user did specify a visual waypoint
|
||||
if (target == null || target.GetEntry() != 1)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpSelect);
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpSelect);
|
||||
return false;
|
||||
}
|
||||
|
||||
PreparedStatement stmt = WorldDatabase.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_ALL_BY_WPGUID);
|
||||
stmt.AddValue(0, target.GetSpawnId());
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
WaypointPath path = Global.WaypointMgr.GetPathByVisualGUID(target.GetGUID());
|
||||
if (path == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotfounddbproblem, target.GetSpawnId());
|
||||
handler.SendSysMessage("|cff00ff00Path does not exist or target has no path|r");
|
||||
handler.SetSentErrorMessage(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
WaypointNode node = Global.WaypointMgr.GetNodeByVisualGUID(target.GetGUID());
|
||||
if (node == null)
|
||||
{
|
||||
handler.SendSysMessage("|cff00ff00Path does not exist or target has no path|r");
|
||||
handler.SetSentErrorMessage(true);
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
handler.SendSysMessage("|cff00ffffDEBUG: .wp show info:|r");
|
||||
handler.SendSysMessage($"|cff00ff00Show info: Path Id: |r|cff00ffff{path.Id}|r");
|
||||
handler.SendSysMessage($"|cff00ff00Show info: Path MoveType: |r|cff00ffff{(uint)path.MoveType}|r");
|
||||
handler.SendSysMessage($"|cff00ff00Show info: Path Flags: |r|cff00ffff{(uint)path.Flags}|r");
|
||||
handler.SendSysMessage($"|cff00ff00Show info: Node Id: |r|cff00ffff{node.Id}|r");
|
||||
handler.SendSysMessage($"|cff00ff00Show info: Node Delay: |r|cff00ffff{node.Id}|r");
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (subCommand == "on")
|
||||
{
|
||||
WaypointPath path = Global.WaypointMgr.GetPath(pathId);
|
||||
if (path == null)
|
||||
{
|
||||
handler.SendSysMessage($"|cff00ff00Path does not exist: id {pathId}|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage("|cff00ffffDEBUG: wp show info:|r");
|
||||
do
|
||||
if (path.Nodes.Empty())
|
||||
{
|
||||
pathId = result.Read<uint>(0);
|
||||
uint point = result.Read<uint>(1);
|
||||
uint delay = result.Read<uint>(2);
|
||||
uint flag = result.Read<uint>(3);
|
||||
|
||||
handler.SendSysMessage("|cff00ff00Show info: for current point: |r|cff00ffff{0}|r|cff00ff00, Path ID: |r|cff00ffff{1}|r", point, pathId);
|
||||
handler.SendSysMessage("|cff00ff00Show info: delay: |r|cff00ffff{0}|r", delay);
|
||||
handler.SendSysMessage("|cff00ff00Show info: Move flag: |r|cff00ffff{0}|r", flag);
|
||||
}
|
||||
while (result.NextRow());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (subCommand == "on")
|
||||
{
|
||||
PreparedStatement stmt = WorldDatabase.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_POS_BY_ID);
|
||||
stmt.AddValue(0, pathId);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage("|cffff33ffPath no found.|r");
|
||||
return false;
|
||||
}
|
||||
|
||||
handler.SendSysMessage("|cff00ff00DEBUG: wp on, PathID: |cff00ffff{0}|r", pathId);
|
||||
|
||||
// Delete all visuals for this NPC
|
||||
stmt = WorldDatabase.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_WPGUID_BY_ID);
|
||||
stmt.AddValue(0, pathId);
|
||||
SQLResult result2 = DB.World.Query(stmt);
|
||||
|
||||
if (!result2.IsEmpty())
|
||||
{
|
||||
bool hasError = false;
|
||||
do
|
||||
{
|
||||
ulong wpguid = result2.Read<ulong>(0);
|
||||
|
||||
if (Creature.DeleteFromDB(wpguid))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotremoved, wpguid);
|
||||
hasError = true;
|
||||
}
|
||||
|
||||
}
|
||||
while (result2.NextRow());
|
||||
|
||||
if (hasError)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointToofar1);
|
||||
handler.SendSysMessage(CypherStrings.WaypointToofar2);
|
||||
handler.SendSysMessage(CypherStrings.WaypointToofar3);
|
||||
}
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
uint point = result.Read<uint>(0);
|
||||
float x = result.Read<float>(1);
|
||||
float y = result.Read<float>(2);
|
||||
float z = result.Read<float>(3);
|
||||
float o = result.Read<float>(4);
|
||||
|
||||
uint id = 1;
|
||||
|
||||
Player chr = handler.GetSession().GetPlayer();
|
||||
Map map = chr.GetMap();
|
||||
|
||||
Creature creature = Creature.CreateCreature(id, map, new Position(x, y, z, o));
|
||||
if (creature == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
PhasingHandler.InheritPhaseShift(creature, chr);
|
||||
creature.SaveToDB(map.GetId(), new List<Difficulty>() { map.GetDifficultyID() });
|
||||
|
||||
ulong dbGuid = creature.GetSpawnId();
|
||||
|
||||
// current "wpCreature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
|
||||
creature.CleanupsBeforeDelete();
|
||||
creature.Dispose();
|
||||
|
||||
// To call _LoadGoods(); _LoadQuests(); CreateTrainerSpells();
|
||||
creature = Creature.CreateCreatureFromDB(dbGuid, map, true, true);
|
||||
if (creature == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, id);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
creature.SetDisplayId(target.GetDisplayId());
|
||||
creature.SetObjectScale(0.5f);
|
||||
creature.SetLevel(Math.Min(point, SharedConst.StrongMaxLevel));
|
||||
}
|
||||
|
||||
// Set "wpguid" column to the visual waypoint
|
||||
stmt = WorldDatabase.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_DATA_WPGUID);
|
||||
stmt.AddValue(0, creature.GetSpawnId());
|
||||
stmt.AddValue(1, pathId);
|
||||
stmt.AddValue(2, point);
|
||||
DB.World.Execute(stmt);
|
||||
}
|
||||
while (result.NextRow());
|
||||
|
||||
handler.SendSysMessage("|cff00ff00Showing the current creature's path.|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (subCommand == "first")
|
||||
{
|
||||
handler.SendSysMessage("|cff00ff00DEBUG: wp first, pathid: {0}|r", pathId);
|
||||
|
||||
PreparedStatement stmt = WorldDatabase.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_POS_FIRST_BY_ID);
|
||||
stmt.AddValue(0, pathId);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotfound, pathId);
|
||||
return false;
|
||||
}
|
||||
|
||||
float x = result.Read<float>(0);
|
||||
float y = result.Read<float>(1);
|
||||
float z = result.Read<float>(2);
|
||||
float o = result.Read<float>(3);
|
||||
|
||||
Player chr = handler.GetSession().GetPlayer();
|
||||
Map map = chr.GetMap();
|
||||
|
||||
Creature creature = Creature.CreateCreature(1, map, new Position(x, y, z, 0));
|
||||
if (creature == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
PhasingHandler.InheritPhaseShift(creature, chr);
|
||||
creature.SaveToDB(map.GetId(), new List<Difficulty>() { map.GetDifficultyID() });
|
||||
|
||||
ulong dbGuid = creature.GetSpawnId();
|
||||
|
||||
// current "creature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
|
||||
creature.CleanupsBeforeDelete();
|
||||
creature.Dispose();
|
||||
|
||||
creature = Creature.CreateCreatureFromDB(dbGuid, map, true, true);
|
||||
if (creature == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpNotcreated, 1);
|
||||
return false;
|
||||
handler.SendSysMessage($"|cff00ff00Path does not have any nodes: id {pathId}|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
uint? displayId = null;
|
||||
if (target != null)
|
||||
displayId = target.GetDisplayId();
|
||||
|
||||
Global.WaypointMgr.VisualizePath(handler.GetPlayer(), path, displayId);
|
||||
|
||||
ObjectGuid guid = Global.WaypointMgr.GetVisualGUIDByNode(path.Id, path.Nodes.First().Id);
|
||||
if (!guid.IsEmpty())
|
||||
{
|
||||
creature.SetDisplayId(target.GetDisplayId());
|
||||
creature.SetObjectScale(0.5f);
|
||||
handler.SendSysMessage($"|cff00ff00Path with id {pathId} is already showing.|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage($"|cff00ff00Showing path with id {pathId}.|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (subCommand == "last")
|
||||
else if (subCommand == "off")
|
||||
{
|
||||
handler.SendSysMessage("|cff00ff00DEBUG: wp last, PathID: |r|cff00ffff{0}|r", pathId);
|
||||
|
||||
PreparedStatement stmt = WorldDatabase.GetPreparedStatement(WorldStatements.SEL_WAYPOINT_DATA_POS_LAST_BY_ID);
|
||||
stmt.AddValue(0, pathId);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
WaypointPath path = Global.WaypointMgr.GetPath(pathId);
|
||||
if (path == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotfoundlast, pathId);
|
||||
return false;
|
||||
handler.SendSysMessage($"|cff00ff00Path does not exist: id {pathId}|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
float x = result.Read<float>(0);
|
||||
float y = result.Read<float>(1);
|
||||
float z = result.Read<float>(2);
|
||||
float o = result.Read<float>(3);
|
||||
|
||||
Player chr = handler.GetSession().GetPlayer();
|
||||
Map map = chr.GetMap();
|
||||
Position pos = new(x, y, z, o);
|
||||
|
||||
Creature creature = Creature.CreateCreature(1, map, pos);
|
||||
if (creature == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotcreated, 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
PhasingHandler.InheritPhaseShift(creature, chr);
|
||||
creature.SaveToDB(map.GetId(), new List<Difficulty>() { map.GetDifficultyID() });
|
||||
|
||||
ulong dbGuid = creature.GetSpawnId();
|
||||
|
||||
// current "creature" variable is deleted and created fresh new, otherwise old values might trigger asserts or cause undefined behavior
|
||||
creature.CleanupsBeforeDelete();
|
||||
creature.Dispose();
|
||||
|
||||
creature = Creature.CreateCreatureFromDB(dbGuid, map, true, true);
|
||||
if (creature == null)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotcreated, 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target != null)
|
||||
{
|
||||
creature.SetDisplayId(target.GetDisplayId());
|
||||
creature.SetObjectScale(0.5f);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (subCommand == "off")
|
||||
{
|
||||
PreparedStatement stmt = WorldDatabase.GetPreparedStatement(WorldStatements.SEL_CREATURE_BY_ID);
|
||||
stmt.AddValue(0, 1);
|
||||
SQLResult result = DB.World.Query(stmt);
|
||||
|
||||
if (result.IsEmpty())
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpNotfound);
|
||||
return false;
|
||||
}
|
||||
bool hasError = false;
|
||||
do
|
||||
{
|
||||
ulong lowguid = result.Read<ulong>(0);
|
||||
|
||||
if (Creature.DeleteFromDB(lowguid))
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointNotremoved, lowguid);
|
||||
hasError = true;
|
||||
}
|
||||
}
|
||||
while (result.NextRow());
|
||||
// set "wpguid" column to "empty" - no visual waypoint spawned
|
||||
stmt = WorldDatabase.GetPreparedStatement(WorldStatements.UPD_WAYPOINT_DATA_ALL_WPGUID);
|
||||
|
||||
DB.World.Execute(stmt);
|
||||
//DB.World.PExecute("UPDATE creature_movement SET wpguid = '0' WHERE wpguid <> '0'");
|
||||
|
||||
if (hasError)
|
||||
{
|
||||
handler.SendSysMessage(CypherStrings.WaypointToofar1);
|
||||
handler.SendSysMessage(CypherStrings.WaypointToofar2);
|
||||
handler.SendSysMessage(CypherStrings.WaypointToofar3);
|
||||
}
|
||||
Global.WaypointMgr.DevisualizePath(handler.GetPlayer(), path);
|
||||
|
||||
handler.SendSysMessage(CypherStrings.WaypointVpAllremoved);
|
||||
return true;
|
||||
}
|
||||
|
||||
handler.SendSysMessage("|cffff33ffDEBUG: wpshow - no valid command found|r");
|
||||
handler.SendSysMessage("|cffff33ffDEBUG: .wp show - no valid command found|r");
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -664,7 +363,7 @@ namespace Game.Chat.Commands
|
||||
}
|
||||
|
||||
CreatureAddon addon = Global.ObjectMgr.GetCreatureAddon(guidLow);
|
||||
if (addon == null || addon.path_id == 0)
|
||||
if (addon == null || addon.PathId == 0)
|
||||
{
|
||||
handler.SendSysMessage("|cffff33ffTarget does not have a loaded path.|r");
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user