aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Loot
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2024-09-24 14:40:23 +0200
committerShauren <shauren.trinity@gmail.com>2024-09-24 14:40:23 +0200
commit3238175a62750ea5127feb69ce86d0c3c05dfc52 (patch)
tree0236bf8ffdd36edbf836cc7596bb64f49eda7b1b /src/server/game/Loot
parentd3985a046020e21c8aef5b0a930c517e686bf701 (diff)
Core/Items: Implemented ITEM_BONUS_DISENCHANT_LOOT_ID
Diffstat (limited to 'src/server/game/Loot')
-rw-r--r--src/server/game/Loot/Loot.cpp45
-rw-r--r--src/server/game/Loot/Loot.h3
-rw-r--r--src/server/game/Loot/LootMgr.cpp12
3 files changed, 52 insertions, 8 deletions
diff --git a/src/server/game/Loot/Loot.cpp b/src/server/game/Loot/Loot.cpp
index 6314e9d9f01..663acfb3b9c 100644
--- a/src/server/game/Loot/Loot.cpp
+++ b/src/server/game/Loot/Loot.cpp
@@ -482,7 +482,7 @@ bool LootRoll::TryToStart(Map* map, Loot& loot, uint32 lootListId, uint16 enchan
m_voteMask = ROLL_ALL_TYPE_MASK;
if (itemTemplate->HasFlag(ITEM_FLAG2_CAN_ONLY_ROLL_GREED))
m_voteMask = RollMask(m_voteMask & ~ROLL_FLAG_TYPE_NEED);
- if (ItemDisenchantLootEntry const* disenchant = GetItemDisenchantLoot(); !disenchant || disenchant->SkillRequired > enchantingSkill)
+ if (Optional<uint16> disenchantSkillRequired = GetItemDisenchantSkillRequired(); !disenchantSkillRequired || disenchantSkillRequired > enchantingSkill)
m_voteMask = RollMask(m_voteMask & ~ROLL_FLAG_TYPE_DISENCHANT);
if (playerCount > 1) // check if more than one player can loot this item
@@ -606,7 +606,7 @@ bool LootRoll::AllPlayerVoted(RollVoteMap::const_iterator& winnerItr)
return notVoted == 0;
}
-ItemDisenchantLootEntry const* LootRoll::GetItemDisenchantLoot() const
+Optional<uint32> LootRoll::GetItemDisenchantLootId() const
{
WorldPackets::Item::ItemInstance itemInstance;
itemInstance.Initialize(*m_lootItem);
@@ -614,11 +614,43 @@ ItemDisenchantLootEntry const* LootRoll::GetItemDisenchantLoot() const
BonusData bonusData;
bonusData.Initialize(itemInstance);
if (!bonusData.CanDisenchant)
- return nullptr;
+ return {};
+
+ if (bonusData.DisenchantLootId)
+ return bonusData.DisenchantLootId;
ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(m_lootItem->itemid);
- uint32 itemLevel = Item::GetItemLevel(itemTemplate, bonusData, 1, 0, 0, 0, 0, false, 0);
- return Item::GetDisenchantLoot(itemTemplate, bonusData.Quality, itemLevel);
+
+ // ignore temporary item level scaling (pvp or timewalking)
+ uint32 itemLevel = Item::GetItemLevel(itemTemplate, bonusData, bonusData.RequiredLevel, 0, 0, 0, 0, false, 0);
+
+ ItemDisenchantLootEntry const* disenchantLoot = Item::GetBaseDisenchantLoot(itemTemplate, bonusData.Quality, itemLevel);
+ if (!disenchantLoot)
+ return {};
+
+ return disenchantLoot->ID;
+}
+
+Optional<uint16> LootRoll::GetItemDisenchantSkillRequired() const
+{
+ WorldPackets::Item::ItemInstance itemInstance;
+ itemInstance.Initialize(*m_lootItem);
+
+ BonusData bonusData;
+ bonusData.Initialize(itemInstance);
+ if (!bonusData.CanDisenchant)
+ return {};
+
+ ItemTemplate const* itemTemplate = sObjectMgr->GetItemTemplate(m_lootItem->itemid);
+
+ // ignore temporary item level scaling (pvp or timewalking)
+ uint32 itemLevel = Item::GetItemLevel(itemTemplate, bonusData, bonusData.RequiredLevel, 0, 0, 0, 0, false, 0);
+
+ ItemDisenchantLootEntry const* disenchantLoot = Item::GetBaseDisenchantLoot(itemTemplate, bonusData.Quality, itemLevel);
+ if (!disenchantLoot)
+ return {};
+
+ return disenchantLoot->SkillRequired;
}
// terminate the roll
@@ -646,9 +678,8 @@ void LootRoll::Finish(RollVoteMap::const_iterator winnerItr)
if (winnerItr->second.Vote == RollVote::Disenchant)
{
- ItemDisenchantLootEntry const* disenchant = ASSERT_NOTNULL(GetItemDisenchantLoot());
Loot loot(m_map, m_loot->GetOwnerGUID(), LOOT_DISENCHANTING, nullptr);
- loot.FillLoot(disenchant->ID, LootTemplates_Disenchant, player, true, false, LOOT_MODE_DEFAULT, ItemContext::NONE);
+ loot.FillLoot(*GetItemDisenchantLootId(), LootTemplates_Disenchant, player, true, false, LOOT_MODE_DEFAULT, ItemContext::NONE);
if (!loot.AutoStore(player, NULL_BAG, NULL_SLOT, true))
{
for (uint32 i = 0; i < loot.items.size(); ++i)
diff --git a/src/server/game/Loot/Loot.h b/src/server/game/Loot/Loot.h
index 3b5cbca7fb5..f29975ebeee 100644
--- a/src/server/game/Loot/Loot.h
+++ b/src/server/game/Loot/Loot.h
@@ -270,7 +270,8 @@ private:
void FillPacket(WorldPackets::Loot::LootItemData& lootItem) const;
void Finish(RollVoteMap::const_iterator winnerItr);
bool AllPlayerVoted(RollVoteMap::const_iterator& winnerItr);
- ItemDisenchantLootEntry const* GetItemDisenchantLoot() const;
+ Optional<uint32> GetItemDisenchantLootId() const;
+ Optional<uint16> GetItemDisenchantSkillRequired() const;
Map* m_map;
RollVoteMap m_rollVoteMap;
bool m_isStarted;
diff --git a/src/server/game/Loot/LootMgr.cpp b/src/server/game/Loot/LootMgr.cpp
index 2104cc0c5ab..dc17eeaa479 100644
--- a/src/server/game/Loot/LootMgr.cpp
+++ b/src/server/game/Loot/LootMgr.cpp
@@ -1078,6 +1078,18 @@ void LoadLootTemplates_Disenchant()
lootIdSetUsed.insert(lootid);
}
+ for (ItemBonusEntry const* itemBonus : sItemBonusStore)
+ {
+ if (itemBonus->Type != ITEM_BONUS_DISENCHANT_LOOT_ID)
+ continue;
+
+ uint32 lootid = itemBonus->Value[0];
+ if (!lootIdSet.contains(lootid))
+ LootTemplates_Disenchant.ReportNonExistingId(lootid);
+ else
+ lootIdSetUsed.insert(lootid);
+ }
+
for (uint32 lootId : lootIdSetUsed)
lootIdSet.erase(lootId);