some cleanup
This commit is contained in:
parent
7ed81799b4
commit
e9411aa244
|
@ -306,19 +306,15 @@ void Game::look(const ThingPtr& thing)
|
|||
if(!isOnline() || !thing || !checkBotProtection())
|
||||
return;
|
||||
|
||||
int stackpos = getThingStackpos(thing);
|
||||
if(stackpos != -1)
|
||||
m_protocolGame->sendLookAt(thing->getPosition(), thing->getId(), stackpos);
|
||||
m_protocolGame->sendLookAt(thing->getPosition(), thing->getId(), thing->getStackpos());
|
||||
}
|
||||
|
||||
void Game::open(const ThingPtr& thing, int containerId)
|
||||
void Game::open(const ItemPtr& item, int containerId)
|
||||
{
|
||||
if(!isOnline() || !thing || !checkBotProtection())
|
||||
if(!isOnline() || !item || !checkBotProtection())
|
||||
return;
|
||||
|
||||
int stackpos = getThingStackpos(thing);
|
||||
if(stackpos != -1)
|
||||
m_protocolGame->sendUseItem(thing->getPosition(), thing->getId(), stackpos, containerId);
|
||||
m_protocolGame->sendUseItem(item->getPosition(), item->getId(), item->getStackpos(), containerId);
|
||||
}
|
||||
|
||||
void Game::use(const ThingPtr& thing)
|
||||
|
@ -326,40 +322,44 @@ void Game::use(const ThingPtr& thing)
|
|||
if(!isOnline() || !thing || !checkBotProtection())
|
||||
return;
|
||||
|
||||
m_localPlayer->lockWalk();
|
||||
|
||||
int stackpos = getThingStackpos(thing);
|
||||
if(stackpos != -1)
|
||||
m_protocolGame->sendUseItem(thing->getPosition(), thing->getId(), stackpos, 0);
|
||||
}
|
||||
|
||||
void Game::useWith(const ThingPtr& fromThing, const ThingPtr& toThing)
|
||||
{
|
||||
if(!isOnline() || !fromThing || !toThing || !checkBotProtection())
|
||||
return;
|
||||
|
||||
Position pos = fromThing->getPosition();
|
||||
Position pos = thing->getPosition();
|
||||
if(!pos.isValid()) // virtual item
|
||||
pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
|
||||
|
||||
int fromStackpos = getThingStackpos(fromThing);
|
||||
if(fromStackpos == -1)
|
||||
m_localPlayer->lockWalk();
|
||||
|
||||
m_protocolGame->sendUseItem(pos, thing->getId(), thing->getStackpos(), 0);
|
||||
}
|
||||
|
||||
void Game::useInventoryItem(int itemId)
|
||||
{
|
||||
if(!isOnline() || !checkBotProtection())
|
||||
return;
|
||||
|
||||
Position pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
|
||||
m_localPlayer->lockWalk();
|
||||
|
||||
m_protocolGame->sendUseItem(pos, itemId, 0, 0);
|
||||
}
|
||||
|
||||
void Game::useWith(const ItemPtr& item, const ThingPtr& toThing)
|
||||
{
|
||||
if(!isOnline() || !item || !toThing || !checkBotProtection())
|
||||
return;
|
||||
|
||||
Position pos = item->getPosition();
|
||||
if(!pos.isValid()) // virtual item
|
||||
pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
|
||||
|
||||
m_localPlayer->lockWalk();
|
||||
|
||||
if(CreaturePtr creature = toThing->asCreature()) {
|
||||
m_protocolGame->sendUseOnCreature(pos, fromThing->getId(), fromStackpos, creature->getId());
|
||||
} else {
|
||||
int toStackpos = getThingStackpos(toThing);
|
||||
if(toStackpos == -1)
|
||||
return;
|
||||
|
||||
m_protocolGame->sendUseItemEx(pos, fromThing->getId(), fromStackpos, toThing->getPosition(), toThing->getId(), toStackpos);
|
||||
}
|
||||
if(CreaturePtr creature = toThing->asCreature())
|
||||
m_protocolGame->sendUseOnCreature(pos, item->getId(), item->getStackpos(), creature->getId());
|
||||
else
|
||||
m_protocolGame->sendUseItemEx(pos, item->getId(), item->getStackpos(), toThing->getPosition(), toThing->getId(), toThing->getStackpos());
|
||||
}
|
||||
|
||||
void Game::useInventoryItem(int itemId, const ThingPtr& toThing)
|
||||
void Game::useInventoryItemWith(int itemId, const ThingPtr& toThing)
|
||||
{
|
||||
if(!isOnline() || !toThing || !checkBotProtection())
|
||||
return;
|
||||
|
@ -367,15 +367,11 @@ void Game::useInventoryItem(int itemId, const ThingPtr& toThing)
|
|||
m_localPlayer->lockWalk();
|
||||
|
||||
Position pos = Position(0xFFFF, 0, 0); // means that is a item in inventory
|
||||
int toStackpos = getThingStackpos(toThing);
|
||||
if(toStackpos == -1)
|
||||
return;
|
||||
|
||||
if(CreaturePtr creature = toThing->asCreature()) {
|
||||
if(CreaturePtr creature = toThing->asCreature())
|
||||
m_protocolGame->sendUseOnCreature(pos, itemId, 0, creature->getId());
|
||||
} else {
|
||||
m_protocolGame->sendUseItemEx(pos, itemId, 0, toThing->getPosition(), toThing->getId(), toStackpos);
|
||||
}
|
||||
else
|
||||
m_protocolGame->sendUseItemEx(pos, itemId, 0, toThing->getPosition(), toThing->getId(), toThing->getStackpos());
|
||||
}
|
||||
|
||||
void Game::move(const ThingPtr& thing, const Position& toPos, int count)
|
||||
|
@ -385,11 +381,7 @@ void Game::move(const ThingPtr& thing, const Position& toPos, int count)
|
|||
|
||||
m_localPlayer->lockWalk();
|
||||
|
||||
int stackpos = getThingStackpos(thing);
|
||||
if(stackpos == -1)
|
||||
return;
|
||||
|
||||
m_protocolGame->sendThrow(thing->getPosition(), thing->getId(), stackpos, toPos, count);
|
||||
m_protocolGame->sendThrow(thing->getPosition(), thing->getId(), thing->getStackpos(), toPos, count);
|
||||
}
|
||||
|
||||
void Game::attack(const CreaturePtr& creature)
|
||||
|
@ -440,26 +432,7 @@ void Game::rotate(const ThingPtr& thing)
|
|||
if(!isOnline() || !thing || !checkBotProtection())
|
||||
return;
|
||||
|
||||
int stackpos = getThingStackpos(thing);
|
||||
if(stackpos != -1)
|
||||
m_protocolGame->sendRotateItem(thing->getPosition(), thing->getId(), stackpos);
|
||||
}
|
||||
|
||||
//TODO: move this to Thing class
|
||||
int Game::getThingStackpos(const ThingPtr& thing)
|
||||
{
|
||||
// thing is at map
|
||||
if(thing->getPosition().x != 65535) {
|
||||
if(TilePtr tile = g_map.getTile(thing->getPosition()))
|
||||
return tile->getThingStackpos(thing);
|
||||
else {
|
||||
logError("could not get tile");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// thing is at container or inventory
|
||||
return 0;
|
||||
m_protocolGame->sendRotateItem(thing->getPosition(), thing->getId(), thing->getStackpos());
|
||||
}
|
||||
|
||||
void Game::talk(const std::string& message)
|
||||
|
|
|
@ -67,10 +67,11 @@ public:
|
|||
|
||||
// item related
|
||||
void look(const ThingPtr& thing);
|
||||
void open(const ThingPtr& thing, int containerId);
|
||||
void open(const ItemPtr& item, int containerId);
|
||||
void use(const ThingPtr& thing);
|
||||
void useWith(const ThingPtr& fromThing, const ThingPtr& toThing);
|
||||
void useInventoryItem(int itemId, const ThingPtr& toThing);
|
||||
void useWith(const ItemPtr& fromThing, const ThingPtr& toThing);
|
||||
void useInventoryItem(int itemId);
|
||||
void useInventoryItemWith(int itemId, const ThingPtr& toThing);
|
||||
void move(const ThingPtr &thing, const Position& toPos, int count);
|
||||
|
||||
// attack/follow related
|
||||
|
@ -106,8 +107,6 @@ public:
|
|||
void addVip(const std::string& name);
|
||||
void removeVip(int playerId);
|
||||
|
||||
int getThingStackpos(const ThingPtr& thing);
|
||||
|
||||
bool checkBotProtection();
|
||||
|
||||
bool isOnline() { return !!m_localPlayer; }
|
||||
|
|
|
@ -55,10 +55,14 @@ const TilePtr& Thing::getTile()
|
|||
|
||||
int Thing::getStackpos()
|
||||
{
|
||||
const TilePtr& tile = getTile();
|
||||
if(tile)
|
||||
if(m_position.x == 65535 && asItem()) // is inside a container
|
||||
return 0;
|
||||
else if(const TilePtr& tile = getTile())
|
||||
return tile->getThingStackpos(asThing());
|
||||
return -1;
|
||||
else {
|
||||
logTraceError("got a thing with invalid stackpos");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
void Thing::internalDraw(const Point& dest, float scaleFactor, int w, int h, int xPattern, int yPattern, int zPattern, int layer, int animationPhase)
|
||||
|
|
|
@ -197,9 +197,10 @@ void OTClient::registerLuaFunctions()
|
|||
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>("useInventoryItem", std::bind(&Game::useInventoryItem, &g_game, _1));
|
||||
g_lua.bindClassStaticFunction<Game>("useWith", std::bind(&Game::useWith, &g_game, _1, _2));
|
||||
g_lua.bindClassStaticFunction<Game>("useInventoryItemWith", std::bind(&Game::useInventoryItemWith, &g_game, _1, _2));
|
||||
g_lua.bindClassStaticFunction<Game>("move", std::bind(&Game::move, &g_game, _1, _2, _3));
|
||||
g_lua.bindClassStaticFunction<Game>("useInventoryItem", std::bind(&Game::useInventoryItem, &g_game, _1, _2));
|
||||
g_lua.bindClassStaticFunction<Game>("turn", std::bind(&Game::turn, &g_game, _1));
|
||||
g_lua.bindClassStaticFunction<Game>("walk", std::bind(&Game::walk, &g_game, _1));
|
||||
g_lua.bindClassStaticFunction<Game>("forceWalk", std::bind(&Game::forceWalk, &g_game, _1));
|
||||
|
|
|
@ -65,7 +65,7 @@ public:
|
|||
void sendAcceptTrade();
|
||||
void sendRejectTrade();
|
||||
void sendUseItem(const Position& position, int itemId, int stackpos, int index);
|
||||
void sendUseItemEx(const Position& fromPos, int fromThingId, int fromStackpos, const Position& toPos, int toThingId, int toStackpos);
|
||||
void sendUseItemEx(const Position& fromPos, int itemId, int fromStackpos, const Position& toPos, int toThingId, int toStackpos);
|
||||
void sendUseOnCreature(const Position& pos, int thingId, int stackpos, uint creatureId);
|
||||
void sendRotateItem(const Position& pos, int thingId, int stackpos);
|
||||
void sendCloseContainer(int containerId);
|
||||
|
|
|
@ -262,12 +262,12 @@ void ProtocolGame::sendUseItem(const Position& position, int itemId, int stackpo
|
|||
send(oMsg);
|
||||
}
|
||||
|
||||
void ProtocolGame::sendUseItemEx(const Position& fromPos, int fromThingId, int fromStackpos, const Position& toPos, int toThingId, int toStackpos)
|
||||
void ProtocolGame::sendUseItemEx(const Position& fromPos, int itemId, int fromStackpos, const Position& toPos, int toThingId, int toStackpos)
|
||||
{
|
||||
OutputMessage oMsg;
|
||||
oMsg.addU8(Proto::ClientUseTwoObjects);
|
||||
addPosition(oMsg, fromPos);
|
||||
oMsg.addU16(fromThingId);
|
||||
oMsg.addU16(itemId);
|
||||
oMsg.addU8(fromStackpos);
|
||||
addPosition(oMsg, toPos);
|
||||
oMsg.addU16(toThingId);
|
||||
|
|
Loading…
Reference in New Issue