/** * 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(); }