[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("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) ||

View File

@ -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 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.");
return;
}
auto repop_link = EQ::SayLinkEngine::GenerateQuestSaylink(
"#repop",
false,
"repop"
);
if (!strcasecmp(sep->arg[1], "off")) {
std::string query = StringFormat(
"UPDATE npc_types SET qglobal = 0 WHERE id = '%i'",
target->GetNPCTypeID());
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 (!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.");
auto repop_link = EQ::SayLinkEngine::GenerateQuestSaylink(
"#repop",
false,
"repop"
);
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;
}
if (!strcasecmp(sep->arg[1], "view")) {
const NPCType *type = content_db.LoadNPCTypesData(target->GetNPCTypeID());
if (!type) {
c->Message(Chat::Yellow, "Invalid NPC type.");
c->Message(
Chat::White,
fmt::format(
"{} ({}) {} view quest globals.",
target->GetCleanName(),
target->GetID(),
npc_type->qglobal ? "can" : "cannot"
).c_str()
);
}
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.");
}
return;
}
c->Message(Chat::Yellow, "Invalid action specified.");
}