aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2022-08-25 14:46:34 +0200
committerShauren <shauren.trinity@gmail.com>2022-08-25 14:46:34 +0200
commitba251da7c3615100cba60511a60cfa4f6b3bf0e2 (patch)
tree4e301fe0b144d1aab0f3cd4b2d114fe8ec60f213 /src
parent605b75f6c06647345b44e9ef1975d01122ef129f (diff)
Core/Loot: Removed unneccessary field from Loot class and pass it as parameter everywhere
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Entities/Player/Player.cpp11
-rw-r--r--src/server/game/Entities/Player/Player.h2
-rw-r--r--src/server/game/Handlers/LootHandler.cpp6
-rw-r--r--src/server/game/Loot/Loot.h4
-rw-r--r--src/server/game/Loot/LootItemStorage.cpp14
-rw-r--r--src/server/game/Loot/LootItemStorage.h2
6 files changed, 16 insertions, 23 deletions
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index b44260c7066..6185f49737c 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -8922,9 +8922,6 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type, bool aeLooting/* = fa
loot = &item->loot;
- // Store container id
- loot->containerID = item->GetGUID();
-
// If item doesn't already have loot, attempt to load it. If that
// fails then this is first time opening, generate loot
if (!item->m_lootGenerated && !sLootItemStorage->LoadStoredLoot(item, this))
@@ -8950,7 +8947,7 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type, bool aeLooting/* = fa
// Force save the loot and money items that were just rolled
// Also saves the container item ID in Loot struct (not to DB)
if (loot->gold > 0 || loot->unlootedCount > 0)
- sLootItemStorage->AddNewStoredLoot(loot, this);
+ sLootItemStorage->AddNewStoredLoot(item->GetGUID().GetCounter(), loot, this);
break;
}
@@ -26061,7 +26058,7 @@ void Player::AutoStoreLoot(uint8 bag, uint8 slot, uint32 loot_id, LootStore cons
Unit::ProcSkillsAndAuras(this, nullptr, PROC_FLAG_LOOTED, PROC_FLAG_NONE, PROC_SPELL_TYPE_MASK_ALL, PROC_SPELL_PHASE_NONE, PROC_HIT_NONE, nullptr, nullptr, nullptr);
}
-void Player::StoreLootItem(uint8 lootSlot, Loot* loot, AELootResult* aeResult/* = nullptr*/)
+void Player::StoreLootItem(ObjectGuid lootWorldObjectGuid, uint8 lootSlot, Loot* loot, AELootResult* aeResult/* = nullptr*/)
{
NotNormalLootItem* qitem = nullptr;
NotNormalLootItem* ffaitem = nullptr;
@@ -26150,8 +26147,8 @@ void Player::StoreLootItem(uint8 lootSlot, Loot* loot, AELootResult* aeResult/*
aeResult->Add(newitem, item->count, loot->loot_type);
// LootItem is being removed (looted) from the container, delete it from the DB.
- if (!loot->containerID.IsEmpty())
- sLootItemStorage->RemoveStoredLootItemForContainer(loot->containerID.GetCounter(), item->itemid, item->count, item->itemIndex);
+ if (lootWorldObjectGuid.IsItem() && loot->loot_type == LOOT_CORPSE)
+ sLootItemStorage->RemoveStoredLootItemForContainer(lootWorldObjectGuid.GetCounter(), item->itemid, item->count, item->itemIndex);
ApplyItemLootedSpell(newitem, true);
}
diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h
index 2f7d79c8781..30522d21adb 100644
--- a/src/server/game/Entities/Player/Player.h
+++ b/src/server/game/Entities/Player/Player.h
@@ -1412,7 +1412,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
bool StoreNewItemInBestSlots(uint32 item_id, uint32 item_count);
void AutoStoreLoot(uint8 bag, uint8 slot, uint32 loot_id, LootStore const& store, ItemContext context = ItemContext::NONE, bool broadcast = false, bool createdByPlayer = false);
void AutoStoreLoot(uint32 loot_id, LootStore const& store, ItemContext context = ItemContext::NONE, bool broadcast = false, bool createdByPlayer = false) { AutoStoreLoot(NULL_BAG, NULL_SLOT, loot_id, store, context, broadcast, createdByPlayer); }
- void StoreLootItem(uint8 lootSlot, Loot* loot, AELootResult* aeResult = nullptr);
+ void StoreLootItem(ObjectGuid lootWorldObjectGuid, uint8 lootSlot, Loot* loot, AELootResult* aeResult = nullptr);
InventoryResult CanTakeMoreSimilarItems(uint32 entry, uint32 count, Item* pItem, uint32* no_space_count = nullptr, uint32* offendingItemId = nullptr) const;
InventoryResult CanStoreItem(uint8 bag, uint8 slot, ItemPosCountVec& dest, uint32 entry, uint32 count, Item* pItem = nullptr, bool swap = false, uint32* no_space_count = nullptr) const;
diff --git a/src/server/game/Handlers/LootHandler.cpp b/src/server/game/Handlers/LootHandler.cpp
index 4fbe3c96b63..615f574d08e 100644
--- a/src/server/game/Handlers/LootHandler.cpp
+++ b/src/server/game/Handlers/LootHandler.cpp
@@ -123,7 +123,7 @@ void WorldSession::HandleAutostoreLootItemOpcode(WorldPackets::Loot::LootItem& p
loot = &creature->loot;
}
- player->StoreLootItem(req.LootListID - 1, loot, aeResultPtr);
+ player->StoreLootItem(lguid, req.LootListID - 1, loot, aeResultPtr);
// If player is removing the last LootItem, delete the empty container.
if (loot->isLooted() && lguid.IsItem())
@@ -257,8 +257,8 @@ void WorldSession::HandleLootMoneyOpcode(WorldPackets::Loot::LootMoney& /*packet
loot->gold = 0;
// Delete the money loot record from the DB
- if (!loot->containerID.IsEmpty())
- sLootItemStorage->RemoveStoredMoneyForContainer(loot->containerID.GetCounter());
+ if (guid.IsItem() && loot->loot_type == LOOT_CORPSE)
+ sLootItemStorage->RemoveStoredMoneyForContainer(guid.GetCounter());
// Delete container if empty
if (loot->isLooted() && guid.IsItem())
diff --git a/src/server/game/Loot/Loot.h b/src/server/game/Loot/Loot.h
index a1bd2d26a6c..d5d1f771f08 100644
--- a/src/server/game/Loot/Loot.h
+++ b/src/server/game/Loot/Loot.h
@@ -220,10 +220,6 @@ struct TC_GAME_API Loot
LootType loot_type; // required for achievement system
uint8 maxDuplicates; // Max amount of items with the same entry that can drop (default is 1; on 25 man raid mode 3)
- // GUID of container that holds this loot (item_instance.entry)
- // Only set for inventory items that can be right-click looted
- ObjectGuid containerID;
-
Loot(uint32 _gold = 0);
~Loot();
diff --git a/src/server/game/Loot/LootItemStorage.cpp b/src/server/game/Loot/LootItemStorage.cpp
index 476f80d4e09..e1cf342fd4d 100644
--- a/src/server/game/Loot/LootItemStorage.cpp
+++ b/src/server/game/Loot/LootItemStorage.cpp
@@ -143,7 +143,7 @@ bool LootItemStorage::LoadStoredLoot(Item* item, Player* player)
{
std::shared_lock<std::shared_mutex> lock(*GetLock());
- auto itr = _lootItemStore.find(loot->containerID.GetCounter());
+ auto itr = _lootItemStore.find(item->GetGUID().GetCounter());
if (itr == _lootItemStore.end())
return false;
@@ -235,7 +235,7 @@ void LootItemStorage::RemoveStoredLootItemForContainer(uint64 containerId, uint3
itr->second.RemoveItem(itemId, count, itemIndex);
}
-void LootItemStorage::AddNewStoredLoot(Loot* loot, Player* player)
+void LootItemStorage::AddNewStoredLoot(uint64 containerId, Loot* loot, Player* player)
{
// Saves the money and item loot associated with an openable item to the DB
if (loot->isLooted()) // no money and no loot
@@ -245,22 +245,22 @@ void LootItemStorage::AddNewStoredLoot(Loot* loot, Player* player)
{
std::shared_lock<std::shared_mutex> lock(*GetLock());
- auto itr = _lootItemStore.find(loot->containerID.GetCounter());
+ auto itr = _lootItemStore.find(containerId);
if (itr != _lootItemStore.end())
{
- TC_LOG_ERROR("misc", "Trying to store item loot by player: %s for container id: %s that is already in storage!", player->GetGUID().ToString().c_str(), loot->containerID.ToString().c_str());
+ TC_LOG_ERROR("misc", "Trying to store item loot by player: %s for container id: " UI64FMTD " that is already in storage!", player->GetGUID().ToString().c_str(), containerId);
return;
}
}
- StoredLootContainer container(loot->containerID.GetCounter());
+ StoredLootContainer container(containerId);
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
if (loot->gold)
container.AddMoney(loot->gold, trans);
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_ITEMCONTAINER_ITEMS);
- stmt->setUInt64(0, loot->containerID.GetCounter());
+ stmt->setUInt64(0, containerId);
trans->Append(stmt);
for (LootItem const& li : loot->items)
@@ -286,7 +286,7 @@ void LootItemStorage::AddNewStoredLoot(Loot* loot, Player* player)
// write
{
std::unique_lock<std::shared_mutex> lock(*GetLock());
- _lootItemStore.emplace(loot->containerID.GetCounter(), std::move(container));
+ _lootItemStore.emplace(containerId, std::move(container));
}
}
diff --git a/src/server/game/Loot/LootItemStorage.h b/src/server/game/Loot/LootItemStorage.h
index a696e43d475..9ff9ff55310 100644
--- a/src/server/game/Loot/LootItemStorage.h
+++ b/src/server/game/Loot/LootItemStorage.h
@@ -84,7 +84,7 @@ class LootItemStorage
void RemoveStoredMoneyForContainer(uint64 containerId);
void RemoveStoredLootForContainer(uint64 containerId);
void RemoveStoredLootItemForContainer(uint64 containerId, uint32 itemId, uint32 count, uint32 itemIndex);
- void AddNewStoredLoot(Loot* loot, Player* player);
+ void AddNewStoredLoot(uint64 containerId, Loot* loot, Player* player);
private:
LootItemStorage() { }