improve containers

This commit is contained in:
Henrique Santiago
2012-01-12 22:31:39 -02:00
parent b812d60690
commit ea70f90e92
14 changed files with 169 additions and 36 deletions

View File

@@ -125,7 +125,7 @@ void Game::processTextMessage(const std::string& type, const std::string& messag
void Game::processContainerAddItem(int containerId, const ItemPtr& item)
{
if(item)
item->setPos(Position(65535, containerId, 0));
item->setPos(Position(65535, containerId + 0x40, 0));
g_lua.callGlobalField("Game", "onContainerAddItem", containerId, item);
}
@@ -250,6 +250,16 @@ void Game::look(const ThingPtr& thing)
m_protocolGame->sendLookAt(thing->getPos(), thing->getId(), stackpos);
}
void Game::open(const ThingPtr& thing, int containerId)
{
if(!m_online || !thing || !checkBotProtection())
return;
int stackpos = getThingStackpos(thing);
if(stackpos != -1)
m_protocolGame->sendUseItem(thing->getPos(), thing->getId(), stackpos, containerId);
}
void Game::use(const ThingPtr& thing)
{
if(!m_online || !thing || !checkBotProtection())
@@ -257,7 +267,7 @@ void Game::use(const ThingPtr& thing)
int stackpos = getThingStackpos(thing);
if(stackpos != -1)
m_protocolGame->sendUseItem(thing->getPos(), thing->getId(), stackpos, 0);// last 0 has something to do with container
m_protocolGame->sendUseItem(thing->getPos(), thing->getId(), stackpos, 0);
}
void Game::useWith(const ThingPtr& fromThing, const ThingPtr& toThing)

View File

@@ -57,6 +57,7 @@ public:
void walk(Otc::Direction direction);
void turn(Otc::Direction direction);
void look(const ThingPtr& thing);
void open(const ThingPtr& thing, int containerId);
void use(const ThingPtr& thing);
void useWith(const ThingPtr& fromThing, const ThingPtr& toThing);
void attack(const CreaturePtr& creature);

View File

@@ -179,6 +179,7 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction<Game>("openOutfitWindow", std::bind(&Game::openOutfitWindow, &g_game));
g_lua.bindClassStaticFunction<Game>("setOutfit", std::bind(&Game::setOutfit, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("look", std::bind(&Game::look, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("open", std::bind(&Game::open, &g_game, _1, _2));
g_lua.bindClassStaticFunction<Game>("use", std::bind(&Game::use, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("useWith", std::bind(&Game::useWith, &g_game, _1, _2));
g_lua.bindClassStaticFunction<Game>("attack", std::bind(&Game::attack, &g_game, _1));

View File

@@ -441,7 +441,7 @@ void ProtocolGame::parseOpenContainer(InputMessage& msg)
for(int i = 0; i < itemCount; i++) {
ItemPtr item = internalGetItem(msg);
g_lua.callGlobalField("Game", "onContainerAddItem", containerId, item);
g_game.processContainerAddItem(containerId, item);
}
}
@@ -455,7 +455,7 @@ void ProtocolGame::parseContainerAddItem(InputMessage& msg)
{
int containerId = msg.getU8();
ItemPtr item = internalGetItem(msg);
g_lua.callGlobalField("Game", "onContainerAddItem", containerId, item);
g_game.processContainerAddItem(containerId, item);
}
void ProtocolGame::parseContainerUpdateItem(InputMessage& msg)
@@ -470,7 +470,7 @@ void ProtocolGame::parseContainerRemoveItem(InputMessage& msg)
{
int containerId = msg.getU8();
int slot = msg.getU8();
g_lua.callGlobalField("Game", "onContainerUpdateItem", containerId, slot);
g_lua.callGlobalField("Game", "onContainerRemoveItem", containerId, slot);
}
void ProtocolGame::parseAddInventoryItem(InputMessage& msg)

View File

@@ -98,7 +98,7 @@ public:
return Otc::InvalidDirection;
}
bool isValid() const { return x >= 0 && y >= 0 && z >= 0 && x < 65536 && y < 65536 && z < 16; }
bool isValid() const { return x >= 0 && y >= 0 && z >= 0 && x <= 65535 && y <= 65535 && z <= 255; }
Position operator+(const Position& other) const { return Position(x + other.x, y + other.y, z + other.z); }
Position& operator+=(const Position& other) { x+=other.x; y+=other.y; z +=other.z; return *this; }