mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 01:11:29 +00:00
* [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>
57 lines
1.0 KiB
C++
57 lines
1.0 KiB
C++
#include "../client.h"
|
|
|
|
void command_countitem(Client *c, const Seperator *sep)
|
|
{
|
|
int arguments = sep->argnum;
|
|
if (!arguments || !sep->IsNumber(1)) {
|
|
c->Message(Chat::White, "Usage: #countitem [Item ID]");
|
|
return;
|
|
}
|
|
|
|
Mob* target = c;
|
|
if (
|
|
c->GetTarget() &&
|
|
(
|
|
c->GetTarget()->IsClient() ||
|
|
c->GetTarget()->IsNPC()
|
|
)
|
|
) {
|
|
target = c->GetTarget();
|
|
}
|
|
|
|
auto item_id = Strings::ToUnsignedInt(sep->arg[1]);
|
|
if (!database.GetItem(item_id)) {
|
|
c->Message(
|
|
Chat::White,
|
|
fmt::format(
|
|
"Item ID {} could not be found.",
|
|
item_id
|
|
).c_str()
|
|
);
|
|
return;
|
|
}
|
|
|
|
uint16 item_count = 0;
|
|
if (target->IsClient()) {
|
|
item_count = target->CastToClient()->CountItem(item_id);
|
|
} else if (target->IsNPC()) {
|
|
item_count = target->CastToNPC()->CountItem(item_id);
|
|
}
|
|
|
|
c->Message(
|
|
Chat::White,
|
|
fmt::format(
|
|
"{} {} {} {}.",
|
|
c->GetTargetDescription(target, TargetDescriptionType::UCYou),
|
|
c == target ? "have" : "has",
|
|
(
|
|
item_count ?
|
|
std::to_string(item_count) :
|
|
"no"
|
|
),
|
|
database.CreateItemLink(item_id)
|
|
).c_str()
|
|
);
|
|
}
|
|
|