mirror of
https://github.com/brighton-chi/mod-aoe-loot.git
synced 2026-02-07 20:51:10 +00:00
Update aoe_loot.cpp
This commit is contained in:
@@ -72,6 +72,11 @@ bool AoeLootCommandScript::HandleStartAoeLootCommand(ChatHandler* handler, Optio
|
|||||||
if (!player || !creature || !player->IsInWorld())
|
if (!player || !creature || !player->IsInWorld())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (!creature->hasLootRecipient() || !creature->isTappedBy(player)) {
|
||||||
|
// Not a valid loot target for this player
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Skip if corpse is not valid for looting
|
// Skip if corpse is not valid for looting
|
||||||
if (!creature->HasDynamicFlag(UNIT_DYNFLAG_LOOTABLE))
|
if (!creature->HasDynamicFlag(UNIT_DYNFLAG_LOOTABLE))
|
||||||
{
|
{
|
||||||
@@ -84,7 +89,9 @@ bool AoeLootCommandScript::HandleStartAoeLootCommand(ChatHandler* handler, Optio
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Additional permission check
|
// Additional permission check
|
||||||
if (!player->GetMap()->Instanceable() && !player->isAllowedToLoot(creature))
|
if (!player->GetMap()->Instanceable())
|
||||||
|
{
|
||||||
|
if(!player->isAllowedToLoot(creature))
|
||||||
{
|
{
|
||||||
if (sConfigMgr->GetOption<bool>("AOELoot.Debug", true))
|
if (sConfigMgr->GetOption<bool>("AOELoot.Debug", true))
|
||||||
{
|
{
|
||||||
@@ -93,6 +100,7 @@ bool AoeLootCommandScript::HandleStartAoeLootCommand(ChatHandler* handler, Optio
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Double-check distance to prevent exploits
|
// Double-check distance to prevent exploits
|
||||||
if (player->GetDistance(creature) > range)
|
if (player->GetDistance(creature) > range)
|
||||||
@@ -105,8 +113,8 @@ bool AoeLootCommandScript::HandleStartAoeLootCommand(ChatHandler* handler, Optio
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set loot GUID to current creature
|
|
||||||
player->SetLootGUID(creature->GetGUID());
|
player->SetLootGUID(creature->GetGUID());
|
||||||
|
|
||||||
Loot* loot = &creature->loot;
|
Loot* loot = &creature->loot;
|
||||||
|
|
||||||
uint32 maxSlots = loot->GetMaxSlotInLootFor(player);
|
uint32 maxSlots = loot->GetMaxSlotInLootFor(player);
|
||||||
@@ -127,8 +135,9 @@ bool AoeLootCommandScript::HandleStartAoeLootCommand(ChatHandler* handler, Optio
|
|||||||
if (!lootItem)
|
if (!lootItem)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Check if player can loot this item
|
if (!player->GetMap()->Instanceable())
|
||||||
if (!lootItem->AllowedForPlayer(player, creature->GetGUID()))
|
{
|
||||||
|
if(!player->isAllowedToLoot(creature))
|
||||||
{
|
{
|
||||||
if (sConfigMgr->GetOption<bool>("AOELoot.Debug", true))
|
if (sConfigMgr->GetOption<bool>("AOELoot.Debug", true))
|
||||||
{
|
{
|
||||||
@@ -137,6 +146,7 @@ bool AoeLootCommandScript::HandleStartAoeLootCommand(ChatHandler* handler, Optio
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Skip items that are currently being rolled on in group
|
// Skip items that are currently being rolled on in group
|
||||||
if (lootItem->is_blocked)
|
if (lootItem->is_blocked)
|
||||||
@@ -151,18 +161,6 @@ bool AoeLootCommandScript::HandleStartAoeLootCommand(ChatHandler* handler, Optio
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First pass - only process quest items
|
|
||||||
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(lootItem->itemid);
|
|
||||||
|
|
||||||
if (!itemTemplate || !(itemTemplate->Class == ITEM_CLASS_QUEST))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (sConfigMgr->GetOption<bool>("AOELoot.Debug", true))
|
|
||||||
{
|
|
||||||
LOG_DEBUG("module.aoe_loot", "AOE Loot: Attempting to loot quest item ID: {} Count: {} Slot: {} from {}", lootItem->itemid, static_cast<uint32_t>(lootItem->count), i, creature->GetGUID().ToString());
|
|
||||||
handler->PSendSysMessage(fmt::format("AOE Loot: Attempting to loot quest item ID: {} Count: {} Slot: {} from {}", lootItem->itemid, static_cast<uint32_t>(lootItem->count), i, creature->GetGUID().ToString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store the loot item in the player's inventory
|
// Store the loot item in the player's inventory
|
||||||
InventoryResult msg;
|
InventoryResult msg;
|
||||||
player->StoreLootItem(i, loot, msg);
|
player->StoreLootItem(i, loot, msg);
|
||||||
@@ -176,87 +174,24 @@ bool AoeLootCommandScript::HandleStartAoeLootCommand(ChatHandler* handler, Optio
|
|||||||
handler->PSendSysMessage(fmt::format("AOE Loot: Successfully looted quest item (ID: {}) x{} from {}", lootItem->itemid, static_cast<uint32_t>(lootItem->count), creature->GetGUID().ToString()));
|
handler->PSendSysMessage(fmt::format("AOE Loot: Successfully looted quest item (ID: {}) x{} from {}", lootItem->itemid, static_cast<uint32_t>(lootItem->count), creature->GetGUID().ToString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process items - second pass for non-quest items
|
|
||||||
for (uint32 i = 0; i < maxSlots; ++i)
|
|
||||||
{
|
|
||||||
LootItem* lootItem = loot->LootItemInSlot(i, player);
|
|
||||||
|
|
||||||
if (!lootItem)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Check if player can loot this item
|
|
||||||
if (!lootItem->AllowedForPlayer(player, creature->GetGUID()))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip items that are currently being rolled on in group
|
|
||||||
if (lootItem->is_blocked)
|
|
||||||
{
|
|
||||||
if (sConfigMgr->GetOption<bool>("AOELoot.Debug", true))
|
|
||||||
{
|
|
||||||
totalSkippedItems++;
|
|
||||||
|
|
||||||
LOG_DEBUG("module.aoe_loot", "AOE Loot: Item in slot {} is currently being rolled on - skipping", i);
|
|
||||||
handler->PSendSysMessage(fmt::format("AOE Loot: Item in slot {} is currently being rolled on - skipping", i));
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Second pass - skip quest items (already processed)
|
|
||||||
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(lootItem->itemid);
|
|
||||||
|
|
||||||
if (!itemTemplate || (itemTemplate->Class == ITEM_CLASS_QUEST))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (sConfigMgr->GetOption<bool>("AOELoot.Debug", true))
|
|
||||||
{
|
|
||||||
LOG_DEBUG("module.aoe_loot", "AOE Loot: Attempting to loot item ID: {} Count: {} Slot: {} from {}", lootItem->itemid, static_cast<uint32_t>(lootItem->count), i, creature->GetGUID().ToString());
|
|
||||||
handler->PSendSysMessage(fmt::format("AOE Loot: Attempting to loot item ID: {} Count: {} Slot: {} from {}", lootItem->itemid, static_cast<uint32_t>(lootItem->count), i, creature->GetGUID().ToString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
InventoryResult msg;
|
|
||||||
player->StoreLootItem(i, loot, msg);
|
|
||||||
|
|
||||||
if (sConfigMgr->GetOption<bool>("AOELoot.Debug", true))
|
|
||||||
{
|
|
||||||
totalItemsLooted++;
|
|
||||||
itemsLootedFromCorpse++;
|
|
||||||
|
|
||||||
LOG_DEBUG("module.aoe_loot", "AOE Loot: Successfully looted item (ID: {}) x{} from {}", lootItem->itemid, static_cast<uint32_t>(lootItem->count), creature->GetGUID().ToString());
|
|
||||||
handler->PSendSysMessage(fmt::format("AOE Loot: Successfully looted item (ID: {}) x{} from {}", lootItem->itemid, static_cast<uint32_t>(lootItem->count), creature->GetGUID().ToString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Process gold
|
// Process gold
|
||||||
if (loot->gold > 0)
|
if (loot->gold > 0)
|
||||||
{
|
{
|
||||||
uint32 copperAmount = loot->gold;
|
// Create a dummy packet for money loot
|
||||||
player->ModifyMoney(copperAmount);
|
WorldPacket moneyPacket(CMSG_LOOT_MONEY, 0);
|
||||||
player->UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_LOOT_MONEY, copperAmount);
|
// Send the packet to loot money
|
||||||
loot->gold = 0;
|
player->GetSession()->HandleLootMoneyOpcode(moneyPacket);
|
||||||
|
|
||||||
if (sConfigMgr->GetOption<bool>("AOELoot.Debug", true))
|
if (sConfigMgr->GetOption<bool>("AOELoot.Debug", true))
|
||||||
{
|
{
|
||||||
totalCopperLooted += copperAmount;
|
LOG_DEBUG("module.aoe_loot", "AOE Loot: Looted {} copper from {}", loot->gold, creature->GetGUID().ToString());
|
||||||
|
handler->PSendSysMessage(fmt::format("AOE Loot: Looted {} copper from {}", loot->gold, creature->GetGUID().ToString()));
|
||||||
LOG_DEBUG("module.aoe_loot", "AOE Loot: Looted {} copper from {}", copperAmount, creature->GetGUID().ToString());
|
|
||||||
handler->PSendSysMessage(fmt::format("AOE Loot: Looted {} copper from {}", copperAmount, creature->GetGUID().ToString()));
|
|
||||||
}
|
}
|
||||||
handler->PSendSysMessage(fmt::format("AOE Loot: Looted {} copper from {}", copperAmount, creature->GetGUID().ToString()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the corpse is now fully looted
|
// Check if the corpse is now fully looted
|
||||||
if (loot->isLooted())
|
if (loot->isLooted() && loot->quest_items.empty())
|
||||||
{
|
{
|
||||||
if (sConfigMgr->GetOption<bool>("AOELoot.Debug", true))
|
|
||||||
{
|
|
||||||
totalCorpsesLooted++;
|
|
||||||
LOG_DEBUG("module.aoe_loot", "AOE Loot: All loot removed from corpse for {}", creature->GetGUID().ToString());
|
|
||||||
handler->PSendSysMessage(fmt::format("AOE Loot: All loot removed from corpse for {}", creature->GetGUID().ToString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cleanup the loot object from the corpse
|
// Cleanup the loot object from the corpse
|
||||||
creature->AllLootRemovedFromCorpse();
|
creature->AllLootRemovedFromCorpse();
|
||||||
creature->RemoveDynamicFlag(UNIT_DYNFLAG_LOOTABLE);
|
creature->RemoveDynamicFlag(UNIT_DYNFLAG_LOOTABLE);
|
||||||
@@ -268,7 +203,7 @@ bool AoeLootCommandScript::HandleStartAoeLootCommand(ChatHandler* handler, Optio
|
|||||||
LOG_DEBUG("module.aoe_loot", "AOE Loot: Summary - Looted {} items, {} gold from {} corpses, skipped {} items", totalItemsLooted, totalCopperLooted, totalCorpsesLooted, totalSkippedItems);
|
LOG_DEBUG("module.aoe_loot", "AOE Loot: Summary - Looted {} items, {} gold from {} corpses, skipped {} items", totalItemsLooted, totalCopperLooted, totalCorpsesLooted, totalSkippedItems);
|
||||||
handler->PSendSysMessage(fmt::format("AOE Loot: Looted {} items and {} gold from {} corpses", totalItemsLooted, totalCopperLooted, totalCorpsesLooted));
|
handler->PSendSysMessage(fmt::format("AOE Loot: Looted {} items and {} gold from {} corpses", totalItemsLooted, totalCopperLooted, totalCorpsesLooted));
|
||||||
}
|
}
|
||||||
|
player->SetLootGUID(ObjectGuid::Empty);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user