Core/Items: Add ItemContext param to Item::Create function
Port From (https://github.com/TrinityCore/TrinityCore/commit/0a2d9ad2f7673e2b7ee62b7cc6f1a19639d37864)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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<ushort>(14));
|
||||
SetModifier(ItemModifier.BattlePetDisplayId, fields.Read<uint>(16));
|
||||
|
||||
SetContext(fields.Read<byte>(17));
|
||||
SetContext((ItemContext)fields.Read<byte>(17));
|
||||
|
||||
var bonusListString = new StringArray(fields.Read<string>(18), ' ');
|
||||
List<uint> bonusListIDs = new List<uint>();
|
||||
@@ -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<bool>(6);
|
||||
loot_item.needs_quest = item_result.Read<bool>(7);
|
||||
loot_item.randomBonusListId = item_result.Read<uint>(8);
|
||||
loot_item.context = item_result.Read<byte>(9);
|
||||
loot_item.context = (ItemContext)item_result.Read<byte>(9);
|
||||
|
||||
StringArray bonusLists = new StringArray(item_result.Read<string>(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);
|
||||
|
||||
@@ -1089,7 +1089,7 @@ namespace Game.Entities
|
||||
uint randomBonusListId = result.Read<uint>(4);
|
||||
uint fixedScalingLevel = result.Read<uint>(5);
|
||||
uint artifactKnowledgeLevel = result.Read<uint>(6);
|
||||
byte context = result.Read<byte>(7);
|
||||
ItemContext context = (ItemContext)result.Read<byte>(7);
|
||||
List<uint> bonusListIDs = new List<uint>();
|
||||
var bonusListIdTokens = new StringArray(result.Read<string>(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)
|
||||
|
||||
@@ -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<uint> bonuses)
|
||||
public VoidStorageItem(ulong id, uint entry, ObjectGuid creator, uint randomBonusListId, uint fixedScalingLevel, uint artifactKnowledgeLevel, ItemContext context, List<uint> 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<uint> BonusListIDs = new List<uint>();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ItemPosCount> pos, uint itemId, bool update, uint randomPropertyId = 0, List<ObjectGuid> allowedLooters = null, byte context = 0, List<uint> bonusListIDs = null, bool addToCollection = true)
|
||||
public Item StoreNewItem(List<ItemPosCount> pos, uint itemId, bool update, uint randomPropertyId = 0, List<ObjectGuid> allowedLooters = null, ItemContext context = 0, List<uint> 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)
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user