diff --git a/Source/Game/Handlers/SpellHandler.cs b/Source/Game/Handlers/SpellHandler.cs index 81826f263..61e244e13 100644 --- a/Source/Game/Handlers/SpellHandler.cs +++ b/Source/Game/Handlers/SpellHandler.cs @@ -115,6 +115,7 @@ namespace Game { Loot loot = new(player.GetMap(), item.GetGUID(), LootType.Item, null); item.loot = loot; + item.m_lootGenerated = true; loot.GenerateMoneyLoot(item.GetTemplate().MinMoneyLoot, item.GetTemplate().MaxMoneyLoot); loot.FillLoot(item.GetEntry(), LootStorage.Items, player, true, loot.gold != 0); diff --git a/Source/Game/Loot/LootItemStorage.cs b/Source/Game/Loot/LootItemStorage.cs index 5ccbadb30..3e42e0021 100644 --- a/Source/Game/Loot/LootItemStorage.cs +++ b/Source/Game/Loot/LootItemStorage.cs @@ -7,6 +7,7 @@ using Framework.Database; using Game.Entities; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Linq; using System.Text; namespace Game.Loots @@ -127,6 +128,25 @@ namespace Game.Loots } } + if (!loot.items.Empty()) + { + loot.items = loot.items.OrderBy(p => p.LootListId).ToList(); + + int lootListId = 0; + // add dummy loot items to ensure items are indexable by their LootListId + while (loot.items.Count <= loot.items.Last().LootListId) + { + if (loot.items[lootListId].LootListId != lootListId) + { + loot.items.Add(loot.items[lootListId]); + loot.items.Last().LootListId = (uint)lootListId; + loot.items.Last().is_looted = true; + } + + ++lootListId; + } + } + // Mark the item if it has loot so it won't be generated again on open item.loot = loot; item.m_lootGenerated = true; @@ -280,7 +300,7 @@ namespace Game.Loots var bounds = _lootItems.LookupByKey(itemId); foreach (var itr in bounds) { - if (itr.Count == count) + if (itr.ItemIndex == itemIndex) { _lootItems.Remove(itr.ItemId); break;