diff options
author | Shauren <shauren.trinity@gmail.com> | 2025-06-25 12:16:03 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2025-06-25 12:16:03 +0200 |
commit | e284dc0a8025c5e4da65271914c88d9afac95667 (patch) | |
tree | 225f9bd64fd7a6d37b2e3a5b02c7a088da998456 | |
parent | 53f71a9838adf466783bde5240434961bf82f8ce (diff) |
Core/Commands: Waypoint command fixes
* .wp add will now add data to waypoint_path table
* .wp reload will no longer crash the server
* Replace deprecated command handler arguments
6 files changed, 97 insertions, 150 deletions
diff --git a/src/server/database/Database/Implementation/WorldDatabase.cpp b/src/server/database/Database/Implementation/WorldDatabase.cpp index 9ddb30f8a8c..d26903117d4 100644 --- a/src/server/database/Database/Implementation/WorldDatabase.cpp +++ b/src/server/database/Database/Implementation/WorldDatabase.cpp @@ -44,14 +44,15 @@ void WorldDatabaseConnection::DoPrepareStatements() PrepareStatement(WORLD_UPD_CREATURE_WANDER_DISTANCE, "UPDATE creature SET wander_distance = ?, MovementType = ? WHERE guid = ?", CONNECTION_ASYNC); PrepareStatement(WORLD_UPD_CREATURE_SPAWN_TIME_SECS, "UPDATE creature SET spawntimesecs = ? WHERE guid = ?", CONNECTION_ASYNC); PrepareStatement(WORLD_INS_CREATURE_FORMATION, "INSERT INTO creature_formations (leaderGUID, memberGUID, dist, angle, groupAI) VALUES (?, ?, ?, ?, ?)", CONNECTION_ASYNC); - PrepareStatement(WORLD_SEL_WAYPOINT_PATH_BY_PATHID, "SELECT PathId, MoveType, Flags FROM waypoint_path WHERE PathId = ?", CONNECTION_SYNCH); + PrepareStatement(WORLD_SEL_WAYPOINT_PATH, "SELECT PathId, MoveType, Flags, Velocity FROM waypoint_path WHERE PathId = ? OR 1 = ?", CONNECTION_SYNCH); + PrepareStatement(WORLD_INS_WAYPOINT_PATH, "INSERT INTO waypoint_path (PathId, MoveType, Flags, Velocity, Comment) VALUES (?, ?, ?, ?, ?)", CONNECTION_ASYNC); PrepareStatement(WORLD_INS_WAYPOINT_PATH_NODE, "INSERT INTO waypoint_path_node (PathId, NodeId, PositionX, PositionY, PositionZ, Orientation) VALUES (?, ?, ?, ?, ?, ?)", CONNECTION_ASYNC); + PrepareStatement(WORLD_SEL_WAYPOINT_PATH_NODE, "SELECT PathId, NodeId, PositionX, PositionY, PositionZ, Orientation, Delay FROM waypoint_path_node WHERE PathId = ? OR 1 = ? ORDER BY NodeId", CONNECTION_SYNCH); PrepareStatement(WORLD_DEL_WAYPOINT_PATH_NODE, "DELETE FROM waypoint_path_node WHERE PathId = ? AND NodeId = ?", CONNECTION_ASYNC); PrepareStatement(WORLD_UPD_WAYPOINT_PATH_NODE, "UPDATE waypoint_path_node SET NodeId = NodeId - 1 WHERE PathId = ? AND NodeId > ?", CONNECTION_ASYNC); PrepareStatement(WORLD_UPD_WAYPOINT_PATH_NODE_POSITION, "UPDATE waypoint_path_node SET PositionX = ?, PositionY = ?, PositionZ = ?, Orientation = ? WHERE PathId = ? AND NodeId = ?", CONNECTION_ASYNC); PrepareStatement(WORLD_SEL_WAYPOINT_PATH_NODE_MAX_PATHID, "SELECT MAX(PathId) FROM waypoint_path_node", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_WAYPOINT_PATH_NODE_MAX_NODEID, "SELECT MAX(NodeId) FROM waypoint_path_node WHERE PathId = ?", CONNECTION_SYNCH); - PrepareStatement(WORLD_SEL_WAYPOINT_PATH_NODE_BY_PATHID, "SELECT PathId, NodeId, PositionX, PositionY, PositionZ, Orientation, Delay FROM waypoint_path_node WHERE PathId = ? ORDER BY NodeId", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_WAYPOINT_PATH_NODE_POS_BY_PATHID, "SELECT NodeId, PositionX, PositionY, PositionZ, Orientation FROM waypoint_path_node WHERE PathId = ?", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_WAYPOINT_PATH_NODE_POS_FIRST_BY_PATHID, "SELECT PositionX, PositionY, PositionZ, Orientation FROM waypoint_path_node WHERE NodeId = 1 AND PathId = ?", CONNECTION_SYNCH); PrepareStatement(WORLD_SEL_WAYPOINT_PATH_NODE_POS_LAST_BY_PATHID, "SELECT PositionX, PositionY, PositionZ, Orientation FROM waypoint_path_node WHERE PathId = ? ORDER BY NodeId DESC LIMIT 1", CONNECTION_SYNCH); diff --git a/src/server/database/Database/Implementation/WorldDatabase.h b/src/server/database/Database/Implementation/WorldDatabase.h index d24be6862b1..4bc54d47d5f 100644 --- a/src/server/database/Database/Implementation/WorldDatabase.h +++ b/src/server/database/Database/Implementation/WorldDatabase.h @@ -49,13 +49,14 @@ enum WorldDatabaseStatements : uint32 WORLD_UPD_CREATURE_WANDER_DISTANCE, WORLD_UPD_CREATURE_SPAWN_TIME_SECS, WORLD_INS_CREATURE_FORMATION, - WORLD_SEL_WAYPOINT_PATH_BY_PATHID, + WORLD_SEL_WAYPOINT_PATH, + WORLD_INS_WAYPOINT_PATH, + WORLD_SEL_WAYPOINT_PATH_NODE, WORLD_INS_WAYPOINT_PATH_NODE, WORLD_DEL_WAYPOINT_PATH_NODE, WORLD_UPD_WAYPOINT_PATH_NODE, WORLD_UPD_WAYPOINT_PATH_NODE_POSITION, WORLD_SEL_WAYPOINT_PATH_NODE_MAX_PATHID, - WORLD_SEL_WAYPOINT_PATH_NODE_BY_PATHID, WORLD_SEL_WAYPOINT_PATH_NODE_POS_BY_PATHID, WORLD_SEL_WAYPOINT_PATH_NODE_POS_FIRST_BY_PATHID, WORLD_SEL_WAYPOINT_PATH_NODE_POS_LAST_BY_PATHID, diff --git a/src/server/game/Movement/Waypoints/WaypointDefines.h b/src/server/game/Movement/Waypoints/WaypointDefines.h index 68225a7e8b5..eb388481f71 100644 --- a/src/server/game/Movement/Waypoints/WaypointDefines.h +++ b/src/server/game/Movement/Waypoints/WaypointDefines.h @@ -51,15 +51,7 @@ struct WaypointNode { constexpr WaypointNode() : Id(0), X(0.f), Y(0.f), Z(0.f), MoveType(WaypointMoveType::Walk) { } constexpr WaypointNode(uint32 id, float x, float y, float z, Optional<float> orientation = { }, Optional<Milliseconds> delay = {}) - { - Id = id; - X = x; - Y = y; - Z = z; - Orientation = orientation; - Delay = delay; - MoveType = WaypointMoveType::Walk; - } + : Id(id), X(x), Y(y), Z(z), Orientation(orientation), Delay(delay), MoveType(WaypointMoveType::Walk) { } uint32 Id; float X; @@ -74,12 +66,7 @@ struct WaypointPath { WaypointPath() = default; WaypointPath(uint32 id, std::vector<WaypointNode>&& nodes, WaypointMoveType moveType = WaypointMoveType::Walk, WaypointPathFlags flags = WaypointPathFlags::None) - { - Id = id; - Nodes = std::move(nodes); - Flags = flags; - MoveType = moveType; - } + : Nodes(std::move(nodes)), Id(id), MoveType(moveType), Flags(flags) { } std::vector<WaypointNode> Nodes; std::vector<std::pair<std::size_t, std::size_t>> ContinuousSegments; diff --git a/src/server/game/Movement/Waypoints/WaypointManager.cpp b/src/server/game/Movement/Waypoints/WaypointManager.cpp index a1ccec0efcd..c1e8d4dde36 100644 --- a/src/server/game/Movement/Waypoints/WaypointManager.cpp +++ b/src/server/game/Movement/Waypoints/WaypointManager.cpp @@ -22,9 +22,13 @@ #include "MapUtils.h" #include "ObjectAccessor.h" #include "Optional.h" +#include "QueryResultStructured.h" #include "TemporarySummon.h" #include "Unit.h" +DEFINE_FIELD_ACCESSOR_CACHE(WaypointMgr::PathQueryResult, PreparedResultSet, (PathId)(MoveType)(Flags)(Velocity)); +DEFINE_FIELD_ACCESSOR_CACHE(WaypointMgr::PathNodeQueryResult, PreparedResultSet, (PathId)(NodeId)(PositionX)(PositionY)(PositionZ)(Orientation)(Delay)); + WaypointMgr::WaypointMgr() = default; WaypointMgr::~WaypointMgr() = default; @@ -41,8 +45,11 @@ void WaypointMgr::_LoadPaths() _pathStore.clear(); - // 0 1 2 3 - QueryResult result = WorldDatabase.Query("SELECT PathId, MoveType, Flags, Velocity FROM waypoint_path"); + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_PATH); + stmt->setUInt32(0, 0); + stmt->setUInt32(1, 1); + + PreparedQueryResult result = WorldDatabase.Query(stmt); if (!result) { @@ -54,7 +61,7 @@ void WaypointMgr::_LoadPaths() do { - LoadPathFromDB(result->Fetch()); + LoadPathFromDB({ .Result = *result }); ++count; } while (result->NextRow()); @@ -64,8 +71,12 @@ void WaypointMgr::_LoadPaths() void WaypointMgr::_LoadPathNodes() { uint32 oldMSTime = getMSTime(); - // 0 1 2 3 4 5 6 - QueryResult result = WorldDatabase.Query("SELECT PathId, NodeId, PositionX, PositionY, PositionZ, Orientation, Delay FROM waypoint_path_node ORDER BY PathId, NodeId"); + + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_PATH_NODE); + stmt->setUInt32(0, 0); + stmt->setUInt32(1, 1); + + PreparedQueryResult result = WorldDatabase.Query(stmt); if (!result) { @@ -77,7 +88,7 @@ void WaypointMgr::_LoadPathNodes() do { - LoadPathNodesFromDB(result->Fetch()); + LoadPathNodesFromDB({ .Result = *result }); ++count; } while (result->NextRow()); @@ -85,13 +96,13 @@ void WaypointMgr::_LoadPathNodes() TC_LOG_INFO("server.loading", ">> Loaded {} waypoint path nodes in {} ms", count, GetMSTimeDiffToNow(oldMSTime)); } -void WaypointMgr::LoadPathFromDB(Field* fields) +void WaypointMgr::LoadPathFromDB(PathQueryResult const& fields) { - uint32 pathId = fields[0].GetUInt32(); + uint32 pathId = fields.PathId().GetUInt32(); WaypointPath& path = _pathStore[pathId]; - path.MoveType = WaypointMoveType(fields[1].GetUInt8()); + path.MoveType = WaypointMoveType(fields.MoveType().GetUInt8()); if (path.MoveType >= WaypointMoveType::Max) { TC_LOG_ERROR("sql.sql", "PathId {} in `waypoint_path` has invalid MoveType {}, ignoring", pathId, AsUnderlyingType(path.MoveType)); @@ -99,8 +110,8 @@ void WaypointMgr::LoadPathFromDB(Field* fields) } path.Id = pathId; - path.Flags = WaypointPathFlags(fields[2].GetUInt8()); - path.Velocity = fields[3].GetFloatOrNull(); + path.Flags = WaypointPathFlags(fields.Flags().GetUInt8()); + path.Velocity = fields.Velocity().GetFloatOrNull(); if (path.Velocity && *path.Velocity <= 0.0f) { @@ -111,9 +122,9 @@ void WaypointMgr::LoadPathFromDB(Field* fields) path.Nodes.clear(); } -void WaypointMgr::LoadPathNodesFromDB(Field* fields) +void WaypointMgr::LoadPathNodesFromDB(PathNodeQueryResult const& fields) { - uint32 pathId = fields[0].GetUInt32(); + uint32 pathId = fields.PathId().GetUInt32(); WaypointPath* path = Trinity::Containers::MapGetValuePtr(_pathStore, pathId); if (!path) @@ -122,19 +133,19 @@ void WaypointMgr::LoadPathNodesFromDB(Field* fields) return; } - float x = fields[2].GetFloat(); - float y = fields[3].GetFloat(); - float z = fields[4].GetFloat(); - Optional<float> o = fields[5].GetFloatOrNull(); + float x = fields.PositionX().GetFloat(); + float y = fields.PositionY().GetFloat(); + float z = fields.PositionZ().GetFloat(); + Optional<float> o = fields.Orientation().GetFloatOrNull(); Optional<Milliseconds> delay; - if (uint32 delayMs = fields[6].GetUInt32()) + if (uint32 delayMs = fields.Delay().GetUInt32()) delay.emplace(delayMs); Trinity::NormalizeMapCoord(x); Trinity::NormalizeMapCoord(y); - path->Nodes.emplace_back(fields[1].GetUInt32(), x, y, z, o, delay); + path->Nodes.emplace_back(fields.NodeId().GetUInt32(), x, y, z, o, delay); } void WaypointMgr::DoPostLoadingChecks() @@ -161,8 +172,9 @@ void WaypointMgr::ReloadPath(uint32 pathId) { // waypoint_path { - WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_PATH_BY_PATHID); + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_PATH); stmt->setUInt32(0, pathId); + stmt->setUInt32(1, 0); PreparedQueryResult result = WorldDatabase.Query(stmt); @@ -174,14 +186,15 @@ void WaypointMgr::ReloadPath(uint32 pathId) do { - LoadPathFromDB(result->Fetch()); + LoadPathFromDB({ .Result = *result }); } while (result->NextRow()); } // waypoint_path_data { - WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_PATH_NODE_BY_PATHID); + WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_PATH_NODE); stmt->setUInt32(0, pathId); + stmt->setUInt32(1, 0); PreparedQueryResult result = WorldDatabase.Query(stmt); @@ -193,7 +206,7 @@ void WaypointMgr::ReloadPath(uint32 pathId) do { - LoadPathNodesFromDB(result->Fetch()); + LoadPathNodesFromDB({ .Result = *result }); } while (result->NextRow()); if (WaypointPath* path = Trinity::Containers::MapGetValuePtr(_pathStore, pathId)) diff --git a/src/server/game/Movement/Waypoints/WaypointManager.h b/src/server/game/Movement/Waypoints/WaypointManager.h index 31169de46a1..b7455507d5e 100644 --- a/src/server/game/Movement/Waypoints/WaypointManager.h +++ b/src/server/game/Movement/Waypoints/WaypointManager.h @@ -30,6 +30,9 @@ class Unit; class TC_GAME_API WaypointMgr { + struct PathQueryResult; + struct PathNodeQueryResult; + public: WaypointMgr(WaypointMgr const&) = delete; WaypointMgr(WaypointMgr&&) = delete; @@ -43,8 +46,8 @@ class TC_GAME_API WaypointMgr // Loads all paths from database, should only run on startup void LoadPaths(); - void LoadPathFromDB(Field* fields); - void LoadPathNodesFromDB(Field* fields); + void LoadPathFromDB(PathQueryResult const& fields); + void LoadPathNodesFromDB(PathNodeQueryResult const& fields); void DoPostLoadingChecks(); void VisualizePath(Unit* owner, WaypointPath const* path, Optional<uint32> displayId); diff --git a/src/server/scripts/Commands/cs_wp.cpp b/src/server/scripts/Commands/cs_wp.cpp index 498570496cc..1e60b0fb7dd 100644 --- a/src/server/scripts/Commands/cs_wp.cpp +++ b/src/server/scripts/Commands/cs_wp.cpp @@ -35,31 +35,28 @@ EndScriptData */ #include "Player.h" #include "RBAC.h" #include "WaypointManager.h" -#include "WorldSession.h" -#if TRINITY_COMPILER == TRINITY_COMPILER_GNU -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif +using namespace Trinity::ChatCommands; class wp_commandscript : public CommandScript { public: wp_commandscript() : CommandScript("wp_commandscript") { } - std::vector<ChatCommand> GetCommands() const override + ChatCommandTable GetCommands() const override { - static std::vector<ChatCommand> wpCommandTable = + static ChatCommandTable wpCommandTable = { - { "add", rbac::RBAC_PERM_COMMAND_WP_ADD, false, &HandleWpAddCommand, "" }, - { "load", rbac::RBAC_PERM_COMMAND_WP_LOAD, false, &HandleWpLoadCommand, "" }, - { "modify", rbac::RBAC_PERM_COMMAND_WP_MODIFY, false, &HandleWpModifyCommand, "" }, - { "unload", rbac::RBAC_PERM_COMMAND_WP_UNLOAD, false, &HandleWpUnLoadCommand, "" }, - { "reload", rbac::RBAC_PERM_COMMAND_WP_RELOAD, false, &HandleWpReloadCommand, "" }, - { "show", rbac::RBAC_PERM_COMMAND_WP_SHOW, false, &HandleWpShowCommand, "" }, + { "add", HandleWpAddCommand, rbac::RBAC_PERM_COMMAND_WP_ADD, Console::No }, + { "load", HandleWpLoadCommand, rbac::RBAC_PERM_COMMAND_WP_LOAD, Console::No }, + { "modify", HandleWpModifyCommand, rbac::RBAC_PERM_COMMAND_WP_MODIFY, Console::No }, + { "unload", HandleWpUnLoadCommand, rbac::RBAC_PERM_COMMAND_WP_UNLOAD, Console::No }, + { "reload", HandleWpReloadCommand, rbac::RBAC_PERM_COMMAND_WP_RELOAD, Console::No }, + { "show", HandleWpShowCommand, rbac::RBAC_PERM_COMMAND_WP_SHOW, Console::No }, }; - static std::vector<ChatCommand> commandTable = + static ChatCommandTable commandTable = { - { "wp", rbac::RBAC_PERM_COMMAND_WP, false, nullptr, "", wpCommandTable }, + { "wp", wpCommandTable }, }; return commandTable; } @@ -80,22 +77,15 @@ public: * -> adds a waypoint to the currently selected creature * * - * @param args if the user did not provide a GUID, it is NULL + * @param pathid (optional) * * @return true - command did succeed, false - something went wrong */ - static bool HandleWpAddCommand(ChatHandler* handler, char const* args) + static bool HandleWpAddCommand(ChatHandler* handler, Optional<uint32> pathid) { - // optional - char* path_number = nullptr; - uint32 pathid = 0; - - if (*args) - path_number = strtok((char*)args, " "); - Creature* target = handler->getSelectedCreature(); - if (!path_number) + if (!pathid) { if (target) pathid = target->GetWaypointPathId(); @@ -108,22 +98,27 @@ public: uint32 maxpathid = result->Fetch()->GetInt32(); pathid = maxpathid+1; handler->PSendSysMessage("%s%s|r", "|cff00ff00", "New path started."); + + stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_WAYPOINT_PATH); + stmt->setUInt32(0, *pathid); // PathId + stmt->setUInt8(1, AsUnderlyingType(WaypointMoveType::Walk)); // MoveType + stmt->setUInt8(2, AsUnderlyingType(WaypointPathFlags::None)); // Flags + stmt->setNull(3); // Velocity + stmt->setString(4, "Created by .wp add"sv); // Comment + WorldDatabase.Execute(stmt); } } - else - pathid = atoi(path_number); // PathId -> ID of the Path // point -> number of the waypoint (if not 0) - - if (!pathid) + if (!pathid || pathid == 0u) { handler->PSendSysMessage("%s%s|r", "|cffff33ff", "Current creature haven't loaded path."); return true; } WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_WAYPOINT_PATH_NODE_MAX_NODEID); - stmt->setUInt32(0, pathid); + stmt->setUInt32(0, *pathid); PreparedQueryResult result = WorldDatabase.Query(stmt); uint32 nodeId = 0; @@ -131,10 +126,9 @@ public: nodeId = (*result)[0].GetUInt32() + 1; Player* player = handler->GetPlayer(); - //Map* map = player->GetMap(); stmt = WorldDatabase.GetPreparedStatement(WORLD_INS_WAYPOINT_PATH_NODE); - stmt->setUInt32(0, pathid); + stmt->setUInt32(0, *pathid); stmt->setUInt32(1, nodeId); stmt->setFloat(2, player->GetPositionX()); stmt->setFloat(3, player->GetPositionY()); @@ -146,38 +140,23 @@ public: { uint32 displayId = target->GetDisplayId(); - WaypointPath const* path = sWaypointMgr->GetPath(pathid); + WaypointPath const* path = sWaypointMgr->GetPath(*pathid); if (!path) return true; sWaypointMgr->DevisualizePath(handler->GetPlayer(), path); - sWaypointMgr->ReloadPath(pathid); + sWaypointMgr->ReloadPath(*pathid); sWaypointMgr->VisualizePath(handler->GetPlayer(), path, displayId); } - handler->PSendSysMessage("%s%s%u%s%u%s|r", "|cff00ff00", "PathID: |r|cff00ffff", pathid, "|r|cff00ff00: Waypoint |r|cff00ffff", nodeId, "|r|cff00ff00 created. "); + handler->PSendSysMessage("%s%s%u%s%u%s|r", "|cff00ff00", "PathID: |r|cff00ffff", *pathid, "|r|cff00ff00: Waypoint |r|cff00ffff", nodeId, "|r|cff00ff00 created. "); return true; } // HandleWpAddCommand - static bool HandleWpLoadCommand(ChatHandler* handler, char const* args) + static bool HandleWpLoadCommand(ChatHandler* handler, uint32 pathid) { - if (!*args) - return false; - - // optional - char* path_number = nullptr; - - if (*args) - path_number = strtok((char*)args, " "); - - uint32 pathid = 0; - ObjectGuid::LowType guidLow = UI64LIT(0); Creature* target = handler->getSelectedCreature(); - // Did player provide a PathId? - if (!path_number) - return false; - if (!target) { handler->SendSysMessage(LANG_SELECT_CREATURE); @@ -192,15 +171,13 @@ public: return false; } - pathid = atoi(path_number); - if (!pathid) { handler->PSendSysMessage("%s%s|r", "|cffff33ff", "No valid path number provided."); return true; } - guidLow = target->GetSpawnId(); + ObjectGuid::LowType guidLow = target->GetSpawnId(); WorldDatabasePreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_CREATURE_ADDON_BY_GUID); @@ -238,13 +215,8 @@ public: return true; } - static bool HandleWpReloadCommand(ChatHandler* handler, char const* args) + static bool HandleWpReloadCommand(ChatHandler* handler, uint32 id) { - if (!*args) - return false; - - uint32 id = atoi(args); - if (!id) return false; @@ -253,7 +225,7 @@ public: return true; } - static bool HandleWpUnLoadCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleWpUnLoadCommand(ChatHandler* handler) { Creature* target = handler->getSelectedCreature(); WorldDatabasePreparedStatement* stmt = nullptr; @@ -297,20 +269,8 @@ public: return true; } - static bool HandleWpModifyCommand(ChatHandler* handler, char const* args) + static bool HandleWpModifyCommand(ChatHandler* handler, Variant<EXACT_SEQUENCE("del"), EXACT_SEQUENCE("move")> show) { - if (!*args) - return false; - - // first arg: add del text emote spell waittime move - char* show_str = strtok((char*)args, " "); - if (!show_str) - { - return false; - } - - std::string show = show_str; - // Did user provide a GUID // or did the user select a creature? // -> variable lowguid is filled with the GUID of the NPC @@ -339,7 +299,7 @@ public: return false; } - if (show == "del") + if (show.holds_alternative<EXACT_SEQUENCE("del")>()) { handler->PSendSysMessage("|cff00ff00DEBUG: .wp modify del, PathId: |r|cff00ffff%u|r, NodeId: |r|cff00ffff%u|r", path->Id, node->Id); @@ -353,9 +313,9 @@ public: handler->SendSysMessage(LANG_WAYPOINT_REMOVED); return true; } - else if (show == "move") + else if (show.holds_alternative<EXACT_SEQUENCE("move")>()) { - handler->PSendSysMessage("|cff00ff00DEBUG: .wp move, PathId: |r|cff00ffff%u|r, NodeId: |r|cff00ffff%u|r", path->Id, node->Id); + handler->PSendSysMessage("|cff00ff00DEBUG: .wp modify move, PathId: |r|cff00ffff%u|r, NodeId: |r|cff00ffff%u|r", path->Id, node->Id); uint32 displayId = target->GetDisplayId(); @@ -370,24 +330,12 @@ public: return false; } - static bool HandleWpShowCommand(ChatHandler* handler, char const* args) + static bool HandleWpShowCommand(ChatHandler* handler, Variant<EXACT_SEQUENCE("off"), EXACT_SEQUENCE("on"), EXACT_SEQUENCE("info")> show, Optional<uint32> pathid) { - if (!*args) - return false; - - // first arg: on, off, first, last - char* show_str = strtok((char*)args, " "); - if (!show_str) - return false; - - // second arg: GUID (optional, if a creature is selected) - char* guid_str = strtok((char*)nullptr, " "); - - uint32 pathid = 0; Creature* target = handler->getSelectedCreature(); // Did player provide a PathID? - if (!guid_str) + if (!pathid) { // No PathID provided // -> Player must have selected a creature @@ -408,16 +356,10 @@ public: // -> Creature selection is ignored <- if (target) handler->SendSysMessage(LANG_WAYPOINT_CREATSELECTED); - - pathid = Trinity::StringTo<uint32>(guid_str).value_or(0); } - std::string show = show_str; - - //handler->PSendSysMessage("wpshow - show: %s", show); - // Show info for the selected waypoint - if (show == "info") + if (show.holds_alternative<EXACT_SEQUENCE("info")>()) { if (!target || target->GetEntry() != VISUAL_WAYPOINT) { @@ -451,18 +393,18 @@ public: return true; } - else if (show == "on") + else if (show.holds_alternative<EXACT_SEQUENCE("on")>()) { - WaypointPath const* path = sWaypointMgr->GetPath(pathid); + WaypointPath const* path = sWaypointMgr->GetPath(*pathid); if (!path) { - handler->PSendSysMessage("|cff00ff00Path does not exist: id %u|r", pathid); + handler->PSendSysMessage("|cff00ff00Path does not exist: id %u|r", *pathid); return true; } if (path->Nodes.empty()) { - handler->PSendSysMessage("|cff00ff00Path does not have any nodes: id %u|r", pathid); + handler->PSendSysMessage("|cff00ff00Path does not have any nodes: id %u|r", *pathid); return true; } @@ -475,19 +417,19 @@ public: ObjectGuid const& guid = sWaypointMgr->GetVisualGUIDByNode(path->Id, path->Nodes.front().Id); if (!guid.IsEmpty()) { - handler->SendSysMessage("|cff00ff00Path with id %u is already showing.|r", pathid); + handler->SendSysMessage("|cff00ff00Path with id %u is already showing.|r", *pathid); return true; } - handler->SendSysMessage("|cff00ff00Showing path with id %u.|r", pathid); + handler->SendSysMessage("|cff00ff00Showing path with id %u.|r", *pathid); return true; } - else if (show == "off") + else if (show.holds_alternative<EXACT_SEQUENCE("off")>()) { - WaypointPath const* path = sWaypointMgr->GetPath(pathid); + WaypointPath const* path = sWaypointMgr->GetPath(*pathid); if (!path) { - handler->PSendSysMessage("|cff00ff00Path does not exist: id %u|r", pathid); + handler->PSendSysMessage("|cff00ff00Path does not exist: id %u|r", *pathid); return true; } |