static bool HandleListInventoryCommand(ChatHandler* handler, Optional<PlayerIdentifier> targetIdentifier)
{
if (!targetIdentifier)
targetIdentifier = PlayerIdentifier::FromTarget(handler);
if (!targetIdentifier)
{
handler->PSendSysMessage("Syntax: .list inventory [$playername]|nOutputs a list of character with $playername (or selected if name not provided) Inventory.");
return true;
}
Player* target = targetIdentifier->GetConnectedPlayer();
// check if target is ingame
if (target)
{
std::string Output = target->GetSession()->GetPlayerInfo();
for (uint8 i = EQUIPMENT_SLOT_START; i < INVENTORY_SLOT_ITEM_END; i++)
if (Item* pItem = target->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
handler->PSendSysMessage("%s%sx%u - %s", Output.c_str(), (handler->IsConsole() ? "[" + std::to_string(pItem->GetEntry()) + "] [" + pItem->GetTemplate()->Name1 + "]" : pItem->GetItemLink()), pItem->GetCount(), i >= INVENTORY_SLOT_BAG_END ? "Bag" : "Equipped");
for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; i++)
for (uint8 j = 0; j < MAX_BAG_SIZE; j++)
if (Item* pItem = target->GetItemByPos(((i << 8) | j)))
handler->PSendSysMessage("%s%sx%u - Bag", Output.c_str(), (handler->IsConsole() ? "[" + std::to_string(pItem->GetEntry()) + "] [" + pItem->GetTemplate()->Name1 + "]" : pItem->GetItemLink()), pItem->GetCount());
for (uint8 i = BANK_SLOT_ITEM_START; i < BANK_SLOT_ITEM_END; i++)
if (Item* pItem = target->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
handler->PSendSysMessage("%s%sx%u - Bank", Output.c_str(), (handler->IsConsole() ? "[" + std::to_string(pItem->GetEntry()) + "] [" + pItem->GetTemplate()->Name1 + "]" : pItem->GetItemLink()), pItem->GetCount());
for (uint8 i = BANK_SLOT_BAG_START; i < BANK_SLOT_BAG_END; i++)
if (Item* pItem = target->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
{
handler->PSendSysMessage("%s%sx%u - Bank", Output.c_str(), (handler->IsConsole() ? "[" + std::to_string(pItem->GetEntry()) + "] [" + pItem->GetTemplate()->Name1 + "]" : pItem->GetItemLink()), pItem->GetCount());
for (uint8 j = 0; j < MAX_BAG_SIZE; j++)
if (Item* pItem2 = target->GetItemByPos(i, j))
handler->PSendSysMessage("%s%sx%u - Bank", Output.c_str(), (handler->IsConsole() ? "[" + std::to_string(pItem->GetEntry()) + "] [" + pItem2->GetTemplate()->Name1 + "]" : pItem2->GetItemLink()), pItem2->GetCount());
}
for (uint8 i = CURRENCYTOKEN_SLOT_START; i < CURRENCYTOKEN_SLOT_END; i++)
if (Item* pItem = target->GetItemByPos(INVENTORY_SLOT_BAG_0, i))
handler->PSendSysMessage("%s%sx%u - Currency", Output.c_str(), (handler->IsConsole() ? "[" + std::to_string(pItem->GetEntry()) + "][" + pItem->GetTemplate()->Name1 + "]" : pItem->GetItemLink()), pItem->GetCount());
}
else // otherwise db lookup
{
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SEL_CHARACTER_INVENTORY);
stmt->setUInt32(0, targetIdentifier->GetGUID().GetCounter());
PreparedQueryResult queryResult = CharacterDatabase.Query(stmt);
if (queryResult)
{
do
{
Field* fields = queryResult->Fetch();
Item* item = nullptr;
ObjectGuid::LowType bagGuid = fields[11].GetUInt32();
uint8 slot = fields[12].GetUInt8();
ObjectGuid::LowType itemGuid = fields[13].GetUInt32();
uint32 itemEntry = fields[14].GetUInt32();
if (ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemEntry))
{
item = NewItemOrBag(proto);
if (!item->LoadFromDB(itemGuid, targetIdentifier->GetGUID(), fields, itemEntry))
{
delete item;
continue;
}
std::ostringstream ItemLink;
if (!handler->IsConsole())
ItemLink << item->GetItemLink();
else
ItemLink << "[" << itemEntry << "] [" << proto->Name1 << "]";
handler->PSendSysMessage("GUID %u: %s has %sx%u", targetIdentifier->GetGUID().GetCounter(), targetIdentifier->GetName().c_str(), ItemLink.str().c_str(), item->GetCount());
delete item;
}
} while (queryResult->NextRow());
}
else
handler->PSendSysMessage("Player %s not found, or doesn't have any items.", targetIdentifier->GetName().c_str());
}
return true;
}