From fc484d0b1cc7160a9a1481ec5c7fa0a1125eb985 Mon Sep 17 00:00:00 2001 From: Kinglykrab <89047260+Kinglykrab@users.noreply.github.com> Date: Fri, 6 May 2022 19:13:28 -0400 Subject: [PATCH] [Commands] Cleanup #gassign Command. (#2101) * [Commands] Cleanup #gassign Command. - Cleanup messages and logic. * Update gassign.cpp * Update gassign.cpp --- zone/command.cpp | 2 +- zone/gm_commands/gassign.cpp | 21 +++++++++++++++------ zone/waypoints.cpp | 31 ++++++++++++++++++++++--------- zone/zonedb.h | 2 +- 4 files changed, 39 insertions(+), 17 deletions(-) diff --git a/zone/command.cpp b/zone/command.cpp index 761f60a90..41aa2a1a7 100755 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -188,7 +188,7 @@ int command_init(void) command_add("flymode", "[0/1/2/3/4/5] - Set your or your player target's flymode to ground/flying/levitate/water/floating/levitate_running", AccountStatus::Guide, command_flymode) || command_add("fov", "- Check wether you're behind or in your target's field of view", AccountStatus::QuestTroupe, command_fov) || command_add("freeze", "- Freeze your target", AccountStatus::QuestTroupe, command_freeze) || - command_add("gassign", "[id] - Assign targetted NPC to predefined wandering grid id", AccountStatus::GMAdmin, command_gassign) || + command_add("gassign", "[Grid ID] - Assign targetted NPC to predefined wandering grid id", AccountStatus::GMAdmin, command_gassign) || command_add("gearup", "Developer tool to quickly equip a character", AccountStatus::GMMgmt, command_gearup) || command_add("gender", "[0/1/2] - Change your or your target's gender to male/female/neuter", AccountStatus::Guide, command_gender) || command_add("getplayerburiedcorpsecount", "- Get your or your target's total number of buried player corpses.", AccountStatus::GMAdmin, command_getplayerburiedcorpsecount) || diff --git a/zone/gm_commands/gassign.cpp b/zone/gm_commands/gassign.cpp index 1a830b2fd..81260ff8a 100755 --- a/zone/gm_commands/gassign.cpp +++ b/zone/gm_commands/gassign.cpp @@ -2,13 +2,22 @@ void command_gassign(Client *c, const Seperator *sep) { - if (sep->IsNumber(1) && c->GetTarget() && c->GetTarget()->IsNPC() && - c->GetTarget()->CastToNPC()->GetSpawnPointID() > 0) { - int spawn2id = c->GetTarget()->CastToNPC()->GetSpawnPointID(); - database.AssignGrid(c, atoi(sep->arg[1]), spawn2id); + if (!c->GetTarget() || !c->GetTarget()->IsNPC()) { + c->Message(Chat::White, "You must target an NPC to use this command."); + return; } - else { - c->Message(Chat::White, "Usage: #gassign [num] - must have an npc target!"); + + int arguments = sep->argnum; + if (!arguments || !sep->IsNumber(1)) { + c->Message(Chat::White, "Usage: #gassign [Grid ID]"); + return; + } + + auto grid_id = std::stoul(sep->arg[1]); + + auto target = c->GetTarget()->CastToNPC(); + if (target->GetSpawnPointID() > 0) { + database.AssignGrid(c, grid_id, target->GetID()); } } diff --git a/zone/waypoints.cpp b/zone/waypoints.cpp index e27ec4e03..91016544c 100644 --- a/zone/waypoints.cpp +++ b/zone/waypoints.cpp @@ -1041,18 +1041,31 @@ bool ZoneDatabase::GetWaypoints(uint32 grid, uint16 zoneid, uint32 num, wplist* return true; } -void ZoneDatabase::AssignGrid(Client *client, int grid, int spawn2id) { - std::string query = StringFormat("UPDATE spawn2 SET pathgrid = %d WHERE id = %d", grid, spawn2id); - auto results = QueryDatabase(query); +void ZoneDatabase::AssignGrid(Client *client, uint32 grid_id, uint32 entity_id) { + auto target_npc = entity_list.GetNPCByID(entity_id); + auto spawn2_id = target_npc ? target_npc->GetSpawnPointID() : 0; + if (spawn2_id) { + std::string query = fmt::format( + "UPDATE spawn2 SET pathgrid = {} WHERE id = {}", + grid_id, + spawn2_id + ); + auto results = QueryDatabase(query); - if (!results.Success()) - return; + if (!results.Success() || results.RowsAffected() != 1) { + return; + } - if (results.RowsAffected() != 1) { - return; + client->Message( + Chat::White, + fmt::format( + "{} (Spawn2 ID {}) will now use Grid ID {}.", + target_npc->GetCleanName(), + spawn2_id, + grid_id + ).c_str() + ); } - - client->Message(Chat::White, "Grid assign: spawn2 id = %d updated", spawn2id); } diff --git a/zone/zonedb.h b/zone/zonedb.h index e12a0ed19..355a6d632 100644 --- a/zone/zonedb.h +++ b/zone/zonedb.h @@ -480,7 +480,7 @@ public: uint8 GetGridType(uint32 grid, uint32 zoneid); uint8 GetGridType2(uint32 grid, uint16 zoneid); bool GetWaypoints(uint32 grid, uint16 zoneid, uint32 num, wplist* wp); - void AssignGrid(Client *client, int grid, int spawn2id); + void AssignGrid(Client *client, uint32 grid_id, uint32 entity_id); int GetHighestGrid(uint32 zoneid); int GetHighestWaypoint(uint32 zoneid, uint32 gridid); int GetRandomWaypointLocFromGrid(glm::vec4 &loc, uint16 zoneid, int grid);