eqemu-server/zone/gm_commands/setcrystals.cpp
Alex King 2a6cf8c8e7
[Strings] Add more number formatters (#2873)
* [Strings] Add more number formatters

# Notes
- Adds `Strings::ToUnsignedInt` for `uint32` support.
- Adds `Strings::ToBigInt` for `int64` support.
- Adds `Strings::ToUnsignedBigInt` for `uint64` support.
- Adds `Strings::ToFloat` for `float` support.
- Replaces all `std::stoi` references with `Strings::ToInt`.
- Replaces all `atoi` references with `Strings::ToInt`.
- Replaces all `std::stoul` references with `Strings::ToUnsignedInt`.
- Replaces all `atoul` references with `Strings::ToUnsignedInt`.
- Replaces all `std::stoll` references with `Strings::ToBigInt`.
- Replaces all `atoll` references with `Strings::ToBigInt`.
- Replaces all `std::stoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `atoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `std::stof` references with `Strings::ToFloat`.

* [Strings] Add more number formatters

- Adds `Strings::ToUnsignedInt` for `uint32` support.
- Adds `Strings::ToBigInt` for `int64` support.
- Adds `Strings::ToUnsignedBigInt` for `uint64` support.
- Adds `Strings::ToFloat` for `float` support.
- Replaces all `std::stoi` references with `Strings::ToInt`.
- Replaces all `atoi` references with `Strings::ToInt`.
- Replaces all `std::stoul` references with `Strings::ToUnsignedInt`.
- Replaces all `atoul` references with `Strings::ToUnsignedInt`.
- Replaces all `std::stoll` references with `Strings::ToBigInt`.
- Replaces all `atoll` references with `Strings::ToBigInt`.
- Replaces all `std::stoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `atoull` references with `Strings::ToUnsignedBigInt`.
- Replaces all `std::stof` references with `Strings::ToFloat`.

* Rebase cleanup

* Changes/benchmarks/tests

---------

Co-authored-by: Akkadius <akkadius1@gmail.com>
2023-03-04 17:01:19 -06:00

53 lines
1.3 KiB
C++
Executable File

#include "../client.h"
void command_setcrystals(Client *c, const Seperator *sep)
{
int arguments = sep->argnum;
if (arguments <= 1 || !sep->IsNumber(2)) {
c->Message(Chat::White, "Usage: #setcrystals [Ebon|Radiant] [Crystal Amount]");
return;
}
Client *target = c;
if (c->GetTarget() && c->GetTarget()->IsClient()) {
target = c->GetTarget()->CastToClient();
}
std::string crystal_type = Strings::ToLower(sep->arg[1]);
uint32 crystal_amount = static_cast<uint32>(std::min(
Strings::ToUnsignedBigInt(sep->arg[2]),
(uint64) 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;
}
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->GetTargetDescription(target, TargetDescriptionType::UCYou),
c == target ? "have" : "has",
crystal_amount,
crystal_link
).c_str()
);
}