more changes in container API
This commit is contained in:
parent
86cade0aa9
commit
2dde63d2bc
|
@ -23,12 +23,14 @@
|
||||||
#include "container.h"
|
#include "container.h"
|
||||||
#include "item.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_id = id;
|
||||||
m_capacity = 20;
|
m_capacity = capacity;
|
||||||
m_name = "Container";
|
m_name = name;
|
||||||
m_hasParent = false;
|
m_containerItem = containerItem;
|
||||||
|
m_hasParent = hasParent;
|
||||||
|
m_closed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemPtr Container::getItem(int slot)
|
ItemPtr Container::getItem(int slot)
|
||||||
|
@ -45,6 +47,7 @@ void Container::onOpen(const ContainerPtr& previousContainer)
|
||||||
|
|
||||||
void Container::onClose()
|
void Container::onClose()
|
||||||
{
|
{
|
||||||
|
m_closed = true;
|
||||||
callLuaField("onClose");
|
callLuaField("onClose");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,26 +29,20 @@
|
||||||
|
|
||||||
class Container : public LuaObject
|
class Container : public LuaObject
|
||||||
{
|
{
|
||||||
public:
|
protected:
|
||||||
Container();
|
Container(int id, int capacity, const std::string& name, const ItemPtr& containerItem, bool hasParent);
|
||||||
|
|
||||||
|
public:
|
||||||
ItemPtr getItem(int slot);
|
ItemPtr getItem(int slot);
|
||||||
std::deque<ItemPtr> getItems() { return m_items; }
|
std::deque<ItemPtr> getItems() { return m_items; }
|
||||||
|
int getItemsCount() { return m_items.size(); }
|
||||||
Position getSlotPosition(int slot) { return Position(0xffff, m_id | 0x40, slot); }
|
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 getId() { return m_id; }
|
||||||
int getCapacity() { return m_capacity; }
|
int getCapacity() { return m_capacity; }
|
||||||
int getItemsCount() { return m_items.size(); }
|
|
||||||
ItemPtr getContainerItem() { return m_containerItem; }
|
ItemPtr getContainerItem() { return m_containerItem; }
|
||||||
|
std::string getName() { return m_name; }
|
||||||
bool hasParent() { return m_hasParent; }
|
bool hasParent() { return m_hasParent; }
|
||||||
|
bool isClosed() { return m_closed; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onOpen(const ContainerPtr& previousContainer);
|
void onOpen(const ContainerPtr& previousContainer);
|
||||||
|
@ -68,6 +62,7 @@ private:
|
||||||
ItemPtr m_containerItem;
|
ItemPtr m_containerItem;
|
||||||
std::string m_name;
|
std::string m_name;
|
||||||
bool m_hasParent;
|
bool m_hasParent;
|
||||||
|
bool m_closed;
|
||||||
std::deque<ItemPtr> m_items;
|
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)
|
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 previousContainer = getContainer(containerId);
|
||||||
ContainerPtr container = ContainerPtr(new Container());
|
ContainerPtr container = ContainerPtr(new Container(containerId, capacity, name, containerItem, hasParent));
|
||||||
container->setId(containerId);
|
|
||||||
container->setCapacity(capacity);
|
|
||||||
container->setName(name);
|
|
||||||
container->setContainerItem(containerItem);
|
|
||||||
container->setHasParent(hasParent);
|
|
||||||
m_containers[containerId] = container;
|
m_containers[containerId] = container;
|
||||||
container->onAddItems(items);
|
container->onAddItems(items);
|
||||||
|
|
||||||
|
|
|
@ -187,21 +187,16 @@ void OTClient::registerLuaFunctions()
|
||||||
g_lua.bindClassMemberFunction<ProtocolGame>("getPosition", &ProtocolGame::getPosition);
|
g_lua.bindClassMemberFunction<ProtocolGame>("getPosition", &ProtocolGame::getPosition);
|
||||||
|
|
||||||
g_lua.registerClass<Container>();
|
g_lua.registerClass<Container>();
|
||||||
g_lua.bindClassStaticFunction<Container>("create", []{ return ContainerPtr(new Container); });
|
|
||||||
g_lua.bindClassMemberFunction<Container>("getItem", &Container::getItem);
|
g_lua.bindClassMemberFunction<Container>("getItem", &Container::getItem);
|
||||||
g_lua.bindClassMemberFunction<Container>("getItems", &Container::getItems);
|
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>("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>("getName", &Container::getName);
|
||||||
g_lua.bindClassMemberFunction<Container>("getId", &Container::getId);
|
g_lua.bindClassMemberFunction<Container>("getId", &Container::getId);
|
||||||
g_lua.bindClassMemberFunction<Container>("getCapacity", &Container::getCapacity);
|
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>("getContainerItem", &Container::getContainerItem);
|
||||||
g_lua.bindClassMemberFunction<Container>("hasParent", &Container::hasParent);
|
g_lua.bindClassMemberFunction<Container>("hasParent", &Container::hasParent);
|
||||||
|
g_lua.bindClassMemberFunction<Container>("isClosed", &Container::isClosed);
|
||||||
|
|
||||||
g_lua.registerClass<Thing>();
|
g_lua.registerClass<Thing>();
|
||||||
g_lua.bindClassMemberFunction<Thing>("setId", &Thing::setId);
|
g_lua.bindClassMemberFunction<Thing>("setId", &Thing::setId);
|
||||||
|
|
Loading…
Reference in New Issue