feat(Core/Commands): add .npc showloot to display corpse loot (#26374)

This commit is contained in:
Kitzunu
2026-07-04 23:01:54 +02:00
committed by GitHub
parent 3586fc9593
commit 8cca034053
3 changed files with 70 additions and 1 deletions

View File

@@ -1520,6 +1520,15 @@ enum AcoreStrings
LANG_PET_RENAME_SUCCESS = 35454,
// Wintergrasp shutdown deferral
LANG_WG_SHUTDOWN_DEFERRED = 35455
LANG_WG_SHUTDOWN_DEFERRED = 35455,
// npc showloot command
LANG_COMMAND_NOT_DEAD_OR_NO_LOOT = 35456,
LANG_COMMAND_NPC_SHOWLOOT_HEADER = 35457,
LANG_COMMAND_NPC_SHOWLOOT_MONEY = 35458,
LANG_COMMAND_NPC_SHOWLOOT_ITEMS = 35459,
LANG_COMMAND_NPC_SHOWLOOT_ENTRY = 35460,
LANG_COMMAND_NPC_SHOWLOOT_QUEST = 35461
};
#endif

View File

@@ -24,6 +24,7 @@
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "Language.h"
#include "LootMgr.h"
#include "MapMgr.h"
#include "ObjectMgr.h"
#include "Pet.h"
@@ -201,6 +202,7 @@ public:
{ "follow", npcFollowCommandTable },
{ "load", HandleNpcLoadCommand, SEC_ADMINISTRATOR, Console::Yes },
{ "set", npcSetCommandTable },
{ "showloot", HandleNpcShowLootCommand, rbac::RBAC_PERM_COMMAND_NPC_SHOWLOOT, Console::No },
{ "spawngroup", HandleNpcSpawnGroupCommand, SEC_ADMINISTRATOR, Console::No },
{ "despawngroup", HandleNpcDespawnGroupCommand, SEC_ADMINISTRATOR, Console::No }
};
@@ -1490,6 +1492,50 @@ public:
return true;
}
static void ShowLootEntry(ChatHandler* handler, LootItem const& item)
{
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(item.itemid);
std::string name = itemTemplate ? itemTemplate->Name1 : "Unknown item";
if (itemTemplate)
if (ItemLocale const* il = sObjectMgr->GetItemLocale(item.itemid))
ObjectMgr::GetLocaleString(il->Name, handler->GetSessionDbLocaleIndex(), name);
uint32 color = ItemQualityColors[itemTemplate ? itemTemplate->Quality : uint32(ITEM_QUALITY_POOR)];
handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_ENTRY, item.count, color, item.itemid, name, item.itemid);
}
static bool HandleNpcShowLootCommand(ChatHandler* handler)
{
Creature* creatureTarget = handler->getSelectedCreature();
if (!creatureTarget || creatureTarget->IsPet())
{
handler->SendErrorMessage(LANG_SELECT_CREATURE);
return false;
}
Loot const& loot = creatureTarget->loot;
if (!creatureTarget->isDead() || (loot.empty() && loot.quest_items.empty()))
{
handler->SendErrorMessage(LANG_COMMAND_NOT_DEAD_OR_NO_LOOT, creatureTarget->GetName());
return false;
}
handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_HEADER, creatureTarget->GetName(), creatureTarget->GetEntry());
handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_MONEY, loot.gold / GOLD, (loot.gold % GOLD) / SILVER, loot.gold % SILVER);
handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_ITEMS, loot.items.size());
for (LootItem const& item : loot.items)
if (!item.is_looted)
ShowLootEntry(handler, item);
handler->PSendSysMessage(LANG_COMMAND_NPC_SHOWLOOT_QUEST, loot.quest_items.size());
for (LootItem const& item : loot.quest_items)
if (!item.is_looted)
ShowLootEntry(handler, item);
return true;
}
};
void AddSC_npc_commandscript()