aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2019-11-23 00:03:42 +0100
committerShauren <shauren.trinity@gmail.com>2019-11-23 00:03:42 +0100
commit0a2d9ad2f7673e2b7ee62b7cc6f1a19639d37864 (patch)
tree0b48ab1588b0d711dba4a768ffcbe8e3d9a360f9 /src
parentec9d624aec9e0a39b1bcee7d4077f46be358faad (diff)
Core/Items: Add ItemContext param to Item::Create function
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Achievements/AchievementMgr.cpp2
-rw-r--r--src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp2
-rw-r--r--src/server/game/BlackMarket/BlackMarketMgr.cpp2
-rw-r--r--src/server/game/DataStores/DB2Stores.cpp87
-rw-r--r--src/server/game/DataStores/DB2Stores.h2
-rw-r--r--src/server/game/Entities/Item/AzeriteItem/AzeriteItem.cpp4
-rw-r--r--src/server/game/Entities/Item/AzeriteItem/AzeriteItem.h2
-rw-r--r--src/server/game/Entities/Item/Container/Bag.cpp3
-rw-r--r--src/server/game/Entities/Item/Container/Bag.h2
-rw-r--r--src/server/game/Entities/Item/Item.cpp15
-rw-r--r--src/server/game/Entities/Item/Item.h7
-rw-r--r--src/server/game/Entities/Player/Player.cpp33
-rw-r--r--src/server/game/Entities/Player/Player.h16
-rw-r--r--src/server/game/Entities/Unit/Unit.cpp2
-rw-r--r--src/server/game/Groups/Group.cpp4
-rw-r--r--src/server/game/Handlers/MailHandler.cpp2
-rw-r--r--src/server/game/Handlers/QuestHandler.cpp2
-rw-r--r--src/server/game/Handlers/VoidStorageHandler.cpp2
-rw-r--r--src/server/game/Loot/Loot.cpp12
-rw-r--r--src/server/game/Loot/Loot.h8
-rw-r--r--src/server/game/Mails/Mail.cpp4
-rw-r--r--src/server/game/Maps/Map.cpp8
-rw-r--r--src/server/game/Maps/Map.h3
-rw-r--r--src/server/game/Server/Packets/ItemPacketsCommon.cpp8
-rw-r--r--src/server/game/Server/Packets/ItemPacketsCommon.h3
-rw-r--r--src/server/game/Spells/Auras/SpellAuraEffects.cpp2
-rw-r--r--src/server/game/Spells/Spell.h2
-rw-r--r--src/server/game/Spells/SpellEffects.cpp19
-rw-r--r--src/server/game/Spells/SpellScript.cpp4
-rw-r--r--src/server/game/Spells/SpellScript.h2
-rw-r--r--src/server/scripts/Commands/cs_misc.cpp4
-rw-r--r--src/server/scripts/Commands/cs_send.cpp2
-rw-r--r--src/server/scripts/Spells/spell_generic.cpp2
-rw-r--r--src/server/scripts/Spells/spell_item.cpp2
34 files changed, 144 insertions, 130 deletions
diff --git a/src/server/game/Achievements/AchievementMgr.cpp b/src/server/game/Achievements/AchievementMgr.cpp
index 91d527d90ef..516d5a06402 100644
--- a/src/server/game/Achievements/AchievementMgr.cpp
+++ b/src/server/game/Achievements/AchievementMgr.cpp
@@ -532,7 +532,7 @@ void PlayerAchievementMgr::CompletedAchievement(AchievementEntry const* achievem
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
- Item* item = reward->ItemId ? Item::CreateItem(reward->ItemId, 1, _owner) : NULL;
+ Item* item = reward->ItemId ? Item::CreateItem(reward->ItemId, 1, ItemContext::NONE, _owner) : NULL;
if (item)
{
// save new item before send
diff --git a/src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp b/src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp
index fc7bbc6b955..53b874bf115 100644
--- a/src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp
+++ b/src/server/game/AuctionHouseBot/AuctionHouseBotSeller.cpp
@@ -948,7 +948,7 @@ void AuctionBotSeller::AddNewAuctions(SellerConfiguration& config)
uint32 stackCount = GetStackSizeForItem(prototype, config);
- Item* item = Item::CreateItem(itemId, stackCount);
+ Item* item = Item::CreateItem(itemId, stackCount, ItemContext::NONE);
if (!item)
{
TC_LOG_ERROR("ahbot", "AHBot: Item::CreateItem() returned NULL for item %u (stack: %u)", itemId, stackCount);
diff --git a/src/server/game/BlackMarket/BlackMarketMgr.cpp b/src/server/game/BlackMarket/BlackMarketMgr.cpp
index eb026696f47..eee7be2d39b 100644
--- a/src/server/game/BlackMarket/BlackMarketMgr.cpp
+++ b/src/server/game/BlackMarket/BlackMarketMgr.cpp
@@ -291,7 +291,7 @@ void BlackMarketMgr::SendAuctionWonMail(BlackMarketEntry* entry, CharacterDataba
// Create item
BlackMarketTemplate const* templ = entry->GetTemplate();
- Item* item = Item::CreateItem(templ->Item.ItemID, templ->Quantity);
+ Item* item = Item::CreateItem(templ->Item.ItemID, templ->Quantity, ItemContext::Black_Market);
if (!item)
return;
diff --git a/src/server/game/DataStores/DB2Stores.cpp b/src/server/game/DataStores/DB2Stores.cpp
index 1d2df455f4c..694768fa1cf 100644
--- a/src/server/game/DataStores/DB2Stores.cpp
+++ b/src/server/game/DataStores/DB2Stores.cpp
@@ -1941,17 +1941,12 @@ uint32 DB2Manager::GetItemBonusListForItemLevelDelta(int16 delta) const
return 0;
}
-std::set<uint32> DB2Manager::GetItemBonusTree(uint32 itemId, uint32 itemContext) const
+template<typename Visitor>
+void VisitItemBonusTree(uint32 itemId, Visitor visitor)
{
- std::set<uint32> bonusListIDs;
-
- ItemSparseEntry const* proto = sItemSparseStore.LookupEntry(itemId);
- if (!proto)
- return bonusListIDs;
-
auto itemIdRange = _itemToBonusTree.equal_range(itemId);
if (itemIdRange.first == itemIdRange.second)
- return bonusListIDs;
+ return;
for (auto itemTreeItr = itemIdRange.first; itemTreeItr != itemIdRange.second; ++itemTreeItr)
{
@@ -1961,45 +1956,59 @@ std::set<uint32> DB2Manager::GetItemBonusTree(uint32 itemId, uint32 itemContext)
for (ItemBonusTreeNodeEntry const* bonusTreeNode : treeItr->second)
{
- if (bonusTreeNode->ItemContext != itemContext)
- continue;
+ visitor(bonusTreeNode);
+ }
+ }
+}
- if (bonusTreeNode->ChildItemBonusListID)
- {
- bonusListIDs.insert(bonusTreeNode->ChildItemBonusListID);
- }
- else if (bonusTreeNode->ChildItemLevelSelectorID)
- {
- ItemLevelSelectorEntry const* selector = sItemLevelSelectorStore.LookupEntry(bonusTreeNode->ChildItemLevelSelectorID);
- if (!selector)
- continue;
+std::set<uint32> DB2Manager::GetItemBonusTree(uint32 itemId, ItemContext itemContext) const
+{
+ std::set<uint32> bonusListIDs;
+
+ ItemSparseEntry const* proto = sItemSparseStore.LookupEntry(itemId);
+ if (!proto)
+ return bonusListIDs;
+
+ VisitItemBonusTree(itemId, [this, proto, itemContext, &bonusListIDs](ItemBonusTreeNodeEntry const* bonusTreeNode)
+ {
+ if (ItemContext(bonusTreeNode->ItemContext) != itemContext)
+ return;
+
+ if (bonusTreeNode->ChildItemBonusListID)
+ {
+ bonusListIDs.insert(bonusTreeNode->ChildItemBonusListID);
+ }
+ else if (bonusTreeNode->ChildItemLevelSelectorID)
+ {
+ ItemLevelSelectorEntry const* selector = sItemLevelSelectorStore.LookupEntry(bonusTreeNode->ChildItemLevelSelectorID);
+ if (!selector)
+ return;
- int16 delta = int16(selector->MinItemLevel) - proto->ItemLevel;
+ int16 delta = int16(selector->MinItemLevel) - proto->ItemLevel;
- if (uint32 bonus = GetItemBonusListForItemLevelDelta(delta))
- bonusListIDs.insert(bonus);
+ if (uint32 bonus = GetItemBonusListForItemLevelDelta(delta))
+ bonusListIDs.insert(bonus);
- if (ItemLevelSelectorQualitySetEntry const* selectorQualitySet = sItemLevelSelectorQualitySetStore.LookupEntry(selector->ItemLevelSelectorQualitySetID))
+ if (ItemLevelSelectorQualitySetEntry const* selectorQualitySet = sItemLevelSelectorQualitySetStore.LookupEntry(selector->ItemLevelSelectorQualitySetID))
+ {
+ auto itemSelectorQualities = _itemLevelQualitySelectorQualities.find(selector->ItemLevelSelectorQualitySetID);
+ if (itemSelectorQualities != _itemLevelQualitySelectorQualities.end())
{
- auto itemSelectorQualities = _itemLevelQualitySelectorQualities.find(selector->ItemLevelSelectorQualitySetID);
- if (itemSelectorQualities != _itemLevelQualitySelectorQualities.end())
- {
- ItemQualities quality = ITEM_QUALITY_UNCOMMON;
- if (selector->MinItemLevel >= selectorQualitySet->IlvlEpic)
- quality = ITEM_QUALITY_EPIC;
- else if (selector->MinItemLevel >= selectorQualitySet->IlvlRare)
- quality = ITEM_QUALITY_RARE;
-
- auto itemSelectorQuality = std::lower_bound(itemSelectorQualities->second.begin(), itemSelectorQualities->second.end(),
- quality, ItemLevelSelectorQualityEntryComparator{});
-
- if (itemSelectorQuality != itemSelectorQualities->second.end())
- bonusListIDs.insert((*itemSelectorQuality)->QualityItemBonusListID);
- }
+ ItemQualities quality = ITEM_QUALITY_UNCOMMON;
+ if (selector->MinItemLevel >= selectorQualitySet->IlvlEpic)
+ quality = ITEM_QUALITY_EPIC;
+ else if (selector->MinItemLevel >= selectorQualitySet->IlvlRare)
+ quality = ITEM_QUALITY_RARE;
+
+ auto itemSelectorQuality = std::lower_bound(itemSelectorQualities->second.begin(), itemSelectorQualities->second.end(),
+ quality, ItemLevelSelectorQualityEntryComparator{});
+
+ if (itemSelectorQuality != itemSelectorQualities->second.end())
+ bonusListIDs.insert((*itemSelectorQuality)->QualityItemBonusListID);
}
}
}
- }
+ });
return bonusListIDs;
}
diff --git a/src/server/game/DataStores/DB2Stores.h b/src/server/game/DataStores/DB2Stores.h
index b74a87ba11e..b5a748885fb 100644
--- a/src/server/game/DataStores/DB2Stores.h
+++ b/src/server/game/DataStores/DB2Stores.h
@@ -298,7 +298,7 @@ public:
std::vector<uint32> const* GetGlyphRequiredSpecs(uint32 glyphPropertiesId) const;
ItemBonusList const* GetItemBonusList(uint32 bonusListId) const;
uint32 GetItemBonusListForItemLevelDelta(int16 delta) const;
- std::set<uint32> GetItemBonusTree(uint32 itemId, uint32 itemContext) const;
+ std::set<uint32> GetItemBonusTree(uint32 itemId, ItemContext itemContext) const;
ItemChildEquipmentEntry const* GetItemChildEquipment(uint32 itemId) const;
ItemClassEntry const* GetItemClassByOldEnum(uint32 itemClass) const;
bool HasItemCurrencyCost(uint32 itemId) const;
diff --git a/src/server/game/Entities/Item/AzeriteItem/AzeriteItem.cpp b/src/server/game/Entities/Item/AzeriteItem/AzeriteItem.cpp
index 1eb600e5722..60b4770365c 100644
--- a/src/server/game/Entities/Item/AzeriteItem/AzeriteItem.cpp
+++ b/src/server/game/Entities/Item/AzeriteItem/AzeriteItem.cpp
@@ -33,9 +33,9 @@ AzeriteItem::AzeriteItem() : Item()
SetUpdateFieldValue(m_values.ModifyValue(&AzeriteItem::m_azeriteItemData).ModifyValue(&UF::AzeriteItemData::DEBUGknowledgeWeek), -1);
}
-bool AzeriteItem::Create(ObjectGuid::LowType guidlow, uint32 itemId, Player const* owner)
+bool AzeriteItem::Create(ObjectGuid::LowType guidlow, uint32 itemId, ItemContext context, Player const* owner)
{
- if (!Item::Create(guidlow, itemId, owner))
+ if (!Item::Create(guidlow, itemId, context, owner))
return false;
SetUpdateFieldValue(m_values.ModifyValue(&AzeriteItem::m_azeriteItemData).ModifyValue(&UF::AzeriteItemData::Level), 1);
diff --git a/src/server/game/Entities/Item/AzeriteItem/AzeriteItem.h b/src/server/game/Entities/Item/AzeriteItem/AzeriteItem.h
index 830b71b9a98..124e5fa9b11 100644
--- a/src/server/game/Entities/Item/AzeriteItem/AzeriteItem.h
+++ b/src/server/game/Entities/Item/AzeriteItem/AzeriteItem.h
@@ -31,7 +31,7 @@ class TC_GAME_API AzeriteItem : public Item
public:
AzeriteItem();
- bool Create(ObjectGuid::LowType guidlow, uint32 itemId, Player const* owner) override;
+ bool Create(ObjectGuid::LowType guidlow, uint32 itemId, ItemContext context, Player const* owner) override;
void SaveToDB(CharacterDatabaseTransaction& trans) override;
void LoadAzeriteItemData(Player* owner, AzeriteItemData& azeriteItem);
diff --git a/src/server/game/Entities/Item/Container/Bag.cpp b/src/server/game/Entities/Item/Container/Bag.cpp
index 43f0f518adf..8415eb51651 100644
--- a/src/server/game/Entities/Item/Container/Bag.cpp
+++ b/src/server/game/Entities/Item/Container/Bag.cpp
@@ -67,7 +67,7 @@ void Bag::RemoveFromWorld()
Item::RemoveFromWorld();
}
-bool Bag::Create(ObjectGuid::LowType guidlow, uint32 itemid, Player const* owner)
+bool Bag::Create(ObjectGuid::LowType guidlow, uint32 itemid, ItemContext context, Player const* owner)
{
ItemTemplate const* itemProto = sObjectMgr->GetItemTemplate(itemid);
@@ -90,6 +90,7 @@ bool Bag::Create(ObjectGuid::LowType guidlow, uint32 itemid, Player const* owner
SetUpdateFieldValue(m_values.ModifyValue(&Item::m_itemData).ModifyValue(&UF::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/src/server/game/Entities/Item/Container/Bag.h b/src/server/game/Entities/Item/Container/Bag.h
index b9f4f3c1beb..4fc0620358d 100644
--- a/src/server/game/Entities/Item/Container/Bag.h
+++ b/src/server/game/Entities/Item/Container/Bag.h
@@ -34,7 +34,7 @@ class TC_GAME_API Bag : public Item
void AddToWorld() override;
void RemoveFromWorld() override;
- bool Create(ObjectGuid::LowType guidlow, uint32 itemid, Player const* owner) override;
+ bool Create(ObjectGuid::LowType guidlow, uint32 itemid, ItemContext context, Player const* owner) override;
void Clear();
void StoreItem(uint8 slot, Item* pItem, bool update);
diff --git a/src/server/game/Entities/Item/Item.cpp b/src/server/game/Entities/Item/Item.cpp
index c702be312db..f4ec2ce9ddb 100644
--- a/src/server/game/Entities/Item/Item.cpp
+++ b/src/server/game/Entities/Item/Item.cpp
@@ -417,7 +417,7 @@ Item::Item()
memset(&_bonusData, 0, sizeof(_bonusData));
}
-bool Item::Create(ObjectGuid::LowType guidlow, uint32 itemId, Player const* owner)
+bool Item::Create(ObjectGuid::LowType guidlow, uint32 itemId, ItemContext context, Player const* owner)
{
Object::_Create(ObjectGuid::Create<HighGuid::Item>(guidlow));
@@ -445,6 +445,7 @@ bool Item::Create(ObjectGuid::LowType guidlow, uint32 itemId, Player const* owne
SetExpiration(itemProto->GetDuration());
SetCreatePlayedTime(0);
+ SetContext(context);
if (itemProto->GetArtifactID())
{
@@ -823,7 +824,7 @@ bool Item::LoadFromDB(ObjectGuid::LowType guid, ObjectGuid ownerGuid, Field* fie
SetModifier(ITEM_MODIFIER_BATTLE_PET_LEVEL, fields[15].GetUInt16());
SetModifier(ITEM_MODIFIER_BATTLE_PET_DISPLAY_ID, fields[16].GetUInt32());
- SetContext(fields[17].GetUInt8());
+ SetContext(ItemContext(fields[17].GetUInt8()));
Tokenizer bonusListString(fields[18].GetString(), ' ');
std::vector<int32> bonusListIDs;
@@ -1454,7 +1455,7 @@ void Item::SendTimeUpdate(Player* owner)
owner->GetSession()->SendPacket(itemTimeUpdate.Write());
}
-Item* Item::CreateItem(uint32 itemEntry, uint32 count, Player const* player /*= nullptr*/)
+Item* Item::CreateItem(uint32 itemEntry, uint32 count, ItemContext context, Player const* player /*= nullptr*/)
{
if (count < 1)
return nullptr; //don't create item at zero count
@@ -1468,7 +1469,7 @@ Item* Item::CreateItem(uint32 itemEntry, uint32 count, Player const* player /*=
ASSERT(count != 0, "proto->Stackable == 0 but checked at loading already");
Item* item = NewItemOrBag(proto);
- if (item->Create(sObjectMgr->GetGenerator<HighGuid::Item>().Generate(), itemEntry, player))
+ if (item->Create(sObjectMgr->GetGenerator<HighGuid::Item>().Generate(), itemEntry, context, player))
{
item->SetCount(count);
return item;
@@ -1483,7 +1484,7 @@ Item* Item::CreateItem(uint32 itemEntry, uint32 count, Player const* player /*=
Item* Item::CloneItem(uint32 count, Player const* player /*= nullptr*/) const
{
- Item* newItem = CreateItem(GetEntry(), count, player);
+ Item* newItem = CreateItem(GetEntry(), count, GetContext(), player);
if (!newItem)
return nullptr;
@@ -2112,7 +2113,7 @@ void Item::ItemContainerSaveLootToDB()
stmt_items->setBool(7, _li->is_underthreshold);
stmt_items->setBool(8, _li->needs_quest);
stmt_items->setUInt32(9, _li->randomBonusListId);
- stmt_items->setUInt8(10, _li->context);
+ stmt_items->setUInt8(10, AsUnderlyingType(_li->context));
std::ostringstream bonusListIDs;
for (int32 bonusListID : _li->BonusListIDs)
bonusListIDs << bonusListID << ' ';
@@ -2175,7 +2176,7 @@ bool Item::ItemContainerLoadLootFromDB()
loot_item.is_underthreshold = fields[6].GetBool();
loot_item.needs_quest = fields[7].GetBool();
loot_item.randomBonusListId = fields[8].GetUInt32();
- loot_item.context = fields[9].GetUInt8();
+ loot_item.context = ItemContext(fields[9].GetUInt8());
Tokenizer bonusLists(fields[10].GetString(), ' ');
std::transform(bonusLists.begin(), bonusLists.end(), std::back_inserter(loot_item.BonusListIDs), [](char const* token)
{
diff --git a/src/server/game/Entities/Item/Item.h b/src/server/game/Entities/Item/Item.h
index 5b5cb12a569..f32838feeb7 100644
--- a/src/server/game/Entities/Item/Item.h
+++ b/src/server/game/Entities/Item/Item.h
@@ -162,12 +162,12 @@ class TC_GAME_API Item : public Object
friend void AddItemToUpdateQueueOf(Item* item, Player* player);
friend void RemoveItemFromUpdateQueueOf(Item* item, Player* player);
public:
- static Item* CreateItem(uint32 itemEntry, uint32 count, Player const* player = nullptr);
+ static Item* CreateItem(uint32 itemEntry, uint32 count, ItemContext context, Player const* player = nullptr);
Item* CloneItem(uint32 count, Player const* player = nullptr) const;
Item();
- virtual bool Create(ObjectGuid::LowType guidlow, uint32 itemId, Player const* owner);
+ virtual bool Create(ObjectGuid::LowType guidlow, uint32 itemId, ItemContext context, Player const* owner);
ItemTemplate const* GetTemplate() const;
BonusData const* GetBonus() const { return &_bonusData; }
@@ -399,7 +399,8 @@ class TC_GAME_API Item : public Object
void SetArtifactXP(uint64 xp) { SetUpdateFieldValue(m_values.ModifyValue(&Item::m_itemData).ModifyValue(&UF::ItemData::ArtifactXP), xp); }
void GiveArtifactXp(uint64 amount, Item* sourceItem, uint32 artifactCategoryId);
- void SetContext(int32 context) { SetUpdateFieldValue(m_values.ModifyValue(&Item::m_itemData).ModifyValue(&UF::ItemData::Context), context); }
+ ItemContext GetContext() const { return ItemContext(*m_itemData->Context); }
+ void SetContext(ItemContext context) { SetUpdateFieldValue(m_values.ModifyValue(&Item::m_itemData).ModifyValue(&UF::ItemData::Context), int32(context)); }
void SetPetitionId(uint32 petitionId) { SetUpdateFieldValue(m_values.ModifyValue(&Item::m_itemData).ModifyValue(&UF::ItemData::Enchantment, 0).ModifyValue(&UF::ItemEnchantment::ID), petitionId); }
void SetPetitionNumSignatures(uint32 signatures) { SetUpdateFieldValue(m_values.ModifyValue(&Item::m_itemData).ModifyValue(&UF::ItemData::Enchantment, 0).ModifyValue(&UF::ItemEnchantment::Duration), signatures); }
diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp
index b5a96465e79..3c3b77f7157 100644
--- a/src/server/game/Entities/Player/Player.cpp
+++ b/src/server/game/Entities/Player/Player.cpp
@@ -697,7 +697,7 @@ bool Player::StoreNewItemInBestSlots(uint32 titem_id, uint32 titem_amount)
if (msg != EQUIP_ERR_OK)
break;
- EquipNewItem(eDest, titem_id, true);
+ EquipNewItem(eDest, titem_id, ItemContext::NONE, true);
AutoUnequipOffhandIfNeed();
--titem_amount;
}
@@ -8505,7 +8505,7 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type, bool aeLooting/* = fa
if (groupRules)
group->UpdateLooterGuid(go, true);
- loot->FillLoot(lootid, LootTemplates_Gameobject, this, !groupRules, false, go->GetLootMode());
+ loot->FillLoot(lootid, LootTemplates_Gameobject, this, !groupRules, false, go->GetLootMode(), GetMap()->GetDifficultyLootItemContext());
go->SetLootGenerationTime();
// get next RR player (for next loot)
@@ -11269,7 +11269,7 @@ InventoryResult Player::CanStoreItems(Item** items, int count, uint32* offending
InventoryResult Player::CanEquipNewItem(uint8 slot, uint16 &dest, uint32 item, bool swap) const
{
dest = 0;
- Item* pItem = Item::CreateItem(item, 1, this);
+ Item* pItem = Item::CreateItem(item, 1, ItemContext::NONE, this);
if (pItem)
{
InventoryResult result = CanEquipItem(slot, dest, pItem, swap);
@@ -11899,13 +11899,13 @@ InventoryResult Player::CanRollForItemInLFG(ItemTemplate const* proto, WorldObje
// Return stored item (if stored to stack, it can diff. from pItem). And pItem ca be deleted in this case.
Item* Player::StoreNewItem(ItemPosCountVec const& pos, uint32 itemId, bool update, ItemRandomBonusListId randomBonusListId /*= 0*/,
- GuidSet const& allowedLooters /*= GuidSet()*/, uint8 context /*= 0*/, std::vector<int32> const& bonusListIDs /*= std::vector<int32>()*/, bool addToCollection /*= true*/)
+ GuidSet const& allowedLooters /*= GuidSet()*/, ItemContext context /*= ItemContext::NONE*/, std::vector<int32> const& bonusListIDs /*= std::vector<int32>()*/, bool addToCollection /*= true*/)
{
uint32 count = 0;
for (ItemPosCountVec::const_iterator itr = pos.begin(); itr != pos.end(); ++itr)
count += itr->count;
- Item* item = Item::CreateItem(itemId, count, this);
+ Item* item = Item::CreateItem(itemId, count, context, this);
if (item)
{
ItemAddedQuestCheck(itemId, count);
@@ -11914,7 +11914,6 @@ Item* Player::StoreNewItem(ItemPosCountVec const& pos, uint32 itemId, bool updat
item->AddItemFlag(ITEM_FIELD_FLAG_NEW_ITEM);
- item->SetContext(context);
item->SetBonuses(bonusListIDs);
item = StoreItem(pos, item, update);
@@ -12092,9 +12091,9 @@ Item* Player::_StoreItem(uint16 pos, Item* pItem, uint32 count, bool clone, bool
}
}
-Item* Player::EquipNewItem(uint16 pos, uint32 item, bool update)
+Item* Player::EquipNewItem(uint16 pos, uint32 item, ItemContext context, bool update)
{
- if (Item* pItem = Item::CreateItem(item, 1, this))
+ if (Item* pItem = Item::CreateItem(item, 1, context, this))
{
ItemAddedQuestCheck(item, 1);
UpdateCriteria(CRITERIA_TYPE_RECEIVE_EPIC_ITEM, item, 1);
@@ -15532,7 +15531,7 @@ void Player::RewardQuest(Quest const* quest, uint32 reward, Object* questGiver,
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::Quest_Reward);
}
}
}
@@ -18883,7 +18882,7 @@ void Player::_LoadVoidStorage(PreparedQueryResult result)
ItemRandomBonusListId randomBonusListId = fields[4].GetUInt32();
uint32 fixedScalingLevel = fields[5].GetUInt32();
uint32 artifactKnowledgeLevel = fields[6].GetUInt32();
- uint8 context = fields[7].GetUInt8();
+ ItemContext context = ItemContext(fields[7].GetUInt8());
std::vector<int32> bonusListIDs;
Tokenizer bonusListIdTokens(fields[8].GetString(), ' ');
for (char const* token : bonusListIdTokens)
@@ -20715,7 +20714,7 @@ void Player::_SaveVoidStorage(CharacterDatabaseTransaction& trans)
stmt->setUInt32(5, _voidStorageItems[i]->RandomBonusListId);
stmt->setUInt32(6, _voidStorageItems[i]->FixedScalingLevel);
stmt->setUInt32(7, _voidStorageItems[i]->ArtifactKnowledgeLevel);
- stmt->setUInt8(8, _voidStorageItems[i]->Context);
+ stmt->setUInt8(8, AsUnderlyingType(_voidStorageItems[i]->Context));
std::ostringstream bonusListIDs;
for (int32 bonusListID : _voidStorageItems[i]->BonusListIDs)
bonusListIDs << bonusListID << ' ';
@@ -22530,8 +22529,8 @@ inline bool Player::_StoreOrEquipNewItem(uint32 vendorslot, uint32 item, uint8 c
}
Item* it = bStore ?
- StoreNewItem(vDest, item, true, GenerateItemRandomBonusListId(item), {}, 0, crItem->BonusListIDs, false) :
- EquipNewItem(uiDest, item, true);
+ StoreNewItem(vDest, item, true, GenerateItemRandomBonusListId(item), {}, ItemContext::Vendor, crItem->BonusListIDs, false) :
+ EquipNewItem(uiDest, item, ItemContext::Vendor, true);
if (it)
{
uint32 new_count = pVendor->UpdateVendorItemCurrentCount(crItem, count);
@@ -25796,10 +25795,10 @@ void Player::InitRunes()
SetUpdateFieldValue(m_values.ModifyValue(&Unit::m_unitData).ModifyValue(&UF::UnitData::PowerRegenInterruptedFlatModifier, runeIndex), 0.0f);
}
-void Player::AutoStoreLoot(uint8 bag, uint8 slot, uint32 loot_id, LootStore const& store, bool broadcast)
+void Player::AutoStoreLoot(uint8 bag, uint8 slot, uint32 loot_id, LootStore const& store, ItemContext context, bool broadcast)
{
Loot loot;
- loot.FillLoot (loot_id, store, this, true);
+ loot.FillLoot (loot_id, store, this, true, false, LOOT_MODE_DEFAULT, context);
uint32 max_slot = loot.GetMaxSlotInLootFor(this);
for (uint32 i = 0; i < max_slot; ++i)
@@ -27462,13 +27461,13 @@ void Player::RefundItem(Item* item)
CharacterDatabase.CommitTransaction(trans);
}
-void Player::SendItemRetrievalMail(uint32 itemEntry, uint32 count)
+void Player::SendItemRetrievalMail(uint32 itemEntry, uint32 count, ItemContext context)
{
MailSender sender(MAIL_CREATURE, UI64LIT(34337) /* The Postmaster */);
MailDraft draft("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.
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
- if (Item* item = Item::CreateItem(itemEntry, count, nullptr))
+ if (Item* item = Item::CreateItem(itemEntry, count, context, nullptr))
{
item->SaveToDB(trans);
draft.AddItem(item);
diff --git a/src/server/game/Entities/Player/Player.h b/src/server/game/Entities/Player/Player.h
index 0c2131a3e9b..68bcf733a25 100644
--- a/src/server/game/Entities/Player/Player.h
+++ b/src/server/game/Entities/Player/Player.h
@@ -905,9 +905,9 @@ struct BGData
struct VoidStorageItem
{
- VoidStorageItem() : ItemId(0), ItemEntry(0), RandomBonusListId(0), FixedScalingLevel(0), ArtifactKnowledgeLevel(0), Context(0) { }
+ VoidStorageItem() : ItemId(0), ItemEntry(0), RandomBonusListId(0), FixedScalingLevel(0), ArtifactKnowledgeLevel(0), Context(ItemContext::NONE) { }
VoidStorageItem(uint64 id, uint32 entry, ObjectGuid const& creator, ItemRandomBonusListId randomBonusListId,
- uint32 fixedScalingLevel, uint32 artifactKnowledgeLevel, uint8 context, std::vector<int32> const& bonuses)
+ uint32 fixedScalingLevel, uint32 artifactKnowledgeLevel, ItemContext context, std::vector<int32> const& bonuses)
: ItemId(id), ItemEntry(entry), CreatorGuid(creator), RandomBonusListId(randomBonusListId),
FixedScalingLevel(fixedScalingLevel), ArtifactKnowledgeLevel(artifactKnowledgeLevel), Context(context)
{
@@ -922,7 +922,7 @@ struct VoidStorageItem
ItemRandomBonusListId RandomBonusListId;
uint32 FixedScalingLevel;
uint32 ArtifactKnowledgeLevel;
- uint8 Context;
+ ItemContext Context;
std::vector<int32> BonusListIDs;
};
@@ -1164,16 +1164,16 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
bool HasItemTotemCategory(uint32 TotemCategory) const;
InventoryResult CanUseItem(ItemTemplate const* pItem) const;
InventoryResult CanRollForItemInLFG(ItemTemplate const* item, WorldObject const* lootedObject) const;
- Item* StoreNewItem(ItemPosCountVec const& pos, uint32 itemId, bool update, ItemRandomBonusListId randomBonusListId = 0, GuidSet const& allowedLooters = GuidSet(), uint8 context = 0, std::vector<int32> const& bonusListIDs = std::vector<int32>(), bool addToCollection = true);
+ Item* StoreNewItem(ItemPosCountVec const& pos, uint32 itemId, bool update, ItemRandomBonusListId randomBonusListId = 0, GuidSet const& allowedLooters = GuidSet(), ItemContext context = ItemContext::NONE, std::vector<int32> const& bonusListIDs = std::vector<int32>(), bool addToCollection = true);
Item* StoreItem(ItemPosCountVec const& pos, Item* pItem, bool update);
- Item* EquipNewItem(uint16 pos, uint32 item, bool update);
+ Item* EquipNewItem(uint16 pos, uint32 item, ItemContext context, bool update);
Item* EquipItem(uint16 pos, Item* pItem, bool update);
void AutoUnequipOffhandIfNeed(bool force = false);
void EquipChildItem(uint8 parentBag, uint8 parentSlot, Item* parentItem);
void AutoUnequipChildItem(Item* parentItem);
bool StoreNewItemInBestSlots(uint32 item_id, uint32 item_count);
- void AutoStoreLoot(uint8 bag, uint8 slot, uint32 loot_id, LootStore const& store, bool broadcast = false);
- void AutoStoreLoot(uint32 loot_id, LootStore const& store, bool broadcast = false) { AutoStoreLoot(NULL_BAG, NULL_SLOT, loot_id, store, broadcast); }
+ void AutoStoreLoot(uint8 bag, uint8 slot, uint32 loot_id, LootStore const& store, ItemContext context = ItemContext::NONE, bool broadcast = false);
+ void AutoStoreLoot(uint32 loot_id, LootStore const& store, ItemContext context = ItemContext::NONE, bool broadcast = false) { AutoStoreLoot(NULL_BAG, NULL_SLOT, loot_id, store, context, broadcast); }
void StoreLootItem(uint8 lootSlot, Loot* loot, AELootResult* aeResult = nullptr);
InventoryResult CanTakeMoreSimilarItems(uint32 entry, uint32 count, Item* pItem, uint32* no_space_count = nullptr, uint32* offendingItemId = nullptr) const;
@@ -1514,7 +1514,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
PlayerMails const& GetMails() const { return m_mail; }
- void SendItemRetrievalMail(uint32 itemEntry, uint32 count); // Item retrieval mails sent by The Postmaster (34337), used in multiple places.
+ void SendItemRetrievalMail(uint32 itemEntry, uint32 count, ItemContext context); // Item retrieval mails sent by The Postmaster (34337), used in multiple places.
/*********************************************************/
/*** MAILED ITEMS SYSTEM ***/
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index 54d583f0437..2a89e251b0e 100644
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -11203,7 +11203,7 @@ void Unit::Kill(Unit* victim, bool durabilityLoss)
Loot* loot = &creature->loot;
loot->clear();
if (uint32 lootid = creature->GetCreatureTemplate()->lootid)
- loot->FillLoot(lootid, LootTemplates_Creature, looter, false, false, creature->GetLootMode());
+ loot->FillLoot(lootid, LootTemplates_Creature, looter, false, false, creature->GetLootMode(), GetMap()->GetDifficultyLootItemContext());
if (creature->GetLootMode() > 0)
loot->generateMoneyLoot(creature->GetCreatureTemplate()->mingold, creature->GetCreatureTemplate()->maxgold);
diff --git a/src/server/game/Groups/Group.cpp b/src/server/game/Groups/Group.cpp
index dcbf16051e1..e377812f029 100644
--- a/src/server/game/Groups/Group.cpp
+++ b/src/server/game/Groups/Group.cpp
@@ -1363,7 +1363,7 @@ void Group::CountTheRoll(Rolls::iterator rollI, Map* allowedMap)
ItemPosCountVec dest;
InventoryResult msg = player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, roll->itemid, item->count);
if (msg == EQUIP_ERR_OK)
- player->AutoStoreLoot(disenchant->ID, LootTemplates_Disenchant, true);
+ player->AutoStoreLoot(disenchant->ID, LootTemplates_Disenchant, ItemContext::NONE, true);
else // If the player's inventory is full, send the disenchant result in a mail.
{
Loot loot;
@@ -1374,7 +1374,7 @@ void Group::CountTheRoll(Rolls::iterator rollI, Map* allowedMap)
{
LootItem* lootItem = loot.LootItemInSlot(i, player);
player->SendEquipError(msg, nullptr, nullptr, lootItem->itemid);
- player->SendItemRetrievalMail(lootItem->itemid, lootItem->count);
+ player->SendItemRetrievalMail(lootItem->itemid, lootItem->count, lootItem->context);
}
}
}
diff --git a/src/server/game/Handlers/MailHandler.cpp b/src/server/game/Handlers/MailHandler.cpp
index bab0a1519e9..22084ebf239 100644
--- a/src/server/game/Handlers/MailHandler.cpp
+++ b/src/server/game/Handlers/MailHandler.cpp
@@ -612,7 +612,7 @@ void WorldSession::HandleMailCreateTextItem(WorldPackets::Mail::MailCreateTextIt
}
Item* bodyItem = new Item; // This is not bag and then can be used new Item.
- if (!bodyItem->Create(sObjectMgr->GetGenerator<HighGuid::Item>().Generate(), MAIL_BODY_ITEM_TEMPLATE, player))
+ if (!bodyItem->Create(sObjectMgr->GetGenerator<HighGuid::Item>().Generate(), MAIL_BODY_ITEM_TEMPLATE, ItemContext::NONE, player))
{
delete bodyItem;
return;
diff --git a/src/server/game/Handlers/QuestHandler.cpp b/src/server/game/Handlers/QuestHandler.cpp
index 395832b2788..5ede842bab7 100644
--- a/src/server/game/Handlers/QuestHandler.cpp
+++ b/src/server/game/Handlers/QuestHandler.cpp
@@ -720,7 +720,7 @@ void WorldSession::HandlePlayerChoiceResponse(WorldPackets::Quest::ChoiceRespons
ItemPosCountVec dest;
if (_player->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, item.Id, item.Quantity) == EQUIP_ERR_OK)
{
- Item* newItem = _player->StoreNewItem(dest, item.Id, true, GenerateItemRandomBonusListId(item.Id), {}, 0, item.BonusListIDs);
+ Item* newItem = _player->StoreNewItem(dest, item.Id, true, GenerateItemRandomBonusListId(item.Id), {}, ItemContext::Quest_Reward, item.BonusListIDs);
_player->SendNewItem(newItem, item.Quantity, true, false);
}
}
diff --git a/src/server/game/Handlers/VoidStorageHandler.cpp b/src/server/game/Handlers/VoidStorageHandler.cpp
index 0b80b5ca71a..2f98f70a488 100644
--- a/src/server/game/Handlers/VoidStorageHandler.cpp
+++ b/src/server/game/Handlers/VoidStorageHandler.cpp
@@ -156,7 +156,7 @@ void WorldSession::HandleVoidStorageTransfer(WorldPackets::VoidStorage::VoidStor
VoidStorageItem itemVS(sObjectMgr->GenerateVoidStorageItemId(), item->GetEntry(), item->GetCreator(),
item->GetItemRandomBonusListId(), item->GetModifier(ITEM_MODIFIER_TIMEWALKER_LEVEL), item->GetModifier(ITEM_MODIFIER_ARTIFACT_KNOWLEDGE_LEVEL),
- uint8(item->m_itemData->Context), item->m_itemData->BonusListIDs);
+ item->GetContext(), item->m_itemData->BonusListIDs);
WorldPackets::VoidStorage::VoidItem voidItem;
voidItem.Guid = ObjectGuid::Create<HighGuid::Item>(itemVS.ItemId);
diff --git a/src/server/game/Loot/Loot.cpp b/src/server/game/Loot/Loot.cpp
index eb37b6b0989..2bace1ded82 100644
--- a/src/server/game/Loot/Loot.cpp
+++ b/src/server/game/Loot/Loot.cpp
@@ -47,7 +47,7 @@ LootItem::LootItem(LootStoreItem const& li)
needs_quest = li.needs_quest;
randomBonusListId = GenerateItemRandomBonusListId(itemid);
- context = 0;
+ context = ItemContext::NONE;
count = 0;
is_looted = 0;
is_blocked = 0;
@@ -95,7 +95,7 @@ void LootItem::AddAllowedLooter(const Player* player)
// --------- Loot ---------
//
-Loot::Loot(uint32 _gold /*= 0*/) : gold(_gold), unlootedCount(0), roundRobinPlayer(), loot_type(LOOT_NONE), maxDuplicates(1), _itemContext(0)
+Loot::Loot(uint32 _gold /*= 0*/) : gold(_gold), unlootedCount(0), roundRobinPlayer(), loot_type(LOOT_NONE), maxDuplicates(1), _itemContext(ItemContext::NONE)
{
}
@@ -153,7 +153,7 @@ void Loot::clear()
roundRobinPlayer.Clear();
loot_type = LOOT_NONE;
i_LootValidatorRefManager.clearReferences();
- _itemContext = 0;
+ _itemContext = ItemContext::NONE;
}
void Loot::NotifyItemRemoved(uint8 lootIndex)
@@ -235,7 +235,7 @@ void Loot::generateMoneyLoot(uint32 minAmount, uint32 maxAmount)
}
// Calls processor of corresponding LootTemplate (which handles everything including references)
-bool Loot::FillLoot(uint32 lootId, LootStore const& store, Player* lootOwner, bool personal, bool noEmptyError, uint16 lootMode /*= LOOT_MODE_DEFAULT*/)
+bool Loot::FillLoot(uint32 lootId, LootStore const& store, Player* lootOwner, bool personal, bool noEmptyError, uint16 lootMode /*= LOOT_MODE_DEFAULT*/, ItemContext context /*= ItemContext::NONE*/)
{
// Must be provided
if (!lootOwner)
@@ -250,7 +250,7 @@ bool Loot::FillLoot(uint32 lootId, LootStore const& store, Player* lootOwner, bo
return false;
}
- _itemContext = lootOwner->GetMap()->GetDifficultyLootItemContext();
+ _itemContext = context;
items.reserve(MAX_NR_LOOT_ITEMS);
quest_items.reserve(MAX_NR_QUEST_ITEMS);
@@ -300,7 +300,7 @@ void Loot::AddItem(LootStoreItem const& item)
LootItem generatedLoot(item);
generatedLoot.context = _itemContext;
generatedLoot.count = std::min(count, proto->GetMaxStackSize());
- if (_itemContext)
+ if (_itemContext != ItemContext::NONE)
{
std::set<uint32> bonusListIDs = sDB2Manager.GetItemBonusTree(generatedLoot.itemid, _itemContext);
generatedLoot.BonusListIDs.insert(generatedLoot.BonusListIDs.end(), bonusListIDs.begin(), bonusListIDs.end());
diff --git a/src/server/game/Loot/Loot.h b/src/server/game/Loot/Loot.h
index 7373cd5e9d8..a8a5d620740 100644
--- a/src/server/game/Loot/Loot.h
+++ b/src/server/game/Loot/Loot.h
@@ -135,7 +135,7 @@ struct TC_GAME_API LootItem
uint32 itemid;
ItemRandomBonusListId randomBonusListId;
std::vector<int32> BonusListIDs;
- uint8 context;
+ ItemContext context;
ConditionContainer conditions; // additional loot condition
GuidSet allowedGUIDs;
ObjectGuid rollWinnerGUID; // Stores the guid of person who won loot, if his bags are full only he can see the item in loot list!
@@ -154,7 +154,7 @@ struct TC_GAME_API LootItem
explicit LootItem(LootStoreItem const& li);
// Empty constructor for creating an empty LootItem to be filled in with DB data
- LootItem() : itemid(0), randomBonusListId(0), context(0), count(0), is_looted(false), is_blocked(false),
+ LootItem() : itemid(0), randomBonusListId(0), context(ItemContext::NONE), count(0), is_looted(false), is_blocked(false),
freeforall(false), is_underthreshold(false), is_counted(false), needs_quest(false), follow_loot_rules(false),
canSave(true){ };
@@ -251,7 +251,7 @@ struct TC_GAME_API Loot
void RemoveLooter(ObjectGuid GUID) { PlayersLooting.erase(GUID); }
void generateMoneyLoot(uint32 minAmount, uint32 maxAmount);
- bool FillLoot(uint32 lootId, LootStore const& store, Player* lootOwner, bool personal, bool noEmptyError = false, uint16 lootMode = LOOT_MODE_DEFAULT);
+ bool FillLoot(uint32 lootId, LootStore const& store, Player* lootOwner, bool personal, bool noEmptyError = false, uint16 lootMode = LOOT_MODE_DEFAULT, ItemContext context = ItemContext::NONE);
// Inserts the item into the loot (called by LootTemplate processors)
void AddItem(LootStoreItem const & item);
@@ -283,7 +283,7 @@ private:
// Loot GUID
ObjectGuid _GUID;
- uint8 _itemContext;
+ ItemContext _itemContext;
};
class TC_GAME_API AELootResult
diff --git a/src/server/game/Mails/Mail.cpp b/src/server/game/Mails/Mail.cpp
index 07efff4589e..aaad1e4fcdf 100644
--- a/src/server/game/Mails/Mail.cpp
+++ b/src/server/game/Mails/Mail.cpp
@@ -106,14 +106,14 @@ void MailDraft::prepareItems(Player* receiver, CharacterDatabaseTransaction& tra
Loot mailLoot;
// can be empty
- mailLoot.FillLoot(m_mailTemplateId, LootTemplates_Mail, receiver, true, true);
+ mailLoot.FillLoot(m_mailTemplateId, LootTemplates_Mail, receiver, true, true, LOOT_MODE_DEFAULT, ItemContext::NONE);
uint32 max_slot = mailLoot.GetMaxSlotInLootFor(receiver);
for (uint32 i = 0; m_items.size() < MAX_MAIL_ITEMS && i < max_slot; ++i)
{
if (LootItem* lootitem = mailLoot.LootItemInSlot(i, receiver))
{
- if (Item* item = Item::CreateItem(lootitem->itemid, lootitem->count, receiver))
+ if (Item* item = Item::CreateItem(lootitem->itemid, lootitem->count, lootitem->context, receiver))
{
item->SaveToDB(trans); // save for prevent lost at next mail load, if send fail then item will deleted
AddItem(item);
diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp
index 6c2b569d58f..246536da3cd 100644
--- a/src/server/game/Maps/Map.cpp
+++ b/src/server/game/Maps/Map.cpp
@@ -3736,16 +3736,16 @@ MapDifficultyEntry const* Map::GetMapDifficulty() const
return sDB2Manager.GetMapDifficultyData(GetId(), GetDifficultyID());
}
-uint8 Map::GetDifficultyLootItemContext() const
+ItemContext Map::GetDifficultyLootItemContext() const
{
if (MapDifficultyEntry const* mapDifficulty = GetMapDifficulty())
if (mapDifficulty->ItemContext)
- return mapDifficulty->ItemContext;
+ return ItemContext(mapDifficulty->ItemContext);
if (DifficultyEntry const* difficulty = sDifficultyStore.LookupEntry(GetDifficultyID()))
- return difficulty->ItemContext;
+ return ItemContext(difficulty->ItemContext);
- return 0;
+ return ItemContext::NONE;
}
uint32 Map::GetId() const
diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h
index 4cfc9c475db..70f2ef71ca6 100644
--- a/src/server/game/Maps/Map.h
+++ b/src/server/game/Maps/Map.h
@@ -64,6 +64,7 @@ struct SummonPropertiesEntry;
class Transport;
enum Difficulty : uint8;
enum WeatherState : uint32;
+enum class ItemContext : uint8;
namespace Trinity { struct ObjectUpdater; }
namespace G3D { class Plane; }
@@ -393,7 +394,7 @@ class TC_GAME_API Map : public GridRefManager<NGridType>
// have meaning only for instanced map (that have set real difficulty)
Difficulty GetDifficultyID() const { return Difficulty(i_spawnMode); }
MapDifficultyEntry const* GetMapDifficulty() const;
- uint8 GetDifficultyLootItemContext() const;
+ ItemContext GetDifficultyLootItemContext() const;
uint32 GetId() const;
bool Instanceable() const;
diff --git a/src/server/game/Server/Packets/ItemPacketsCommon.cpp b/src/server/game/Server/Packets/ItemPacketsCommon.cpp
index 83fb1bd9328..e3a5c95eaf5 100644
--- a/src/server/game/Server/Packets/ItemPacketsCommon.cpp
+++ b/src/server/game/Server/Packets/ItemPacketsCommon.cpp
@@ -38,7 +38,7 @@ void WorldPackets::Item::ItemInstance::Initialize(::Item const* item)
{
ItemBonus = boost::in_place();
ItemBonus->BonusListIDs.insert(ItemBonus->BonusListIDs.end(), bonusListIds.begin(), bonusListIds.end());
- ItemBonus->Context = item->m_itemData->Context;
+ ItemBonus->Context = item->GetContext();
}
if (uint32 mask = item->m_itemData->ModifiersMask)
@@ -56,12 +56,12 @@ void WorldPackets::Item::ItemInstance::Initialize(UF::SocketedGem const* gem)
ItemID = gem->ItemID;
ItemBonusInstanceData bonus;
- bonus.Context = gem->Context;
+ bonus.Context = ItemContext(*gem->Context);
for (uint16 bonusListId : gem->BonusListIDs)
if (bonusListId)
bonus.BonusListIDs.push_back(bonusListId);
- if (bonus.Context || !bonus.BonusListIDs.empty())
+ if (bonus.Context != ItemContext::NONE || !bonus.BonusListIDs.empty())
ItemBonus = bonus;
}
@@ -131,7 +131,7 @@ ByteBuffer& operator>>(ByteBuffer& data, WorldPackets::Item::ItemBonusInstanceDa
{
uint32 bonusListIdSize;
- data >> itemBonusInstanceData.Context;
+ itemBonusInstanceData.Context = data.read<ItemContext>();
data >> bonusListIdSize;
for (uint32 i = 0u; i < bonusListIdSize; ++i)
diff --git a/src/server/game/Server/Packets/ItemPacketsCommon.h b/src/server/game/Server/Packets/ItemPacketsCommon.h
index 3f0d500c069..ef8b1d4d509 100644
--- a/src/server/game/Server/Packets/ItemPacketsCommon.h
+++ b/src/server/game/Server/Packets/ItemPacketsCommon.h
@@ -27,6 +27,7 @@ class ByteBuffer;
class Item;
struct LootItem;
struct VoidStorageItem;
+enum class ItemContext : uint8;
namespace UF
{
@@ -39,7 +40,7 @@ namespace WorldPackets
{
struct ItemBonusInstanceData
{
- uint8 Context = 0;
+ ItemContext Context = ItemContext(0);
std::vector<int32> BonusListIDs;
bool operator==(ItemBonusInstanceData const& r) const;
diff --git a/src/server/game/Spells/Auras/SpellAuraEffects.cpp b/src/server/game/Spells/Auras/SpellAuraEffects.cpp
index 05e36fed435..acb6f0421c7 100644
--- a/src/server/game/Spells/Auras/SpellAuraEffects.cpp
+++ b/src/server/game/Spells/Auras/SpellAuraEffects.cpp
@@ -5225,7 +5225,7 @@ void AuraEffect::HandlePeriodicTriggerSpellAuraTick(Unit* target, Unit* caster)
if (!creature->GetCreatureTemplate()->SkinLootId)
return;
- player->AutoStoreLoot(creature->GetCreatureTemplate()->SkinLootId, LootTemplates_Skinning, true);
+ player->AutoStoreLoot(creature->GetCreatureTemplate()->SkinLootId, LootTemplates_Skinning, ItemContext::NONE, true);
creature->DespawnOrUnsummon();
}
diff --git a/src/server/game/Spells/Spell.h b/src/server/game/Spells/Spell.h
index 5e142928e28..2ca0994b736 100644
--- a/src/server/game/Spells/Spell.h
+++ b/src/server/game/Spells/Spell.h
@@ -564,7 +564,7 @@ class TC_GAME_API Spell
uint32 getState() const { return m_spellState; }
void setState(uint32 state) { m_spellState = state; }
- void DoCreateItem(uint32 i, uint32 itemtype, uint8 context = 0, std::vector<int32> const& bonusListIDs = std::vector<int32>());
+ void DoCreateItem(uint32 i, uint32 itemtype, ItemContext context = ItemContext::NONE, std::vector<int32> const& bonusListIDs = std::vector<int32>());
bool CheckEffectTarget(Unit const* target, SpellEffectInfo const* effect, Position const* losPosition) const;
bool CheckEffectTarget(GameObject const* target, SpellEffectInfo const* effect) const;
diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp
index 4d372838890..c68280212ab 100644
--- a/src/server/game/Spells/SpellEffects.cpp
+++ b/src/server/game/Spells/SpellEffects.cpp
@@ -1325,7 +1325,7 @@ void Spell::EffectHealthLeech(SpellEffIndex /*effIndex*/)
}
}
-void Spell::DoCreateItem(uint32 /*i*/, uint32 itemtype, uint8 context /*= 0*/, std::vector<int32> const& bonusListIDs /*= std::vector<int32>()*/)
+void Spell::DoCreateItem(uint32 /*i*/, uint32 itemtype, ItemContext context /*= ItemContext::NONE*/, std::vector<int32> const& bonusListIDs /*= std::vector<int32>()*/)
{
if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
return;
@@ -1433,7 +1433,7 @@ void Spell::EffectCreateItem(SpellEffIndex effIndex)
if (effectHandleMode != SPELL_EFFECT_HANDLE_HIT_TARGET)
return;
- DoCreateItem(effIndex, effectInfo->ItemType);
+ DoCreateItem(effIndex, effectInfo->ItemType, m_spellInfo->HasAttribute(SPELL_ATTR0_TRADESPELL) ? ItemContext::Trade_Skill : ItemContext::NONE);
ExecuteLogEffectCreateItem(effIndex, effectInfo->ItemType);
}
@@ -1448,9 +1448,10 @@ void Spell::EffectCreateItem2(SpellEffIndex effIndex)
Player* player = unitTarget->ToPlayer();
uint32 item_id = effectInfo->ItemType;
+ ItemContext context = m_spellInfo->HasAttribute(SPELL_ATTR0_TRADESPELL) ? ItemContext::Trade_Skill : ItemContext::NONE;
if (item_id)
- DoCreateItem(effIndex, item_id);
+ DoCreateItem(effIndex, item_id, context);
// special case: fake item replaced by generate using spell_loot_template
if (m_spellInfo->IsLootCrafting())
@@ -1465,10 +1466,10 @@ void Spell::EffectCreateItem2(SpellEffIndex effIndex)
player->DestroyItemCount(item_id, count, true);
// create some random items
- player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell);
+ player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell, context);
}
else
- player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell); // create some random items
+ player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell, context); // create some random items
player->UpdateCraftSkill(m_spellInfo->Id);
}
@@ -1485,7 +1486,7 @@ void Spell::EffectCreateRandomItem(SpellEffIndex /*effIndex*/)
Player* player = unitTarget->ToPlayer();
// create some random items
- player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell);
+ player->AutoStoreLoot(m_spellInfo->Id, LootTemplates_Spell, m_spellInfo->HasAttribute(SPELL_ATTR0_TRADESPELL) ? ItemContext::Trade_Skill : ItemContext::NONE);
/// @todo ExecuteLogEffectCreateItem(i, m_spellInfo->Effects[i].ItemType);
}
@@ -1788,7 +1789,7 @@ void Spell::EffectSummonChangeItem(SpellEffIndex /*effIndex*/)
uint16 pos = m_CastItem->GetPos();
- Item* pNewItem = Item::CreateItem(newitemid, 1, player);
+ Item* pNewItem = Item::CreateItem(newitemid, 1, m_CastItem->GetContext(), player);
if (!pNewItem)
return;
@@ -2381,7 +2382,7 @@ void Spell::EffectEnchantItemPerm(SpellEffIndex effIndex)
player->DestroyItemCount(itemTarget, count, true);
unitTarget = player;
// and add a scroll
- DoCreateItem(effIndex, effectInfo->ItemType);
+ DoCreateItem(effIndex, effectInfo->ItemType, m_spellInfo->HasAttribute(SPELL_ATTR0_TRADESPELL) ? ItemContext::Trade_Skill : ItemContext::NONE);
itemTarget = NULL;
m_targets.SetItemTarget(NULL);
}
@@ -5596,7 +5597,7 @@ void Spell::EffectCreateHeirloomItem(SpellEffIndex effIndex)
std::vector<int32> bonusList;
bonusList.push_back(collectionMgr->GetHeirloomBonus(m_misc.Raw.Data[0]));
- DoCreateItem(effIndex, m_misc.Raw.Data[0], 0, bonusList);
+ DoCreateItem(effIndex, m_misc.Raw.Data[0], ItemContext::NONE, bonusList);
ExecuteLogEffectCreateItem(effIndex, m_misc.Raw.Data[0]);
}
diff --git a/src/server/game/Spells/SpellScript.cpp b/src/server/game/Spells/SpellScript.cpp
index b1a0fc5ec09..b9b8151c597 100644
--- a/src/server/game/Spells/SpellScript.cpp
+++ b/src/server/game/Spells/SpellScript.cpp
@@ -658,9 +658,9 @@ Item* SpellScript::GetCastItem() const
return m_spell->m_CastItem;
}
-void SpellScript::CreateItem(uint32 effIndex, uint32 itemId)
+void SpellScript::CreateItem(uint32 effIndex, uint32 itemId, ItemContext context)
{
- m_spell->DoCreateItem(effIndex, itemId);
+ m_spell->DoCreateItem(effIndex, itemId, context);
}
SpellInfo const* SpellScript::GetTriggeringSpell() const
diff --git a/src/server/game/Spells/SpellScript.h b/src/server/game/Spells/SpellScript.h
index b9318dfcdbd..5c3de1da269 100644
--- a/src/server/game/Spells/SpellScript.h
+++ b/src/server/game/Spells/SpellScript.h
@@ -473,7 +473,7 @@ class TC_GAME_API SpellScript : public _SpellScript
Item* GetCastItem() const;
// Creates item. Calls Spell::DoCreateItem method.
- void CreateItem(uint32 effIndex, uint32 itemId);
+ void CreateItem(uint32 effIndex, uint32 itemId, ItemContext context);
// Returns SpellInfo from the spell that triggered the current one
SpellInfo const* GetTriggeringSpell() const;
diff --git a/src/server/scripts/Commands/cs_misc.cpp b/src/server/scripts/Commands/cs_misc.cpp
index f5c18af74dd..6a7e60c1906 100644
--- a/src/server/scripts/Commands/cs_misc.cpp
+++ b/src/server/scripts/Commands/cs_misc.cpp
@@ -1356,7 +1356,7 @@ public:
return false;
}
- Item* item = playerTarget->StoreNewItem(dest, itemId, true, GenerateItemRandomBonusListId(itemId), GuidSet(), 0, bonusListIDs);
+ Item* item = playerTarget->StoreNewItem(dest, itemId, true, GenerateItemRandomBonusListId(itemId), GuidSet(), ItemContext::NONE, bonusListIDs);
// remove binding (let GM give it to another player later)
if (player == playerTarget)
@@ -1425,7 +1425,7 @@ public:
InventoryResult msg = playerTarget->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, itr->second.GetId(), 1);
if (msg == EQUIP_ERR_OK)
{
- Item* item = playerTarget->StoreNewItem(dest, itr->second.GetId(), true, {}, GuidSet(), 0, bonusListIDs);
+ Item* item = playerTarget->StoreNewItem(dest, itr->second.GetId(), true, {}, GuidSet(), ItemContext::NONE, bonusListIDs);
// remove binding (let GM give it to another player later)
if (player == playerTarget)
diff --git a/src/server/scripts/Commands/cs_send.cpp b/src/server/scripts/Commands/cs_send.cpp
index 3f490186e35..b1aad586c8c 100644
--- a/src/server/scripts/Commands/cs_send.cpp
+++ b/src/server/scripts/Commands/cs_send.cpp
@@ -188,7 +188,7 @@ public:
for (ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
{
- if (Item* item = Item::CreateItem(itr->first, itr->second, handler->GetSession() ? handler->GetSession()->GetPlayer() : 0))
+ if (Item* item = Item::CreateItem(itr->first, itr->second, ItemContext::NONE, handler->GetSession() ? handler->GetSession()->GetPlayer() : 0))
{
item->SaveToDB(trans); // Save to prevent being lost at next mail load. If send fails, the item will be deleted.
draft.AddItem(item);
diff --git a/src/server/scripts/Spells/spell_generic.cpp b/src/server/scripts/Spells/spell_generic.cpp
index 2747f9aeb39..e1ce7af3a81 100644
--- a/src/server/scripts/Spells/spell_generic.cpp
+++ b/src/server/scripts/Spells/spell_generic.cpp
@@ -3394,7 +3394,7 @@ class spell_gen_upper_deck_create_foam_sword : public SpellScriptLoader
return;
}
- CreateItem(effIndex, itemId[urand(0, 4)]);
+ CreateItem(effIndex, itemId[urand(0, 4)], ItemContext::NONE);
}
}
diff --git a/src/server/scripts/Spells/spell_item.cpp b/src/server/scripts/Spells/spell_item.cpp
index d54a0411009..d1c611dcd6e 100644
--- a/src/server/scripts/Spells/spell_item.cpp
+++ b/src/server/scripts/Spells/spell_item.cpp
@@ -1366,7 +1366,7 @@ class spell_item_mingos_fortune_generator : public SpellScriptLoader
return;
}
- CreateItem(effIndex, newitemid);
+ CreateItem(effIndex, newitemid, ItemContext::NONE);
}
void Register() override