diff --git a/Source/Game/Entities/Player/Player.Items.cs b/Source/Game/Entities/Player/Player.Items.cs index a7b001291..78a4d2b72 100644 --- a/Source/Game/Entities/Player/Player.Items.cs +++ b/Source/Game/Entities/Player/Player.Items.cs @@ -5976,7 +5976,7 @@ namespace Game.Entities //Loot public ObjectGuid GetLootGUID() { return m_playerData.LootTargetGUID; } public void SetLootGUID(ObjectGuid guid) { SetUpdateFieldValue(m_values.ModifyValue(m_playerData).ModifyValue(m_playerData.LootTargetGUID), guid); } - public void StoreLootItem(byte lootSlot, Loot loot, AELootResult aeResult = null) + public void StoreLootItem(ObjectGuid lootWorldObjectGuid, byte lootSlot, Loot loot, AELootResult aeResult = null) { LootItem item = loot.LootItemInSlot(lootSlot, this, out NotNormalLootItem qitem, out NotNormalLootItem ffaitem, out NotNormalLootItem conditem); if (item == null || item.is_looted) @@ -6064,8 +6064,8 @@ namespace Game.Entities 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()) - Global.LootItemStorage.RemoveStoredLootItemForContainer(loot.containerID.GetCounter(), item.itemid, item.count, item.itemIndex); + if (lootWorldObjectGuid.IsItem() && loot.loot_type == LootType.Corpse) + Global.LootItemStorage.RemoveStoredLootItemForContainer(lootWorldObjectGuid.GetCounter(), item.itemid, item.count, item.itemIndex); ApplyItemLootedSpell(newitem, true); } @@ -6279,9 +6279,6 @@ namespace Game.Entities 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 && !Global.LootItemStorage.LoadStoredLoot(item, this)) @@ -6307,7 +6304,7 @@ namespace Game.Entities // 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) - Global.LootItemStorage.AddNewStoredLoot(loot, this); + Global.LootItemStorage.AddNewStoredLoot(item.GetGUID().GetCounter(), loot, this); break; } diff --git a/Source/Game/Handlers/LootHandler.cs b/Source/Game/Handlers/LootHandler.cs index 9ae721396..a49f6fdb0 100644 --- a/Source/Game/Handlers/LootHandler.cs +++ b/Source/Game/Handlers/LootHandler.cs @@ -92,7 +92,7 @@ namespace Game loot = creature.loot; } - player.StoreLootItem((byte)(req.LootListID - 1), loot, aeResult); + player.StoreLootItem(lguid, (byte)(req.LootListID - 1), loot, aeResult); // If player is removing the last LootItem, delete the empty container. if (loot.IsLooted() && lguid.IsItem()) @@ -230,8 +230,8 @@ namespace Game loot.gold = 0; // Delete the money loot record from the DB - if (!loot.containerID.IsEmpty()) - Global.LootItemStorage.RemoveStoredMoneyForContainer(loot.containerID.GetCounter()); + if (guid.IsItem() && loot.loot_type == LootType.Corpse) + Global.LootItemStorage.RemoveStoredMoneyForContainer(guid.GetCounter()); // Delete container if empty if (loot.IsLooted() && guid.IsItem()) diff --git a/Source/Game/Loot/Loot.cs b/Source/Game/Loot/Loot.cs index 36593a948..0c7974e63 100644 --- a/Source/Game/Loot/Loot.cs +++ b/Source/Game/Loot/Loot.cs @@ -171,7 +171,6 @@ namespace Game.Loots unlootedCount = 0; loot_type = LootType.None; maxDuplicates = 1; - containerID = ObjectGuid.Empty; } // Inserts the item into the loot (called by LootTemplate processors) @@ -852,8 +851,6 @@ namespace Game.Loots public LootType loot_type; // required for achievement system public byte maxDuplicates; // Max amount of items with the same entry that can drop (default is 1; on 25 man raid mode 3) - public ObjectGuid containerID; - List PlayersLooting = new(); MultiMap PlayerQuestItems = new(); MultiMap PlayerFFAItems = new(); diff --git a/Source/Game/Loot/LootItemStorage.cs b/Source/Game/Loot/LootItemStorage.cs index bf39865b2..7e06dc229 100644 --- a/Source/Game/Loot/LootItemStorage.cs +++ b/Source/Game/Loot/LootItemStorage.cs @@ -100,10 +100,10 @@ namespace Game.Loots public bool LoadStoredLoot(Item item, Player player) { Loot loot = item.loot; - if (!_lootItemStorage.ContainsKey(loot.containerID.GetCounter())) + if (!_lootItemStorage.ContainsKey(item.GetGUID().GetCounter())) return false; - var container = _lootItemStorage[loot.containerID.GetCounter()]; + var container = _lootItemStorage[item.GetGUID().GetCounter()]; loot.gold = container.GetMoney(); LootTemplate lt = LootStorage.Items.GetLootFor(item.GetEntry()); @@ -177,26 +177,26 @@ namespace Game.Loots _lootItemStorage[containerId].RemoveItem(itemId, count, itemIndex); } - public void AddNewStoredLoot(Loot loot, Player player) + public void AddNewStoredLoot(ulong 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 return; - if (_lootItemStorage.ContainsKey(loot.containerID.GetCounter())) + if (_lootItemStorage.ContainsKey(containerId)) { - Log.outError(LogFilter.Misc, $"Trying to store item loot by player: {player.GetGUID()} for container id: {loot.containerID.GetCounter()} that is already in storage!"); + Log.outError(LogFilter.Misc, $"Trying to store item loot by player: {player.GetGUID()} for container id: {containerId} that is already in storage!"); return; } - StoredLootContainer container = new(loot.containerID.GetCounter()); + StoredLootContainer container = new(containerId); SQLTransaction trans = new(); if (loot.gold != 0) container.AddMoney(loot.gold, trans); PreparedStatement stmt = DB.Characters.GetPreparedStatement(CharStatements.DEL_ITEMCONTAINER_ITEMS); - stmt.AddValue(0, loot.containerID.GetCounter()); + stmt.AddValue(0, containerId); trans.Append(stmt); foreach (LootItem li in loot.items) @@ -219,7 +219,7 @@ namespace Game.Loots DB.Characters.CommitTransaction(trans); - _lootItemStorage.TryAdd(loot.containerID.GetCounter(), container); + _lootItemStorage.TryAdd(containerId, container); } ConcurrentDictionary _lootItemStorage = new();