eqemu-server/zone/gm_commands/findrecipe.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

97 lines
2.1 KiB
C++
Executable File

#include "../client.h"
#include "../command.h"
#include "../../common/repositories/tradeskill_recipe_repository.h"
void command_findrecipe(Client *c, const Seperator *sep)
{
int arguments = sep->argnum;
if (!arguments) {
c->Message(Chat::White, "Command Syntax: #findrecipe [Search Criteria]");
return;
}
if (sep->IsNumber(1)) {
auto recipe_id = static_cast<uint16>(Strings::ToUnsignedInt(sep->arg[1]));
auto r = TradeskillRecipeRepository::GetWhere(
database,
fmt::format("id = {}", recipe_id)
);
if (r.empty() || !r[0].id) {
c->Message(
Chat::White,
fmt::format(
"Recipe ID {} could not be found.",
Strings::Commify(std::to_string(recipe_id))
).c_str()
);
return;
}
bool can_view_recipes = c->Admin() >= GetCommandStatus(c, "viewrecipe");
c->Message(
Chat::White,
fmt::format(
"Recipe {} | {}{}",
Strings::Commify(std::to_string(recipe_id)),
r[0].name,
can_view_recipes ? fmt::format(" | {}", Saylink::Silent(fmt::format("#viewrecipe {}", r[0].id), "View")) : ""
).c_str()
);
} else {
auto search_criteria = Strings::ToLower(sep->argplus[1]);
int found_count = 0;
auto rl = TradeskillRecipeRepository::GetWhere(
database,
fmt::format("`name` LIKE '%{}%' ORDER BY `id` ASC", search_criteria)
);
if (rl.empty() || !rl[0].id) {
c->Message(
Chat::White,
fmt::format(
"No recipes were found matching '{}'.",
search_criteria
).c_str()
);
return;
}
bool can_view_recipes = c->Admin() >= GetCommandStatus(c, "viewrecipe");
for (const auto& r : rl) {
c->Message(
Chat::White,
fmt::format(
"Recipe {} | {}{}",
Strings::Commify(std::to_string(r.id)),
r.name,
can_view_recipes ? fmt::format(" | {}", Saylink::Silent(fmt::format("#viewrecipe {}", r.id), "View")) : ""
).c_str()
);
if (found_count == 50) {
break;
}
found_count++;
}
if (found_count == 50) {
c->Message(Chat::White, "50 Recipes found, max reached.");
} else {
c->Message(
Chat::White,
fmt::format(
"{} Recipe{} found.",
found_count,
found_count != 1 ? "s" : ""
).c_str()
);
}
}
}