From 2dde63d2bc7f83ca51d9baf88a5b14d8e026841a Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Tue, 5 Jun 2012 16:21:11 -0300 Subject: [PATCH] more changes in container API --- src/otclient/core/container.cpp | 13 ++++++++----- src/otclient/core/container.h | 19 +++++++------------ src/otclient/core/game.cpp | 7 +------ src/otclient/luafunctions.cpp | 9 ++------- 4 files changed, 18 insertions(+), 30 deletions(-) diff --git a/src/otclient/core/container.cpp b/src/otclient/core/container.cpp index b71ac9d5..4e21ba13 100644 --- a/src/otclient/core/container.cpp +++ b/src/otclient/core/container.cpp @@ -23,12 +23,14 @@ #include "container.h" #include "item.h" -Container::Container() +Container::Container(int id, int capacity, const std::string& name, const ItemPtr& containerItem, bool hasParent) { - m_id = -1; - m_capacity = 20; - m_name = "Container"; - m_hasParent = false; + m_id = id; + m_capacity = capacity; + m_name = name; + m_containerItem = containerItem; + m_hasParent = hasParent; + m_closed = false; } ItemPtr Container::getItem(int slot) @@ -45,6 +47,7 @@ void Container::onOpen(const ContainerPtr& previousContainer) void Container::onClose() { + m_closed = true; callLuaField("onClose"); } diff --git a/src/otclient/core/container.h b/src/otclient/core/container.h index f63586d3..e75f6b07 100644 --- a/src/otclient/core/container.h +++ b/src/otclient/core/container.h @@ -29,26 +29,20 @@ class Container : public LuaObject { -public: - Container(); +protected: + Container(int id, int capacity, const std::string& name, const ItemPtr& containerItem, bool hasParent); +public: ItemPtr getItem(int slot); std::deque getItems() { return m_items; } - + int getItemsCount() { return m_items.size(); } Position getSlotPosition(int slot) { return Position(0xffff, m_id | 0x40, slot); } - - void setId(int id) { m_id = id; } - void setCapacity(int capacity) { m_capacity = capacity; } - void setName(std::string name) { m_name = name; } - void setContainerItem(const ItemPtr& containerItem) { m_containerItem = containerItem; } - void setHasParent(bool hasParent) { m_hasParent = hasParent; } - - std::string getName() { return m_name; } int getId() { return m_id; } int getCapacity() { return m_capacity; } - int getItemsCount() { return m_items.size(); } ItemPtr getContainerItem() { return m_containerItem; } + std::string getName() { return m_name; } bool hasParent() { return m_hasParent; } + bool isClosed() { return m_closed; } protected: void onOpen(const ContainerPtr& previousContainer); @@ -68,6 +62,7 @@ private: ItemPtr m_containerItem; std::string m_name; bool m_hasParent; + bool m_closed; std::deque m_items; }; diff --git a/src/otclient/core/game.cpp b/src/otclient/core/game.cpp index 1da67f72..b097518c 100644 --- a/src/otclient/core/game.cpp +++ b/src/otclient/core/game.cpp @@ -173,12 +173,7 @@ void Game::processCreatureSpeak(const std::string& name, int level, Otc::SpeakTy void Game::processOpenContainer(int containerId, const ItemPtr& containerItem, const std::string& name, int capacity, bool hasParent, const std::vector& items) { ContainerPtr previousContainer = getContainer(containerId); - ContainerPtr container = ContainerPtr(new Container()); - container->setId(containerId); - container->setCapacity(capacity); - container->setName(name); - container->setContainerItem(containerItem); - container->setHasParent(hasParent); + ContainerPtr container = ContainerPtr(new Container(containerId, capacity, name, containerItem, hasParent)); m_containers[containerId] = container; container->onAddItems(items); diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index 9b97c21f..5ba735ac 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -187,21 +187,16 @@ void OTClient::registerLuaFunctions() g_lua.bindClassMemberFunction("getPosition", &ProtocolGame::getPosition); g_lua.registerClass(); - g_lua.bindClassStaticFunction("create", []{ return ContainerPtr(new Container); }); g_lua.bindClassMemberFunction("getItem", &Container::getItem); g_lua.bindClassMemberFunction("getItems", &Container::getItems); + g_lua.bindClassMemberFunction("getItemsCount", &Container::getItemsCount); g_lua.bindClassMemberFunction("getSlotPosition", &Container::getSlotPosition); - g_lua.bindClassMemberFunction("setId", &Container::setId); - g_lua.bindClassMemberFunction("setCapacity", &Container::setCapacity); - g_lua.bindClassMemberFunction("setName", &Container::setName); - g_lua.bindClassMemberFunction("setContainerItem", &Container::setContainerItem); - g_lua.bindClassMemberFunction("setHasParent", &Container::setHasParent); g_lua.bindClassMemberFunction("getName", &Container::getName); g_lua.bindClassMemberFunction("getId", &Container::getId); g_lua.bindClassMemberFunction("getCapacity", &Container::getCapacity); - g_lua.bindClassMemberFunction("getItemsCount", &Container::getItemsCount); g_lua.bindClassMemberFunction("getContainerItem", &Container::getContainerItem); g_lua.bindClassMemberFunction("hasParent", &Container::hasParent); + g_lua.bindClassMemberFunction("isClosed", &Container::isClosed); g_lua.registerClass(); g_lua.bindClassMemberFunction("setId", &Thing::setId);