diff --git a/common/evolving.cpp b/common/evolving.cpp index 79b58ef342..db52e707f0 100644 --- a/common/evolving.cpp +++ b/common/evolving.cpp @@ -1,21 +1,3 @@ -/* EQEMu: Everquest Server Emulator - Copyright (C) 2001-2003 EQEMu Development Team (http://eqemulator.net) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY except by those people which sell it, which - are required to give you total support for your newly bought product; - without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - #include "evolving.h" #include "item_instance.h" #include "events/player_event_logs.h" diff --git a/common/evolving.h b/common/evolving.h index ab191af7d1..1db029b242 100644 --- a/common/evolving.h +++ b/common/evolving.h @@ -1,20 +1,3 @@ -/* EQEMu: Everquest Server Emulator -Copyright (C) 2001-2005 EQEMu Development Team (http://eqemulator.net) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; version 2 of the License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY except by those people which sell it, which - are required to give you total support for your newly bought product; - without even the implied warranty of MERCHANTABILITY or FITNESS FOR - A PARTICULAR PURPOSE. See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ #ifndef EVOLVING_H #define EVOLVING_H diff --git a/common/inventory_profile.cpp b/common/inventory_profile.cpp index 3e0533eb32..8b24d74cfc 100644 --- a/common/inventory_profile.cpp +++ b/common/inventory_profile.cpp @@ -1825,100 +1825,118 @@ int16 EQ::InventoryProfile::FindFirstFreeSlotThatFitsItem(const EQ::ItemData *it } //This function has the same flaw as noted above -//Helper functions for evolving items +// Helper functions for evolving items int16 EQ::InventoryProfile::HasEvolvingItem(uint64 evolve_unique_id, uint8 quantity, uint8 where) { int16 slot_id = INVALID_INDEX; - //Altered by Father Nitwit to support a specification of - //where to search, with a default value to maintain compatibility + // Altered by Father Nitwit to support a specification of + // where to search, with a default value to maintain compatibility // Check each inventory bucket if (where & invWhereWorn) { slot_id = _HasEvolvingItem(m_worn, evolve_unique_id, quantity); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } if (where & invWherePersonal) { slot_id = _HasEvolvingItem(m_inv, evolve_unique_id, quantity); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } if (where & invWhereBank) { slot_id = _HasEvolvingItem(m_bank, evolve_unique_id, quantity); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } if (where & invWhereSharedBank) { slot_id = _HasEvolvingItem(m_shbank, evolve_unique_id, quantity); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } if (where & invWhereTrading) { slot_id = _HasEvolvingItem(m_trade, evolve_unique_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 = _HasEvolvingItem(m_cursor, evolve_unique_id, quantity); - if (slot_id != INVALID_INDEX) + if (slot_id != INVALID_INDEX) { return slot_id; + } } return slot_id; } // Internal Method: Checks an inventory bucket for a particular evolving item unique id -int16 EQ::InventoryProfile::_HasEvolvingItem(std::map& bucket, uint64 evolve_unique_id, uint8 quantity) +int16 EQ::InventoryProfile::_HasEvolvingItem( + std::map &bucket, uint64 evolve_unique_id, uint8 quantity) { 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) + for (auto const &[key, value]: bucket) { + if (!value) { + continue; + } + + if (key <= EQ::invslot::POSSESSIONS_END && key >= EQ::invslot::POSSESSIONS_BEGIN) { + if (((uint64) 1 << key & 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 (key <= EQ::invslot::BANK_END && key >= EQ::invslot::BANK_BEGIN) { + if (key - EQ::invslot::BANK_BEGIN >= m_lookup->InventoryTypeSize.Bank) { continue; + } } - auto inst = iter->second; - if (inst == nullptr) { continue; } - if (inst->GetEvolveUniqueID() == evolve_unique_id) { - quantity_found += (inst->GetCharges() <= 0) ? 1 : inst->GetCharges(); - if (quantity_found >= quantity) - return iter->first; + if (value->GetEvolveUniqueID() == evolve_unique_id) { + quantity_found += value->GetCharges() <= 0 ? 1 : value->GetCharges(); + if (quantity_found >= quantity) { + return key; + } } for (int index = invaug::SOCKET_BEGIN; index <= invaug::SOCKET_END; ++index) { - if (inst->GetAugmentEvolveUniqueID(index) == evolve_unique_id && quantity <= 1) + if (value->GetAugmentEvolveUniqueID(index) == evolve_unique_id && quantity <= 1) { return invslot::SLOT_AUGMENT_GENERIC_RETURN; + } } - if (!inst->IsClassBag()) { continue; } + if (!value->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; } + for (auto const &[bag_key, bag_value]: *value->GetContents()) { + if (!bag_value) { + continue; + } - if (bag_inst->GetEvolveUniqueID() == evolve_unique_id) { - quantity_found += (bag_inst->GetCharges() <= 0) ? 1 : bag_inst->GetCharges(); - if (quantity_found >= quantity) - return CalcSlotId(iter->first, bag_iter->first); + if (bag_value->GetEvolveUniqueID() == evolve_unique_id) { + quantity_found += bag_value->GetCharges() <= 0 ? 1 : bag_value->GetCharges(); + if (quantity_found >= quantity) { + return CalcSlotId(key, bag_key); + } } for (int index = invaug::SOCKET_BEGIN; index <= invaug::SOCKET_END; ++index) { - if (bag_inst->GetAugmentEvolveUniqueID(index) == evolve_unique_id && quantity <= 1) + if (bag_value->GetAugmentEvolveUniqueID(index) == evolve_unique_id && quantity <= 1) { return invslot::SLOT_AUGMENT_GENERIC_RETURN; + } } } } @@ -1927,7 +1945,7 @@ int16 EQ::InventoryProfile::_HasEvolvingItem(std::map& buc } // Internal Method: Checks an inventory queue type bucket for a particular item -int16 EQ::InventoryProfile::_HasEvolvingItem(ItemInstQueue& iqueue, uint64 evolve_unique_id, uint8 quantity) +int16 EQ::InventoryProfile::_HasEvolvingItem(ItemInstQueue &iqueue, uint64 evolve_unique_id, uint8 quantity) { // The downfall of this (these) queue procedure is that callers presume that when an item is // found, it is presented as being available on the cursor. In cases of a parity check, this @@ -1937,36 +1955,44 @@ int16 EQ::InventoryProfile::_HasEvolvingItem(ItemInstQueue& iqueue, uint64 evolv uint32 quantity_found = 0; - for (auto iter = iqueue.cbegin(); iter != iqueue.cend(); ++iter) { - auto inst = *iter; - if (inst == nullptr) { continue; } + for (auto const &inst: iqueue) { + if (!inst) { + continue; + } if (inst->GetEvolveUniqueID() == evolve_unique_id) { - quantity_found += (inst->GetCharges() <= 0) ? 1 : inst->GetCharges(); - if (quantity_found >= quantity) + quantity_found += inst->GetCharges() <= 0 ? 1 : inst->GetCharges(); + if (quantity_found >= quantity) { return invslot::slotCursor; + } } for (int index = invaug::SOCKET_BEGIN; index <= invaug::SOCKET_END; ++index) { - if (inst->GetAugmentEvolveUniqueID(index) == evolve_unique_id && quantity <= 1) + if (inst->GetAugmentEvolveUniqueID(index) == evolve_unique_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; } + for (auto const &[bag_key, bag_value]: *inst->GetContents()) { + if (!bag_value) { + continue; + } - if (bag_inst->GetEvolveUniqueID() == evolve_unique_id) { - quantity_found += (bag_inst->GetCharges() <= 0) ? 1 : bag_inst->GetCharges(); - if (quantity_found >= quantity) - return CalcSlotId(invslot::slotCursor, bag_iter->first); + if (bag_value->GetEvolveUniqueID() == evolve_unique_id) { + quantity_found += bag_value->GetCharges() <= 0 ? 1 : bag_value->GetCharges(); + if (quantity_found >= quantity) { + return CalcSlotId(invslot::slotCursor, bag_key); + } } for (int index = invaug::SOCKET_BEGIN; index <= invaug::SOCKET_END; ++index) { - if (bag_inst->GetAugmentEvolveUniqueID(index) == evolve_unique_id && quantity <= 1) + if (bag_value->GetAugmentEvolveUniqueID(index) == evolve_unique_id && quantity <= 1) { return invslot::SLOT_AUGMENT_GENERIC_RETURN; + } } } diff --git a/common/inventory_profile.h b/common/inventory_profile.h index f5356b1335..267a468cbf 100644 --- a/common/inventory_profile.h +++ b/common/inventory_profile.h @@ -57,6 +57,8 @@ class ItemInstQueue inline std::list::const_iterator cbegin() { return m_list.cbegin(); } inline std::list::const_iterator cend() { return m_list.cend(); } + inline std::list::iterator begin() { return m_list.begin(); } + inline std::list::iterator end() { return m_list.end(); } inline int size() { return static_cast(m_list.size()); } // TODO: change to size_t inline bool empty() { return m_list.empty(); } diff --git a/common/shareddb.cpp b/common/shareddb.cpp index 7aeaf263d9..709f953d92 100644 --- a/common/shareddb.cpp +++ b/common/shareddb.cpp @@ -50,7 +50,6 @@ #include "repositories/skill_caps_repository.h" #include "repositories/inventory_repository.h" #include "repositories/books_repository.h" -#include "../zone/evolving.h" namespace ItemField { @@ -660,8 +659,8 @@ bool SharedDatabase::GetInventory(Client *c) EQ::InventoryProfile &inv = c->GetInv(); // Retrieve character inventory - auto results = InventoryRepository::GetWhere(*this, fmt::format("`charid` = '{}' ORDER BY `slotid`;", char_id)); - auto e_results = CharacterEvolvingItemsRepository::GetWhere(*this, fmt::format("`char_id` = '{}' AND `deleted_at` IS NULL;", char_id)); + auto results = InventoryRepository::GetWhere(*this, fmt::format("`charid` = '{}' ORDER BY `slotid`", char_id)); + auto e_results = CharacterEvolvingItemsRepository::GetWhere(*this, fmt::format("`char_id` = '{}' AND `deleted_at` IS NULL", char_id)); if (results.empty()) { LogError("Error loading inventory for char_id {} from the database.", char_id); diff --git a/common/version.h b/common/version.h index 91d4c7494e..4434579974 100644 --- a/common/version.h +++ b/common/version.h @@ -42,7 +42,7 @@ * Manifest: https://github.com/EQEmu/Server/blob/master/utils/sql/db_update_manifest.txt */ -#define CURRENT_BINARY_DATABASE_VERSION 9284 +#define CURRENT_BINARY_DATABASE_VERSION 9285 #define CURRENT_BINARY_BOTS_DATABASE_VERSION 9045 #endif