From 63105504a46001188d255ac90986a9188b5dc10c Mon Sep 17 00:00:00 2001 From: hondacrx Date: Sat, 23 Nov 2019 00:44:38 -0500 Subject: [PATCH] Core/Items: Add ItemContext param to Item::Create function Port From (https://github.com/TrinityCore/TrinityCore/commit/0a2d9ad2f7673e2b7ee62b7cc6f1a19639d37864) --- Source/Framework/Constants/ItemConst.cs | 2 +- .../Game/Achievements/AchievementManager.cs | 2 +- Source/Game/BlackMarket/BlackMarketManager.cs | 2 +- Source/Game/Chat/Commands/MiscCommands.cs | 4 +- Source/Game/Chat/Commands/SendCommands.cs | 2 +- Source/Game/DataStorage/DB2Manager.cs | 86 ++++++++++--------- Source/Game/Entities/Item/AzeriteItem.cs | 4 +- Source/Game/Entities/Item/Bag.cs | 3 +- Source/Game/Entities/Item/Item.cs | 17 ++-- Source/Game/Entities/Player/Player.DB.cs | 4 +- Source/Game/Entities/Player/Player.Fields.cs | 4 +- Source/Game/Entities/Player/Player.Items.cs | 27 +++--- Source/Game/Entities/Player/Player.Quest.cs | 2 +- Source/Game/Entities/Unit/Unit.Combat.cs | 2 +- Source/Game/Groups/Group.cs | 4 +- Source/Game/Handlers/MailHandler.cs | 2 +- Source/Game/Handlers/QuestHandler.cs | 2 +- Source/Game/Handlers/VoidStorageHandler.cs | 2 +- Source/Game/Loot/Loot.cs | 8 +- Source/Game/Mails/MailDraft.cs | 4 +- Source/Game/Maps/Map.cs | 8 +- Source/Game/Network/Packets/ItemPackets.cs | 10 +-- Source/Game/Scripting/SpellScript.cs | 2 +- Source/Game/Spells/Auras/AuraEffect.cs | 2 +- Source/Game/Spells/SpellEffects.cs | 19 ++-- Source/Scripts/Spells/Generic.cs | 2 +- Source/Scripts/Spells/Items.cs | 2 +- 27 files changed, 119 insertions(+), 109 deletions(-) diff --git a/Source/Framework/Constants/ItemConst.cs b/Source/Framework/Constants/ItemConst.cs index 07ccab93f..55d062c39 100644 --- a/Source/Framework/Constants/ItemConst.cs +++ b/Source/Framework/Constants/ItemConst.cs @@ -348,7 +348,7 @@ namespace Framework.Constants OverrideRequiredLevel = 18 } - enum ItemContext : byte + public enum ItemContext : byte { None = 0, DungeonNormal = 1, diff --git a/Source/Game/Achievements/AchievementManager.cs b/Source/Game/Achievements/AchievementManager.cs index f406c825d..15bc93d31 100644 --- a/Source/Game/Achievements/AchievementManager.cs +++ b/Source/Game/Achievements/AchievementManager.cs @@ -549,7 +549,7 @@ namespace Game.Achievements SQLTransaction trans = new SQLTransaction(); - Item item = reward.ItemId != 0 ? Item.CreateItem(reward.ItemId, 1, _owner) : null; + Item item = reward.ItemId != 0 ? Item.CreateItem(reward.ItemId, 1, ItemContext.None, _owner) : null; if (item) { // save new item before send diff --git a/Source/Game/BlackMarket/BlackMarketManager.cs b/Source/Game/BlackMarket/BlackMarketManager.cs index 4493ddac2..3be690b53 100644 --- a/Source/Game/BlackMarket/BlackMarketManager.cs +++ b/Source/Game/BlackMarket/BlackMarketManager.cs @@ -240,7 +240,7 @@ namespace Game.BlackMarket // Create item BlackMarketTemplate templ = entry.GetTemplate(); - Item item = Item.CreateItem(templ.Item.ItemID, templ.Quantity); + Item item = Item.CreateItem(templ.Item.ItemID, templ.Quantity, ItemContext.BlackMarket); if (!item) return; diff --git a/Source/Game/Chat/Commands/MiscCommands.cs b/Source/Game/Chat/Commands/MiscCommands.cs index 2df71af22..a3d622102 100644 --- a/Source/Game/Chat/Commands/MiscCommands.cs +++ b/Source/Game/Chat/Commands/MiscCommands.cs @@ -345,7 +345,7 @@ namespace Game.Chat return false; } - Item item = playerTarget.StoreNewItem(dest, itemId, true, ItemEnchantmentManager.GenerateItemRandomBonusListId(itemId), null, 0, bonusListIDs); + Item item = playerTarget.StoreNewItem(dest, itemId, true, ItemEnchantmentManager.GenerateItemRandomBonusListId(itemId), null, ItemContext.None, bonusListIDs); // remove binding (let GM give it to another player later) if (player == playerTarget) @@ -420,7 +420,7 @@ namespace Game.Chat InventoryResult msg = playerTarget.CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, template.Value.GetId(), 1); if (msg == InventoryResult.Ok) { - Item item = playerTarget.StoreNewItem(dest, template.Value.GetId(), true, 0, null, 0, bonusListIDs); + Item item = playerTarget.StoreNewItem(dest, template.Value.GetId(), true, 0, null, ItemContext.None, bonusListIDs); // remove binding (let GM give it to another player later) if (player == playerTarget) diff --git a/Source/Game/Chat/Commands/SendCommands.cs b/Source/Game/Chat/Commands/SendCommands.cs index 4b363ddf2..bcbee5d3f 100644 --- a/Source/Game/Chat/Commands/SendCommands.cs +++ b/Source/Game/Chat/Commands/SendCommands.cs @@ -153,7 +153,7 @@ namespace Game.Chat.Commands foreach (var pair in items) { - Item item = Item.CreateItem(pair.Key, pair.Value, handler.GetSession() ? handler.GetSession().GetPlayer() : null); + Item item = Item.CreateItem(pair.Key, pair.Value, ItemContext.None, handler.GetSession() ? handler.GetSession().GetPlayer() : null); if (item) { item.SaveToDB(trans); // save for prevent lost at next mail load, if send fail then item will deleted diff --git a/Source/Game/DataStorage/DB2Manager.cs b/Source/Game/DataStorage/DB2Manager.cs index 09dcb3e30..a3b4afff1 100644 --- a/Source/Game/DataStorage/DB2Manager.cs +++ b/Source/Game/DataStorage/DB2Manager.cs @@ -1144,17 +1144,11 @@ namespace Game.DataStorage return _itemLevelDeltaToBonusListContainer.LookupByKey(delta); } - public List GetItemBonusTree(uint itemId, uint itemContext) + void VisitItemBonusTree(uint itemId, Action visitor) { - List bonusListIDs = new List(); - - ItemSparseRecord proto = CliDB.ItemSparseStorage.LookupByKey(itemId); - if (proto == null) - return bonusListIDs; - var itemIdRange = _itemToBonusTree.LookupByKey(itemId); if (itemIdRange.Empty()) - return bonusListIDs; + return; foreach (var itemTreeId in itemIdRange) { @@ -1163,47 +1157,59 @@ namespace Game.DataStorage continue; foreach (ItemBonusTreeNodeRecord bonusTreeNode in treeList) + visitor(bonusTreeNode); + } + } + + public List GetItemBonusTree(uint itemId, ItemContext itemContext) + { + List bonusListIDs = new List(); + + ItemSparseRecord proto = CliDB.ItemSparseStorage.LookupByKey(itemId); + if (proto == null) + return bonusListIDs; + + VisitItemBonusTree(itemId, bonusTreeNode => + { + if ((ItemContext)bonusTreeNode.ItemContext != itemContext) + return; + + if (bonusTreeNode.ChildItemBonusListID != 0) { - if (bonusTreeNode.ItemContext != itemContext) - continue; + bonusListIDs.Add(bonusTreeNode.ChildItemBonusListID); + } + else if (bonusTreeNode.ChildItemLevelSelectorID != 0) + { + ItemLevelSelectorRecord selector = CliDB.ItemLevelSelectorStorage.LookupByKey(bonusTreeNode.ChildItemLevelSelectorID); + if (selector == null) + return; - if (bonusTreeNode.ChildItemBonusListID != 0) + short delta = (short)(selector.MinItemLevel - proto.ItemLevel); + + uint bonus = GetItemBonusListForItemLevelDelta(delta); + if (bonus != 0) + bonusListIDs.Add(bonus); + + ItemLevelSelectorQualitySetRecord selectorQualitySet = CliDB.ItemLevelSelectorQualitySetStorage.LookupByKey(selector.ItemLevelSelectorQualitySetID); + if (selectorQualitySet != null) { - bonusListIDs.Add(bonusTreeNode.ChildItemBonusListID); - } - else if (bonusTreeNode.ChildItemLevelSelectorID != 0) - { - ItemLevelSelectorRecord selector = CliDB.ItemLevelSelectorStorage.LookupByKey(bonusTreeNode.ChildItemLevelSelectorID); - if (selector == null) - continue; - - short delta = (short)(selector.MinItemLevel - proto.ItemLevel); - - uint bonus = GetItemBonusListForItemLevelDelta(delta); - if (bonus != 0) - bonusListIDs.Add(bonus); - - ItemLevelSelectorQualitySetRecord selectorQualitySet = CliDB.ItemLevelSelectorQualitySetStorage.LookupByKey(selector.ItemLevelSelectorQualitySetID); - if (selectorQualitySet != null) + var itemSelectorQualities = _itemLevelQualitySelectorQualities.LookupByKey(selector.ItemLevelSelectorQualitySetID); + if (itemSelectorQualities != null) { - var itemSelectorQualities = _itemLevelQualitySelectorQualities.LookupByKey(selector.ItemLevelSelectorQualitySetID); - if (itemSelectorQualities != null) - { - ItemQuality quality = ItemQuality.Uncommon; - if (selector.MinItemLevel >= selectorQualitySet.IlvlEpic) - quality = ItemQuality.Epic; - else if (selector.MinItemLevel >= selectorQualitySet.IlvlRare) - quality = ItemQuality.Rare; + ItemQuality quality = ItemQuality.Uncommon; + if (selector.MinItemLevel >= selectorQualitySet.IlvlEpic) + quality = ItemQuality.Epic; + else if (selector.MinItemLevel >= selectorQualitySet.IlvlRare) + quality = ItemQuality.Rare; - var itemSelectorQuality = itemSelectorQualities.FirstOrDefault(p => p.Quality < (byte)quality); + var itemSelectorQuality = itemSelectorQualities.FirstOrDefault(p => p.Quality < (byte)quality); - if (itemSelectorQuality != null) - bonusListIDs.Add(itemSelectorQuality.QualityItemBonusListID); - } + if (itemSelectorQuality != null) + bonusListIDs.Add(itemSelectorQuality.QualityItemBonusListID); } } } - } + }); return bonusListIDs; } diff --git a/Source/Game/Entities/Item/AzeriteItem.cs b/Source/Game/Entities/Item/AzeriteItem.cs index 5724e2974..f8685dc6a 100644 --- a/Source/Game/Entities/Item/AzeriteItem.cs +++ b/Source/Game/Entities/Item/AzeriteItem.cs @@ -40,9 +40,9 @@ namespace Game.Entities SetUpdateFieldValue(m_values.ModifyValue(m_azeriteItemData).ModifyValue(m_azeriteItemData.DEBUGknowledgeWeek), -1); } - public override bool Create(ulong guidlow, uint itemId, Player owner) + public override bool Create(ulong guidlow, uint itemId, ItemContext context, Player owner) { - if (!base.Create(guidlow, itemId, owner)) + if (!base.Create(guidlow, itemId, context, owner)) return false; SetUpdateFieldValue(m_values.ModifyValue(m_azeriteItemData).ModifyValue(m_azeriteItemData.Level), 1u); diff --git a/Source/Game/Entities/Item/Bag.cs b/Source/Game/Entities/Item/Bag.cs index 10f14283d..dd8cce2ec 100644 --- a/Source/Game/Entities/Item/Bag.cs +++ b/Source/Game/Entities/Item/Bag.cs @@ -70,7 +70,7 @@ namespace Game.Entities base.RemoveFromWorld(); } - public override bool Create(ulong guidlow, uint itemid, Player owner) + public override bool Create(ulong guidlow, uint itemid, ItemContext context, Player owner) { var itemProto = Global.ObjectMgr.GetItemTemplate(itemid); @@ -93,6 +93,7 @@ namespace Game.Entities SetUpdateFieldValue(m_values.ModifyValue(m_itemData).ModifyValue(m_itemData.MaxDurability), itemProto.MaxDurability); SetDurability(itemProto.MaxDurability); SetCount(1); + SetContext(context); // Setting the number of Slots the Container has SetBagSize(itemProto.GetContainerSlots()); diff --git a/Source/Game/Entities/Item/Item.cs b/Source/Game/Entities/Item/Item.cs index 9f147bb4b..2c6492179 100644 --- a/Source/Game/Entities/Item/Item.cs +++ b/Source/Game/Entities/Item/Item.cs @@ -47,7 +47,7 @@ namespace Game.Entities loot = new Loot(); } - public virtual bool Create(ulong guidlow, uint itemid, Player owner) + public virtual bool Create(ulong guidlow, uint itemid, ItemContext context, Player owner) { _Create(ObjectGuid.Create(HighGuid.Item, guidlow)); @@ -77,6 +77,7 @@ namespace Game.Entities SetExpiration(itemProto.GetDuration()); SetCreatePlayedTime(0); + SetContext(context); if (itemProto.GetArtifactID() != 0) { @@ -442,7 +443,7 @@ namespace Game.Entities SetModifier(ItemModifier.BattlePetLevel, fields.Read(14)); SetModifier(ItemModifier.BattlePetDisplayId, fields.Read(16)); - SetContext(fields.Read(17)); + SetContext((ItemContext)fields.Read(17)); var bonusListString = new StringArray(fields.Read(18), ' '); List bonusListIDs = new List(); @@ -1110,7 +1111,7 @@ namespace Game.Entities owner.SendPacket(itemTimeUpdate); } - public static Item CreateItem(uint item, uint count, Player player = null) + public static Item CreateItem(uint item, uint count, ItemContext context, Player player = null) { if (count < 1) return null; //don't create item at zero count @@ -1122,7 +1123,7 @@ namespace Game.Entities count = pProto.GetMaxStackSize(); Item pItem = Bag.NewItemOrBag(pProto); - if (pItem.Create(Global.ObjectMgr.GetGenerator(HighGuid.Item).Generate(), item, player)) + if (pItem.Create(Global.ObjectMgr.GetGenerator(HighGuid.Item).Generate(), item, context, player)) { pItem.SetCount(count); return pItem; @@ -1134,7 +1135,7 @@ namespace Game.Entities public Item CloneItem(uint count, Player player = null) { - Item newItem = CreateItem(GetEntry(), count, player); + Item newItem = CreateItem(GetEntry(), count, GetContext(), player); if (newItem == null) return null; @@ -1802,7 +1803,7 @@ namespace Game.Entities loot_item.is_underthreshold = item_result.Read(6); loot_item.needs_quest = item_result.Read(7); loot_item.randomBonusListId = item_result.Read(8); - loot_item.context = item_result.Read(9); + loot_item.context = (ItemContext)item_result.Read(9); StringArray bonusLists = new StringArray(item_result.Read(10), ' '); if (!bonusLists.IsEmpty()) @@ -2358,7 +2359,9 @@ namespace Game.Entities SetState(ItemUpdateState.Changed, owner); } - public void SetContext(int context) { SetUpdateFieldValue(m_values.ModifyValue(m_itemData).ModifyValue(m_itemData.Context), context); } + public ItemContext GetContext() { return (ItemContext)(int)m_itemData.Context; } + public void SetContext(ItemContext context) { SetUpdateFieldValue(m_values.ModifyValue(m_itemData).ModifyValue(m_itemData.Context), (int)context); } + public void SetPetitionId(uint petitionId) { SetUpdateFieldValue(m_itemData.ModifyValue(m_itemData.Enchantment, 0).ModifyValue((ItemEnchantment itemEnchantment) => itemEnchantment.ID), petitionId); diff --git a/Source/Game/Entities/Player/Player.DB.cs b/Source/Game/Entities/Player/Player.DB.cs index 7c0949dfc..6c39ca1de 100644 --- a/Source/Game/Entities/Player/Player.DB.cs +++ b/Source/Game/Entities/Player/Player.DB.cs @@ -1089,7 +1089,7 @@ namespace Game.Entities uint randomBonusListId = result.Read(4); uint fixedScalingLevel = result.Read(5); uint artifactKnowledgeLevel = result.Read(6); - byte context = result.Read(7); + ItemContext context = (ItemContext)result.Read(7); List bonusListIDs = new List(); var bonusListIdTokens = new StringArray(result.Read(8), ' '); for (var i = 0; i < bonusListIdTokens.Length; ++i) @@ -2266,7 +2266,7 @@ namespace Game.Entities stmt.AddValue(5, (byte)_voidStorageItems[i].RandomBonusListId); stmt.AddValue(6, _voidStorageItems[i].FixedScalingLevel); stmt.AddValue(7, _voidStorageItems[i].ArtifactKnowledgeLevel); - stmt.AddValue(8, _voidStorageItems[i].Context); + stmt.AddValue(8, (byte)_voidStorageItems[i].Context); StringBuilder bonusListIDs = new StringBuilder(); foreach (uint bonusListID in _voidStorageItems[i].BonusListIDs) diff --git a/Source/Game/Entities/Player/Player.Fields.cs b/Source/Game/Entities/Player/Player.Fields.cs index ddecaedc4..197433e8c 100644 --- a/Source/Game/Entities/Player/Player.Fields.cs +++ b/Source/Game/Entities/Player/Player.Fields.cs @@ -445,7 +445,7 @@ namespace Game.Entities public class VoidStorageItem { - public VoidStorageItem(ulong id, uint entry, ObjectGuid creator, uint randomBonusListId, uint fixedScalingLevel, uint artifactKnowledgeLevel, byte context, List bonuses) + public VoidStorageItem(ulong id, uint entry, ObjectGuid creator, uint randomBonusListId, uint fixedScalingLevel, uint artifactKnowledgeLevel, ItemContext context, List bonuses) { ItemId = id; ItemEntry = entry; @@ -465,7 +465,7 @@ namespace Game.Entities public uint RandomBonusListId; public uint FixedScalingLevel; public uint ArtifactKnowledgeLevel; - public byte Context; + public ItemContext Context; public List BonusListIDs = new List(); } diff --git a/Source/Game/Entities/Player/Player.Items.cs b/Source/Game/Entities/Player/Player.Items.cs index e7b9b0c61..a8cb176fe 100644 --- a/Source/Game/Entities/Player/Player.Items.cs +++ b/Source/Game/Entities/Player/Player.Items.cs @@ -1238,7 +1238,7 @@ namespace Game.Entities if (msg != InventoryResult.Ok) break; - EquipNewItem(eDest, titem_id, true); + EquipNewItem(eDest, titem_id, ItemContext.None, true); AutoUnequipOffhandIfNeed(); titem_amount--; } @@ -1260,13 +1260,13 @@ namespace Game.Entities Log.outError(LogFilter.Player, "STORAGE: Can't equip or store initial item {0} for race {1} class {2}, error msg = {3}", titem_id, GetRace(), GetClass(), msg); return false; } - public Item StoreNewItem(List pos, uint itemId, bool update, uint randomPropertyId = 0, List allowedLooters = null, byte context = 0, List bonusListIDs = null, bool addToCollection = true) + public Item StoreNewItem(List pos, uint itemId, bool update, uint randomPropertyId = 0, List allowedLooters = null, ItemContext context = 0, List bonusListIDs = null, bool addToCollection = true) { uint count = 0; foreach (var itemPosCount in pos) count += itemPosCount.count; - Item item = Item.CreateItem(itemId, count, this); + Item item = Item.CreateItem(itemId, count, context, this); if (item != null) { ItemAddedQuestCheck(itemId, count); @@ -1275,7 +1275,6 @@ namespace Game.Entities item.AddItemFlag(ItemFieldFlags.NewItem); - item.SetContext(context); item.SetBonuses(bonusListIDs); item = StoreItem(pos, item, update); @@ -1598,9 +1597,9 @@ namespace Game.Entities // not found req. item count and have unequippable items return res; } - Item EquipNewItem(ushort pos, uint item, bool update) + Item EquipNewItem(ushort pos, uint item, ItemContext context, bool update) { - Item pItem = Item.CreateItem(item, 1, this); + Item pItem = Item.CreateItem(item, 1, context, this); if (pItem != null) { ItemAddedQuestCheck(item, 1); @@ -2509,7 +2508,7 @@ namespace Game.Entities } } - Item it = bStore ? StoreNewItem(vDest, item, true, ItemEnchantmentManager.GenerateItemRandomBonusListId(item), null, 0, crItem.BonusListIDs, false) : EquipNewItem(uiDest, item, true); + Item it = bStore ? StoreNewItem(vDest, item, true, ItemEnchantmentManager.GenerateItemRandomBonusListId(item), null, ItemContext.Vendor, crItem.BonusListIDs, false) : EquipNewItem(uiDest, item, ItemContext.Vendor, true); if (it != null) { uint new_count = pVendor.UpdateVendorItemCurrentCount(crItem, count); @@ -3831,13 +3830,13 @@ namespace Game.Entities return max_personal_rating; } - public void SendItemRetrievalMail(uint itemEntry, uint count) + public void SendItemRetrievalMail(uint itemEntry, uint count, ItemContext context) { MailSender sender = new MailSender(MailMessageType.Creature, 34337); MailDraft draft = new MailDraft("Recovered Item", "We recovered a lost item in the twisting nether and noted that it was yours.$B$BPlease find said object enclosed."); // This is the text used in Cataclysm, it probably wasn't changed. SQLTransaction trans = new SQLTransaction(); - Item item = Item.CreateItem(itemEntry, count, null); + Item item = Item.CreateItem(itemEntry, count, context, null); if (item) { item.SaveToDB(trans); @@ -5090,7 +5089,7 @@ namespace Game.Entities InventoryResult CanEquipNewItem(byte slot, out ushort dest, uint item, bool swap) { dest = 0; - Item pItem = Item.CreateItem(item, 1, this); + Item pItem = Item.CreateItem(item, 1, ItemContext.None, this); if (pItem != null) { InventoryResult result = CanEquipItem(slot, out dest, pItem, swap); @@ -6065,11 +6064,11 @@ namespace Game.Entities pItem.SetState(ItemUpdateState.Changed, this); } } - public void AutoStoreLoot(uint loot_id, LootStore store, bool broadcast = false) { AutoStoreLoot(ItemConst.NullBag, ItemConst.NullSlot, loot_id, store, broadcast); } - void AutoStoreLoot(byte bag, byte slot, uint loot_id, LootStore store, bool broadcast = false) + public void AutoStoreLoot(uint loot_id, LootStore store, ItemContext context = 0, bool broadcast = false) { AutoStoreLoot(ItemConst.NullBag, ItemConst.NullSlot, loot_id, store, context, broadcast); } + void AutoStoreLoot(byte bag, byte slot, uint loot_id, LootStore store, ItemContext context = 0, bool broadcast = false) { Loot loot = new Loot(); - loot.FillLoot(loot_id, store, this, true); + loot.FillLoot(loot_id, store, this, true, false, LootModes.Default, context); uint max_slot = loot.GetMaxSlotInLootFor(this); for (uint i = 0; i < max_slot; ++i) @@ -6351,7 +6350,7 @@ namespace Game.Entities if (groupRules) group.UpdateLooterGuid(go, true); - loot.FillLoot(lootid, LootStorage.Gameobject, this, !groupRules, false, go.GetLootMode()); + loot.FillLoot(lootid, LootStorage.Gameobject, this, !groupRules, false, go.GetLootMode(), GetMap().GetDifficultyLootItemContext()); go.SetLootGenerationTime(); // get next RR player (for next loot) diff --git a/Source/Game/Entities/Player/Player.Quest.cs b/Source/Game/Entities/Player/Player.Quest.cs index b0f92459b..1cab59a81 100644 --- a/Source/Game/Entities/Player/Player.Quest.cs +++ b/Source/Game/Entities/Player/Player.Quest.cs @@ -995,7 +995,7 @@ namespace Game.Entities SendNewItem(item, quest.RewardItemCount[i], true, false); } else if (quest.IsDFQuest()) - SendItemRetrievalMail(quest.RewardItemId[i], quest.RewardItemCount[i]); + SendItemRetrievalMail(quest.RewardItemId[i], quest.RewardItemCount[i], ItemContext.QuestReward); } } } diff --git a/Source/Game/Entities/Unit/Unit.Combat.cs b/Source/Game/Entities/Unit/Unit.Combat.cs index 0ed4b6668..84aaa4d3f 100644 --- a/Source/Game/Entities/Unit/Unit.Combat.cs +++ b/Source/Game/Entities/Unit/Unit.Combat.cs @@ -1477,7 +1477,7 @@ namespace Game.Entities loot.Clear(); uint lootid = creature.GetCreatureTemplate().LootId; if (lootid != 0) - loot.FillLoot(lootid, LootStorage.Creature, looter, false, false, creature.GetLootMode()); + loot.FillLoot(lootid, LootStorage.Creature, looter, false, false, creature.GetLootMode(), GetMap().GetDifficultyLootItemContext()); if (creature.GetLootMode() > 0) loot.GenerateMoneyLoot(creature.GetCreatureTemplate().MinGold, creature.GetCreatureTemplate().MaxGold); diff --git a/Source/Game/Groups/Group.cs b/Source/Game/Groups/Group.cs index b59d1df91..52c0db2b1 100644 --- a/Source/Game/Groups/Group.cs +++ b/Source/Game/Groups/Group.cs @@ -1269,7 +1269,7 @@ namespace Game.Groups List dest = new List(); InventoryResult msg = player.CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, roll.itemid, item.count); if (msg == InventoryResult.Ok) - player.AutoStoreLoot(disenchant.Id, LootStorage.Disenchant, true); + player.AutoStoreLoot(disenchant.Id, LootStorage.Disenchant, ItemContext.None, true); else // If the player's inventory is full, send the disenchant result in a mail. { Loot loot = new Loot(); @@ -1280,7 +1280,7 @@ namespace Game.Groups { LootItem lootItem = loot.LootItemInSlot(i, player); player.SendEquipError(msg, null, null, lootItem.itemid); - player.SendItemRetrievalMail(lootItem.itemid, lootItem.count); + player.SendItemRetrievalMail(lootItem.itemid, lootItem.count, lootItem.context); } } } diff --git a/Source/Game/Handlers/MailHandler.cs b/Source/Game/Handlers/MailHandler.cs index de6c01f89..aec155796 100644 --- a/Source/Game/Handlers/MailHandler.cs +++ b/Source/Game/Handlers/MailHandler.cs @@ -610,7 +610,7 @@ namespace Game } Item bodyItem = new Item(); // This is not bag and then can be used new Item. - if (!bodyItem.Create(Global.ObjectMgr.GetGenerator(HighGuid.Item).Generate(), 8383, player)) + if (!bodyItem.Create(Global.ObjectMgr.GetGenerator(HighGuid.Item).Generate(), 8383, ItemContext.None, player)) return; // in mail template case we need create new item text diff --git a/Source/Game/Handlers/QuestHandler.cs b/Source/Game/Handlers/QuestHandler.cs index e8dc7f742..892c6e7bc 100644 --- a/Source/Game/Handlers/QuestHandler.cs +++ b/Source/Game/Handlers/QuestHandler.cs @@ -696,7 +696,7 @@ namespace Game List dest = new List(); if (_player.CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, item.Id, (uint)item.Quantity) == InventoryResult.Ok) { - Item newItem = _player.StoreNewItem(dest, item.Id, true, ItemEnchantmentManager.GenerateItemRandomBonusListId(item.Id), null, 0, item.BonusListIDs); + Item newItem = _player.StoreNewItem(dest, item.Id, true, ItemEnchantmentManager.GenerateItemRandomBonusListId(item.Id), null, ItemContext.QuestReward, item.BonusListIDs); _player.SendNewItem(newItem, (uint)item.Quantity, true, false); } } diff --git a/Source/Game/Handlers/VoidStorageHandler.cs b/Source/Game/Handlers/VoidStorageHandler.cs index 9c8af3dda..f317eb8f7 100644 --- a/Source/Game/Handlers/VoidStorageHandler.cs +++ b/Source/Game/Handlers/VoidStorageHandler.cs @@ -157,7 +157,7 @@ namespace Game VoidStorageItem itemVS = new VoidStorageItem(Global.ObjectMgr.GenerateVoidStorageItemId(), item.GetEntry(), item.GetCreator(), item.GetItemRandomBonusListId(), item.GetModifier(ItemModifier.TimewalkerLevel), item.GetModifier(ItemModifier.ArtifactKnowledgeLevel), - (byte)item.m_itemData.Context, item.m_itemData.BonusListIDs); + item.GetContext(), item.m_itemData.BonusListIDs); VoidItem voidItem; voidItem.Guid = ObjectGuid.Create(HighGuid.Item, itemVS.ItemId); diff --git a/Source/Game/Loot/Loot.cs b/Source/Game/Loot/Loot.cs index 09cf9e190..48ae9e568 100644 --- a/Source/Game/Loot/Loot.cs +++ b/Source/Game/Loot/Loot.cs @@ -88,7 +88,7 @@ namespace Game.Loots public uint itemid; public uint randomBonusListId; public List BonusListIDs = new List(); - public byte context; + public ItemContext context; public List conditions = new List(); // additional loot condition public List allowedGUIDs = new List(); public ObjectGuid rollWinnerGUID; // Stores the guid of person who won loot, if his bags are full only he can see the item in loot list! @@ -198,7 +198,7 @@ namespace Game.Loots } // Calls processor of corresponding LootTemplate (which handles everything including references) - public bool FillLoot(uint lootId, LootStore store, Player lootOwner, bool personal, bool noEmptyError = false, LootModes lootMode = LootModes.Default) + public bool FillLoot(uint lootId, LootStore store, Player lootOwner, bool personal, bool noEmptyError = false, LootModes lootMode = LootModes.Default, ItemContext context = 0) { // Must be provided if (lootOwner == null) @@ -212,7 +212,7 @@ namespace Game.Loots return false; } - _itemContext = (byte)lootOwner.GetMap().GetDifficultyLootItemContext(); + _itemContext = context; tab.Process(this, store.IsRatesAllowed(), (byte)lootMode); // Processing is done there, callback via Loot.AddItem() @@ -866,7 +866,7 @@ namespace Game.Loots // Loot GUID ObjectGuid _GUID; - byte _itemContext; + ItemContext _itemContext; } public class AELootResult diff --git a/Source/Game/Mails/MailDraft.cs b/Source/Game/Mails/MailDraft.cs index 6af0780dd..d8084f950 100644 --- a/Source/Game/Mails/MailDraft.cs +++ b/Source/Game/Mails/MailDraft.cs @@ -59,7 +59,7 @@ namespace Game.Mails Loot mailLoot = new Loot(); // can be empty - mailLoot.FillLoot(m_mailTemplateId, LootStorage.Mail, receiver, true, true); + mailLoot.FillLoot(m_mailTemplateId, LootStorage.Mail, receiver, true, true, LootModes.Default, ItemContext.None); uint max_slot = mailLoot.GetMaxSlotInLootFor(receiver); for (uint i = 0; m_items.Count < SharedConst.MaxMailItems && i < max_slot; ++i) @@ -67,7 +67,7 @@ namespace Game.Mails LootItem lootitem = mailLoot.LootItemInSlot(i, receiver); if (lootitem != null) { - Item item = Item.CreateItem(lootitem.itemid, lootitem.count, receiver); + Item item = Item.CreateItem(lootitem.itemid, lootitem.count, lootitem.context, receiver); if (item != null) { item.SaveToDB(trans); // save for prevent lost at next mail load, if send fail then item will deleted diff --git a/Source/Game/Maps/Map.cs b/Source/Game/Maps/Map.cs index 936e931fd..1fe989b8b 100644 --- a/Source/Game/Maps/Map.cs +++ b/Source/Game/Maps/Map.cs @@ -3017,17 +3017,17 @@ namespace Game.Maps return Global.DB2Mgr.GetMapDifficultyData(GetId(), GetDifficultyID()); } - public int GetDifficultyLootItemContext() + public ItemContext GetDifficultyLootItemContext() { MapDifficultyRecord mapDifficulty = GetMapDifficulty(); if (mapDifficulty != null && mapDifficulty.ItemContext != 0) - return mapDifficulty.ItemContext; + return (ItemContext)mapDifficulty.ItemContext; DifficultyRecord difficulty = CliDB.DifficultyStorage.LookupByKey(GetDifficultyID()); if (difficulty != null) - return difficulty.ItemContext; + return (ItemContext)difficulty.ItemContext; - return 0; + return ItemContext.None; } public uint GetId() diff --git a/Source/Game/Network/Packets/ItemPackets.cs b/Source/Game/Network/Packets/ItemPackets.cs index 94e878d9e..39193a982 100644 --- a/Source/Game/Network/Packets/ItemPackets.cs +++ b/Source/Game/Network/Packets/ItemPackets.cs @@ -682,7 +682,7 @@ namespace Game.Network.Packets { public void Write(WorldPacket data) { - data.WriteUInt8(Context); + data.WriteUInt8((byte)Context); data.WriteInt32(BonusListIDs.Count); foreach (uint bonusID in BonusListIDs) data.WriteUInt32(bonusID); @@ -690,7 +690,7 @@ namespace Game.Network.Packets public void Read(WorldPacket data) { - Context = data.ReadUInt8(); + Context = (ItemContext)data.ReadUInt8(); uint bonusListIdSize = data.ReadUInt32(); BonusListIDs = new List(); @@ -730,7 +730,7 @@ namespace Game.Network.Packets return !(left == right); } - public byte Context; + public ItemContext Context; public List BonusListIDs = new List(); } @@ -746,7 +746,7 @@ namespace Game.Network.Packets { ItemBonus.HasValue = true; ItemBonus.Value.BonusListIDs.AddRange(bonusListIds); - ItemBonus.Value.Context = (byte)item.m_itemData.Context; + ItemBonus.Value.Context = item.GetContext(); } uint mask = item.m_itemData.ModifiersMask; @@ -802,7 +802,7 @@ namespace Game.Network.Packets ItemID = gem.ItemId; ItemBonusInstanceData bonus = new ItemBonusInstanceData(); - bonus.Context = gem.Context; + bonus.Context = (ItemContext)(byte)gem.Context; foreach (ushort bonusListId in gem.BonusListIDs) if (bonusListId != 0) bonus.BonusListIDs.Add(bonusListId); diff --git a/Source/Game/Scripting/SpellScript.cs b/Source/Game/Scripting/SpellScript.cs index 53e4cd0ba..95d1b2dbe 100644 --- a/Source/Game/Scripting/SpellScript.cs +++ b/Source/Game/Scripting/SpellScript.cs @@ -734,7 +734,7 @@ namespace Game.Scripting public Item GetCastItem() { return m_spell.m_CastItem; } // Creates item. Calls Spell.DoCreateItem method. - public void CreateItem(uint effIndex, uint itemId) { m_spell.DoCreateItem(effIndex, itemId); } + public void CreateItem(uint effIndex, uint itemId, ItemContext context) { m_spell.DoCreateItem(effIndex, itemId, context); } // Returns SpellInfo from the spell that triggered the current one public SpellInfo GetTriggeringSpell() { return m_spell.m_triggeredByAuraSpell; } diff --git a/Source/Game/Spells/Auras/AuraEffect.cs b/Source/Game/Spells/Auras/AuraEffect.cs index 57945cce0..222b6b5e2 100644 --- a/Source/Game/Spells/Auras/AuraEffect.cs +++ b/Source/Game/Spells/Auras/AuraEffect.cs @@ -5031,7 +5031,7 @@ namespace Game.Spells if (creature.GetCreatureTemplate().SkinLootId == 0) return; - player.AutoStoreLoot(creature.GetCreatureTemplate().SkinLootId, LootStorage.Skinning, true); + player.AutoStoreLoot(creature.GetCreatureTemplate().SkinLootId, LootStorage.Skinning, ItemContext.None, true); creature.DespawnOrUnsummon(); } diff --git a/Source/Game/Spells/SpellEffects.cs b/Source/Game/Spells/SpellEffects.cs index 3d9309623..a94461778 100644 --- a/Source/Game/Spells/SpellEffects.cs +++ b/Source/Game/Spells/SpellEffects.cs @@ -1042,7 +1042,7 @@ namespace Game.Spells } } - public void DoCreateItem(uint i, uint itemtype, byte context = 0, List bonusListIds = null) + public void DoCreateItem(uint i, uint itemtype, ItemContext context = 0, List bonusListIds = null) { if (unitTarget == null || !unitTarget.IsTypeId(TypeId.Player)) return; @@ -1146,7 +1146,7 @@ namespace Game.Spells if (effectHandleMode != SpellEffectHandleMode.HitTarget) return; - DoCreateItem(effIndex, effectInfo.ItemType); + DoCreateItem(effIndex, effectInfo.ItemType, m_spellInfo.HasAttribute(SpellAttr0.Tradespell) ? ItemContext.TradeSkill : ItemContext.None); ExecuteLogEffectCreateItem(effIndex, effectInfo.ItemType); } @@ -1162,9 +1162,10 @@ namespace Game.Spells Player player = unitTarget.ToPlayer(); uint item_id = effectInfo.ItemType; + ItemContext context = m_spellInfo.HasAttribute(SpellAttr0.Tradespell) ? ItemContext.TradeSkill : ItemContext.None; if (item_id != 0) - DoCreateItem(effIndex, item_id); + DoCreateItem(effIndex, item_id, context); // special case: fake item replaced by generate using spell_loot_template if (m_spellInfo.IsLootCrafting()) @@ -1179,10 +1180,10 @@ namespace Game.Spells player.DestroyItemCount(item_id, count, true); // create some random items - player.AutoStoreLoot(m_spellInfo.Id, LootStorage.Spell); + player.AutoStoreLoot(m_spellInfo.Id, LootStorage.Spell, context); } else - player.AutoStoreLoot(m_spellInfo.Id, LootStorage.Spell); // create some random items + player.AutoStoreLoot(m_spellInfo.Id, LootStorage.Spell, context); // create some random items player.UpdateCraftSkill(m_spellInfo.Id); } @@ -1200,7 +1201,7 @@ namespace Game.Spells Player player = unitTarget.ToPlayer(); // create some random items - player.AutoStoreLoot(m_spellInfo.Id, LootStorage.Spell); + player.AutoStoreLoot(m_spellInfo.Id, LootStorage.Spell, m_spellInfo.HasAttribute(SpellAttr0.Tradespell) ? ItemContext.TradeSkill : ItemContext.None); // @todo ExecuteLogEffectCreateItem(i, GetEffect(i].ItemType); } @@ -1511,7 +1512,7 @@ namespace Game.Spells ushort pos = m_CastItem.GetPos(); - Item pNewItem = Item.CreateItem(newitemid, 1, player); + Item pNewItem = Item.CreateItem(newitemid, 1, m_CastItem.GetContext(), player); if (pNewItem == null) return; @@ -2112,7 +2113,7 @@ namespace Game.Spells player.DestroyItemCount(itemTarget, ref count, true); unitTarget = player; // and add a scroll - DoCreateItem(effIndex, effectInfo.ItemType); + DoCreateItem(effIndex, effectInfo.ItemType, m_spellInfo.HasAttribute(SpellAttr0.Tradespell) ? ItemContext.TradeSkill : ItemContext.None); itemTarget = null; m_targets.SetItemTarget(null); } @@ -5497,7 +5498,7 @@ namespace Game.Spells List bonusList = new List(); bonusList.Add(collectionMgr.GetHeirloomBonus(m_misc.Data0)); - DoCreateItem(effIndex, m_misc.Data0, 0, bonusList); + DoCreateItem(effIndex, m_misc.Data0, ItemContext.None, bonusList); ExecuteLogEffectCreateItem(effIndex, m_misc.Data0); } diff --git a/Source/Scripts/Spells/Generic.cs b/Source/Scripts/Spells/Generic.cs index f83b9e76d..d645338a0 100644 --- a/Source/Scripts/Spells/Generic.cs +++ b/Source/Scripts/Spells/Generic.cs @@ -2703,7 +2703,7 @@ namespace Scripts.Spells.Generic return; } - CreateItem(effIndex, itemId[RandomHelper.URand(0, 4)]); + CreateItem(effIndex, itemId[RandomHelper.URand(0, 4)], ItemContext.None); } } diff --git a/Source/Scripts/Spells/Items.cs b/Source/Scripts/Spells/Items.cs index 4e2d5bfcd..77555db19 100644 --- a/Source/Scripts/Spells/Items.cs +++ b/Source/Scripts/Spells/Items.cs @@ -1345,7 +1345,7 @@ namespace Scripts.Spells.Items return; } - CreateItem(effIndex, newitemid); + CreateItem(effIndex, newitemid, ItemContext.None); } public override void Register()