Skip to content

Commit

Permalink
Review Changes
Browse files Browse the repository at this point in the history
Updates to resolve review comments and a rebase.
  • Loading branch information
neckkola committed Dec 14, 2024
1 parent 642f1c2 commit a17d490
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 86 deletions.
18 changes: 0 additions & 18 deletions common/evolving.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
17 changes: 0 additions & 17 deletions common/evolving.h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
120 changes: 73 additions & 47 deletions common/inventory_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int16, ItemInstance*>& bucket, uint64 evolve_unique_id, uint8 quantity)
int16 EQ::InventoryProfile::_HasEvolvingItem(
std::map<int16, ItemInstance *> &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;
}
}
}
}
Expand All @@ -1927,7 +1945,7 @@ int16 EQ::InventoryProfile::_HasEvolvingItem(std::map<int16, ItemInstance*>& 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
Expand All @@ -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;
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions common/inventory_profile.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class ItemInstQueue

inline std::list<EQ::ItemInstance*>::const_iterator cbegin() { return m_list.cbegin(); }
inline std::list<EQ::ItemInstance*>::const_iterator cend() { return m_list.cend(); }
inline std::list<EQ::ItemInstance*>::iterator begin() { return m_list.begin(); }
inline std::list<EQ::ItemInstance*>::iterator end() { return m_list.end(); }

inline int size() { return static_cast<int>(m_list.size()); } // TODO: change to size_t
inline bool empty() { return m_list.empty(); }
Expand Down
5 changes: 2 additions & 3 deletions common/shareddb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion common/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* Manifest: https://github.com/EQEmu/Server/blob/master/utils/sql/db_update_manifest.txt
*/

#define CURRENT_BINARY_DATABASE_VERSION 9286
#define CURRENT_BINARY_DATABASE_VERSION 9287
#define CURRENT_BINARY_BOTS_DATABASE_VERSION 9045

#endif
Expand Down

0 comments on commit a17d490

Please sign in to comment.