From 264c6cb0195b79c422971751ce1332971375fd79 Mon Sep 17 00:00:00 2001 From: Kinglykrab <89047260+Kinglykrab@users.noreply.github.com> Date: Sun, 14 Nov 2021 20:47:36 -0500 Subject: [PATCH] [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. --- zone/command.cpp | 56 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 17 deletions(-) diff --git a/zone/command.cpp b/zone/command.cpp index b0a25eeb7..6e6cb5fea 100755 --- a/zone/command.cpp +++ b/zone/command.cpp @@ -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 "); - 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(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 "); + + 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)