From 551c0ef368d44b53f8a14785e815c4103f991637 Mon Sep 17 00:00:00 2001 From: KimLS Date: Thu, 19 Feb 2015 23:34:43 -0800 Subject: [PATCH] Basic arch work, doesn't make a ton of sense yet but it will --- common/CMakeLists.txt | 4 ++ common/inventory.cpp | 13 ------ common/inventory.h | 15 +++---- common/inventory_database_controller.cpp | 0 common/inventory_database_controller.h | 24 +++++++++++ common/item_container.cpp | 52 ++++++++++++++++++++++++ common/item_container.h | 42 +++++++++++++++++++ common/item_instance.h | 4 ++ 8 files changed, 132 insertions(+), 22 deletions(-) create mode 100644 common/inventory_database_controller.cpp create mode 100644 common/inventory_database_controller.h create mode 100644 common/item_container.cpp create mode 100644 common/item_container.h diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index a992b8feb..49828d082 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -31,8 +31,10 @@ SET(common_sources guild_base.cpp guilds.cpp inventory.cpp + inventory_database_controller.cpp ipc_mutex.cpp item.cpp + item_container.cpp item_instance.cpp md5.cpp memory_mapped_file.cpp @@ -138,8 +140,10 @@ SET(common_headers guild_base.h guilds.h inventory.h + inventory_database_controller.h ipc_mutex.h item.h + item_container.h item_data.h item_fieldlist.h item_instance.h diff --git a/common/inventory.cpp b/common/inventory.cpp index 5ca07becf..01d8474ad 100644 --- a/common/inventory.cpp +++ b/common/inventory.cpp @@ -23,16 +23,3 @@ EQEmu::Inventory::Inventory() { EQEmu::Inventory::~Inventory() { } - -std::shared_ptr EQEmu::Inventory::GetItem(InventoryType type, int16 slot) { - auto area = items_.find(type); - - if(area != items_.end()) { - auto item = area->second.find(slot); - if(item != area->second.end()) { - return item->second; - } - } - - return std::shared_ptr(nullptr); -} \ No newline at end of file diff --git a/common/inventory.h b/common/inventory.h index 163a5be57..edb252308 100644 --- a/common/inventory.h +++ b/common/inventory.h @@ -19,16 +19,15 @@ #ifndef COMMON_INVENTORY_H #define COMMON_INVENTORY_H -#include "item_instance.h" -#include -#include -#include +#include "item_container.h" + +#include namespace EQEmu { - enum InventoryType : int16 + enum InventoryType : int { - InvTypePersonal, + InvTypePersonal = 0, InvTypeBank, InvTypeSharedBank, InvTypeTrade, @@ -45,10 +44,8 @@ namespace EQEmu Inventory(); ~Inventory(); - std::shared_ptr GetItem(InventoryType type, int16 slot); - private: - std::map>> items_; + std::map containers_; }; } // EQEmu diff --git a/common/inventory_database_controller.cpp b/common/inventory_database_controller.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/common/inventory_database_controller.h b/common/inventory_database_controller.h new file mode 100644 index 000000000..d3337dd75 --- /dev/null +++ b/common/inventory_database_controller.h @@ -0,0 +1,24 @@ +/* EQEMu: Everquest Server Emulator + Copyright (C) 2001-2015 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 COMMON_INVENTORY_DATABASE_CONTROLLER_H +#define COMMON_INVENTORY_DATABASE_CONTROLLER_H + + + +#endif diff --git a/common/item_container.cpp b/common/item_container.cpp new file mode 100644 index 000000000..3349c7c7b --- /dev/null +++ b/common/item_container.cpp @@ -0,0 +1,52 @@ +#include "item_container.h" +#include +#include + +struct EQEmu::ItemContainer::impl +{ + std::map> items; +}; + +EQEmu::ItemContainer::ItemContainer() +{ + impl_ = new impl; +} + +EQEmu::ItemContainer::~ItemContainer() +{ + delete impl_; +} + +std::shared_ptr EQEmu::ItemContainer::Get(int slot_id) { + auto iter = impl_->items.find(slot_id); + if(iter != impl_->items.end()) { + return iter->second; + } + + return std::shared_ptr(nullptr); +} + +bool EQEmu::ItemContainer::Put(int slot_id, std::shared_ptr inst) { + if(!inst) + return false; + + auto iter = impl_->items.find(slot_id); + if(iter == impl_->items.end()) { + impl_->items[slot_id] = inst; + //trigger put in slot_id + return true; + } + + return false; +} + +bool EQEmu::ItemContainer::Delete(int slot_id) { + auto iter = impl_->items.find(slot_id); + if(iter == impl_->items.end()) { + return false; + } else { + impl_->items.erase(iter); + //trigger delete in slotid + return true; + } +} diff --git a/common/item_container.h b/common/item_container.h new file mode 100644 index 000000000..5a58b46c2 --- /dev/null +++ b/common/item_container.h @@ -0,0 +1,42 @@ +/* EQEMu: Everquest Server Emulator +Copyright (C) 2001-2015 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 COMMON_ITEM_CONTAINER_H +#define COMMON_ITEM_CONTAINER_H + +#include "item_instance.h" +#include + +namespace EQEmu +{ + class ItemContainer + { + public: + ItemContainer(); + ~ItemContainer(); + + std::shared_ptr Get(int slot_id); + bool Put(int slot_id, std::shared_ptr inst); + bool Delete(int slot_id); + private: + struct impl; + impl *impl_; + }; +} // EQEmu + +#endif diff --git a/common/item_instance.h b/common/item_instance.h index 582e80164..abae938ad 100644 --- a/common/item_instance.h +++ b/common/item_instance.h @@ -26,6 +26,7 @@ namespace EQEmu { + class ItemContainer; class ItemInstance { public: @@ -35,6 +36,7 @@ namespace EQEmu ~ItemInstance(); std::shared_ptr GetItem(int index); + void SetContainer(ItemContainer *parent) { parent_ = parent; } private: const ItemData *base_item_; ItemData *modified_item_; @@ -46,7 +48,9 @@ namespace EQEmu uint32 ornament_icon_; uint32 ornament_hero_model_; uint64 tracking_id_; + std::map> contents_; + ItemContainer *parent_; }; } // EQEmu