void ProtocolGame::sendMoveCreature(const Creature* creature, const Tile* newTile, const Position& newPos,
uint32_t newStackpos, const Tile* oldTile, const Position& oldPos, uint32_t oldStackpos, bool teleport)
{
if(creature == player)
{
NetworkMessage_ptr msg = getOutputBuffer();
if(msg)
{
TRACK_MESSAGE(msg);
if(teleport || oldStackpos >= 10)
{
//New Code
if (newPos.z > oldPos.z && newPos.z - oldPos.z == 1) {
msg.AddByte(0x6D);
msg.AddPosition(oldPos);
msg.AddByte(oldStackPos);
msg.AddPosition(newPos);
std::cout << "MoveDownCreature called" << std::endl;
MoveDownCreature(msg, creature, newPos, oldPos);
}
else if (newPos.z < oldPos.z && oldPos.z - newPos.z == 1) {
msg.AddByte(0x6D);
msg.AddPosition(oldPos);
msg.AddByte(oldStackPos);
msg.AddPosition(newPos);
std::cout << "MoveUpCreature called" << std::endl;
MoveUpCreature(msg, creature, newPos, oldPos);
}
else {
RemoveTileItem(msg, oldPos, oldStackpos);
AddMapDescription(msg, newPos);
}
//End of New Code
//Old Code
//RemoveTileItem(msg, oldPos, oldStackpos);
//AddMapDescription(msg, newPos);
}
else
{
if(oldPos.z != 7 || newPos.z < 8)
{
msg->AddByte(0x6D);
msg->AddPosition(oldPos);
msg->AddByte(oldStackpos);
msg->AddPosition(newPos);
}
else
RemoveTileItem(msg, oldPos, oldStackpos);
if(newPos.z > oldPos.z)
MoveDownCreature(msg, creature, newPos, oldPos, oldStackpos);
else if(newPos.z < oldPos.z)
MoveUpCreature(msg, creature, newPos, oldPos, oldStackpos);
if(oldPos.y > newPos.y) // north, for old x
{
msg->AddByte(0x65);
GetMapDescription(oldPos.x - Map::maxClientViewportX, newPos.y - Map::maxClientViewportY, newPos.z, (Map::maxClientViewportX+1)*2, 1, msg);
}
else if(oldPos.y < newPos.y) // south, for old x
{
msg->AddByte(0x67);
GetMapDescription(oldPos.x - Map::maxClientViewportX, newPos.y + (Map::maxClientViewportY+1), newPos.z, (Map::maxClientViewportX+1)*2, 1, msg);
}
if(oldPos.x < newPos.x) // east, [with new y]
{
msg->AddByte(0x66);
GetMapDescription(newPos.x + (Map::maxClientViewportX+1), newPos.y - Map::maxClientViewportY, newPos.z, 1, (Map::maxClientViewportY+1)*2, msg);
}
else if(oldPos.x > newPos.x) // west, [with new y]
{
msg->AddByte(0x68);
GetMapDescription(newPos.x - Map::maxClientViewportX, newPos.y - Map::maxClientViewportY, newPos.z, 1, (Map::maxClientViewportY+1)*2, msg);
}
}
}
}
else if(canSee(oldPos) && canSee(newPos))
{
if(!player->canSeeCreature(creature))
return;
NetworkMessage_ptr msg = getOutputBuffer();
if(msg)
{
TRACK_MESSAGE(msg);
if(!teleport && (oldPos.z != 7 || newPos.z < 8) && oldStackpos < 10)
{
msg->AddByte(0x6D);
msg->AddPosition(oldPos);
msg->AddByte(oldStackpos);
msg->AddPosition(newPos);
}
else
{
RemoveTileItem(msg, oldPos, oldStackpos);
AddTileCreature(msg, newPos, newStackpos, creature);
}
}
}
else if(canSee(oldPos))
{
if(!player->canSeeCreature(creature))
return;
NetworkMessage_ptr msg = getOutputBuffer();
if(msg)
{
TRACK_MESSAGE(msg);
RemoveTileItem(msg, oldPos, oldStackpos);
}
}
else if(canSee(newPos) && player->canSeeCreature(creature))
{
NetworkMessage_ptr msg = getOutputBuffer();
if(msg)
{
TRACK_MESSAGE(msg);
AddTileCreature(msg, newPos, newStackpos, creature);
}
}
}