[Commands] Cleanup #scribespell and #scribespells Commands. (#2534)

- Cleanup messages and logic.
This commit is contained in:
Kinglykrab
2022-11-14 14:05:34 -05:00
committed by GitHub
parent 9c967c24b8
commit 8d184fc6c0
3 changed files with 96 additions and 65 deletions
+31 -27
View File
@@ -2,21 +2,22 @@
void command_scribespells(Client *c, const Seperator *sep)
{
Client *target = c;
if (c->GetTarget() && c->GetTarget()->IsClient() && c->GetGM()) {
target = c->GetTarget()->CastToClient();
}
if (sep->argnum < 1 || !sep->IsNumber(1)) {
auto arguments = sep->argnum;
if (!arguments || !sep->IsNumber(1)) {
c->Message(Chat::White, "Usage: #scribespells [Max Level] [Min Level]");
return;
}
uint8 rule_max_level = (uint8) RuleI(Character, MaxLevel);
uint8 max_level = (uint8) std::stoi(sep->arg[1]);
auto t = c;
if (c->GetTarget() && c->GetTarget()->IsClient() && c->GetGM()) {
t = c->GetTarget()->CastToClient();
}
uint8 rule_max_level = RuleI(Character, MaxLevel);
auto max_level = static_cast<uint8>(std::stoul(sep->arg[1]));
uint8 min_level = (
sep->IsNumber(2) ?
(uint8) std::stoi(sep->arg[2]) :
static_cast<uint8>(std::stoul(sep->arg[2])) :
1
); // Default to Level 1 if there isn't a 2nd argument
@@ -31,35 +32,38 @@ void command_scribespells(Client *c, const Seperator *sep)
}
if (max_level < 1 || min_level < 1) {
c->Message(Chat::White, "Level must be greater than or equal to 1.");
c->Message(Chat::White, "Maximum Level and Minimum Level must be greater than 0.");
return;
}
if (min_level > max_level) {
c->Message(Chat::White, "Minimum Level must be less than or equal to Maximum Level.");
c->Message(Chat::White, "Maximum Level must be greater than Minimum Level.");
return;
}
uint16 scribed_spells = target->ScribeSpells(min_level, max_level);
if (c != target) {
std::string spell_message = (
scribed_spells > 0 ?
(
scribed_spells == 1 ?
"A new spell" :
const auto scribed_spells = t->ScribeSpells(min_level, max_level);
if (c != t) {
const auto target_description = c->GetTargetDescription(t);
if (!scribed_spells) {
c->Message(
Chat::White,
fmt::format(
"{} New spells",
scribed_spells
)
) :
"No new spells"
);
"No new spells scribed for {}.",
target_description
).c_str()
);
return;
}
c->Message(
Chat::White,
fmt::format(
"{} scribed for {}.",
spell_message,
c->GetTargetDescription(target)
"{} New spell{} scribed for {}.",
scribed_spells,
scribed_spells != 1 ? "s" : "",
target_description
).c_str()
);
}