more changes in container API
This commit is contained in:
parent
86cade0aa9
commit
2dde63d2bc
|
@ -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");
|
||||
}
|
||||
|
||||
|
|
|
@ -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<ItemPtr> 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<ItemPtr> m_items;
|
||||
};
|
||||
|
||||
|
|
|
@ -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<ItemPtr>& 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);
|
||||
|
||||
|
|
|
@ -187,21 +187,16 @@ void OTClient::registerLuaFunctions()
|
|||
g_lua.bindClassMemberFunction<ProtocolGame>("getPosition", &ProtocolGame::getPosition);
|
||||
|
||||
g_lua.registerClass<Container>();
|
||||
g_lua.bindClassStaticFunction<Container>("create", []{ return ContainerPtr(new Container); });
|
||||
g_lua.bindClassMemberFunction<Container>("getItem", &Container::getItem);
|
||||
g_lua.bindClassMemberFunction<Container>("getItems", &Container::getItems);
|
||||
g_lua.bindClassMemberFunction<Container>("getItemsCount", &Container::getItemsCount);
|
||||
g_lua.bindClassMemberFunction<Container>("getSlotPosition", &Container::getSlotPosition);
|
||||
g_lua.bindClassMemberFunction<Container>("setId", &Container::setId);
|
||||
g_lua.bindClassMemberFunction<Container>("setCapacity", &Container::setCapacity);
|
||||
g_lua.bindClassMemberFunction<Container>("setName", &Container::setName);
|
||||
g_lua.bindClassMemberFunction<Container>("setContainerItem", &Container::setContainerItem);
|
||||
g_lua.bindClassMemberFunction<Container>("setHasParent", &Container::setHasParent);
|
||||
g_lua.bindClassMemberFunction<Container>("getName", &Container::getName);
|
||||
g_lua.bindClassMemberFunction<Container>("getId", &Container::getId);
|
||||
g_lua.bindClassMemberFunction<Container>("getCapacity", &Container::getCapacity);
|
||||
g_lua.bindClassMemberFunction<Container>("getItemsCount", &Container::getItemsCount);
|
||||
g_lua.bindClassMemberFunction<Container>("getContainerItem", &Container::getContainerItem);
|
||||
g_lua.bindClassMemberFunction<Container>("hasParent", &Container::hasParent);
|
||||
g_lua.bindClassMemberFunction<Container>("isClosed", &Container::isClosed);
|
||||
|
||||
g_lua.registerClass<Thing>();
|
||||
g_lua.bindClassMemberFunction<Thing>("setId", &Thing::setId);
|
||||
|
|
Loading…
Reference in New Issue