[Commands] Cleanup #qglobal Command. (#2115)

- Cleanup messages and logic.
This commit is contained in:
Kinglykrab 2022-05-06 20:37:45 -04:00 committed by GitHub
parent 1e45ffa24d
commit 78d44440eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 105 additions and 38 deletions

View File

@ -281,7 +281,7 @@ int command_init(void)
command_add("push", "Lets you do spell push", AccountStatus::GMLeadAdmin, command_push) || command_add("push", "Lets you do spell push", AccountStatus::GMLeadAdmin, command_push) ||
command_add("proximity", "Shows NPC proximity", AccountStatus::GMLeadAdmin, command_proximity) || 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("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("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("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) || command_add("raidloot", "[All|GroupLeader|RaidLeader|Selected] - Sets your Raid Loot Type if you have permission to do so.", AccountStatus::Player, command_raidloot) ||

View File

@ -2,61 +2,128 @@
void command_qglobal(Client *c, const Seperator *sep) void command_qglobal(Client *c, const Seperator *sep)
{ {
//In-game switch for qglobal column int arguments = sep->argnum;
if (sep->arg[1][0] == 0) { if (!arguments) {
c->Message(Chat::White, "Syntax: #qglobal [on/off/view]. Requires NPC target."); 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; return;
} }
Mob *target = c->GetTarget();
if (!target || !target->IsNPC()) { if (!c->GetTarget() || !c->GetTarget()->IsNPC()) {
c->Message(Chat::Red, "NPC Target Required!"); c->Message(Chat::White, "You must target an NPC to use this command.");
return; return;
} }
if (!strcasecmp(sep->arg[1], "on")) { auto target = c->GetTarget()->CastToNPC();
std::string query = StringFormat(
"UPDATE npc_types SET qglobal = 1 WHERE id = '%i'", bool is_off = !strcasecmp(sep->arg[1], "off");
target->GetNPCTypeID()); bool is_on = !strcasecmp(sep->arg[1], "on");
auto results = content_db.QueryDatabase(query); 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()) { 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; return;
} }
c->Message(Chat::Yellow, "Success! Changes take effect on zone reboot."); auto repop_link = EQ::SayLinkEngine::GenerateQuestSaylink(
return; "#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()) { 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; return;
} }
c->Message(Chat::Yellow, "Success! Changes take effect on zone reboot."); auto repop_link = EQ::SayLinkEngine::GenerateQuestSaylink(
return; "#repop",
} false,
"repop"
);
if (!strcasecmp(sep->arg[1], "view")) { c->Message(
const NPCType *type = content_db.LoadNPCTypesData(target->GetNPCTypeID()); Chat::White,
if (!type) { fmt::format(
c->Message(Chat::Yellow, "Invalid NPC type."); "{} ({}) will now be able to view quest globals, {} them to apply this change.",
} target->GetCleanName(),
else if (type->qglobal) { target->GetID(),
c->Message(Chat::Yellow, "This NPC has quest globals active."); repop_link
} ).c_str()
else { );
c->Message(Chat::Yellow, "This NPC has quest globals disabled.");
}
return; 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()
);
}
} }