Пример #1
0
 /**
  * Update all NPCs for this player.
  *
  * @param p The Player class to apply updates to.
  * @param str The stream to write the bytes to.
  */
 public void updateNPC(Player p, Stream str) {
   if (p == null || str == null) {
     return;
   }
   update.outOffset = 0;
   byte[] newNPCIds = new byte[Engine.npcs.length];
   int updateByteCount = 0;
   str.createFrameVarSizeWord(222);
   str.initBitAccess();
   str.writeBits(8, p.npcListSize);
   int size = p.npcListSize;
   p.npcListSize = 0;
   for (int i = 0; i < size; i++) {
     if (p.npcList[i] != null) {
       if (withinDistance(p, p.npcList[i]) && !p.rebuildNPCList) {
         Engine.npcMovement.updateNPCMovement(p.npcList[i], str);
         appendNPCUpdateMasks(p.npcList[i], update);
         p.npcList[p.npcListSize++] = p.npcList[i];
       } else {
         p.npcsInList[p.npcList[i].npcId] = 0;
         str.writeBits(1, 1);
         str.writeBits(2, 3);
       }
     }
   }
   for (NPC n : Engine.npcs) {
     if (n == null || !withinDistance(p, n) || p.npcsInList[n.npcId] == 1) {
       continue;
     }
     newNPCIds[n.npcId] = 1;
     addNewNPC(p, n, str);
   }
   p.rebuildNPCList = false;
   if (update.outOffset > 3) str.writeBits(15, 32767);
   str.finishBitAccess();
   str.writeBytes(update.outBuffer, update.outOffset, 0);
   str.endFrameVarSizeWord();
 }
Пример #2
0
 /**
  * Add a new npc to this players client.
  *
  * @param p The player the NPC is being added to.
  * @param npc The NPC being added.
  * @param str The stream the bytes are being written to.
  */
 public void addNewNPC(Player p, NPC npc, Stream str) {
   if (npc == null || str == null || p == null) {
     return;
   }
   p.npcsInList[npc.npcId] = 1;
   p.npcList[p.npcListSize++] = npc;
   str.writeBits(15, npc.npcId);
   str.writeBits(14, npc.npcType);
   str.writeBits(1, npc.updateReq ? 1 : 0);
   int y = npc.absY - p.absY;
   if (y > 15) {
     y += 32;
   }
   int x = npc.absX - p.absX;
   if (x > 15) {
     x += 32;
   }
   str.writeBits(5, y);
   str.writeBits(5, x);
   str.writeBits(3, 0);
   str.writeBits(1, 1);
   appendNPCUpdateMasks(npc, update);
 }