From f239908840d835b7e3de7d1e555908062acf6d22 Mon Sep 17 00:00:00 2001 From: Necropola Date: Mon, 17 May 2021 00:15:51 +0200 Subject: [PATCH] fix(Core/Loot): make Loot::AddItem() honor LootItem::AllowedForPlayer() (#5774) Original Author: @Wyrserth --- src/server/game/Loot/LootMgr.cpp | 32 ++++++++++++++++++++++++++++++++ src/server/game/Loot/LootMgr.h | 1 + 2 files changed, 33 insertions(+) diff --git a/src/server/game/Loot/LootMgr.cpp b/src/server/game/Loot/LootMgr.cpp index 928df7950..d5d5f30fd 100644 --- a/src/server/game/Loot/LootMgr.cpp +++ b/src/server/game/Loot/LootMgr.cpp @@ -474,6 +474,36 @@ void Loot::AddItem(LootStoreItem const& item) lootItems.push_back(generatedLoot); count -= proto->GetMaxStackSize(); + // In some cases, a dropped item should be visible/lootable only for some players in group + bool canSeeItemInLootWindow = false; + if (auto player = ObjectAccessor::FindPlayer(lootOwnerGUID)) + { + if (auto group = player->GetGroup()) + { + for (auto itr = group->GetFirstMember(); itr != nullptr; itr = itr->next()) + { + if (auto member = itr->GetSource()) + { + if (generatedLoot.AllowedForPlayer(member)) + { + canSeeItemInLootWindow = true; + break; + } + } + } + } + else if (generatedLoot.AllowedForPlayer(player)) + { + canSeeItemInLootWindow = true; + } + } + + if (!canSeeItemInLootWindow) + { + LOG_DEBUG("loot", "Skipping ++unlootedCount for unlootable item: %u", item.itemid); + continue; + } + // non-conditional one-player only items are counted here, // free for all items are counted in FillFFALoot(), // non-ffa conditionals are counted in FillNonQuestNonFFAConditionalLoot() @@ -489,6 +519,8 @@ bool Loot::FillLoot(uint32 lootId, LootStore const& store, Player* lootOwner, bo if (!lootOwner) return false; + lootOwnerGUID = lootOwner->GetGUID(); + LootTemplate const* tab = store.GetLootFor(lootId); if (!tab) diff --git a/src/server/game/Loot/LootMgr.h b/src/server/game/Loot/LootMgr.h index 10f9b76e4..890542938 100644 --- a/src/server/game/Loot/LootMgr.h +++ b/src/server/game/Loot/LootMgr.h @@ -309,6 +309,7 @@ struct Loot uint32 gold; uint8 unlootedCount{0}; ObjectGuid roundRobinPlayer; // GUID of the player having the Round-Robin ownership for the loot. If 0, round robin owner has released. + ObjectGuid lootOwnerGUID; LootType loot_type{LOOT_NONE}; // required for achievement system // GUID of container that holds this loot (item_instance.entry), set for items that can be looted