diff options
| author | Shauren <shauren.trinity@gmail.com> | 2022-09-14 20:49:38 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2022-09-14 20:49:38 +0200 |
| commit | f19f32f2a49cf0eb235f1aa12106322bf9db2a15 (patch) | |
| tree | 1c01c7b4f087777b9e57d039bf40e3987957dc35 /src/server/game/Entities | |
| parent | d0a5d04c4c8f17ecd0ba6efaa114da051d303155 (diff) | |
Core/Loot: Store references to Loot objects directly in players loot view map instead of guids of world objects holding that loot
Diffstat (limited to 'src/server/game/Entities')
| -rw-r--r-- | src/server/game/Entities/Player/Player.cpp | 37 | ||||
| -rw-r--r-- | src/server/game/Entities/Player/Player.h | 8 |
2 files changed, 12 insertions, 33 deletions
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index 9e5cf7b1371..9bd1c78d664 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -8704,31 +8704,13 @@ void Player::ApplyAllAzeriteEmpoweredItemMods(bool apply) } } -ObjectGuid Player::GetLootWorldObjectGUID(ObjectGuid const& lootObjectGuid) const +Loot* Player::GetLootByWorldObjectGUID(ObjectGuid const& lootWorldObjectGuid) const { - auto itr = m_AELootView.find(lootObjectGuid); - if (itr != m_AELootView.end()) - return itr->second; - - return ObjectGuid::Empty; -} - -void Player::RemoveAELootedWorldObject(ObjectGuid const& lootWorldObjectGuid) -{ - auto itr = std::find_if(m_AELootView.begin(), m_AELootView.end(), [&lootWorldObjectGuid](std::pair<ObjectGuid const, ObjectGuid> const& lootView) + auto itr = std::find_if(m_AELootView.begin(), m_AELootView.end(), [&lootWorldObjectGuid](std::pair<ObjectGuid const, Loot*> const& lootView) { - return lootView.second == lootWorldObjectGuid; - }); - if (itr != m_AELootView.end()) - m_AELootView.erase(itr); -} - -bool Player::HasLootWorldObjectGUID(ObjectGuid const& lootWorldObjectGuid) const -{ - return m_AELootView.end() != std::find_if(m_AELootView.begin(), m_AELootView.end(), [&lootWorldObjectGuid](std::pair<ObjectGuid const, ObjectGuid> const& lootView) - { - return lootView.second == lootWorldObjectGuid; + return lootView.second->GetOwnerGUID() == lootWorldObjectGuid; }); + return itr != m_AELootView.end() ? itr->second : nullptr; } /* If in a battleground a player dies, and an enemy removes the insignia, the player's bones is lootable @@ -8860,8 +8842,6 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type, bool aeLooting/* = fa if (lootid) { - loot->clear(); - Group* group = GetGroup(); bool groupRules = (group && go->GetGOInfo()->type == GAMEOBJECT_TYPE_CHEST && go->GetGOInfo()->chest.usegrouplootrules); @@ -9018,8 +8998,9 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type, bool aeLooting/* = fa if (creature->CanGeneratePickPocketLoot()) { creature->StartPickPocketRefillTimer(); - loot->clear(); + loot = new Loot(GetMap(), creature->GetGUID(), LOOT_PICKPOCKETING); + creature->m_loot.reset(loot); if (uint32 lootid = creature->GetCreatureTemplate()->pickpocketLootId) loot->FillLoot(lootid, LootTemplates_Pickpocketing, this, true); @@ -9151,7 +9132,7 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type, bool aeLooting/* = fa // add 'this' player as one of the players that are looting 'loot' loot->AddLooter(GetGUID()); - m_AELootView[loot->GetGUID()] = guid; + m_AELootView[loot->GetGUID()] = loot; if (loot_type == LOOT_CORPSE && !guid.IsItem()) SetUnitFlag(UNIT_FLAG_LOOTING); @@ -13052,7 +13033,7 @@ void Player::SwapItem(uint16 src, uint16 dst) { if (Item* bagItem = bag->GetItemByPos(i)) { - if (HasLootWorldObjectGUID(bagItem->GetGUID())) + if (GetLootByWorldObjectGUID(bagItem->GetGUID())) { m_session->DoLootReleaseAll(); released = true; // so we don't need to look at dstBag @@ -13069,7 +13050,7 @@ void Player::SwapItem(uint16 src, uint16 dst) { if (Item* bagItem = bag->GetItemByPos(i)) { - if (HasLootWorldObjectGUID(bagItem->GetGUID())) + if (GetLootByWorldObjectGUID(bagItem->GetGUID())) { m_session->DoLootReleaseAll(); break; diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h index 40eaae73828..9b52a94a6d0 100644 --- a/src/server/game/Entities/Player/Player.h +++ b/src/server/game/Entities/Player/Player.h @@ -2062,10 +2062,8 @@ class TC_GAME_API Player : public Unit, public GridObject<Player> ObjectGuid const& GetLootGUID() const { return m_playerData->LootTargetGUID; } void SetLootGUID(ObjectGuid const& guid) { SetUpdateFieldValue(m_values.ModifyValue(&Player::m_playerData).ModifyValue(&UF::PlayerData::LootTargetGUID), guid); } - ObjectGuid GetLootWorldObjectGUID(ObjectGuid const& lootObjectGuid) const; - void RemoveAELootedWorldObject(ObjectGuid const& lootWorldObjectGuid); - bool HasLootWorldObjectGUID(ObjectGuid const& lootWorldObjectGuid) const; - std::unordered_map<ObjectGuid, ObjectGuid> const& GetAELootView() const { return m_AELootView; } + Loot* GetLootByWorldObjectGUID(ObjectGuid const& lootWorldObjectGuid) const; + std::unordered_map<ObjectGuid, Loot*> const& GetAELootView() const { return m_AELootView; } void RemovedInsignia(Player* looterPlr); @@ -3178,7 +3176,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player> SceneMgr m_sceneMgr; - std::unordered_map<ObjectGuid /*LootObject*/, ObjectGuid /*world object*/> m_AELootView; + std::unordered_map<ObjectGuid /*LootObject*/, Loot*> m_AELootView; void _InitHonorLevelOnLoadFromDB(uint32 honor, uint32 honorLevel); std::unique_ptr<RestMgr> _restMgr; |
