[Commands] Add #setmana Command. (#1839)

* [Commands] Add #setmana Command.
- Add #setmana [Mana] command to set an NPC or player's mana to a specified amount, or to max if the amount is greater than their max.
- Cleanup #mana command message and logic.

* Update mana.cpp
This commit is contained in:
Kinglykrab 2021-11-27 19:07:47 -05:00 committed by GitHub
parent b3b9899a23
commit c4c5256438
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 87 additions and 15 deletions

View File

@ -492,6 +492,7 @@ SET(gm_commands
gm_commands/setgraveyard.cpp
gm_commands/setlanguage.cpp
gm_commands/setlsinfo.cpp
gm_commands/setmana.cpp
gm_commands/setpass.cpp
gm_commands/setpvppoints.cpp
gm_commands/setskill.cpp

View File

@ -328,6 +328,7 @@ int command_init(void)
command_add("setgraveyard", "[zone name] - Creates a graveyard for the specified zone based on your target's LOC.", AccountStatus::GMMgmt, command_setgraveyard) ||
command_add("setlanguage", "[language ID] [value] - Set your target's language skillnum to value", AccountStatus::Guide, command_setlanguage) ||
command_add("setlsinfo", "[email] [password] - Set login server email address and password (if supported by login server)", AccountStatus::Steward, command_setlsinfo) ||
command_add("setmana", "[Mana] - Set your or your target's Mana", AccountStatus::GMAdmin, command_setmana) ||
command_add("setpass", "[accountname] [password] - Set local password for accountname", AccountStatus::GMLeadAdmin, command_setpass) ||
command_add("setpvppoints", "[Amount] - Set your or your player target's PVP points", AccountStatus::GMAdmin, command_setpvppoints) ||
command_add("setskill", "[skillnum] [value] - Set your target's skill skillnum to value", AccountStatus::Guide, command_setskill) ||

View File

@ -249,6 +249,7 @@ void command_setfaction(Client *c, const Seperator *sep);
void command_setgraveyard(Client *c, const Seperator *sep);
void command_setlanguage(Client *c, const Seperator *sep);
void command_setlsinfo(Client *c, const Seperator *sep);
void command_setmana(Client *c, const Seperator *sep);
void command_setpass(Client *c, const Seperator *sep);
void command_setpvppoints(Client *c, const Seperator *sep);
void command_setskill(Client *c, const Seperator *sep);

View File

@ -3,25 +3,31 @@
void command_mana(Client *c, const Seperator *sep)
{
auto target = c->GetTarget() ? c->GetTarget() : c;
int mana = 0;
if (target->IsClient()) {
target->CastToClient()->SetMana(target->CastToClient()->CalcMaxMana());
mana = target->CastToClient()->CalcMaxMana();
target->CastToClient()->SetMana(mana);
}
else {
target->SetMana(target->CalcMaxMana());
mana = target->CalcMaxMana();
target->SetMana(mana);
}
if (c != target) {
c->Message(
Chat::White,
fmt::format(
"Set {} ({}) to full Mana.",
target->GetCleanName(),
target->GetID()
).c_str()
);
}
else {
c->Message(Chat::White, "Restored your Mana to full.");
}
c->Message(
Chat::White,
fmt::format(
"Set {} to full Mana ({}).",
(
c == target ?
"yourself" :
fmt::format(
"{} ({})",
target->GetCleanName(),
target->GetID()
)
),
mana
).c_str()
);
}

View File

@ -0,0 +1,63 @@
#include "../client.h"
void command_setmana(Client *c, const Seperator *sep)
{
int arguments = sep->argnum;
if (!arguments || !sep->IsNumber(1)) {
c->Message(Chat::White, "Usage: #setmana [Mana]");
return;
}
auto mana = static_cast<int>(std::min(std::stoll(sep->arg[1]), (long long) 2000000000));
bool set_to_max = false;
Mob* target = c;
if (c->GetTarget()) {
target = c->GetTarget();
}
if (target->IsClient()) {
if (mana >= target->CastToClient()->CalcMaxMana()) {
mana = target->CastToClient()->CalcMaxMana();
set_to_max = true;
}
target->CastToClient()->SetMana(mana);
} else {
if (mana >= target->CalcMaxMana()) {
mana = target->CalcMaxMana();
set_to_max = true;
}
target->SetMana(mana);
}
c->Message(
Chat::White,
fmt::format(
"Set {} to {} Mana{}.",
(
c == target ?
"yourself" :
fmt::format(
"{} ({})",
target->GetCleanName(),
target->GetID()
)
),
(
set_to_max ?
"full" :
std::to_string(mana)
),
(
set_to_max ?
fmt::format(
" ({})",
mana
) :
""
)
).c_str()
);
}