public void sendItems(int interfaceId, int childId, int type, Item[] inventory) { PacketBuilder pb = new PacketBuilder().setId(105).setSize(Packet.Size.VariableShort); pb.addInt((interfaceId << 16) + childId); pb.addUShort(type); pb.addUShort(inventory.Length); for (int i = 0; i < inventory.Length; i++) { Item item = inventory[i]; int id = -1, amount = 0; if (inventory[i] != null) { id = item.getItemId(); amount = item.getItemAmount(); } if (amount > 254) { pb.addByteS(255); pb.addInt(amount); } else { pb.addByteS(amount); } pb.addUShort(id + 1); } connection.SendPacket(pb.toPacket()); }
public void sendMapRegion() { player.getUpdateFlags().setLastRegion((Location)player.getLocation().Clone()); if (player.getLocation().getX() >= 19000) { sendFightCaveMapdata(); return; } PacketBuilder pb = new PacketBuilder().setId(162).setSize(Packet.Size.VariableShort); bool forceSend = true; if (((((player.getLocation().getRegionX() / 8) == 48) || ((player.getLocation().getRegionX() / 8) == 49)) && ((player.getLocation().getRegionY() / 8) == 48)) || (((player.getLocation().getRegionX() / 8) == 48) && ((player.getLocation().getRegionY() / 8) == 148))) { forceSend = false; } pb.addShortA(player.getLocation().getLocalX()); for (int xCalc = (player.getLocation().getRegionX() - 6) / 8; xCalc <= ((player.getLocation().getRegionX() + 6) / 8); xCalc++) { for (int yCalc = (player.getLocation().getRegionY() - 6) / 8; yCalc <= ((player.getLocation().getRegionY() + 6) / 8); yCalc++) { int region = yCalc + (xCalc << 8); if (forceSend || ((yCalc != 49) && (yCalc != 149) && (yCalc != 147) && (xCalc != 50) && ((xCalc != 49) || (yCalc != 47)))) { int[] mapData = MapData.getData(region); if (mapData == null) { pb.addInt2(0); pb.addInt2(0); pb.addInt2(0); pb.addInt2(0); } else { pb.addInt2(mapData[0]); pb.addInt2(mapData[1]); pb.addInt2(mapData[2]); pb.addInt2(mapData[3]); } } } } pb.addByteS(player.getLocation().getZ()); pb.addUShort(player.getLocation().getRegionX()); pb.addShortA(player.getLocation().getRegionY()); pb.addShortA(player.getLocation().getLocalY()); connection.SendPacket(pb.toPacket()); Server.getGroundItems().refreshGlobalItems(player); Server.getGlobalObjects().refreshGlobalObjects(player); }
private static void appendHitUpdate(Npc Npc, PacketBuilder updateBlock) { NpcData npcDef = NpcData.forId(Npc.getId()); int ratio = 1; if (npcDef != null) { ratio = Npc.getHp() * 255 / npcDef.getHitpoints(); } else { misc.WriteError("Missing npcDef npcId: " + Npc.getId()); } updateBlock.addByte((byte)Npc.getHits().getHitDamage1()); updateBlock.addByteC((int)Npc.getHits().getHitType1()); //TODO: <- check updateBlock.addByteS((byte)ratio); }
private static void appendHitUpdate(Player p, PacketBuilder updateBlock) { int ratio = p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS) * 255 / p.getSkills().getMaxLevel(Skills.SKILL.HITPOINTS); if (p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS) > p.getSkills().getMaxLevel(Skills.SKILL.HITPOINTS)) { ratio = p.getSkills().getMaxLevel(3) * 255 / p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS); } if (p.getHits().getHitDamage1() < 128) //damage can be either addByte [for damage less then 128 otherwise UShort] { updateBlock.addByte((byte)p.getHits().getHitDamage1()); } else { updateBlock.addUShort(p.getHits().getHitDamage1() + 0x8000); } updateBlock.addByteA((byte)p.getHits().getHitType1()); updateBlock.addByteS(ratio); }
private static void appendHit2Update(Npc Npc, PacketBuilder updateBlock) { updateBlock.addByteC((byte)Npc.getHits().getHitDamage2()); updateBlock.addByteS((byte)Npc.getHits().getHitType2()); }
private static void appendHitUpdate(Player p, PacketBuilder updateBlock) { int ratio = p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS) * 255 / p.getSkills().getMaxLevel(Skills.SKILL.HITPOINTS); if (p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS) > p.getSkills().getMaxLevel(Skills.SKILL.HITPOINTS)) { ratio = p.getSkills().getMaxLevel(3) * 255 / p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS); } if(p.getHits().getHitDamage1() < 128) //damage can be either addByte [for damage less then 128 otherwise UShort] updateBlock.addByte((byte)p.getHits().getHitDamage1()); else updateBlock.addUShort(p.getHits().getHitDamage1() + 0x8000); updateBlock.addByteA((byte)p.getHits().getHitType1()); updateBlock.addByteS(ratio); }
private static void appendHit2Update(Player p, PacketBuilder updateBlock) { updateBlock.addByte((byte)p.getHits().getHitDamage2()); updateBlock.addByteS((byte)p.getHits().getHitType2()); }
public void sendFightCaveMapdata() { lastX = lastX == 0 ? 2413 : (player.getLocation().getX() - (20000 + (200 * player.getIndex()))); lastY = lastY == 0 ? 5116 : (player.getLocation().getY() - 20000); PacketBuilder pb = new PacketBuilder().setId(214).setSize(Packet.Size.VariableShort); pb.addUShortA(player.getLocation().getLocalX()); pb.addUShortA(player.getLocation().getRegionX()); pb.addByteS(player.getLocation().getZ()); pb.addUShortA(player.getLocation().getLocalY()); pb.initBitAccess(); for (int height = 0; height < 4; height++) { for (int xCalc = ((lastX >> 3) - 6); xCalc <= ((lastX >> 3) + 6); xCalc++) { for (int yCalc = ((lastY >> 3) - 6); yCalc <= ((lastY >> 3) + 6); yCalc++) { int region = yCalc / 8 + (xCalc / 8 << 8); if (height == player.getLocation().getZ() && region == 9551) { pb.addBits(1, 1); pb.addBits(26, (xCalc << 14) | (yCalc << 3) | (0 << 1) | (0 << 24)); } else { pb.addBits(1, 0); } } } } pb.finishBitAccess(); int[] sent = new int[4 * 13 * 13]; int sentIndex = 0; for (int xCalc = (((lastX >> 3) - 6) / 8); xCalc <= (((lastX >> 3) + 6) / 8); xCalc++) { outer: for (int yCalc = (((lastY >> 3) - 6) / 8); yCalc <= (((lastY >> 3) + 6) / 8); yCalc++) { int region = yCalc + (xCalc << 8); if (region != 9551) { continue; } for (int i = 0; i < sentIndex; i++) { if (sent[i] == region) { goto outer; } } sent[sentIndex] = region; sentIndex++; int[] mapData = MapData.getData(region); if (mapData == null) { pb.addInt2(0); pb.addInt2(0); pb.addInt2(0); pb.addInt2(0); } else { pb.addInt2(mapData[0]); pb.addInt2(mapData[1]); pb.addInt2(mapData[2]); pb.addInt2(mapData[3]); } } } pb.addUShort(player.getLocation().getRegionY()); connection.SendPacket(pb.toPacket()); }