Core/Items: Add location filters to Player::GetItemByEntry

This commit is contained in:
Shauren
2019-11-29 00:10:29 +01:00
parent 235ec18143
commit 96575e33bb
9 changed files with 79 additions and 37 deletions

View File

@@ -44,7 +44,7 @@ uint32 DB2Meta::GetRecordSize() const
{
for (uint8 j = 0; j < Fields[i].ArraySize; ++j)
{
if (i >= FileFieldCount && i == ParentIndexField)
if (i >= FileFieldCount && int32(i) == ParentIndexField)
{
size += 4;
continue;

View File

@@ -2610,7 +2610,7 @@ bool CriteriaHandler::ModifierSatisfied(ModifierTreeEntry const* modifier, uint6
}
case CRITERIA_ADDITIONAL_CONDITION_AZERITE_ITEM_LEVEL: // 235
{
Item const* heartOfAzeroth = referencePlayer->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH);
Item const* heartOfAzeroth = referencePlayer->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH, ITEM_SEARCH_EVERYWHERE);
if (!heartOfAzeroth || heartOfAzeroth->ToAzeriteItem()->GetLevel() < reqValue)
return false;
break;
@@ -2659,7 +2659,7 @@ bool CriteriaHandler::ModifierSatisfied(ModifierTreeEntry const* modifier, uint6
break;
case CRITERIA_ADDITIONAL_CONDITION_UNLOCKED_AZERITE_ESSENCE_RANK_LOWER: // 259
{
if (Item const* heartOfAzeroth = referencePlayer->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH))
if (Item const* heartOfAzeroth = referencePlayer->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH, ITEM_SEARCH_EVERYWHERE))
if (AzeriteItem const* azeriteItem = heartOfAzeroth->ToAzeriteItem())
for (UF::UnlockedAzeriteEssence const& essence : azeriteItem->m_azeriteItemData->UnlockedEssences)
if (essence.AzeriteEssenceID == reqValue && essence.Rank < secondaryAsset)
@@ -2668,7 +2668,7 @@ bool CriteriaHandler::ModifierSatisfied(ModifierTreeEntry const* modifier, uint6
}
case CRITERIA_ADDITIONAL_CONDITION_UNLOCKED_AZERITE_ESSENCE_RANK_EQUAL: // 260
{
if (Item const* heartOfAzeroth = referencePlayer->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH))
if (Item const* heartOfAzeroth = referencePlayer->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH, ITEM_SEARCH_EVERYWHERE))
if (AzeriteItem const* azeriteItem = heartOfAzeroth->ToAzeriteItem())
for (UF::UnlockedAzeriteEssence const& essence : azeriteItem->m_azeriteItemData->UnlockedEssences)
if (essence.AzeriteEssenceID == reqValue && essence.Rank == secondaryAsset)
@@ -2677,7 +2677,7 @@ bool CriteriaHandler::ModifierSatisfied(ModifierTreeEntry const* modifier, uint6
}
case CRITERIA_ADDITIONAL_CONDITION_UNLOCKED_AZERITE_ESSENCE_RANK_GREATER: // 261
{
if (Item const* heartOfAzeroth = referencePlayer->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH))
if (Item const* heartOfAzeroth = referencePlayer->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH, ITEM_SEARCH_EVERYWHERE))
if (AzeriteItem const* azeriteItem = heartOfAzeroth->ToAzeriteItem())
for (UF::UnlockedAzeriteEssence const& essence : azeriteItem->m_azeriteItemData->UnlockedEssences)
if (essence.AzeriteEssenceID == reqValue && essence.Rank > secondaryAsset)
@@ -2700,7 +2700,7 @@ bool CriteriaHandler::ModifierSatisfied(ModifierTreeEntry const* modifier, uint6
return false;
break;
case CRITERIA_ADDITIONAL_CONDITION_SELECTED_AZERITE_ESSENCE_RANK_LOWER: // 266
if (Item const* heartOfAzeroth = referencePlayer->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH))
if (Item const* heartOfAzeroth = referencePlayer->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH, ITEM_SEARCH_EVERYWHERE))
if (AzeriteItem const* azeriteItem = heartOfAzeroth->ToAzeriteItem())
if (UF::SelectedAzeriteEssences const* selectedEssences = azeriteItem->GetSelectedAzeriteEssences())
for (UF::UnlockedAzeriteEssence const& essence : azeriteItem->m_azeriteItemData->UnlockedEssences)
@@ -2708,7 +2708,7 @@ bool CriteriaHandler::ModifierSatisfied(ModifierTreeEntry const* modifier, uint6
return true;
return false;
case CRITERIA_ADDITIONAL_CONDITION_SELECTED_AZERITE_ESSENCE_RANK_GREATER: // 267
if (Item const* heartOfAzeroth = referencePlayer->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH))
if (Item const* heartOfAzeroth = referencePlayer->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH, ITEM_SEARCH_EVERYWHERE))
if (AzeriteItem const* azeriteItem = heartOfAzeroth->ToAzeriteItem())
if (UF::SelectedAzeriteEssences const* selectedEssences = azeriteItem->GetSelectedAzeriteEssences())
for (UF::UnlockedAzeriteEssence const& essence : azeriteItem->m_azeriteItemData->UnlockedEssences)

View File

@@ -2006,7 +2006,7 @@ void GameObject::Use(Unit* user)
}
case 2: // Heart Forge
{
Item const* item = player->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH);
Item const* item = player->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH, ITEM_SEARCH_EVERYWHERE);
if (!item)
return;

View File

@@ -6780,7 +6780,7 @@ void Player::ModifyCurrency(uint32 id, int32 count, bool printLog/* = true*/, bo
if (id == CURRENCY_TYPE_AZERITE)
{
if (count > 0)
if (Item* heartOfAzeroth = GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH))
if (Item* heartOfAzeroth = GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH, ITEM_SEARCH_EVERYWHERE))
heartOfAzeroth->ToAzeriteItem()->GiveXP(uint64(count));
return;
}
@@ -12910,31 +12910,61 @@ void Player::DestroyConjuredItems(bool update)
DestroyItem(INVENTORY_SLOT_BAG_0, i, update);
}
Item* Player::GetItemByEntry(uint32 entry) const
Item* Player::GetItemByEntry(uint32 entry, ItemSearchLocation where /*= ITEM_SEARCH_DEFAULT*/) const
{
// in inventory
uint8 inventoryEnd = INVENTORY_SLOT_ITEM_START + GetInventorySlotCount();
for (uint8 i = INVENTORY_SLOT_ITEM_START; i < inventoryEnd; ++i)
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
if (pItem->GetEntry() == entry)
return pItem;
if (where & ITEM_SEARCH_IN_EQUIPMENT)
{
for (uint8 i = EQUIPMENT_SLOT_START; i < INVENTORY_SLOT_BAG_END; ++i)
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
if (pItem->GetEntry() == entry)
return pItem;
for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; ++i)
if (Bag* pBag = GetBagByPos(i))
for (uint32 j = 0; j < pBag->GetBagSize(); ++j)
if (Item* pItem = pBag->GetItemByPos(j))
if (pItem->GetEntry() == entry)
return pItem;
}
for (uint8 i = EQUIPMENT_SLOT_START; i < INVENTORY_SLOT_BAG_END; ++i)
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
if (pItem->GetEntry() == entry)
return pItem;
if (where & ITEM_SEARCH_IN_INVENTORY)
{
// in inventory
uint8 inventoryEnd = INVENTORY_SLOT_ITEM_START + GetInventorySlotCount();
for (uint8 i = INVENTORY_SLOT_ITEM_START; i < inventoryEnd; ++i)
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
if (pItem->GetEntry() == entry)
return pItem;
for (uint8 i = CHILD_EQUIPMENT_SLOT_START; i < CHILD_EQUIPMENT_SLOT_END; ++i)
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
if (pItem->GetEntry() == entry)
return pItem;
for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; ++i)
if (Bag* pBag = GetBagByPos(i))
for (uint32 j = 0; j < pBag->GetBagSize(); ++j)
if (Item* pItem = pBag->GetItemByPos(j))
if (pItem->GetEntry() == entry)
return pItem;
for (uint8 i = CHILD_EQUIPMENT_SLOT_START; i < CHILD_EQUIPMENT_SLOT_END; ++i)
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
if (pItem->GetEntry() == entry)
return pItem;
}
if (where & ITEM_SEARCH_IN_BANK)
{
for (uint8 i = BANK_SLOT_ITEM_START; i < BANK_SLOT_ITEM_END; ++i)
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
if (pItem->GetEntry() == entry)
return pItem;
for (uint8 i = BANK_SLOT_BAG_START; i < BANK_SLOT_BAG_END; ++i)
if (Bag* pBag = GetBagByPos(i))
for (uint32 j = 0; j < pBag->GetBagSize(); ++j)
if (Item* pItem = pBag->GetItemByPos(j))
if (pItem->GetEntry() == entry)
return pItem;
}
if (where & ITEM_SEARCH_IN_REAGENT_BANK)
{
for (uint8 i = REAGENT_SLOT_START; i < REAGENT_SLOT_END; ++i)
if (Item* pItem = GetItemByPos(INVENTORY_SLOT_BAG_0, i))
if (pItem->GetEntry() == entry)
return pItem;
}
return nullptr;
}
@@ -27180,7 +27210,7 @@ void Player::ActivateTalentGroup(ChrSpecializationEntry const* spec)
activeGlyphs.IsFullUpdate = true;
SendDirectMessage(activeGlyphs.Write());
if (Item* item = GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH))
if (Item* item = GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH, ITEM_SEARCH_EVERYWHERE))
{
if (AzeriteItem* azeriteItem = item->ToAzeriteItem())
{

View File

@@ -650,6 +650,17 @@ struct ItemPosCount
};
typedef std::vector<ItemPosCount> ItemPosCountVec;
enum ItemSearchLocation
{
ITEM_SEARCH_IN_EQUIPMENT = 0x01,
ITEM_SEARCH_IN_INVENTORY = 0x02,
ITEM_SEARCH_IN_BANK = 0x04,
ITEM_SEARCH_IN_REAGENT_BANK = 0x08,
ITEM_SEARCH_DEFAULT = ITEM_SEARCH_IN_EQUIPMENT | ITEM_SEARCH_IN_INVENTORY,
ITEM_SEARCH_EVERYWHERE = ITEM_SEARCH_IN_EQUIPMENT | ITEM_SEARCH_IN_INVENTORY | ITEM_SEARCH_IN_BANK | ITEM_SEARCH_IN_REAGENT_BANK
};
enum TransferAbortReason
{
TRANSFER_ABORT_NONE = 0,
@@ -1107,7 +1118,7 @@ class TC_GAME_API Player : public Unit, public GridObject<Player>
uint32 GetItemCount(uint32 item, bool inBankAlso = false, Item* skipItem = nullptr) const;
uint32 GetItemCountWithLimitCategory(uint32 limitCategory, Item* skipItem = nullptr) const;
Item* GetItemByGuid(ObjectGuid guid) const;
Item* GetItemByEntry(uint32 entry) const;
Item* GetItemByEntry(uint32 entry, ItemSearchLocation where = ITEM_SEARCH_DEFAULT) const;
std::vector<Item*> GetItemListByEntry(uint32 entry, bool inBankAlso = false) const;
Item* GetItemByPos(uint16 pos) const;
Item* GetItemByPos(uint8 bag, uint8 slot) const;

View File

@@ -27,7 +27,7 @@ void WorldSession::HandleAzeriteEssenceUnlockMilestone(WorldPackets::Azerite::Az
if (!AzeriteItem::FindHeartForge(_player))
return;
Item* item = _player->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH);
Item* item = _player->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH, ITEM_SEARCH_EVERYWHERE);
if (!item)
return;
@@ -58,8 +58,8 @@ void WorldSession::HandleAzeriteEssenceActivateEssence(WorldPackets::Azerite::Az
{
WorldPackets::Azerite::AzeriteEssenceSelectionResult activateEssenceResult;
activateEssenceResult.AzeriteEssenceID = azeriteEssenceActivateEssence.AzeriteEssenceID;
Item* item = _player->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH);
if (!item || !item->IsEquipped())
Item* item = _player->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH, ITEM_SEARCH_IN_EQUIPMENT);
if (!item)
{
activateEssenceResult.Reason = AzeriteEssenceActivateResult::NotEquipped;
activateEssenceResult.Slot = azeriteEssenceActivateEssence.Slot;

View File

@@ -66,7 +66,7 @@ void WorldSession::HandleInspectOpcode(WorldPackets::Inspect::Inspect& inspect)
inspectResult.GuildData->AchievementPoints = guild->GetAchievementMgr().GetAchievementPoints();
}
if (Item const* heartOfAzeroth = player->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH))
if (Item const* heartOfAzeroth = player->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH, ITEM_SEARCH_EVERYWHERE))
if (AzeriteItem const* azeriteItem = heartOfAzeroth->ToAzeriteItem())
inspectResult.AzeriteLevel = azeriteItem->GetEffectiveLevel();

View File

@@ -5830,7 +5830,7 @@ void Spell::EffectLearnAzeriteEssencePower(SpellEffIndex /*effIndex*/)
if (!playerTarget)
return;
Item* heartOfAzeroth = playerTarget->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH);
Item* heartOfAzeroth = playerTarget->GetItemByEntry(ITEM_ID_HEART_OF_AZEROTH, ITEM_SEARCH_EVERYWHERE);
if (!heartOfAzeroth)
return;

View File

@@ -47,6 +47,7 @@ class WorldObject;
struct SpellDestination;
struct SpellModifier;
struct SpellValue;
enum class ItemContext : uint8;
#define SPELL_EFFECT_ANY (uint16)-1
#define SPELL_AURA_ANY (uint16)-1