Kinglykrab 216b6ef426
[Saylinks] Convert all GM Command Saylinks to Silent Saylinks. (#2373)
* [Saylinks] Convert all GM Command Saylinks to Silent Saylinks.
- This cleans up all non-silent GM Command Saylinks that we had before due to the way they worked before. All saylinks like this should be silent now.
- Add source short hand capability for say links with same link as text.

* Defaults to r anyway.

* Spacing.
2022-08-13 20:40:22 -04:00

117 lines
2.9 KiB
C++
Executable File

#include "../client.h"
void command_qglobal(Client *c, const Seperator *sep)
{
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;
}
if (!c->GetTarget() || !c->GetTarget()->IsNPC()) {
c->Message(Chat::White, "You must target an NPC to use this command.");
return;
}
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::White,
fmt::format(
"Failed to disable quest global flag for {}.",
c->GetTargetDescription(target)
).c_str()
);
return;
}
auto repop_link = Saylink::Silent("#repop", "repop");
c->Message(
Chat::White,
fmt::format(
"{} will no longer be able to view quest globals, {} them to apply this change.",
c->GetTargetDescription(target),
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::White,
fmt::format(
"Failed to enable quest global flag for {}.",
c->GetTargetDescription(target)
).c_str()
);
return;
}
auto repop_link = Saylink::Silent("#repop", "repop");
c->Message(
Chat::White,
fmt::format(
"{} will now be able to view quest globals, {} them to apply this change.",
c->GetTargetDescription(target),
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::White,
fmt::format(
"{} {} view quest globals.",
c->GetTargetDescription(target),
npc_type->qglobal ? "can" : "cannot"
).c_str()
);
}
}