From a64425ebe6fff2b4c54fcc890ce8cfd939bdb195 Mon Sep 17 00:00:00 2001 From: Paul Coene Date: Sat, 2 Sep 2023 21:21:48 -0400 Subject: [PATCH] [Commands] npc_edit faction and #setfaction duplicate and incorrect. (#3577) * [Commands] npc_edit faction and #setfaction duplicate and incorrect. * Fix assignment --- zone/gm_commands/npcedit.cpp | 43 +++++++++++++++---------- zone/gm_commands/set.cpp | 2 -- zone/gm_commands/set/faction.cpp | 54 -------------------------------- 3 files changed, 26 insertions(+), 73 deletions(-) delete mode 100755 zone/gm_commands/set/faction.cpp diff --git a/zone/gm_commands/npcedit.cpp b/zone/gm_commands/npcedit.cpp index 71ca3f884..dcb338581 100755 --- a/zone/gm_commands/npcedit.cpp +++ b/zone/gm_commands/npcedit.cpp @@ -339,24 +339,33 @@ void command_npcedit(Client *c, const Seperator *sep) } } else if (!strcasecmp(sep->arg[1], "faction")) { if (sep->IsNumber(2)) { - auto faction_id = Strings::ToInt(sep->arg[2]); - auto faction_name = content_db.GetFactionName(faction_id); - n.npc_faction_id = faction_id; - d = fmt::format( - "{} is now using Faction {}.", - npc_id_string, - ( - !faction_name.empty() ? - fmt::format( - "{} ({})", - faction_name, - faction_id - ) : - Strings::Commify(sep->arg[2]) - ) - ); + auto npc_faction_id = Strings::ToInt(sep->arg[2]); + const NPCFactionList* cf = content_db.GetNPCFactionEntry(npc_faction_id); + if (cf) { + auto faction_id = cf->primaryfaction; + auto faction_name = content_db.GetFactionName(faction_id); + + n.npc_faction_id = npc_faction_id; + d = fmt::format( + "{} is now using Faction {}.", + npc_id_string, + ( + !faction_name.empty() ? + fmt::format( + "{} ({})", + faction_name, + faction_id + ) : + Strings::Commify(sep->arg[2]) + ) + ); + } + else { + c->Message(Chat::White, "Need to provide a valid, existing, npc_faction_id"); + return; + } } else { - c->Message(Chat::White, "Usage: #npcedit faction [Faction ID] - Sets an NPC's Faction ID"); + c->Message(Chat::White, "Usage: #npcedit faction [npc_faction_id] - Sets an NPC's npc Faction ID (not primary faction) but lookup into table."); return; } } else if (!strcasecmp(sep->arg[1], "adventure_template_id")) { diff --git a/zone/gm_commands/set.cpp b/zone/gm_commands/set.cpp index e554cdbc7..8626db5cc 100644 --- a/zone/gm_commands/set.cpp +++ b/zone/gm_commands/set.cpp @@ -13,7 +13,6 @@ #include "set/endurance.cpp" #include "set/endurance_full.cpp" #include "set/exp.cpp" -#include "set/faction.cpp" #include "set/flymode.cpp" #include "set/frozen.cpp" #include "set/gender.cpp" @@ -80,7 +79,6 @@ void command_set(Client *c, const Seperator *sep) Cmd{.cmd = "endurance", .u = "endurance [Amount]", .fn = SetEndurance, .a = {"#setendurance"}}, Cmd{.cmd = "endurance_full", .u = "endurance_full", .fn = SetEnduranceFull, .a = {"#endurance"}}, Cmd{.cmd = "exp", .u = "exp [aa|exp] [Amount]", .fn = SetEXP, .a = {"#setxp"}}, - Cmd{.cmd = "faction", .u = "faction [Faction ID]", .fn = SetFaction, .a = {"#setfaction"}}, Cmd{.cmd = "flymode", .u = "flymode [Flymode ID]", .fn = SetFlymode, .a = {"#flymode"}}, Cmd{.cmd = "frozen", .u = "frozen [on|off]", .fn = SetFrozen, .a = {"#freeze", "#unfreeze"}}, Cmd{.cmd = "gender", .u = "gender [Gender ID]", .fn = SetGender, .a = {"#gender"}}, diff --git a/zone/gm_commands/set/faction.cpp b/zone/gm_commands/set/faction.cpp deleted file mode 100755 index e40754fd1..000000000 --- a/zone/gm_commands/set/faction.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include "../../client.h" - -void SetFaction(Client *c, const Seperator *sep) -{ - const auto arguments = sep->argnum; - if (arguments < 2 || !sep->IsNumber(2)) { - c->Message(Chat::White, "Usage: #set faction [Faction ID]"); - return; - } - - if ( - !c->GetTarget() || - ( - c->GetTarget() && - c->GetTarget()->IsClient() - ) - ) { - c->Message(Chat::White, "You must target an NPC to use this command."); - return; - } - - NPC* t = c->GetTarget()->CastToNPC(); - - const uint32 npc_id = t->GetNPCTypeID(); - const int faction_id = Strings::ToInt(sep->arg[2]); - - const std::string& faction_name = content_db.GetFactionName(faction_id); - - if (faction_name.empty()) { - c->Message( - Chat::White, - "Invalid Faction ID, please specify a valid Faction ID." - ); - return; - } - - c->Message( - Chat::White, - fmt::format( - "Faction Changed | Name: {} ({}) Faction: {} ({}).", - t->GetCleanName(), - npc_id, - content_db.GetFactionName(faction_id), - faction_id - ).c_str() - ); - - const std::string &query = fmt::format( - "UPDATE npc_types SET npc_faction_id = {} WHERE id = {}", - faction_id, - npc_id - ); - content_db.QueryDatabase(query); -}