Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Commands] Cleanup #qglobal Command. #2115

Merged
merged 1 commit into from
May 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion zone/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down
139 changes: 103 additions & 36 deletions zone/gm_commands/qglobal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}