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

117 lines
2.7 KiB
C++
Executable File

#include "../client.h"
void command_viewzoneloot(Client *c, const Seperator *sep)
{
std::map<uint32, ItemList> zone_loot_list;
auto npc_list = entity_list.GetNPCList();
uint32 loot_amount = 0, loot_id = 1, search_item_id = 0;
if (sep->argnum == 1 && sep->IsNumber(1)) {
search_item_id = Strings::ToInt(sep->arg[1]);
}
else if (sep->argnum == 1 && !sep->IsNumber(1)) {
c->Message(
Chat::Yellow,
"Usage: #viewzoneloot [item id]"
);
return;
}
for (auto npc_entity : npc_list) {
auto current_npc_item_list = npc_entity.second->GetItemList();
zone_loot_list.insert({npc_entity.second->GetID(), current_npc_item_list});
}
for (auto loot_item : zone_loot_list) {
uint32 current_entity_id = loot_item.first;
auto current_item_list = loot_item.second;
auto current_npc = entity_list.GetNPCByID(current_entity_id);
std::string npc_link;
if (current_npc) {
std::string npc_name = current_npc->GetCleanName();
uint32 instance_id = zone->GetInstanceID();
uint32 zone_id = zone->GetZoneID();
std::string command_link = Saylink::Silent(
fmt::format(
"#{} {} {} {} {}",
(instance_id != 0 ? "zoneinstance" : "zone"),
(instance_id != 0 ? instance_id : zone_id),
current_npc->GetX(),
current_npc->GetY(),
current_npc->GetZ()
),
"Goto"
);
npc_link = fmt::format(
" NPC: {} (ID {}) [{}]",
npc_name,
current_entity_id,
command_link
);
}
for (auto current_item : current_item_list) {
if (search_item_id == 0 || current_item->item_id == search_item_id) {
EQ::SayLinkEngine linker;
linker.SetLinkType(EQ::saylink::SayLinkLootItem);
linker.SetLootData(current_item);
c->Message(
Chat::White,
fmt::format(
"{}. {} ({}){}",
loot_id,
linker.GenerateLink(),
current_item->item_id,
npc_link
).c_str()
);
loot_id++;
loot_amount++;
}
}
}
if (search_item_id != 0) {
std::string drop_string = (
loot_amount > 0 ?
fmt::format(
"dropping in {} {}",
loot_amount,
(loot_amount > 1 ? "places" : "place")
) :
"not dropping"
);
c->Message(
Chat::White,
fmt::format(
"{} ({}) is {}.",
database.CreateItemLink(search_item_id),
search_item_id,
drop_string
).c_str()
);
}
else {
std::string drop_string = (
loot_amount > 0 ?
fmt::format(
"{} {} dropping",
(loot_amount > 1 ? "items" : "item"),
(loot_amount > 1 ? "are" : "is")
) :
"items are dropping"
);
c->Message(
Chat::White,
fmt::format(
"{} {}.",
loot_amount,
drop_string
).c_str()
);
}
}