[Inventory] Add GetInventorySlots() Method (#4566)

* [Inventory] Add GetInventorySlots() Method

* Update client.cpp

* Push
This commit is contained in:
Alex King
2025-01-06 00:48:39 -05:00
committed by GitHub
parent a3a498634f
commit 1ed282f6ff
27 changed files with 204 additions and 197 deletions
+15 -25
View File
@@ -2,31 +2,21 @@
void command_emptyinventory(Client *c, const Seperator *sep)
{
auto target = c;
Client* t = c;
if (c->GetGM() && c->GetTarget() && c->GetTarget()->IsClient()) {
target = c->GetTarget()->CastToClient();
t = c->GetTarget()->CastToClient();
}
EQ::ItemInstance *item = nullptr;
static const int16 slots[][2] = {
{ EQ::invslot::POSSESSIONS_BEGIN, EQ::invslot::POSSESSIONS_END },
{ EQ::invbag::GENERAL_BAGS_BEGIN, EQ::invbag::GENERAL_BAGS_END },
{ EQ::invbag::CURSOR_BAG_BEGIN, EQ::invbag::CURSOR_BAG_END},
{ EQ::invslot::BANK_BEGIN, EQ::invslot::BANK_END },
{ EQ::invbag::BANK_BAGS_BEGIN, EQ::invbag::BANK_BAGS_END },
{ EQ::invslot::SHARED_BANK_BEGIN, EQ::invslot::SHARED_BANK_END },
{ EQ::invbag::SHARED_BANK_BAGS_BEGIN, EQ::invbag::SHARED_BANK_BAGS_END },
};
int removed_count = 0;
const size_t size = sizeof(slots) / sizeof(slots[0]);
for (int slot_index = 0; slot_index < size; ++slot_index) {
for (int slot_id = slots[slot_index][0]; slot_id <= slots[slot_index][1]; ++slot_id) {
item = target->GetInv().GetItem(slot_id);
if (item) {
int stack_size = std::max(static_cast<int>(item->GetCharges()), 1);
removed_count += stack_size;
target->DeleteItemInInventory(slot_id, 0, true);
}
uint32 removed_count = 0;
for (const int16& slot_id : t->GetInventorySlots()) {
item = t->GetInv().GetItem(slot_id);
if (item) {
uint32 stack_size = std::max(static_cast<uint32>(item->GetCharges()), static_cast<uint32>(1));
removed_count += stack_size;
t->DeleteItemInInventory(slot_id, 0, true);
}
}
@@ -35,8 +25,8 @@ void command_emptyinventory(Client *c, const Seperator *sep)
Chat::White,
fmt::format(
"{} {} no items to delete.",
c->GetTargetDescription(target, TargetDescriptionType::UCYou),
c == target ? "have" : "has"
c->GetTargetDescription(t, TargetDescriptionType::UCYou),
c == t ? "have" : "has"
).c_str()
);
return;
@@ -46,9 +36,9 @@ void command_emptyinventory(Client *c, const Seperator *sep)
Chat::White,
fmt::format(
"Inventory cleared for {}, {} item{} deleted.",
c->GetTargetDescription(target),
c->GetTargetDescription(t),
removed_count,
removed_count != 1 ? "s" : ""
).c_str()
);
}
}