Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.74 KB | None | 0 0
  1. void ProtocolGame::sendMoveCreature(const Creature* creature, const Tile* newTile, const Position& newPos,
  2.     uint32_t newStackpos, const Tile* oldTile, const Position& oldPos, uint32_t oldStackpos, bool teleport)
  3. {
  4.     if(creature == player)
  5.     {
  6.         NetworkMessage_ptr msg = getOutputBuffer();
  7.         if(msg)
  8.         {
  9.             TRACK_MESSAGE(msg);
  10.             if(teleport || oldStackpos >= 10)
  11.             {
  12.                 RemoveTileItem(msg, oldPos, oldStackpos);
  13.                 AddMapDescription(msg, newPos);
  14.             }
  15.             else
  16.             {
  17.                 if(oldPos.z != 7 || newPos.z < 8)
  18.                 {
  19.                     msg->AddByte(0x6D);
  20.                     msg->AddPosition(oldPos);
  21.                     msg->AddByte(oldStackpos);
  22.                     msg->AddPosition(newPos);
  23.                 }
  24.                 else
  25.                     RemoveTileItem(msg, oldPos, oldStackpos);
  26.  
  27.                 if(newPos.z > oldPos.z)
  28.                     MoveDownCreature(msg, creature, newPos, oldPos, oldStackpos);
  29.                 else if(newPos.z < oldPos.z)
  30.                     MoveUpCreature(msg, creature, newPos, oldPos, oldStackpos);
  31.  
  32.                 if (oldPos.y > newPos.y) { // north, for old x
  33.                     msg->AddByte(0x65);
  34.                     GetMapDescription(oldPos.x - Protocol::getPortX(), newPos.y - Protocol::getPortY(), newPos.z, (Protocol::getPortX()+1)*2, 1, msg);
  35.                 } else if (oldPos.y < newPos.y) { // south, for old x
  36.                     msg->AddByte(0x67);
  37.                     GetMapDescription(oldPos.x - Protocol::getPortX(), newPos.y + (Protocol::getPortY()+1), newPos.z, (Protocol::getPortX()+1)*2, 1, msg);
  38.                 }
  39.                 if (oldPos.x < newPos.x) { // east, [with new y]
  40.                     msg->AddByte(0x66);
  41.                     GetMapDescription(newPos.x + (Protocol::getPortX()+1), newPos.y - Protocol::getPortY(), newPos.z, 1, (Protocol::getPortY()+1)*2, msg);
  42.                 } else if (oldPos.x > newPos.x) { // west, [with new y]
  43.                     msg->AddByte(0x68);
  44.                     GetMapDescription(newPos.x - Protocol::getPortX(), newPos.y - Protocol::getPortY(), newPos.z, 1, (Protocol::getPortY()+1)*2, msg);
  45.                 }
  46.             }
  47.         }
  48.     }
  49.     else if(canSee(oldPos) && canSee(newPos))
  50.     {
  51.         if(!player->canSeeCreature(creature))
  52.             return;
  53.  
  54.         NetworkMessage_ptr msg = getOutputBuffer();
  55.         if(msg)
  56.         {
  57.             TRACK_MESSAGE(msg);
  58.             if(!teleport && (oldPos.z != 7 || newPos.z < 8) && oldStackpos < 10)
  59.             {
  60.                 msg->AddByte(0x6D);
  61.                 msg->AddPosition(oldPos);
  62.                 msg->AddByte(oldStackpos);
  63.                 msg->AddPosition(newPos);
  64.             }
  65.             else
  66.             {
  67.                 RemoveTileItem(msg, oldPos, oldStackpos);
  68.                 AddTileCreature(msg, newPos, newStackpos, creature);
  69.             }
  70.         }
  71.     }
  72.     else if(canSee(oldPos))
  73.     {
  74.         if(!player->canSeeCreature(creature))
  75.             return;
  76.  
  77.         NetworkMessage_ptr msg = getOutputBuffer();
  78.         if(msg)
  79.         {
  80.             TRACK_MESSAGE(msg);
  81.             RemoveTileItem(msg, oldPos, oldStackpos);
  82.         }
  83.     }
  84.     else if(canSee(newPos) && player->canSeeCreature(creature))
  85.     {
  86.         NetworkMessage_ptr msg = getOutputBuffer();
  87.         if(msg)
  88.         {
  89.             TRACK_MESSAGE(msg);
  90.             AddTileCreature(msg, newPos, newStackpos, creature);
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement