diff --git a/common/inventory_profile.cpp b/common/inventory_profile.cpp index 603f4111b..fa5606f13 100644 --- a/common/inventory_profile.cpp +++ b/common/inventory_profile.cpp @@ -28,6 +28,7 @@ #include "strings.h" #include "../common/light_source.h" +#include "data_verification.h" //#include @@ -44,6 +45,7 @@ ItemInstQueue::~ItemInstQueue() for (auto iter = m_list.begin(); iter != m_list.end(); ++iter) { safe_delete(*iter); } + m_list.clear(); } @@ -62,8 +64,9 @@ void ItemInstQueue::push_front(EQ::ItemInstance* inst) // Remove item from front of queue EQ::ItemInstance* ItemInstQueue::pop() { - if (m_list.empty()) + if (m_list.empty()) { return nullptr; + } EQ::ItemInstance* inst = m_list.front(); m_list.pop_front(); @@ -73,8 +76,9 @@ EQ::ItemInstance* ItemInstQueue::pop() // Remove item from back of queue EQ::ItemInstance* ItemInstQueue::pop_back() { - if (m_list.empty()) + if (m_list.empty()) { return nullptr; + } EQ::ItemInstance* inst = m_list.back(); m_list.pop_back(); @@ -87,7 +91,6 @@ EQ::ItemInstance* ItemInstQueue::peek_front() const return (m_list.empty()) ? nullptr : m_list.front(); } - // // class EQ::InventoryProfile // @@ -96,26 +99,31 @@ EQ::InventoryProfile::~InventoryProfile() for (auto iter = m_worn.begin(); iter != m_worn.end(); ++iter) { safe_delete(iter->second); } + m_worn.clear(); for (auto iter = m_inv.begin(); iter != m_inv.end(); ++iter) { safe_delete(iter->second); } + m_inv.clear(); for (auto iter = m_bank.begin(); iter != m_bank.end(); ++iter) { safe_delete(iter->second); } + m_bank.clear(); for (auto iter = m_shbank.begin(); iter != m_shbank.end(); ++iter) { safe_delete(iter->second); } + m_shbank.clear(); for (auto iter = m_trade.begin(); iter != m_trade.end(); ++iter) { safe_delete(iter->second); } + m_trade.clear(); } @@ -136,6 +144,7 @@ void EQ::InventoryProfile::CleanDirty() { delete (*iter); ++iter; } + dirty_inst.clear(); } @@ -157,59 +166,44 @@ EQ::ItemInstance* EQ::InventoryProfile::GetItem(int16 slot_id) const } // Non bag slots - else if (slot_id >= invslot::TRADE_BEGIN && slot_id <= invslot::TRADE_END) { + if (EQ::ValueWithin(slot_id, invslot::TRADE_BEGIN, invslot::TRADE_END)) { result = _GetItem(m_trade, slot_id); - } - else if (slot_id >= invslot::SHARED_BANK_BEGIN && slot_id <= invslot::SHARED_BANK_END) { - // Shared Bank slots + } else if (EQ::ValueWithin(slot_id, invslot::SHARED_BANK_BEGIN, invslot::SHARED_BANK_END)) { result = _GetItem(m_shbank, slot_id); - } - else if (slot_id >= invslot::BANK_BEGIN && slot_id <= invslot::BANK_END) { - // Bank slots + } else if (EQ::ValueWithin(slot_id, invslot::BANK_BEGIN, invslot::BANK_END)) { result = _GetItem(m_bank, slot_id); - } - else if ((slot_id >= invslot::GENERAL_BEGIN && slot_id <= invslot::GENERAL_END)) { - // Personal inventory slots + } else if (EQ::ValueWithin(slot_id, invslot::GENERAL_BEGIN, invslot::GENERAL_END)) { result = _GetItem(m_inv, slot_id); - } - else if ((slot_id >= invslot::EQUIPMENT_BEGIN && slot_id <= invslot::EQUIPMENT_END) || - (slot_id >= invslot::TRIBUTE_BEGIN && slot_id <= invslot::TRIBUTE_END) || - (slot_id >= invslot::GUILD_TRIBUTE_BEGIN && slot_id <= invslot::GUILD_TRIBUTE_END)) { - // Equippable slots (on body) + } else if ( + EQ::ValueWithin(slot_id, invslot::EQUIPMENT_BEGIN, invslot::EQUIPMENT_END) || + EQ::ValueWithin(slot_id, invslot::TRIBUTE_BEGIN, invslot::TRIBUTE_END) || + EQ::ValueWithin(slot_id, invslot::GUILD_TRIBUTE_BEGIN, invslot::GUILD_TRIBUTE_END) + ) { result = _GetItem(m_worn, slot_id); } // Inner bag slots - else if (slot_id >= invbag::TRADE_BAGS_BEGIN && slot_id <= invbag::TRADE_BAGS_END) { - // Trade bag slots + else if (EQ::ValueWithin(slot_id, invbag::TRADE_BAGS_BEGIN, invbag::TRADE_BAGS_END)) { ItemInstance* inst = _GetItem(m_trade, InventoryProfile::CalcSlotId(slot_id)); if (inst && inst->IsClassBag()) { result = inst->GetItem(InventoryProfile::CalcBagIdx(slot_id)); } - } - else if (slot_id >= invbag::SHARED_BANK_BAGS_BEGIN && slot_id <= invbag::SHARED_BANK_BAGS_END) { - // Shared Bank bag slots + } else if (EQ::ValueWithin(slot_id, invbag::SHARED_BANK_BAGS_BEGIN, invbag::SHARED_BANK_BAGS_END)) { ItemInstance* inst = _GetItem(m_shbank, InventoryProfile::CalcSlotId(slot_id)); if (inst && inst->IsClassBag()) { result = inst->GetItem(InventoryProfile::CalcBagIdx(slot_id)); } - } - else if (slot_id >= invbag::BANK_BAGS_BEGIN && slot_id <= invbag::BANK_BAGS_END) { - // Bank bag slots + } else if (EQ::ValueWithin(slot_id, invbag::BANK_BAGS_BEGIN, invbag::BANK_BAGS_END)) { ItemInstance* inst = _GetItem(m_bank, InventoryProfile::CalcSlotId(slot_id)); if (inst && inst->IsClassBag()) { result = inst->GetItem(InventoryProfile::CalcBagIdx(slot_id)); } - } - else if (slot_id >= invbag::CURSOR_BAG_BEGIN && slot_id <= invbag::CURSOR_BAG_END) { - // Cursor bag slots + } else if (EQ::ValueWithin(slot_id, invbag::CURSOR_BAG_BEGIN, invbag::CURSOR_BAG_END)) { ItemInstance* inst = m_cursor.peek_front(); if (inst && inst->IsClassBag()) { result = inst->GetItem(InventoryProfile::CalcBagIdx(slot_id)); } - } - else if (slot_id >= invbag::GENERAL_BAGS_BEGIN && slot_id <= invbag::GENERAL_BAGS_END) { - // Personal inventory bag slots + } else if (EQ::ValueWithin(slot_id, invbag::GENERAL_BAGS_BEGIN, invbag::GENERAL_BAGS_END)) { ItemInstance* inst = _GetItem(m_inv, InventoryProfile::CalcSlotId(slot_id)); if (inst && inst->IsClassBag()) { result = inst->GetItem(InventoryProfile::CalcBagIdx(slot_id)); @@ -228,25 +222,27 @@ EQ::ItemInstance* EQ::InventoryProfile::GetItem(int16 slot_id, uint8 bagidx) con // Put an item into specified slot int16 EQ::InventoryProfile::PutItem(int16 slot_id, const ItemInstance& inst) { - if (slot_id <= EQ::invslot::POSSESSIONS_END && slot_id >= EQ::invslot::POSSESSIONS_BEGIN) { - if ((((uint64)1 << slot_id) & m_lookup->PossessionsBitmask) == 0) + if (EQ::ValueWithin(slot_id, EQ::invslot::POSSESSIONS_BEGIN, EQ::invslot::POSSESSIONS_END)) { + if ((((uint64) 1 << slot_id) & m_lookup->PossessionsBitmask) == 0) { return EQ::invslot::SLOT_INVALID; - } - else if (slot_id <= EQ::invbag::GENERAL_BAGS_END && slot_id >= EQ::invbag::GENERAL_BAGS_BEGIN) { + } + } else if (EQ::ValueWithin(slot_id, EQ::invbag::GENERAL_BAGS_BEGIN, EQ::invbag::GENERAL_BAGS_END)) { auto temp_slot = EQ::invslot::GENERAL_BEGIN + ((slot_id - EQ::invbag::GENERAL_BAGS_BEGIN) / EQ::invbag::SLOT_COUNT); - if ((((uint64)1 << temp_slot) & m_lookup->PossessionsBitmask) == 0) + if ((((uint64) 1 << temp_slot) & m_lookup->PossessionsBitmask) == 0) { return EQ::invslot::SLOT_INVALID; - } - else if (slot_id <= EQ::invslot::BANK_END && slot_id >= EQ::invslot::BANK_BEGIN) { - if ((slot_id - EQ::invslot::BANK_BEGIN) >= m_lookup->InventoryTypeSize.Bank) + } + } else if (EQ::ValueWithin(slot_id, EQ::invslot::BANK_BEGIN, EQ::invslot::BANK_END)) { + if ((slot_id - EQ::invslot::BANK_BEGIN) >= m_lookup->InventoryTypeSize.Bank) { return EQ::invslot::SLOT_INVALID; - } - else if (slot_id <= EQ::invbag::BANK_BAGS_END && slot_id >= EQ::invbag::BANK_BAGS_BEGIN) { + } + } else if (EQ::ValueWithin(slot_id, EQ::invbag::BANK_BAGS_BEGIN, EQ::invbag::BANK_BAGS_END)) { auto temp_slot = (slot_id - EQ::invbag::BANK_BAGS_BEGIN) / EQ::invbag::SLOT_COUNT; - if (temp_slot >= m_lookup->InventoryTypeSize.Bank) + if (temp_slot >= m_lookup->InventoryTypeSize.Bank) { return EQ::invslot::SLOT_INVALID; + } } + // Clean up item already in slot (if exists) DeleteItem(slot_id); @@ -281,26 +277,23 @@ bool EQ::InventoryProfile::SwapItem( ) { fail_state = swapInvalid; - if (source_slot <= EQ::invslot::POSSESSIONS_END && source_slot >= EQ::invslot::POSSESSIONS_BEGIN) { - if ((((uint64) 1 << source_slot) & m_lookup->PossessionsBitmask) == 0) { + if (EQ::ValueWithin(source_slot, EQ::invslot::POSSESSIONS_BEGIN, EQ::invslot::POSSESSIONS_END)) { + if ((((uint64)1 << source_slot) & m_lookup->PossessionsBitmask) == 0) { fail_state = swapNotAllowed; return false; } - } - else if (source_slot <= EQ::invbag::GENERAL_BAGS_END && source_slot >= EQ::invbag::GENERAL_BAGS_BEGIN) { + } else if (EQ::ValueWithin(source_slot, EQ::invbag::GENERAL_BAGS_BEGIN, EQ::invbag::GENERAL_BAGS_END)) { auto temp_slot = EQ::invslot::GENERAL_BEGIN + ((source_slot - EQ::invbag::GENERAL_BAGS_BEGIN) / EQ::invbag::SLOT_COUNT); if ((((uint64)1 << temp_slot) & m_lookup->PossessionsBitmask) == 0) { fail_state = swapNotAllowed; return false; } - } - else if (source_slot <= EQ::invslot::BANK_END && source_slot >= EQ::invslot::BANK_BEGIN) { + } else if (EQ::ValueWithin(source_slot, EQ::invslot::BANK_BEGIN, EQ::invslot::BANK_END)) { if ((source_slot - EQ::invslot::BANK_BEGIN) >= m_lookup->InventoryTypeSize.Bank) { fail_state = swapNotAllowed; return false; } - } - else if (source_slot <= EQ::invbag::BANK_BAGS_END && source_slot >= EQ::invbag::BANK_BAGS_BEGIN) { + } else if (EQ::ValueWithin(source_slot, EQ::invbag::BANK_BAGS_BEGIN, EQ::invbag::BANK_BAGS_END)) { auto temp_slot = (source_slot - EQ::invbag::BANK_BAGS_BEGIN) / EQ::invbag::SLOT_COUNT; if (temp_slot >= m_lookup->InventoryTypeSize.Bank) { fail_state = swapNotAllowed; @@ -308,26 +301,23 @@ bool EQ::InventoryProfile::SwapItem( } } - if (destination_slot <= EQ::invslot::POSSESSIONS_END && destination_slot >= EQ::invslot::POSSESSIONS_BEGIN) { + if (EQ::ValueWithin(destination_slot, EQ::invslot::POSSESSIONS_BEGIN, EQ::invslot::POSSESSIONS_END)) { if ((((uint64)1 << destination_slot) & m_lookup->PossessionsBitmask) == 0) { fail_state = swapNotAllowed; return false; } - } - else if (destination_slot <= EQ::invbag::GENERAL_BAGS_END && destination_slot >= EQ::invbag::GENERAL_BAGS_BEGIN) { + } else if (EQ::ValueWithin(destination_slot, EQ::invbag::GENERAL_BAGS_BEGIN, EQ::invbag::GENERAL_BAGS_END)) { auto temp_slot = EQ::invslot::GENERAL_BEGIN + ((destination_slot - EQ::invbag::GENERAL_BAGS_BEGIN) / EQ::invbag::SLOT_COUNT); if ((((uint64)1 << temp_slot) & m_lookup->PossessionsBitmask) == 0) { fail_state = swapNotAllowed; return false; } - } - else if (destination_slot <= EQ::invslot::BANK_END && destination_slot >= EQ::invslot::BANK_BEGIN) { + } else if (EQ::ValueWithin(destination_slot, EQ::invslot::BANK_BEGIN, EQ::invslot::BANK_END)) { if ((destination_slot - EQ::invslot::BANK_BEGIN) >= m_lookup->InventoryTypeSize.Bank) { fail_state = swapNotAllowed; return false; } - } - else if (destination_slot <= EQ::invbag::BANK_BAGS_END && destination_slot >= EQ::invbag::BANK_BAGS_BEGIN) { + } else if (EQ::ValueWithin(destination_slot, EQ::invbag::BANK_BAGS_BEGIN, EQ::invbag::BANK_BAGS_END)) { auto temp_slot = (destination_slot - EQ::invbag::BANK_BAGS_BEGIN) / EQ::invbag::SLOT_COUNT; if (temp_slot >= m_lookup->InventoryTypeSize.Bank) { fail_state = swapNotAllowed; @@ -335,6 +325,7 @@ bool EQ::InventoryProfile::SwapItem( } } + // Temp holding areas for source and destination ItemInstance *source_item_instance = GetItem(source_slot); ItemInstance *destination_item_instance = GetItem(destination_slot); @@ -346,20 +337,23 @@ bool EQ::InventoryProfile::SwapItem( } source_item_instance->SetEvolveEquipped(false); - if ((destination_slot >= invslot::EQUIPMENT_BEGIN && destination_slot <= invslot::EQUIPMENT_END)) { + if (EQ::ValueWithin(destination_slot, invslot::EQUIPMENT_BEGIN, invslot::EQUIPMENT_END)) { auto source_item = source_item_instance->GetItem(); if (!source_item) { fail_state = swapNullData; return false; } + if (race_id && class_id && !source_item->IsEquipable(race_id, class_id)) { fail_state = swapRaceClass; return false; } + if (deity_id && source_item->Deity && !(Deity::GetBitmask(deity_id) & source_item->Deity)) { fail_state = swapDeity; return false; } + if (level && source_item->ReqLevel && level < source_item->ReqLevel) { fail_state = swapLevel; return false; @@ -377,20 +371,23 @@ bool EQ::InventoryProfile::SwapItem( } destination_item_instance->SetEvolveEquipped(false); - if ((source_slot >= invslot::EQUIPMENT_BEGIN && source_slot <= invslot::EQUIPMENT_END)) { + if (EQ::ValueWithin(source_slot, invslot::EQUIPMENT_BEGIN, invslot::EQUIPMENT_END)) { auto destination_item = destination_item_instance->GetItem(); if (!destination_item) { fail_state = swapNullData; return false; } + if (race_id && class_id && !destination_item->IsEquipable(race_id, class_id)) { fail_state = swapRaceClass; return false; } + if (deity_id && destination_item->Deity && !(Deity::GetBitmask(deity_id) & destination_item->Deity)) { fail_state = swapDeity; return false; } + if (level && destination_item->ReqLevel && level < destination_item->ReqLevel) { fail_state = swapLevel; return false; @@ -449,10 +446,8 @@ bool EQ::InventoryProfile::DeleteItem(int16 slot_id, int16 quantity) { bool EQ::InventoryProfile::CheckNoDrop(int16 slot_id, bool recurse) { ItemInstance* inst = GetItem(slot_id); - if (!inst) - return false; - return (!inst->IsDroppable(recurse)); + return inst ? !inst->IsDroppable(recurse) : false; } // Remove item from bucket without memory delete @@ -463,40 +458,32 @@ EQ::ItemInstance* EQ::InventoryProfile::PopItem(int16 slot_id) if (slot_id == invslot::slotCursor) { p = m_cursor.pop(); - } - else if (slot_id >= invslot::EQUIPMENT_BEGIN && slot_id <= invslot::EQUIPMENT_END) { + } else if (EQ::ValueWithin(slot_id, invslot::EQUIPMENT_BEGIN, invslot::EQUIPMENT_END)) { p = m_worn[slot_id]; m_worn.erase(slot_id); - } - else if (slot_id >= invslot::GENERAL_BEGIN && slot_id <= invslot::GENERAL_END) { + } else if (EQ::ValueWithin(slot_id, invslot::GENERAL_BEGIN, invslot::GENERAL_END)) { p = m_inv[slot_id]; m_inv.erase(slot_id); - } - else if (slot_id >= invslot::TRIBUTE_BEGIN && slot_id <= invslot::TRIBUTE_END) { + } else if (EQ::ValueWithin(slot_id, invslot::TRIBUTE_BEGIN, invslot::TRIBUTE_END)) { p = m_worn[slot_id]; m_worn.erase(slot_id); - } - else if (slot_id >= invslot::GUILD_TRIBUTE_BEGIN && slot_id <= invslot::GUILD_TRIBUTE_END) { + } else if (EQ::ValueWithin(slot_id, invslot::GUILD_TRIBUTE_BEGIN, invslot::GUILD_TRIBUTE_END)) { p = m_worn[slot_id]; m_worn.erase(slot_id); - } - else if (slot_id >= invslot::BANK_BEGIN && slot_id <= invslot::BANK_END) { + } else if (EQ::ValueWithin(slot_id, invslot::BANK_BEGIN, invslot::BANK_END)) { p = m_bank[slot_id]; m_bank.erase(slot_id); - } - else if (slot_id >= invslot::SHARED_BANK_BEGIN && slot_id <= invslot::SHARED_BANK_END) { + } else if (EQ::ValueWithin(slot_id, invslot::SHARED_BANK_BEGIN, invslot::SHARED_BANK_END)) { p = m_shbank[slot_id]; m_shbank.erase(slot_id); - } - else if (slot_id >= invslot::TRADE_BEGIN && slot_id <= invslot::TRADE_END) { + } else if (EQ::ValueWithin(slot_id, invslot::TRADE_BEGIN, invslot::TRADE_END)) { p = m_trade[slot_id]; m_trade.erase(slot_id); - } - else { - // Is slot inside bag? - ItemInstance* baginst = GetItem(InventoryProfile::CalcSlotId(slot_id)); - if (baginst != nullptr && baginst->IsClassBag()) { - p = baginst->PopItem(InventoryProfile::CalcBagIdx(slot_id)); + } else { + // Is slot inside bag? + ItemInstance* bag_inst = GetItem(InventoryProfile::CalcSlotId(slot_id)); + if (bag_inst && bag_inst->IsClassBag()) { + p = bag_inst->PopItem(InventoryProfile::CalcBagIdx(slot_id)); } } @@ -504,43 +491,49 @@ EQ::ItemInstance* EQ::InventoryProfile::PopItem(int16 slot_id) return p; } -bool EQ::InventoryProfile::HasSpaceForItem(const ItemData *ItemToTry, int16 Quantity) { - +bool EQ::InventoryProfile::HasSpaceForItem(const ItemData* ItemToTry, int16 Quantity) +{ if (ItemToTry->Stackable) { - for (int16 i = invslot::GENERAL_BEGIN; i <= invslot::GENERAL_END; i++) { - if ((((uint64)1 << i) & m_lookup->PossessionsBitmask) == 0) + if ((((uint64) 1 << i) & m_lookup->PossessionsBitmask) == 0) { continue; - - ItemInstance* InvItem = GetItem(i); - - if (InvItem && (InvItem->GetItem()->ID == ItemToTry->ID) && (InvItem->GetCharges() < InvItem->GetItem()->StackSize)) { - - int ChargeSlotsLeft = InvItem->GetItem()->StackSize - InvItem->GetCharges(); - - if (Quantity <= ChargeSlotsLeft) - return true; - - Quantity -= ChargeSlotsLeft; - } - if (InvItem && InvItem->IsClassBag()) { - int16 BaseSlotID = InventoryProfile::CalcSlotId(i, invbag::SLOT_BEGIN); - uint8 BagSize = InvItem->GetItem()->BagSlots; - for (uint8 BagSlot = invbag::SLOT_BEGIN; BagSlot < BagSize; BagSlot++) { + ItemInstance* inv_item = GetItem(i); - InvItem = GetItem(BaseSlotID + BagSlot); + if ( + inv_item && + inv_item->GetItem()->ID == ItemToTry->ID && + inv_item->GetCharges() < inv_item->GetItem()->StackSize + ) { + int charges_left = inv_item->GetItem()->StackSize - inv_item->GetCharges(); - if (InvItem && (InvItem->GetItem()->ID == ItemToTry->ID) && - (InvItem->GetCharges() < InvItem->GetItem()->StackSize)) { + if (Quantity <= charges_left) { + return true; + } - int ChargeSlotsLeft = InvItem->GetItem()->StackSize - InvItem->GetCharges(); + Quantity -= charges_left; + } - if (Quantity <= ChargeSlotsLeft) + if (inv_item && inv_item->IsClassBag()) { + int16 base_slot_id = InventoryProfile::CalcSlotId(i, invbag::SLOT_BEGIN); + uint8 bag_slots = inv_item->GetItem()->BagSlots; + + for (uint8 bag_slot = invbag::SLOT_BEGIN; bag_slot < bag_slots; bag_slot++) { + inv_item = GetItem(base_slot_id + bag_slot); + + if ( + inv_item && + inv_item->GetItem()->ID == ItemToTry->ID && + inv_item->GetCharges() < inv_item->GetItem()->StackSize + ) { + int charges_left = inv_item->GetItem()->StackSize - inv_item->GetCharges(); + + if (Quantity <= charges_left) { return true; + } - Quantity -= ChargeSlotsLeft; + Quantity -= charges_left; } } } @@ -548,51 +541,46 @@ bool EQ::InventoryProfile::HasSpaceForItem(const ItemData *ItemToTry, int16 Quan } for (int16 i = invslot::GENERAL_BEGIN; i <= invslot::GENERAL_END; i++) { - if ((((uint64)1 << i) & m_lookup->PossessionsBitmask) == 0) + if ((((uint64) 1 << i) & m_lookup->PossessionsBitmask) == 0) { continue; - - ItemInstance* InvItem = GetItem(i); - - if (!InvItem) { - - if (!ItemToTry->Stackable) { - - if (Quantity == 1) - return true; - else - Quantity--; - } - else { - if (Quantity <= ItemToTry->StackSize) - return true; - else - Quantity -= ItemToTry->StackSize; - } - } - else if (InvItem->IsClassBag() && CanItemFitInContainer(ItemToTry, InvItem->GetItem())) { - int16 BaseSlotID = InventoryProfile::CalcSlotId(i, invbag::SLOT_BEGIN); + ItemInstance* inv_item = GetItem(i); - uint8 BagSize = InvItem->GetItem()->BagSlots; + if (!inv_item) { + if (!ItemToTry->Stackable) { + if (Quantity == 1) { + return true; + } else { + Quantity--; + } + } else { + if (Quantity <= ItemToTry->StackSize) { + return true; + } else { + Quantity -= ItemToTry->StackSize; + } + } + } else if (inv_item->IsClassBag() && CanItemFitInContainer(ItemToTry, inv_item->GetItem())) { + int16 base_slot_id = InventoryProfile::CalcSlotId(i, invbag::SLOT_BEGIN); + uint8 bag_slots = inv_item->GetItem()->BagSlots; - for (uint8 BagSlot = invbag::SLOT_BEGIN; BagSlot < BagSize; BagSlot++) { + for (uint8 bag_slot = invbag::SLOT_BEGIN; bag_slot < bag_slots; bag_slot++) { + inv_item = GetItem(base_slot_id + bag_slot); - InvItem = GetItem(BaseSlotID + BagSlot); - - if (!InvItem) { + if (!inv_item) { if (!ItemToTry->Stackable) { - - if (Quantity == 1) + if (Quantity == 1) { return true; - else + } else { Quantity--; - } - else { - if (Quantity <= ItemToTry->StackSize) + } + } else { + if (Quantity <= ItemToTry->StackSize) { return true; - else + } else { Quantity -= ItemToTry->StackSize; + } } } } @@ -600,7 +588,6 @@ bool EQ::InventoryProfile::HasSpaceForItem(const ItemData *ItemToTry, int16 Quan } return false; - } // Checks that user has at least 'quantity' number of items in a given inventory slot @@ -680,40 +667,46 @@ int16 EQ::InventoryProfile::HasItem(uint32 item_id, uint8 quantity, uint8 where) // Check each inventory bucket if (where & invWhereWorn) { slot_id = _HasItem(m_worn, item_id, quantity); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } if (where & invWherePersonal) { slot_id = _HasItem(m_inv, item_id, quantity); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } if (where & invWhereBank) { slot_id = _HasItem(m_bank, item_id, quantity); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } if (where & invWhereSharedBank) { slot_id = _HasItem(m_shbank, item_id, quantity); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } if (where & invWhereTrading) { slot_id = _HasItem(m_trade, item_id, quantity); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } // Behavioral change - Limbo is no longer checked due to improper handling of return value if (where & invWhereCursor) { // Check cursor queue slot_id = _HasItem(m_cursor, item_id, quantity); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } return slot_id; @@ -727,40 +720,46 @@ int16 EQ::InventoryProfile::HasItemByUse(uint8 use, uint8 quantity, uint8 where) // Check each inventory bucket if (where & invWhereWorn) { slot_id = _HasItemByUse(m_worn, use, quantity); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } if (where & invWherePersonal) { slot_id = _HasItemByUse(m_inv, use, quantity); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } if (where & invWhereBank) { slot_id = _HasItemByUse(m_bank, use, quantity); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } if (where & invWhereSharedBank) { slot_id = _HasItemByUse(m_shbank, use, quantity); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } if (where & invWhereTrading) { slot_id = _HasItemByUse(m_trade, use, quantity); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } // Behavioral change - Limbo is no longer checked due to improper handling of return value if (where & invWhereCursor) { // Check cursor queue slot_id = _HasItemByUse(m_cursor, use, quantity); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } return slot_id; @@ -773,40 +772,46 @@ int16 EQ::InventoryProfile::HasItemByLoreGroup(uint32 loregroup, uint8 where) // Check each inventory bucket if (where & invWhereWorn) { slot_id = _HasItemByLoreGroup(m_worn, loregroup); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } if (where & invWherePersonal) { slot_id = _HasItemByLoreGroup(m_inv, loregroup); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } if (where & invWhereBank) { slot_id = _HasItemByLoreGroup(m_bank, loregroup); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } if (where & invWhereSharedBank) { slot_id = _HasItemByLoreGroup(m_shbank, loregroup); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } if (where & invWhereTrading) { slot_id = _HasItemByLoreGroup(m_trade, loregroup); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } // Behavioral change - Limbo is no longer checked due to improper handling of return value if (where & invWhereCursor) { // Check cursor queue slot_id = _HasItemByLoreGroup(m_cursor, loregroup); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } return slot_id; @@ -834,7 +839,7 @@ int16 EQ::InventoryProfile::FindFreeSlot(bool for_bag, bool try_cursor, uint8 mi continue; } - const auto *inst = GetItem(i); + const EQ::ItemInstance* inst = GetItem(i); if (inst && inst->IsClassBag() && inst->GetItem()->BagSize >= min_size) { if (inst->GetItem()->BagType == item::BagTypeQuiver && inst->GetItem()->ItemType != item::ItemTypeArrow) { @@ -842,8 +847,8 @@ int16 EQ::InventoryProfile::FindFreeSlot(bool for_bag, bool try_cursor, uint8 mi } const int16 base_slot_id = InventoryProfile::CalcSlotId(i, invbag::SLOT_BEGIN); + const uint8 slots = inst->GetItem()->BagSlots; - const uint8 slots = inst->GetItem()->BagSlots; for (uint8 j = invbag::SLOT_BEGIN; j < slots; j++) { if (!GetItem(base_slot_id + j)) { // Found available slot within bag @@ -871,22 +876,25 @@ int16 EQ::InventoryProfile::FindFreeSlotForTradeItem(const ItemInstance* inst, i // // I'll probably implement a bitmask in the new inventory system to avoid having to adjust stack bias - if ((general_start < invslot::GENERAL_BEGIN) || (general_start > invslot::GENERAL_END)) - return INVALID_INDEX; - if (bag_start > invbag::SLOT_END) - return INVALID_INDEX; - - if (!inst || !inst->GetID()) + if ( + !EQ::ValueWithin(general_start, invslot::GENERAL_BEGIN, invslot::GENERAL_END) || + bag_start > invbag::SLOT_END || + !inst || + !inst->GetID() + ) { return INVALID_INDEX; + } // step 1: find room for bags (caller should really ask for slots for bags first to avoid sending them to cursor..and bag item loss) if (inst->IsClassBag()) { for (int16 free_slot = general_start; free_slot <= invslot::GENERAL_END; ++free_slot) { - if ((((uint64)1 << free_slot) & m_lookup->PossessionsBitmask) == 0) + if ((((uint64) 1 << free_slot) & m_lookup->PossessionsBitmask) == 0) { continue; + } - if (!m_inv[free_slot]) + if (!m_inv[free_slot]) { return free_slot; + } } return invslot::slotCursor; // return cursor since bags do not stack and will not fit inside other bags..yet...) @@ -895,37 +903,55 @@ int16 EQ::InventoryProfile::FindFreeSlotForTradeItem(const ItemInstance* inst, i // step 2: find partial room for stackables if (inst->IsStackable()) { for (int16 free_slot = general_start; free_slot <= invslot::GENERAL_END; ++free_slot) { - if ((((uint64)1 << free_slot) & m_lookup->PossessionsBitmask) == 0) + if ((((uint64) 1 << free_slot) & m_lookup->PossessionsBitmask) == 0) { continue; + } const ItemInstance* main_inst = m_inv[free_slot]; - if (!main_inst) + if (!main_inst) { continue; + } - if ((main_inst->GetID() == inst->GetID()) && (main_inst->GetCharges() < main_inst->GetItem()->StackSize)) + if ( + main_inst->GetID() == inst->GetID() && + main_inst->GetCharges() < main_inst->GetItem()->StackSize + ) { return free_slot; + } } for (int16 free_slot = general_start; free_slot <= invslot::GENERAL_END; ++free_slot) { - if ((((uint64)1 << free_slot) & m_lookup->PossessionsBitmask) == 0) + if ((((uint64) 1 << free_slot) & m_lookup->PossessionsBitmask) == 0) { continue; + } const ItemInstance* main_inst = m_inv[free_slot]; - if (!main_inst) + if (!main_inst) { continue; + } if (main_inst->IsClassBag()) { // if item-specific containers already have bad items, we won't fix it here... uint8 _bag_start = (free_slot > general_start) ? invbag::SLOT_BEGIN : bag_start; - for (uint8 free_bag_slot = _bag_start; (free_bag_slot < main_inst->GetItem()->BagSlots) && (free_bag_slot <= invbag::SLOT_END); ++free_bag_slot) { + + for ( + uint8 free_bag_slot = _bag_start; + (free_bag_slot < main_inst->GetItem()->BagSlots) && (free_bag_slot <= invbag::SLOT_END); + ++free_bag_slot + ) { const ItemInstance* sub_inst = main_inst->GetItem(free_bag_slot); - if (!sub_inst) + if (!sub_inst) { continue; + } - if ((sub_inst->GetID() == inst->GetID()) && (sub_inst->GetCharges() < sub_inst->GetItem()->StackSize)) + if ( + sub_inst->GetID() == inst->GetID() && + sub_inst->GetCharges() < sub_inst->GetItem()->StackSize + ) { return InventoryProfile::CalcSlotId(free_slot, free_bag_slot); + } } } } @@ -934,18 +960,30 @@ int16 EQ::InventoryProfile::FindFreeSlotForTradeItem(const ItemInstance* inst, i // step 3a: find room for container-specific items (ItemClassArrow) if (inst->GetItem()->ItemType == item::ItemTypeArrow) { for (int16 free_slot = general_start; free_slot <= invslot::GENERAL_END; ++free_slot) { - if ((((uint64)1 << free_slot) & m_lookup->PossessionsBitmask) == 0) + if ((((uint64) 1 << free_slot) & m_lookup->PossessionsBitmask) == 0) { continue; + } const ItemInstance* main_inst = m_inv[free_slot]; - if (!main_inst || (main_inst->GetItem()->BagType != item::BagTypeQuiver) || !main_inst->IsClassBag()) + if ( + !main_inst || + main_inst->GetItem()->BagType != item::BagTypeQuiver || + !main_inst->IsClassBag() + ) { continue; + } uint8 _bag_start = (free_slot > general_start) ? invbag::SLOT_BEGIN : bag_start; - for (uint8 free_bag_slot = _bag_start; (free_bag_slot < main_inst->GetItem()->BagSlots) && (free_bag_slot <= invbag::SLOT_END); ++free_bag_slot) { - if (!main_inst->GetItem(free_bag_slot)) + + for ( + uint8 free_bag_slot = _bag_start; + (free_bag_slot < main_inst->GetItem()->BagSlots) && (free_bag_slot <= invbag::SLOT_END); + ++free_bag_slot + ) { + if (!main_inst->GetItem(free_bag_slot)) { return InventoryProfile::CalcSlotId(free_slot, free_bag_slot); + } } } } @@ -953,47 +991,73 @@ int16 EQ::InventoryProfile::FindFreeSlotForTradeItem(const ItemInstance* inst, i // step 3b: find room for container-specific items (ItemClassSmallThrowing) if (inst->GetItem()->ItemType == item::ItemTypeSmallThrowing) { for (int16 free_slot = general_start; free_slot <= invslot::GENERAL_END; ++free_slot) { - if ((((uint64)1 << free_slot) & m_lookup->PossessionsBitmask) == 0) + if ((((uint64) 1 << free_slot) & m_lookup->PossessionsBitmask) == 0) { continue; + } const ItemInstance* main_inst = m_inv[free_slot]; - if (!main_inst || (main_inst->GetItem()->BagType != item::BagTypeBandolier) || !main_inst->IsClassBag()) + if ( + !main_inst || + main_inst->GetItem()->BagType != item::BagTypeBandolier || + !main_inst->IsClassBag() + ) { continue; + } uint8 _bag_start = (free_slot > general_start) ? invbag::SLOT_BEGIN : bag_start; - for (uint8 free_bag_slot = _bag_start; (free_bag_slot < main_inst->GetItem()->BagSlots) && (free_bag_slot <= invbag::SLOT_END); ++free_bag_slot) { - if (!main_inst->GetItem(free_bag_slot)) + + for ( + uint8 free_bag_slot = _bag_start; + (free_bag_slot < main_inst->GetItem()->BagSlots) && (free_bag_slot <= invbag::SLOT_END); + ++free_bag_slot + ) { + if (!main_inst->GetItem(free_bag_slot)) { return InventoryProfile::CalcSlotId(free_slot, free_bag_slot); + } } } } // step 4: just find an empty slot for (int16 free_slot = general_start; free_slot <= invslot::GENERAL_END; ++free_slot) { - if ((((uint64)1 << free_slot) & m_lookup->PossessionsBitmask) == 0) + if ((((uint64) 1 << free_slot) & m_lookup->PossessionsBitmask) == 0) { continue; + } const ItemInstance* main_inst = m_inv[free_slot]; - if (!main_inst) + if (!main_inst) { return free_slot; + } } for (int16 free_slot = general_start; free_slot <= invslot::GENERAL_END; ++free_slot) { - if ((((uint64)1 << free_slot) & m_lookup->PossessionsBitmask) == 0) + if ((((uint64) 1 << free_slot) & m_lookup->PossessionsBitmask) == 0) { continue; + } const ItemInstance* main_inst = m_inv[free_slot]; if (main_inst && main_inst->IsClassBag()) { - if ((main_inst->GetItem()->BagSize < inst->GetItem()->Size) || (main_inst->GetItem()->BagType == item::BagTypeBandolier) || (main_inst->GetItem()->BagType == item::BagTypeQuiver)) + if ( + main_inst->GetItem()->BagSize < inst->GetItem()->Size || + main_inst->GetItem()->BagType == item::BagTypeBandolier || + main_inst->GetItem()->BagType == item::BagTypeQuiver + ) { continue; + } uint8 _bag_start = (free_slot > general_start) ? invbag::SLOT_BEGIN : bag_start; - for (uint8 free_bag_slot = _bag_start; (free_bag_slot < main_inst->GetItem()->BagSlots) && (free_bag_slot <= invbag::SLOT_END); ++free_bag_slot) { - if (!main_inst->GetItem(free_bag_slot)) + + for ( + uint8 free_bag_slot = _bag_start; + (free_bag_slot < main_inst->GetItem()->BagSlots) && (free_bag_slot <= invbag::SLOT_END); + ++free_bag_slot + ) { + if (!main_inst->GetItem(free_bag_slot)) { return InventoryProfile::CalcSlotId(free_slot, free_bag_slot); + } } } } @@ -1003,7 +1067,8 @@ int16 EQ::InventoryProfile::FindFreeSlotForTradeItem(const ItemInstance* inst, i } // Opposite of below: Get parent bag slot_id from a slot inside of bag -int16 EQ::InventoryProfile::CalcSlotId(int16 slot_id) { +int16 EQ::InventoryProfile::CalcSlotId(int16 slot_id) +{ int16 parent_slot_id = INVALID_INDEX; // this is not a bag range... using this risks over-writing existing items @@ -1011,19 +1076,15 @@ int16 EQ::InventoryProfile::CalcSlotId(int16 slot_id) { // parent_slot_id = EmuConstants::BANK_BEGIN + (slot_id - EmuConstants::BANK_BEGIN) / EmuConstants::ITEM_CONTAINER_SIZE; //else if (slot_id >= 3100 && slot_id <= 3179) should be {3031..3110}..where did this range come from!!? (verified db save range) - if (slot_id >= invbag::GENERAL_BAGS_BEGIN && slot_id <= invbag::GENERAL_BAGS_END) { + if (EQ::ValueWithin(slot_id, invbag::GENERAL_BAGS_BEGIN, invbag::GENERAL_BAGS_END)) { parent_slot_id = invslot::GENERAL_BEGIN + (slot_id - invbag::GENERAL_BAGS_BEGIN) / invbag::SLOT_COUNT; - } - else if (slot_id >= invbag::CURSOR_BAG_BEGIN && slot_id <= invbag::CURSOR_BAG_END) { + } else if (EQ::ValueWithin(slot_id, invbag::CURSOR_BAG_BEGIN, invbag::CURSOR_BAG_END)) { parent_slot_id = invslot::slotCursor; - } - else if (slot_id >= invbag::BANK_BAGS_BEGIN && slot_id <= invbag::BANK_BAGS_END) { + } else if (EQ::ValueWithin(slot_id, invbag::BANK_BAGS_BEGIN, invbag::BANK_BAGS_END)) { parent_slot_id = invslot::BANK_BEGIN + (slot_id - invbag::BANK_BAGS_BEGIN) / invbag::SLOT_COUNT; - } - else if (slot_id >= invbag::SHARED_BANK_BAGS_BEGIN && slot_id <= invbag::SHARED_BANK_BAGS_END) { + } else if (EQ::ValueWithin(slot_id, invbag::SHARED_BANK_BAGS_BEGIN, invbag::SHARED_BANK_BAGS_END)) { parent_slot_id = invslot::SHARED_BANK_BEGIN + (slot_id - invbag::SHARED_BANK_BAGS_BEGIN) / invbag::SLOT_COUNT; - } - else if (slot_id >= invbag::TRADE_BAGS_BEGIN && slot_id <= invbag::TRADE_BAGS_END) { + } else if (EQ::ValueWithin(slot_id, invbag::TRADE_BAGS_BEGIN, invbag::TRADE_BAGS_END)) { parent_slot_id = invslot::TRADE_BEGIN + (slot_id - invbag::TRADE_BAGS_BEGIN) / invbag::SLOT_COUNT; } @@ -1031,26 +1092,24 @@ int16 EQ::InventoryProfile::CalcSlotId(int16 slot_id) { } // Calculate slot_id for an item within a bag -int16 EQ::InventoryProfile::CalcSlotId(int16 bagslot_id, uint8 bagidx) { - if (!InventoryProfile::SupportsContainers(bagslot_id)) +int16 EQ::InventoryProfile::CalcSlotId(int16 bagslot_id, uint8 bagidx) +{ + if (!InventoryProfile::SupportsContainers(bagslot_id)) { return INVALID_INDEX; + } int16 slot_id = INVALID_INDEX; if (bagslot_id == invslot::slotCursor) { slot_id = invbag::CURSOR_BAG_BEGIN + bagidx; - } - else if (bagslot_id >= invslot::GENERAL_BEGIN && bagslot_id <= invslot::GENERAL_END) { - slot_id = invbag::GENERAL_BAGS_BEGIN + (bagslot_id - invslot::GENERAL_BEGIN) * invbag::SLOT_COUNT + bagidx; - } - else if (bagslot_id >= invslot::BANK_BEGIN && bagslot_id <= invslot::BANK_END) { - slot_id = invbag::BANK_BAGS_BEGIN + (bagslot_id - invslot::BANK_BEGIN) * invbag::SLOT_COUNT + bagidx; - } - else if (bagslot_id >= invslot::SHARED_BANK_BEGIN && bagslot_id <= invslot::SHARED_BANK_END) { - slot_id = invbag::SHARED_BANK_BAGS_BEGIN + (bagslot_id - invslot::SHARED_BANK_BEGIN) * invbag::SLOT_COUNT + bagidx; - } - else if (bagslot_id >= invslot::TRADE_BEGIN && bagslot_id <= invslot::TRADE_END) { - slot_id = invbag::TRADE_BAGS_BEGIN + (bagslot_id - invslot::TRADE_BEGIN) * invbag::SLOT_COUNT + bagidx; + } else if (EQ::ValueWithin(bagslot_id, invslot::GENERAL_BEGIN, invslot::GENERAL_END)) { + slot_id = invbag::GENERAL_BAGS_BEGIN + (bagslot_id - invbag::GENERAL_BAGS_BEGIN) * invbag::SLOT_COUNT + bagidx; + } else if (EQ::ValueWithin(bagslot_id, invslot::BANK_BEGIN, invslot::BANK_END)) { + slot_id = invbag::BANK_BAGS_BEGIN + (bagslot_id - invbag::BANK_BAGS_BEGIN) * invbag::SLOT_COUNT + bagidx; + } else if (EQ::ValueWithin(bagslot_id, invslot::SHARED_BANK_BEGIN, invslot::SHARED_BANK_END)) { + slot_id = invbag::SHARED_BANK_BAGS_BEGIN + (bagslot_id - invbag::SHARED_BANK_BAGS_BEGIN) * invbag::SLOT_COUNT + bagidx; + } else if (EQ::ValueWithin(bagslot_id, invslot::TRADE_BEGIN, invslot::TRADE_END)) { + slot_id = invbag::TRADE_BAGS_BEGIN + (bagslot_id - invbag::TRADE_BAGS_BEGIN) * invbag::SLOT_COUNT + bagidx; } return slot_id; @@ -1059,26 +1118,17 @@ int16 EQ::InventoryProfile::CalcSlotId(int16 bagslot_id, uint8 bagidx) { uint8 EQ::InventoryProfile::CalcBagIdx(int16 slot_id) { uint8 index = 0; - // this is not a bag range... using this risks over-writing existing items - //else if (slot_id >= EmuConstants::BANK_BEGIN && slot_id <= EmuConstants::BANK_END) - // index = (slot_id - EmuConstants::BANK_BEGIN) % EmuConstants::ITEM_CONTAINER_SIZE; - - if (slot_id >= invbag::GENERAL_BAGS_BEGIN && slot_id <= invbag::GENERAL_BAGS_END) { + if (EQ::ValueWithin(slot_id, invbag::GENERAL_BAGS_BEGIN, invbag::GENERAL_BAGS_END)) { index = (slot_id - invbag::GENERAL_BAGS_BEGIN) % invbag::SLOT_COUNT; - } - else if (slot_id >= invbag::CURSOR_BAG_BEGIN && slot_id <= invbag::CURSOR_BAG_END) { + } else if (EQ::ValueWithin(slot_id, invbag::CURSOR_BAG_BEGIN, invbag::CURSOR_BAG_END)) { index = (slot_id - invbag::CURSOR_BAG_BEGIN); // % invbag::SLOT_COUNT; - not needed since range is 10 slots - } - else if (slot_id >= invbag::BANK_BAGS_BEGIN && slot_id <= invbag::BANK_BAGS_END) { + } else if (EQ::ValueWithin(slot_id, invbag::BANK_BAGS_BEGIN, invbag::BANK_BAGS_END)) { index = (slot_id - invbag::BANK_BAGS_BEGIN) % invbag::SLOT_COUNT; - } - else if (slot_id >= invbag::SHARED_BANK_BAGS_BEGIN && slot_id <= invbag::SHARED_BANK_BAGS_END) { + } else if (EQ::ValueWithin(slot_id, invbag::SHARED_BANK_BAGS_BEGIN, invbag::SHARED_BANK_BAGS_END)) { index = (slot_id - invbag::SHARED_BANK_BAGS_BEGIN) % invbag::SLOT_COUNT; - } - else if (slot_id >= invbag::TRADE_BAGS_BEGIN && slot_id <= invbag::TRADE_BAGS_END) { + } else if (EQ::ValueWithin(slot_id, invbag::TRADE_BAGS_BEGIN, invbag::TRADE_BAGS_END)) { index = (slot_id - invbag::TRADE_BAGS_BEGIN) % invbag::SLOT_COUNT; - } - else if (slot_id >= invslot::WORLD_BEGIN && slot_id <= invslot::WORLD_END) { + } else if (EQ::ValueWithin(slot_id, invslot::WORLD_BEGIN, invslot::WORLD_END)) { index = (slot_id - invslot::WORLD_BEGIN); // % invbag::SLOT_COUNT; - not needed since range is 10 slots } @@ -1114,45 +1164,53 @@ int16 EQ::InventoryProfile::CalcSlotFromMaterial(uint8 material) uint8 EQ::InventoryProfile::CalcMaterialFromSlot(int16 equipslot) { - switch (equipslot) - { - case invslot::slotHead: - return textures::armorHead; - case invslot::slotChest: - return textures::armorChest; - case invslot::slotArms: - return textures::armorArms; - case invslot::slotWrist1: - //case SLOT_BRACER02: // non-live behavior - return textures::armorWrist; - case invslot::slotHands: - return textures::armorHands; - case invslot::slotLegs: - return textures::armorLegs; - case invslot::slotFeet: - return textures::armorFeet; - case invslot::slotPrimary: - return textures::weaponPrimary; - case invslot::slotSecondary: - return textures::weaponSecondary; - default: - return textures::materialInvalid; + switch (equipslot) { + case invslot::slotHead: + return textures::armorHead; + case invslot::slotChest: + return textures::armorChest; + case invslot::slotArms: + return textures::armorArms; + case invslot::slotWrist1: + return textures::armorWrist; + case invslot::slotHands: + return textures::armorHands; + case invslot::slotLegs: + return textures::armorLegs; + case invslot::slotFeet: + return textures::armorFeet; + case invslot::slotPrimary: + return textures::weaponPrimary; + case invslot::slotSecondary: + return textures::weaponSecondary; + default: + return textures::materialInvalid; } } bool EQ::InventoryProfile::CanItemFitInContainer(const ItemData *ItemToTry, const ItemData *Container) { - if (!ItemToTry || !Container) + if (!ItemToTry || !Container) { return false; + } - if (ItemToTry->Size > Container->BagSize) + if (ItemToTry->Size > Container->BagSize) { return false; + } - if ((Container->BagType == item::BagTypeQuiver) && (ItemToTry->ItemType != item::ItemTypeArrow)) + if ( + Container->BagType == item::BagTypeQuiver && + ItemToTry->ItemType != item::ItemTypeArrow + ) { return false; + } - if ((Container->BagType == item::BagTypeBandolier) && (ItemToTry->ItemType != item::ItemTypeSmallThrowing)) + if ( + Container->BagType == item::BagTypeBandolier && + ItemToTry->ItemType != item::ItemTypeSmallThrowing + ) { return false; + } return true; } @@ -1160,15 +1218,14 @@ bool EQ::InventoryProfile::CanItemFitInContainer(const ItemData *ItemToTry, cons bool EQ::InventoryProfile::SupportsClickCasting(int16 slot_id) { // there are a few non-potion items that identify as ItemTypePotion..so, we still need to ubiquitously include the equipment range - if (slot_id >= invslot::EQUIPMENT_BEGIN && slot_id <= invslot::EQUIPMENT_END) { + if (EQ::ValueWithin(slot_id, invslot::EQUIPMENT_BEGIN, invslot::EQUIPMENT_END)) { return true; - } - else if (slot_id >= invslot::GENERAL_BEGIN && slot_id <= invslot::GENERAL_END) { + } else if (EQ::ValueWithin(slot_id, invslot::GENERAL_BEGIN, invslot::GENERAL_END)) { return true; - } - else if (slot_id >= invbag::GENERAL_BAGS_BEGIN && slot_id <= invbag::GENERAL_BAGS_END) { - if (inventory::StaticLookup(m_mob_version)->AllowClickCastFromBag) + } else if (EQ::ValueWithin(slot_id, invbag::GENERAL_BAGS_BEGIN, invbag::GENERAL_BAGS_END)) { + if (inventory::StaticLookup(m_mob_version)->AllowClickCastFromBag) { return true; + } } return false; @@ -1177,13 +1234,11 @@ bool EQ::InventoryProfile::SupportsClickCasting(int16 slot_id) bool EQ::InventoryProfile::SupportsPotionBeltCasting(int16 slot_id) { // does this have the same criteria as 'SupportsClickCasting' above? (bag clicking per client) - if (slot_id >= invslot::EQUIPMENT_BEGIN && slot_id <= invslot::EQUIPMENT_END) { + if (EQ::ValueWithin(slot_id, invslot::EQUIPMENT_BEGIN, invslot::EQUIPMENT_END)) { return true; - } - else if (slot_id >= invslot::GENERAL_BEGIN && slot_id <= invslot::GENERAL_END) { + } else if (EQ::ValueWithin(slot_id, invslot::GENERAL_BEGIN, invslot::GENERAL_END)) { return true; - } - else if (slot_id >= invbag::GENERAL_BAGS_BEGIN && slot_id <= invbag::GENERAL_BAGS_END) { + } else if (EQ::ValueWithin(slot_id, invbag::GENERAL_BAGS_BEGIN, invbag::GENERAL_BAGS_END)) { return true; } @@ -1193,11 +1248,12 @@ bool EQ::InventoryProfile::SupportsPotionBeltCasting(int16 slot_id) // Test whether a given slot can support a container item bool EQ::InventoryProfile::SupportsContainers(int16 slot_id) { - if ((slot_id == invslot::slotCursor) || - (slot_id >= invslot::GENERAL_BEGIN && slot_id <= invslot::GENERAL_END) || - (slot_id >= invslot::BANK_BEGIN && slot_id <= invslot::BANK_END) || - (slot_id >= invslot::SHARED_BANK_BEGIN && slot_id <= invslot::SHARED_BANK_END) || - (slot_id >= invslot::TRADE_BEGIN && slot_id <= invslot::TRADE_END) + if ( + slot_id == invslot::slotCursor || + EQ::ValueWithin(slot_id, invslot::GENERAL_BEGIN, invslot::GENERAL_END) || + EQ::ValueWithin(slot_id, invslot::BANK_BEGIN, invslot::BANK_END) || + EQ::ValueWithin(slot_id, invslot::SHARED_BANK_BEGIN, invslot::SHARED_BANK_END) || + EQ::ValueWithin(slot_id, invslot::TRADE_BEGIN, invslot::TRADE_END) ) { return true; } @@ -1246,84 +1302,65 @@ uint8 EQ::InventoryProfile::FindBrightestLightType() uint8 brightest_light_type = 0; for (auto iter = m_worn.begin(); iter != m_worn.end(); ++iter) { - if ((iter->first < invslot::EQUIPMENT_BEGIN || iter->first > invslot::EQUIPMENT_END)) + if (!EQ::ValueWithin(iter->first, invslot::EQUIPMENT_BEGIN, invslot::EQUIPMENT_END)) { continue; + } - if (iter->first == invslot::slotAmmo) + if (iter->first == invslot::slotAmmo) { continue; + } - auto inst = iter->second; - if (inst == nullptr) + EQ::ItemInstance* inst = iter->second; + if (!inst) { continue; + } - auto item = inst->GetItem(); - if (item == nullptr) + const EQ::ItemData* item = inst->GetItem(); + if (!item) { continue; + } - if (lightsource::IsLevelGreater(item->Light, brightest_light_type)) + if (lightsource::IsLevelGreater(item->Light, brightest_light_type)) { brightest_light_type = item->Light; + } } uint8 general_light_type = 0; for (auto iter = m_inv.begin(); iter != m_inv.end(); ++iter) { - if (iter->first < invslot::GENERAL_BEGIN || iter->first > invslot::GENERAL_END) + if (!EQ::ValueWithin(iter->first, invslot::GENERAL_BEGIN, invslot::GENERAL_END)) { continue; + } - auto inst = iter->second; - if (inst == nullptr) + EQ::ItemInstance* inst = iter->second; + if (!inst) { continue; + } - auto item = inst->GetItem(); - if (item == nullptr) + const EQ::ItemData* item = inst->GetItem(); + if (!item) { continue; + } - if (!item->IsClassCommon()) - continue; - if (item->Light < 9 || item->Light > 13) + if (!item->IsClassCommon()) { continue; + } - if (lightsource::TypeToLevel(item->Light)) + if (!EQ::ValueWithin(item->Light, 9, 13)) { + continue; + } + + if (lightsource::TypeToLevel(item->Light)) { general_light_type = item->Light; + } } - if (lightsource::IsLevelGreater(general_light_type, brightest_light_type)) + if (lightsource::IsLevelGreater(general_light_type, brightest_light_type)) { brightest_light_type = general_light_type; + } return brightest_light_type; } -void EQ::InventoryProfile::dumpEntireInventory() { - - dumpWornItems(); - dumpInventory(); - dumpBankItems(); - dumpSharedBankItems(); - - std::cout << std::endl; -} - -void EQ::InventoryProfile::dumpWornItems() { - std::cout << "Worn items:" << std::endl; - dumpItemCollection(m_worn); -} - -void EQ::InventoryProfile::dumpInventory() { - std::cout << "Inventory items:" << std::endl; - dumpItemCollection(m_inv); -} - -void EQ::InventoryProfile::dumpBankItems() { - - std::cout << "Bank items:" << std::endl; - dumpItemCollection(m_bank); -} - -void EQ::InventoryProfile::dumpSharedBankItems() { - - std::cout << "Shared Bank items:" << std::endl; - dumpItemCollection(m_shbank); -} - int EQ::InventoryProfile::GetSlotByItemInstCollection(const std::map &collection, ItemInstance *inst) { for (auto iter = collection.begin(); iter != collection.end(); ++iter) { ItemInstance *t_inst = iter->second; @@ -1343,57 +1380,22 @@ int EQ::InventoryProfile::GetSlotByItemInstCollection(const std::map &collection) -{ - for (auto it = collection.cbegin(); it != collection.cend(); ++it) { - auto inst = it->second; - if (!inst || !inst->GetItem()) - continue; - - std::string slot = StringFormat("Slot %d: %s (%d)", it->first, it->second->GetItem()->Name, (inst->GetCharges() <= 0) ? 1 : inst->GetCharges()); - std::cout << slot << std::endl; - - dumpBagContents(inst, &it); - } -} - -void EQ::InventoryProfile::dumpBagContents(ItemInstance *inst, std::map::const_iterator *it) -{ - if (!inst || !inst->IsClassBag()) - return; - - // Go through bag, if bag - for (auto itb = inst->_cbegin(); itb != inst->_cend(); ++itb) { - ItemInstance* baginst = itb->second; - if (!baginst || !baginst->GetItem()) - continue; - - std::string subSlot = StringFormat(" Slot %d: %s (%d)", InventoryProfile::CalcSlotId((*it)->first, itb->first), - baginst->GetItem()->Name, (baginst->GetCharges() <= 0) ? 1 : baginst->GetCharges()); - std::cout << subSlot << std::endl; - } - -} - // Internal Method: Retrieves item within an inventory bucket EQ::ItemInstance* EQ::InventoryProfile::_GetItem(const std::map& bucket, int16 slot_id) const { - if (slot_id <= EQ::invslot::POSSESSIONS_END && slot_id >= EQ::invslot::POSSESSIONS_BEGIN) { - if ((((uint64)1 << slot_id) & m_lookup->PossessionsBitmask) == 0) + if (EQ::ValueWithin(slot_id, EQ::invslot::POSSESSIONS_BEGIN, EQ::invslot::POSSESSIONS_END)) { + if ((((uint64) 1 << slot_id) & m_lookup->PossessionsBitmask) == 0) { return nullptr; - } - else if (slot_id <= EQ::invslot::BANK_END && slot_id >= EQ::invslot::BANK_BEGIN) { - if (slot_id - EQ::invslot::BANK_BEGIN >= m_lookup->InventoryTypeSize.Bank) + } + } else if (EQ::ValueWithin(slot_id, EQ::invslot::BANK_BEGIN, EQ::invslot::BANK_END)) { + if (slot_id - EQ::invslot::BANK_BEGIN >= m_lookup->InventoryTypeSize.Bank) { return nullptr; + } } auto it = bucket.find(slot_id); - if (it != bucket.end()) { - return it->second; - } - // Not found! - return nullptr; + return it != bucket.end() ? it->second : nullptr; } // Internal Method: "put" item into bucket, without regard for what is currently in bucket @@ -1403,14 +1405,14 @@ int16 EQ::InventoryProfile::_PutItem(int16 slot_id, ItemInstance* inst) // What happens here when we _PutItem(MainCursor)? Bad things..really bad things... // // If putting a nullptr into slot, we need to remove slot without memory delete - if (inst == nullptr) { + if (!inst) { //Why do we not delete the poped item here???? PopItem(slot_id); return slot_id; } - int16 result = INVALID_INDEX; - int16 parentSlot = INVALID_INDEX; + int16 result = INVALID_INDEX; + int16 parent_slot = INVALID_INDEX; inst->SetEvolveEquipped(false); @@ -1419,57 +1421,49 @@ int16 EQ::InventoryProfile::_PutItem(int16 slot_id, ItemInstance* inst) m_cursor.pop(); // no memory delete, clients of this function know what they are doing m_cursor.push_front(inst); result = slot_id; - } - else if (slot_id >= invslot::EQUIPMENT_BEGIN && slot_id <= invslot::EQUIPMENT_END) { + } else if (EQ::ValueWithin(slot_id, invslot::EQUIPMENT_BEGIN, invslot::EQUIPMENT_END)) { if ((((uint64)1 << slot_id) & m_lookup->PossessionsBitmask) != 0) { if (inst->IsEvolving()) { inst->SetEvolveEquipped(true); } + m_worn[slot_id] = inst; result = slot_id; } - } - else if ((slot_id >= invslot::GENERAL_BEGIN && slot_id <= invslot::GENERAL_END)) { - if ((((uint64)1 << slot_id) & m_lookup->PossessionsBitmask) != 0) { + } else if (EQ::ValueWithin(slot_id, invslot::GENERAL_BEGIN, invslot::GENERAL_END)) { + if ((((uint64) 1 << slot_id) & m_lookup->PossessionsBitmask) != 0) { m_inv[slot_id] = inst; result = slot_id; } - } - else if (slot_id >= invslot::TRIBUTE_BEGIN && slot_id <= invslot::TRIBUTE_END) { + } else if (EQ::ValueWithin(slot_id, invslot::TRIBUTE_BEGIN, invslot::TRIBUTE_END)) { m_worn[slot_id] = inst; result = slot_id; - } - else if (slot_id >= invslot::GUILD_TRIBUTE_BEGIN && slot_id <= invslot::GUILD_TRIBUTE_END) { + } else if (EQ::ValueWithin(slot_id, invslot::GUILD_TRIBUTE_BEGIN, invslot::GUILD_TRIBUTE_END)) { m_worn[slot_id] = inst; result = slot_id; - } - else if (slot_id >= invslot::BANK_BEGIN && slot_id <= invslot::BANK_END) { + } else if (EQ::ValueWithin(slot_id, invslot::BANK_BEGIN, invslot::BANK_END)) { if (slot_id - EQ::invslot::BANK_BEGIN < m_lookup->InventoryTypeSize.Bank) { m_bank[slot_id] = inst; result = slot_id; } - } - else if (slot_id >= invslot::SHARED_BANK_BEGIN && slot_id <= invslot::SHARED_BANK_END) { + } else if (EQ::ValueWithin(slot_id, invslot::SHARED_BANK_BEGIN, invslot::SHARED_BANK_END)) { m_shbank[slot_id] = inst; result = slot_id; - } - else if (slot_id >= invslot::TRADE_BEGIN && slot_id <= invslot::TRADE_END) { + } else if (EQ::ValueWithin(slot_id, invslot::TRADE_BEGIN, invslot::TRADE_END)) { m_trade[slot_id] = inst; result = slot_id; - } - else { + } else { // Slot must be within a bag - parentSlot = InventoryProfile::CalcSlotId(slot_id); - ItemInstance* baginst = GetItem(parentSlot); // Get parent bag - if (baginst && baginst->IsClassBag()) - { + parent_slot = InventoryProfile::CalcSlotId(slot_id); + ItemInstance* baginst = GetItem(parent_slot); // Get parent bag + if (baginst && baginst->IsClassBag()) { baginst->_PutItem(InventoryProfile::CalcBagIdx(slot_id), inst); result = slot_id; } } if (result == INVALID_INDEX) { - LogError("Invalid slot_id specified ({}) with parent slot id ({})", slot_id, parentSlot); + LogError("Invalid slot_id specified ({}) with parent slot id ({})", slot_id, parent_slot); InventoryProfile::MarkDirty(inst); // Slot not found, clean up } @@ -1482,44 +1476,55 @@ int16 EQ::InventoryProfile::_HasItem(std::map& bucket, uin uint32 quantity_found = 0; for (auto iter = bucket.begin(); iter != bucket.end(); ++iter) { - if (iter->first <= EQ::invslot::POSSESSIONS_END && iter->first >= EQ::invslot::POSSESSIONS_BEGIN) { - if ((((uint64)1 << iter->first) & m_lookup->PossessionsBitmask) == 0) + if (EQ::ValueWithin(iter->first, EQ::invslot::POSSESSIONS_BEGIN, EQ::invslot::POSSESSIONS_END)) { + if ((((uint64) 1 << iter->first) & m_lookup->PossessionsBitmask) == 0) { continue; - } - else if (iter->first <= EQ::invslot::BANK_END && iter->first >= EQ::invslot::BANK_BEGIN) { - if (iter->first - EQ::invslot::BANK_BEGIN >= m_lookup->InventoryTypeSize.Bank) + } + } else if (EQ::ValueWithin(iter->first, EQ::invslot::BANK_BEGIN, EQ::invslot::BANK_END)) { + if (iter->first - EQ::invslot::BANK_BEGIN >= m_lookup->InventoryTypeSize.Bank) { continue; + } } - auto inst = iter->second; - if (inst == nullptr) { continue; } + EQ::ItemInstance* inst = iter->second; + if (!inst) { + continue; + } if (inst->GetID() == item_id) { quantity_found += (inst->GetCharges() <= 0) ? 1 : inst->GetCharges(); - if (quantity_found >= quantity) + if (quantity_found >= quantity) { return iter->first; + } } for (int index = invaug::SOCKET_BEGIN; index <= invaug::SOCKET_END; ++index) { - if (inst->GetAugmentItemID(index) == item_id && quantity <= 1) + if (inst->GetAugmentItemID(index) == item_id && quantity <= 1) { return invslot::SLOT_AUGMENT_GENERIC_RETURN; + } } - if (!inst->IsClassBag()) { continue; } + if (!inst->IsClassBag()) { + continue; + } for (auto bag_iter = inst->_cbegin(); bag_iter != inst->_cend(); ++bag_iter) { - auto bag_inst = bag_iter->second; - if (bag_inst == nullptr) { continue; } + EQ::ItemInstance* bag_inst = bag_iter->second; + if (!bag_inst) { + continue; + } if (bag_inst->GetID() == item_id) { quantity_found += (bag_inst->GetCharges() <= 0) ? 1 : bag_inst->GetCharges(); - if (quantity_found >= quantity) + if (quantity_found >= quantity) { return InventoryProfile::CalcSlotId(iter->first, bag_iter->first); + } } for (int index = invaug::SOCKET_BEGIN; index <= invaug::SOCKET_END; ++index) { - if (bag_inst->GetAugmentItemID(index) == item_id && quantity <= 1) + if (bag_inst->GetAugmentItemID(index) == item_id && quantity <= 1) { return invslot::SLOT_AUGMENT_GENERIC_RETURN; + } } } } @@ -1539,35 +1544,45 @@ int16 EQ::InventoryProfile::_HasItem(ItemInstQueue& iqueue, uint32 item_id, uint uint32 quantity_found = 0; for (auto iter = iqueue.cbegin(); iter != iqueue.cend(); ++iter) { - auto inst = *iter; - if (inst == nullptr) { continue; } + EQ::ItemInstance* inst = *iter; + if (!inst) { + continue; + } if (inst->GetID() == item_id) { quantity_found += (inst->GetCharges() <= 0) ? 1 : inst->GetCharges(); - if (quantity_found >= quantity) + if (quantity_found >= quantity) { return invslot::slotCursor; + } } for (int index = invaug::SOCKET_BEGIN; index <= invaug::SOCKET_END; ++index) { - if (inst->GetAugmentItemID(index) == item_id && quantity <= 1) + if (inst->GetAugmentItemID(index) == item_id && quantity <= 1) { return invslot::SLOT_AUGMENT_GENERIC_RETURN; + } } - if (!inst->IsClassBag()) { continue; } + if (!inst->IsClassBag()) { + continue; + } for (auto bag_iter = inst->_cbegin(); bag_iter != inst->_cend(); ++bag_iter) { - auto bag_inst = bag_iter->second; - if (bag_inst == nullptr) { continue; } + EQ::ItemInstance* bag_inst = bag_iter->second; + if (!bag_inst) { + continue; + } if (bag_inst->GetID() == item_id) { quantity_found += (bag_inst->GetCharges() <= 0) ? 1 : bag_inst->GetCharges(); - if (quantity_found >= quantity) + if (quantity_found >= quantity) { return InventoryProfile::CalcSlotId(invslot::slotCursor, bag_iter->first); + } } for (int index = invaug::SOCKET_BEGIN; index <= invaug::SOCKET_END; ++index) { - if (bag_inst->GetAugmentItemID(index) == item_id && quantity <= 1) + if (bag_inst->GetAugmentItemID(index) == item_id && quantity <= 1) { return invslot::SLOT_AUGMENT_GENERIC_RETURN; + } } } @@ -1584,34 +1599,43 @@ int16 EQ::InventoryProfile::_HasItemByUse(std::map& bucket uint32 quantity_found = 0; for (auto iter = bucket.begin(); iter != bucket.end(); ++iter) { - if (iter->first <= EQ::invslot::POSSESSIONS_END && iter->first >= EQ::invslot::POSSESSIONS_BEGIN) { - if ((((uint64)1 << iter->first) & m_lookup->PossessionsBitmask) == 0) + if (EQ::ValueWithin(iter->first, EQ::invslot::POSSESSIONS_BEGIN, EQ::invslot::POSSESSIONS_END)) { + if ((((uint64) 1 << iter->first) & m_lookup->PossessionsBitmask) == 0) { continue; - } - else if (iter->first <= EQ::invslot::BANK_END && iter->first >= EQ::invslot::BANK_BEGIN) { - if (iter->first - EQ::invslot::BANK_BEGIN >= m_lookup->InventoryTypeSize.Bank) + } + } else if (EQ::ValueWithin(iter->first, EQ::invslot::BANK_BEGIN, EQ::invslot::BANK_END)) { + if (iter->first - EQ::invslot::BANK_BEGIN >= m_lookup->InventoryTypeSize.Bank) { continue; + } } - auto inst = iter->second; - if (inst == nullptr) { continue; } + EQ::ItemInstance* inst = iter->second; + if (!inst) { + continue; + } if (inst->IsClassCommon() && inst->GetItem()->ItemType == use) { quantity_found += (inst->GetCharges() <= 0) ? 1 : inst->GetCharges(); - if (quantity_found >= quantity) + if (quantity_found >= quantity) { return iter->first; + } } - if (!inst->IsClassBag()) { continue; } + if (!inst->IsClassBag()) { + continue; + } for (auto bag_iter = inst->_cbegin(); bag_iter != inst->_cend(); ++bag_iter) { - auto bag_inst = bag_iter->second; - if (bag_inst == nullptr) { continue; } + EQ::ItemInstance* bag_inst = bag_iter->second; + if (!bag_inst) { + continue; + } if (bag_inst->IsClassCommon() && bag_inst->GetItem()->ItemType == use) { quantity_found += (bag_inst->GetCharges() <= 0) ? 1 : bag_inst->GetCharges(); - if (quantity_found >= quantity) + if (quantity_found >= quantity) { return InventoryProfile::CalcSlotId(iter->first, bag_iter->first); + } } } } @@ -1625,25 +1649,33 @@ int16 EQ::InventoryProfile::_HasItemByUse(ItemInstQueue& iqueue, uint8 use, uint uint32 quantity_found = 0; for (auto iter = iqueue.cbegin(); iter != iqueue.cend(); ++iter) { - auto inst = *iter; - if (inst == nullptr) { continue; } + EQ::ItemInstance* inst = *iter; + if (!inst) { + continue; + } if (inst->IsClassCommon() && inst->GetItem()->ItemType == use) { quantity_found += (inst->GetCharges() <= 0) ? 1 : inst->GetCharges(); - if (quantity_found >= quantity) + if (quantity_found >= quantity) { return invslot::slotCursor; + } } - if (!inst->IsClassBag()) { continue; } + if (!inst->IsClassBag()) { + continue; + } for (auto bag_iter = inst->_cbegin(); bag_iter != inst->_cend(); ++bag_iter) { - auto bag_inst = bag_iter->second; - if (bag_inst == nullptr) { continue; } + EQ::ItemInstance* bag_inst = bag_iter->second; + if (!bag_inst) { + continue; + } if (bag_inst->IsClassCommon() && bag_inst->GetItem()->ItemType == use) { quantity_found += (bag_inst->GetCharges() <= 0) ? 1 : bag_inst->GetCharges(); - if (quantity_found >= quantity) + if (quantity_found >= quantity) { return InventoryProfile::CalcSlotId(invslot::slotCursor, bag_iter->first); + } } } @@ -1657,44 +1689,57 @@ int16 EQ::InventoryProfile::_HasItemByUse(ItemInstQueue& iqueue, uint8 use, uint int16 EQ::InventoryProfile::_HasItemByLoreGroup(std::map& bucket, uint32 loregroup) { for (auto iter = bucket.begin(); iter != bucket.end(); ++iter) { - if (iter->first <= EQ::invslot::POSSESSIONS_END && iter->first >= EQ::invslot::POSSESSIONS_BEGIN) { - if ((((uint64)1 << iter->first) & m_lookup->PossessionsBitmask) == 0) + if (EQ::ValueWithin(iter->first, EQ::invslot::POSSESSIONS_BEGIN, EQ::invslot::POSSESSIONS_END)) { + if ((((uint64) 1 << iter->first) & m_lookup->PossessionsBitmask) == 0) { continue; - } - else if (iter->first <= EQ::invslot::BANK_END && iter->first >= EQ::invslot::BANK_BEGIN) { - if (iter->first - EQ::invslot::BANK_BEGIN >= m_lookup->InventoryTypeSize.Bank) + } + } else if (EQ::ValueWithin(iter->first, EQ::invslot::BANK_BEGIN, EQ::invslot::BANK_END)) { + if (iter->first - EQ::invslot::BANK_BEGIN >= m_lookup->InventoryTypeSize.Bank) { continue; + } } - auto inst = iter->second; - if (inst == nullptr) { continue; } + EQ::ItemInstance* inst = iter->second; + if (!inst) { + continue; + } - if (inst->GetItem()->LoreGroup == loregroup) + if (inst->GetItem()->LoreGroup == loregroup) { return iter->first; + } for (int index = invaug::SOCKET_BEGIN; index <= invaug::SOCKET_END; ++index) { auto aug_inst = inst->GetAugment(index); if (aug_inst == nullptr) { continue; } - if (aug_inst->GetItem()->LoreGroup == loregroup) + if (aug_inst->GetItem()->LoreGroup == loregroup) { return invslot::SLOT_AUGMENT_GENERIC_RETURN; + } } - if (!inst->IsClassBag()) { continue; } + if (!inst->IsClassBag()) { + continue; + } for (auto bag_iter = inst->_cbegin(); bag_iter != inst->_cend(); ++bag_iter) { - auto bag_inst = bag_iter->second; - if (bag_inst == nullptr) { continue; } + EQ::ItemInstance* bag_inst = bag_iter->second; + if (!bag_inst) { + continue; + } - if (bag_inst->IsClassCommon() && bag_inst->GetItem()->LoreGroup == loregroup) + if (bag_inst->IsClassCommon() && bag_inst->GetItem()->LoreGroup == loregroup) { return InventoryProfile::CalcSlotId(iter->first, bag_iter->first); + } for (int index = invaug::SOCKET_BEGIN; index <= invaug::SOCKET_END; ++index) { - auto aug_inst = bag_inst->GetAugment(index); - if (aug_inst == nullptr) { continue; } + EQ::ItemInstance* aug_inst = bag_inst->GetAugment(index); + if (!aug_inst) { + continue; + } - if (aug_inst->GetItem()->LoreGroup == loregroup) + if (aug_inst->GetItem()->LoreGroup == loregroup) { return invslot::SLOT_AUGMENT_GENERIC_RETURN; + } } } } @@ -1706,35 +1751,49 @@ int16 EQ::InventoryProfile::_HasItemByLoreGroup(std::map& int16 EQ::InventoryProfile::_HasItemByLoreGroup(ItemInstQueue& iqueue, uint32 loregroup) { for (auto iter = iqueue.cbegin(); iter != iqueue.cend(); ++iter) { - auto inst = *iter; - if (inst == nullptr) { continue; } - - if (inst->GetItem()->LoreGroup == loregroup) - return invslot::slotCursor; - - for (int index = invaug::SOCKET_BEGIN; index <= invaug::SOCKET_END; ++index) { - auto aug_inst = inst->GetAugment(index); - if (aug_inst == nullptr) { continue; } - - if (aug_inst->GetItem()->LoreGroup == loregroup) - return invslot::SLOT_AUGMENT_GENERIC_RETURN; + EQ::ItemInstance* inst = *iter; + if (!inst) { + continue; } - if (!inst->IsClassBag()) { continue; } + if (inst->GetItem()->LoreGroup == loregroup) { + return invslot::slotCursor; + } + + for (int index = invaug::SOCKET_BEGIN; index <= invaug::SOCKET_END; ++index) { + EQ::ItemInstance* aug_inst = inst->GetAugment(index); + if (!aug_inst) { + continue; + } + + if (aug_inst->GetItem()->LoreGroup == loregroup) { + return invslot::SLOT_AUGMENT_GENERIC_RETURN; + } + } + + if (!inst->IsClassBag()) { + continue; + } for (auto bag_iter = inst->_cbegin(); bag_iter != inst->_cend(); ++bag_iter) { - auto bag_inst = bag_iter->second; - if (bag_inst == nullptr) { continue; } + EQ::ItemInstance* bag_inst = bag_iter->second; + if (!bag_inst) { + continue; + } - if (bag_inst->IsClassCommon() && bag_inst->GetItem()->LoreGroup == loregroup) + if (bag_inst->IsClassCommon() && bag_inst->GetItem()->LoreGroup == loregroup) { return InventoryProfile::CalcSlotId(invslot::slotCursor, bag_iter->first); + } for (int index = invaug::SOCKET_BEGIN; index <= invaug::SOCKET_END; ++index) { - auto aug_inst = bag_inst->GetAugment(index); - if (aug_inst == nullptr) { continue; } + EQ::ItemInstance* aug_inst = bag_inst->GetAugment(index); + if (!aug_inst) { + continue; + } - if (aug_inst->GetItem()->LoreGroup == loregroup) + if (aug_inst->GetItem()->LoreGroup == loregroup) { return invslot::SLOT_AUGMENT_GENERIC_RETURN; + } } } @@ -1759,42 +1818,9 @@ std::vector EQ::InventoryProfile::GetAugmentIDsBySlotID(int16 slot_id) return augments; } -std::vector EQ::InventoryProfile::FindAllFreeSlotsThatFitItem(const EQ::ItemData *item_data) -{ - std::vector free_slots{}; - for (int16 i = EQ::invslot::GENERAL_BEGIN; i <= EQ::invslot::GENERAL_END; i++) { - if ((((uint64) 1 << i) & GetLookup()->PossessionsBitmask) == 0) { - continue; - } - - EQ::ItemInstance *inv_item = GetItem(i); - - if (!inv_item) { - // Found available slot in personal inventory - free_slots.push_back(i); - } - - if (inv_item->IsClassBag() && - EQ::InventoryProfile::CanItemFitInContainer(item_data, inv_item->GetItem())) { - - int16 base_slot_id = EQ::InventoryProfile::CalcSlotId(i, EQ::invbag::SLOT_BEGIN); - uint8 bag_size = inv_item->GetItem()->BagSlots; - - for (uint8 bag_slot = EQ::invbag::SLOT_BEGIN; bag_slot < bag_size; bag_slot++) { - auto bag_item = GetItem(base_slot_id + bag_slot); - if (!bag_item) { - // Found available slot within bag - free_slots.push_back(i); - } - } - } - } - return free_slots; -} - int16 EQ::InventoryProfile::FindFirstFreeSlotThatFitsItem(const EQ::ItemData *item_data) { - for (int16 i = EQ::invslot::GENERAL_BEGIN; i <= EQ::invslot::GENERAL_END; i++) { + for (int16 i = EQ::invslot::GENERAL_BEGIN; i <= EQ::invslot::GENERAL_END; i++) { if ((((uint64) 1 << i) & GetLookup()->PossessionsBitmask) == 0) { continue; } diff --git a/common/inventory_profile.h b/common/inventory_profile.h index 8e364aa5a..887afd512 100644 --- a/common/inventory_profile.h +++ b/common/inventory_profile.h @@ -178,7 +178,6 @@ namespace EQ // Locate an available inventory slot int16 FindFreeSlot(bool for_bag, bool try_cursor, uint8 min_size = 0, bool is_arrow = false); int16 FindFreeSlotForTradeItem(const ItemInstance* inst, int16 general_start = invslot::GENERAL_BEGIN, uint8 bag_start = invbag::SLOT_BEGIN); - std::vector FindAllFreeSlotsThatFitItem(const EQ::ItemData *inst); int16 FindFirstFreeSlotThatFitsItem(const EQ::ItemData *inst); // Calculate slot_id for an item within a bag @@ -201,12 +200,6 @@ namespace EQ uint8 FindBrightestLightType(); - void dumpEntireInventory(); - void dumpWornItems(); - void dumpInventory(); - void dumpBankItems(); - void dumpSharedBankItems(); - void SetCustomItemData(uint32 character_id, int16 slot_id, const std::string &identifier, const std::string& value); void SetCustomItemData(uint32 character_id, int16 slot_id, const std::string &identifier, int value); void SetCustomItemData(uint32 character_id, int16 slot_id, const std::string &identifier, float value); @@ -226,8 +219,6 @@ namespace EQ /////////////////////////////// int GetSlotByItemInstCollection(const std::map &collection, ItemInstance *inst); - void dumpItemCollection(const std::map &collection); - void dumpBagContents(ItemInstance *inst, std::map::const_iterator *it); // Retrieves item within an inventory bucket ItemInstance* _GetItem(const std::map& bucket, int16 slot_id) const; diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 7803b63e9..36e461f2e 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -1658,11 +1658,6 @@ void Client::Handle_Connect_OP_ZoneEntry(const EQApplicationPacket *app) m_pp.abilitySlotRefresh = 0; } -#ifdef _EQDEBUG - printf("Dumping inventory on load:\n"); - m_inv.dumpEntireInventory(); -#endif - /* Reset to max so they dont drown on zone in if its underwater */ m_pp.air_remaining = 60; /* Check for PVP Zone status*/