diff options
author | Shauren <shauren.trinity@gmail.com> | 2022-09-11 18:21:01 +0200 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2022-09-11 18:21:01 +0200 |
commit | e9d083a2ee59d297271b04f3b7fb63808f7f0c8c (patch) | |
tree | d32b537dcc05ff251d326f2f9424d4defe205fba /src/server/game/Loot/Loot.cpp | |
parent | 78698463ff6b20255148fb647e9ad33a487bb09d (diff) |
Core/Loot: Set loot guid and type in Loot constructor
Diffstat (limited to 'src/server/game/Loot/Loot.cpp')
-rw-r--r-- | src/server/game/Loot/Loot.cpp | 88 |
1 files changed, 42 insertions, 46 deletions
diff --git a/src/server/game/Loot/Loot.cpp b/src/server/game/Loot/Loot.cpp index 7445d96dc71..70d3da25e8f 100644 --- a/src/server/game/Loot/Loot.cpp +++ b/src/server/game/Loot/Loot.cpp @@ -23,6 +23,7 @@ #include "Log.h" #include "LootMgr.h" #include "LootPackets.h" +#include "Map.h" #include "ObjectAccessor.h" #include "ObjectMgr.h" #include "Player.h" @@ -125,7 +126,9 @@ void LootItem::AddAllowedLooter(const Player* player) // --------- Loot --------- // -Loot::Loot() : gold(0), unlootedCount(0), roundRobinPlayer(), loot_type(LOOT_NONE), maxDuplicates(1), _itemContext(ItemContext::NONE) +Loot::Loot(Map* map, ObjectGuid owner, LootType type) : gold(0), unlootedCount(0), roundRobinPlayer(), loot_type(type), maxDuplicates(1), + _guid(map ? ObjectGuid::Create<HighGuid::LootObject>(map->GetId(), 0, map->GenerateLowGuid<HighGuid::LootObject>()) : ObjectGuid::Empty), + _owner(owner), _itemContext(ItemContext::NONE) { } @@ -159,35 +162,31 @@ void Loot::clear() _itemContext = ItemContext::NONE; } -void Loot::NotifyItemRemoved(uint8 lootIndex) +void Loot::NotifyItemRemoved(uint8 lootIndex, Map const* map) { // notify all players that are looting this that the item was removed // convert the index to the slot the player sees - GuidSet::iterator i_next; - for (GuidSet::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next) + for (auto itr = PlayersLooting.begin(); itr != PlayersLooting.end();) { - i_next = i; - ++i_next; - if (Player* player = ObjectAccessor::FindPlayer(*i)) - player->SendNotifyLootItemRemoved(GetGUID(), lootIndex); + if (Player* player = ObjectAccessor::GetPlayer(map, *itr)) + { + player->SendNotifyLootItemRemoved(GetGUID(), GetOwnerGUID(), lootIndex); + ++itr; + } else - PlayersLooting.erase(i); + itr = PlayersLooting.erase(itr); } } -void Loot::NotifyQuestItemRemoved(uint8 questIndex) +void Loot::NotifyQuestItemRemoved(uint8 questIndex, Map const* map) { // when a free for all questitem is looted // all players will get notified of it being removed // (other questitems can be looted by each group member) // bit inefficient but isn't called often - - GuidSet::iterator i_next; - for (GuidSet::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next) + for (auto itr = PlayersLooting.begin(); itr != PlayersLooting.end();) { - i_next = i; - ++i_next; - if (Player* player = ObjectAccessor::FindPlayer(*i)) + if (Player* player = ObjectAccessor::GetPlayer(map, *itr)) { NotNormalLootItemMap::const_iterator pq = PlayerQuestItems.find(player->GetGUID()); if (pq != PlayerQuestItems.end() && pq->second) @@ -201,26 +200,28 @@ void Loot::NotifyQuestItemRemoved(uint8 questIndex) break; if (j < pql.size()) - player->SendNotifyLootItemRemoved(GetGUID(), items.size() + j); + player->SendNotifyLootItemRemoved(GetGUID(), GetOwnerGUID(), items.size() + j); } + + ++itr; } else - PlayersLooting.erase(i); + itr = PlayersLooting.erase(itr); } } -void Loot::NotifyMoneyRemoved() +void Loot::NotifyMoneyRemoved(Map const* map) { // notify all players that are looting this that the money was removed - GuidSet::iterator i_next; - for (GuidSet::iterator i = PlayersLooting.begin(); i != PlayersLooting.end(); i = i_next) + for (auto itr = PlayersLooting.begin(); itr != PlayersLooting.end();) { - i_next = i; - ++i_next; - if (Player* player = ObjectAccessor::FindPlayer(*i)) + if (Player* player = ObjectAccessor::GetPlayer(map, *itr)) + { player->SendNotifyLootMoneyRemoved(GetGUID()); + ++itr; + } else - PlayersLooting.erase(i); + itr = PlayersLooting.erase(itr); } } @@ -244,8 +245,6 @@ 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) @@ -260,16 +259,16 @@ bool Loot::FillLoot(uint32 lootId, LootStore const& store, Player* lootOwner, bo items.reserve(MAX_NR_LOOT_ITEMS); quest_items.reserve(MAX_NR_QUEST_ITEMS); - tab->Process(*this, store.IsRatesAllowed(), lootMode); // Processing is done there, callback via Loot::AddItem() + tab->Process(*this, store.IsRatesAllowed(), lootMode, 0, lootOwner); // Processing is done there, callback via Loot::AddItem() // Setting access rights for group loot case - Group* group = lootOwner->GetGroup(); + Group const* group = lootOwner->GetGroup(); if (!personal && group) { roundRobinPlayer = lootOwner->GetGUID(); - for (GroupReference* itr = group->GetFirstMember(); itr != nullptr; itr = itr->next()) - if (Player* player = itr->GetSource()) // should actually be looted object instead of lootOwner but looter has to be really close so doesnt really matter + for (GroupReference const* itr = group->GetFirstMember(); itr != nullptr; itr = itr->next()) + if (Player const* player = itr->GetSource()) // should actually be looted object instead of lootOwner but looter has to be really close so doesnt really matter if (player->IsInMap(lootOwner)) FillNotNormalLootFor(player, player->IsAtGroupRewardDistance(lootOwner)); @@ -288,7 +287,7 @@ bool Loot::FillLoot(uint32 lootId, LootStore const& store, Player* lootOwner, bo } // Inserts the item into the loot (called by LootTemplate processors) -void Loot::AddItem(LootStoreItem const& item) +void Loot::AddItem(LootStoreItem const& item, Player const* player) { ItemTemplate const* proto = sObjectMgr->GetItemTemplate(item.itemid); if (!proto) @@ -317,18 +316,15 @@ void Loot::AddItem(LootStoreItem const& item) // In some cases, a dropped item should be visible/lootable only for some players in group bool canSeeItemInLootWindow = false; - if (Player* player = ObjectAccessor::FindPlayer(lootOwnerGUID)) + if (Group const* group = player->GetGroup()) { - if (Group* group = player->GetGroup()) - { - for (GroupReference* itr = group->GetFirstMember(); itr != nullptr; itr = itr->next()) - if (Player* member = itr->GetSource()) - if (generatedLoot.AllowedForPlayer(member)) - canSeeItemInLootWindow = true; - } - else if (generatedLoot.AllowedForPlayer(player)) - canSeeItemInLootWindow = true; + for (GroupReference const* itr = group->GetFirstMember(); itr != nullptr; itr = itr->next()) + if (Player const* member = itr->GetSource()) + if (generatedLoot.AllowedForPlayer(member)) + canSeeItemInLootWindow = true; } + else if (generatedLoot.AllowedForPlayer(player)) + canSeeItemInLootWindow = true; if (!canSeeItemInLootWindow) continue; @@ -690,7 +686,7 @@ void Loot::BuildLootResponse(WorldPackets::Loot::LootResponse& packet, Player* v } } -void Loot::FillNotNormalLootFor(Player* player, bool presentAtLooting) +void Loot::FillNotNormalLootFor(Player const* player, bool presentAtLooting) { ObjectGuid plguid = player->GetGUID(); @@ -707,7 +703,7 @@ void Loot::FillNotNormalLootFor(Player* player, bool presentAtLooting) FillNonQuestNonFFAConditionalLoot(player, presentAtLooting); } -NotNormalLootItemList* Loot::FillFFALoot(Player* player) +NotNormalLootItemList* Loot::FillFFALoot(Player const* player) { NotNormalLootItemList* ql = new NotNormalLootItemList(); @@ -730,7 +726,7 @@ NotNormalLootItemList* Loot::FillFFALoot(Player* player) return ql; } -NotNormalLootItemList* Loot::FillQuestLoot(Player* player) +NotNormalLootItemList* Loot::FillQuestLoot(Player const* player) { if (items.size() == MAX_NR_LOOT_ITEMS) return nullptr; @@ -768,7 +764,7 @@ NotNormalLootItemList* Loot::FillQuestLoot(Player* player) return ql; } -NotNormalLootItemList* Loot::FillNonQuestNonFFAConditionalLoot(Player* player, bool presentAtLooting) +NotNormalLootItemList* Loot::FillNonQuestNonFFAConditionalLoot(Player const* player, bool presentAtLooting) { NotNormalLootItemList* ql = new NotNormalLootItemList(); |