[Commands] Cleanup #stun Command. (#1749)

* [Commands] Cleanup #stun Command.
- Cleanup message.
- Add ConvertSecondsToTime() to string_util.h and convert Quest API Methods to use helper.

* Add days to ConvertSecondsToTime() and cleanup logic.

* Cleanup.

* Typo.

* Cleanup.

* Cleanup.
This commit is contained in:
Kinglykrab
2021-11-14 14:05:44 -05:00
committed by GitHub
parent 90bcc5f03c
commit ddcb184183
4 changed files with 201 additions and 40 deletions
+55 -14
View File
@@ -9291,21 +9291,62 @@ void command_setcrystals(Client *c, const Seperator *sep)
void command_stun(Client *c, const Seperator *sep)
{
Mob *t=c->CastToMob();
uint32 duration;
if(sep->arg[1][0])
{
duration = atoi(sep->arg[1]);
if(c->GetTarget())
t=c->GetTarget();
if(t->IsClient())
t->CastToClient()->Stun(duration);
else
t->CastToNPC()->Stun(duration);
int arguments = sep->argnum;
if (!arguments || !sep->IsNumber(1)) {
c->Message(Chat::White, "Usage: #stun [Duration]");
return;
}
else
c->Message(Chat::White, "Usage: #stun [duration]");
Mob* target = c;
int duration = static_cast<int>(std::min(std::stoll(sep->arg[1]), (long long) 2000000000));
if (duration < 0) {
duration = 0;
}
if (c->GetTarget()) {
target = c->GetTarget();
if (target->IsClient()) {
target->CastToClient()->Stun(duration);
} else if (target->IsNPC()) {
target->CastToNPC()->Stun(duration);
}
} else {
c->Stun(duration);
}
std::string stun_message = (
duration ?
fmt::format(
"You stunned {} for {}.",
(
c == target ?
"yourself" :
fmt::format(
"{} ({})",
target->GetCleanName(),
target->GetID()
)
),
ConvertSecondsToTime(duration)
) :
fmt::format(
"You unstunned {}.",
(
c == target ?
"yourself" :
fmt::format(
"{} ({})",
target->GetCleanName(),
target->GetID()
)
)
)
);
c->Message(
Chat::White,
stun_message.c_str()
);
}