[Commands] Cleanup #setcrystals Command. (#1745)

* [Commands] Cleanup #setcrystals Command.
- Add message.
- Increase cap from 100,000 to 2,000,000,000.

* Cleanup.

* Remove condition, ID is always defined.

* Cleanup.
This commit is contained in:
Kinglykrab 2021-11-14 20:47:36 -05:00 committed by GitHub
parent 9bcb617f90
commit 264c6cb019
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9366,27 +9366,49 @@ void command_setaapts(Client *c, const Seperator *sep)
void command_setcrystals(Client *c, const Seperator *sep)
{
Client *t=c;
int arguments = sep->argnum;
if (arguments <= 1 || !sep->IsNumber(2)) {
c->Message(Chat::White, "Usage: #setcrystals [Ebon|Radiant] [Crystal Amount]");
return;
}
if(c->GetTarget() && c->GetTarget()->IsClient())
t=c->GetTarget()->CastToClient();
Client *target = c;
if(c->GetTarget() && c->GetTarget()->IsClient()) {
target = c->GetTarget()->CastToClient();
}
if(sep->arg[1][0] == '\0' || sep->arg[2][0] == '\0')
c->Message(Chat::White, "Usage: #setcrystals <radiant|ebon> <new crystal count value>");
else if(atoi(sep->arg[2]) <= 0 || atoi(sep->arg[2]) > 100000)
c->Message(Chat::White, "You must have a number greater than 0 for crystals and no more than 100000.");
else if(!strcasecmp(sep->arg[1], "radiant"))
{
t->SetRadiantCrystals(atoi(sep->arg[2]));
std::string crystal_type = str_tolower(sep->arg[1]);
uint32 crystal_amount = static_cast<uint32>(std::min(std::stoull(sep->arg[2]), (unsigned long long) 2000000000));
bool is_ebon = crystal_type.find("ebon") != std::string::npos;
bool is_radiant = crystal_type.find("radiant") != std::string::npos;
if (!is_ebon && !is_radiant) {
c->Message(Chat::White, "Usage: #setcrystals [Ebon|Radiant] [Crystal Amount]");
return;
}
else if(!strcasecmp(sep->arg[1], "ebon"))
{
t->SetEbonCrystals(atoi(sep->arg[2]));
}
else
{
c->Message(Chat::White, "Usage: #setcrystals <radiant|ebon> <new crystal count value>");
uint32 crystal_item_id = (
is_ebon ?
RuleI(Zone, EbonCrystalItemID) :
RuleI(Zone, RadiantCrystalItemID)
);
auto crystal_link = database.CreateItemLink(crystal_item_id);
if (is_radiant) {
target->SetRadiantCrystals(crystal_amount);
} else {
target->SetEbonCrystals(crystal_amount);
}
c->Message(
Chat::White,
fmt::format(
"{} now {} {} {}.",
c == target ? "You" : target->GetCleanName(),
c == target ? "have" : "has",
crystal_amount,
crystal_link
).c_str()
);
}
void command_stun(Client *c, const Seperator *sep)