[Commands] Cleanup #setadventurepoints Command. (#1901)

- Cleanup message and logic.
This commit is contained in:
Kinglykrab
2021-12-24 13:46:17 -05:00
committed by GitHub
parent 6a7782ab8d
commit 7f23c93ce5
2 changed files with 72 additions and 12 deletions
+71 -11
View File
@@ -1,24 +1,84 @@
#include "../client.h"
#include "../../common/data_verification.h"
void command_set_adventure_points(Client *c, const Seperator *sep)
{
Client *t = c;
int arguments = sep->argnum;
if (
!arguments ||
!sep->IsNumber(1) ||
!sep->IsNumber(2)
) {
c->Message(Chat::White, "Usage: #setadventurepoints [Theme] [Points]");
c->Message(Chat::White, "Valid themes are as follows.");
auto theme_map = EQ::constants::GetLDoNThemeMap();
for (const auto& theme : theme_map) {
c->Message(
Chat::White,
fmt::format(
"Theme {} | {}",
theme.first,
theme.second
).c_str()
);
}
c->Message(Chat::White, "Note: Theme 0 splits the points evenly across all Themes.");
return;
}
auto target = c;
if (c->GetTarget() && c->GetTarget()->IsClient()) {
t = c->GetTarget()->CastToClient();
target = c->GetTarget()->CastToClient();
}
if (!sep->arg[1][0]) {
c->Message(Chat::White, "Usage: #setadventurepoints [theme] [points]");
auto theme_id = std::stoul(sep->arg[1]);
if (!EQ::ValueWithin(theme_id, LDoNThemes::Unused, LDoNThemes::TAK)) {
c->Message(Chat::White, "Valid themes are as follows.");
auto theme_map = EQ::constants::GetLDoNThemeMap();
for (const auto& theme : theme_map) {
c->Message(
Chat::White,
fmt::format(
"Theme {} | {}",
theme.first,
theme.second
).c_str()
);
}
c->Message(Chat::White, "Note: Theme 0 splits the points evenly across all Themes.");
return;
}
if (!sep->IsNumber(1) || !sep->IsNumber(2)) {
c->Message(Chat::White, "Usage: #setadventurepoints [theme] [points]");
return;
}
auto points = std::stoi(sep->arg[2]);
c->Message(Chat::White, "Updating adventure points for %s", t->GetName());
t->UpdateLDoNPoints(atoi(sep->arg[1]), atoi(sep->arg[2]));
c->Message(
Chat::White,
fmt::format(
"{} for {}.",
(
theme_id == LDoNThemes::Unused ?
fmt::format(
"Splitting {} Points Evenly",
points
) :
fmt::format(
"Adding {} {} Points",
points,
EQ::constants::GetLDoNThemeName(theme_id)
)
),
(
c == target ?
"Yourself" :
fmt::format(
"{} ({})",
target->GetCleanName(),
target->GetID()
)
)
).c_str()
);
target->UpdateLDoNPoints(theme_id, points);
}