From c7b4fb4b89582522afc4e2bb6ffaf111fd7ad178 Mon Sep 17 00:00:00 2001 From: Kinglykrab Date: Wed, 4 May 2022 15:40:11 -0400 Subject: [PATCH] [Commands] Cleanup #qglobal Command. - Cleanup messages and logic. --- zone/command.cpp | 2 +- zone/gm_commands/qglobal.cpp | 139 ++++++++++++++++++++++++++--------- 2 files changed, 104 insertions(+), 37 deletions(-) diff --git a/zone/command.cpp b/zone/command.cpp index 6dc06cc3fe..eb90cddd03 100755 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -288,7 +288,7 @@ int command_init(void) command_add("push", "Lets you do spell push", AccountStatus::GMLeadAdmin, command_push) || command_add("proximity", "Shows NPC proximity", AccountStatus::GMLeadAdmin, command_proximity) || command_add("pvp", "[On|Off] - Set you or your player target's PVP status", AccountStatus::GMAdmin, command_pvp) || - command_add("qglobal", "[on/off/view] - Toggles qglobal functionality on an NPC", AccountStatus::GMAdmin, command_qglobal) || + command_add("qglobal", "[On|Off|View] - Toggles quest global functionality for your NPC target", AccountStatus::GMAdmin, command_qglobal) || command_add("questerrors", "Shows quest errors.", AccountStatus::GMAdmin, command_questerrors) || command_add("race", "[racenum] - Change your or your target's race. Use racenum 0 to return to normal", AccountStatus::Guide, command_race) || command_add("raidloot", "[All|GroupLeader|RaidLeader|Selected] - Sets your Raid Loot Type if you have permission to do so.", AccountStatus::Player, command_raidloot) || diff --git a/zone/gm_commands/qglobal.cpp b/zone/gm_commands/qglobal.cpp index 7625a26041..2771ebf7a0 100755 --- a/zone/gm_commands/qglobal.cpp +++ b/zone/gm_commands/qglobal.cpp @@ -2,61 +2,128 @@ void command_qglobal(Client *c, const Seperator *sep) { - //In-game switch for qglobal column - if (sep->arg[1][0] == 0) { - c->Message(Chat::White, "Syntax: #qglobal [on/off/view]. Requires NPC target."); + int arguments = sep->argnum; + if (!arguments) { + c->Message(Chat::White, "Usage: #qglobal on - Enables target NPC's ability to view quest globals"); + c->Message(Chat::White, "Usage: #qglobal off - Disables target NPC's ability to view quest globals"); + c->Message(Chat::White, "Usage: #qglobal view - View target NPC's ability to view quest globals"); return; } - Mob *target = c->GetTarget(); - if (!target || !target->IsNPC()) { - c->Message(Chat::Red, "NPC Target Required!"); + if (!c->GetTarget() || !c->GetTarget()->IsNPC()) { + c->Message(Chat::White, "You must target an NPC to use this command."); return; } - if (!strcasecmp(sep->arg[1], "on")) { - std::string query = StringFormat( - "UPDATE npc_types SET qglobal = 1 WHERE id = '%i'", - target->GetNPCTypeID()); - auto results = content_db.QueryDatabase(query); + auto target = c->GetTarget()->CastToNPC(); + + bool is_off = !strcasecmp(sep->arg[1], "off"); + bool is_on = !strcasecmp(sep->arg[1], "on"); + bool is_view = !strcasecmp(sep->arg[1], "view"); + if ( + !is_off && + !is_on && + !is_view + ) { + c->Message(Chat::White, "Usage: #qglobal on - Enables target NPC's ability to view quest globals"); + c->Message(Chat::White, "Usage: #qglobal off - Disables target NPC's ability to view quest globals"); + c->Message(Chat::White, "Usage: #qglobal view - View target NPC's ability to view quest globals"); + return; + } + + if (is_off) { + auto query = fmt::format( + "UPDATE npc_types SET qglobal = 0 WHERE id = {}", + target->GetNPCTypeID() + ); + auto results = content_db.QueryDatabase(query); + if (!results.Success()) { - c->Message(Chat::Yellow, "Could not update database."); + c->Message( + Chat::White, + fmt::format( + "Failed to disable quest global flag for {} ({}).", + target->GetCleanName(), + target->GetID() + ).c_str() + ); return; } - c->Message(Chat::Yellow, "Success! Changes take effect on zone reboot."); + auto repop_link = EQ::SayLinkEngine::GenerateQuestSaylink( + "#repop", + false, + "repop" + ); + + c->Message( + Chat::White, + fmt::format( + "{} ({}) will no longer be able to view quest globals, {} them to apply this change.", + target->GetCleanName(), + target->GetID(), + repop_link + ).c_str() + ); return; - } + } else if (is_on) { + auto query = fmt::format( + "UPDATE npc_types SET qglobal = 1 WHERE id = {}", + target->GetNPCTypeID() + ); + auto results = content_db.QueryDatabase(query); - if (!strcasecmp(sep->arg[1], "off")) { - std::string query = StringFormat( - "UPDATE npc_types SET qglobal = 0 WHERE id = '%i'", - target->GetNPCTypeID()); - auto results = content_db.QueryDatabase(query); if (!results.Success()) { - c->Message(Chat::Yellow, "Could not update database."); + c->Message( + Chat::White, + fmt::format( + "Failed to enable quest global flag for {} ({}).", + target->GetCleanName(), + target->GetID() + ).c_str() + ); return; } - c->Message(Chat::Yellow, "Success! Changes take effect on zone reboot."); - return; - } + auto repop_link = EQ::SayLinkEngine::GenerateQuestSaylink( + "#repop", + false, + "repop" + ); - if (!strcasecmp(sep->arg[1], "view")) { - const NPCType *type = content_db.LoadNPCTypesData(target->GetNPCTypeID()); - if (!type) { - c->Message(Chat::Yellow, "Invalid NPC type."); - } - else if (type->qglobal) { - c->Message(Chat::Yellow, "This NPC has quest globals active."); - } - else { - c->Message(Chat::Yellow, "This NPC has quest globals disabled."); - } + c->Message( + Chat::White, + fmt::format( + "{} ({}) will now be able to view quest globals, {} them to apply this change.", + target->GetCleanName(), + target->GetID(), + repop_link + ).c_str() + ); return; - } + } else if (!strcasecmp(sep->arg[1], "view")) { + const NPCType *npc_type = content_db.LoadNPCTypesData(target->GetNPCTypeID()); + if (!npc_type) { + c->Message( + Chat::White, + fmt::format( + "NPC ID {} was not found.", + target->GetNPCTypeID() + ).c_str() + ); + return; + } - c->Message(Chat::Yellow, "Invalid action specified."); + c->Message( + Chat::White, + fmt::format( + "{} ({}) {} view quest globals.", + target->GetCleanName(), + target->GetID(), + npc_type->qglobal ? "can" : "cannot" + ).c_str() + ); + } }