@Override public GamePacket encode(UpdateSlottedItemsEvent event) { GamePacketBuilder builder = new GamePacketBuilder(134, PacketType.VARIABLE_SHORT); SlottedItem[] items = event.getSlottedItems(); builder.put(DataType.SHORT, event.getInterfaceId()); for (SlottedItem slottedItem : items) { builder.putSmart(slottedItem.getSlot()); Item item = slottedItem.getItem(); int id = item == null ? -1 : item.getId(); int amount = item == null ? 0 : item.getAmount(); builder.put(DataType.SHORT, id + 1); if (amount > 254) { builder.put(DataType.BYTE, 255); builder.put(DataType.INT, amount); } else { builder.put(DataType.BYTE, amount); } } return builder.toGamePacket(); }
/** * Return the flag. * * @param player The player that is return the flag. */ public void returnFlag(Player player) { if (getPlayers(GameType.ACTIVE).contains(player)) { Team team = getTeam(player, GameType.ACTIVE) == Team.SARADOMIN ? Team.ZAMORAK : Team.SARADOMIN; if (teams.get(team).getAttribute(4)) { Item weapon = player.getEquipment().get(EquipmentConstants.WEAPON); if (weapon != null && weapon.getId() == teams.get(team).getFlag()) { player.getEquipment().set(EquipmentConstants.WEAPON, null); teams.get(getTeam(player, GameType.ACTIVE)).addPoint(); teams.get(team).setAttribute(4, false); setAttribute(1, true); setAttribute(3, true); } } } }
@Override public boolean equals(Object obj) { if (obj instanceof SendTileItemMessage) { SendTileItemMessage other = (SendTileItemMessage) obj; return item.equals(other.item) && positionOffset == other.positionOffset; } return false; }
/** * Gets the amount of the item. * * @return The amount. */ public int getAmount() { return item.getAmount(); }
/** * Gets the id of the item. * * @return The id. */ public int getId() { return item.getId(); }
/** * Puts an Appearance block into the specified builder. * * @param block The block. * @param builder The builder. */ private static void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) { Appearance appearance = block.getAppearance(); GamePacketBuilder playerProperties = new GamePacketBuilder(); playerProperties.put(DataType.BYTE, appearance.getGender().toInteger()); playerProperties.put(DataType.BYTE, block.isSkulled() ? 1 : -1); playerProperties.put(DataType.BYTE, block.getHeadIcon()); if (block.appearingAsNpc()) { playerProperties.put(DataType.BYTE, 255); playerProperties.put(DataType.BYTE, 255); playerProperties.put(DataType.SHORT, block.getNpcId()); } else { Inventory equipment = block.getEquipment(); int[] style = appearance.getStyle(); Item item, chest, helm; for (int slot = 0; slot < 4; slot++) { if ((item = equipment.get(slot)) != null) { playerProperties.put(DataType.SHORT, 0x200 + item.getId()); } else { playerProperties.put(DataType.BYTE, 0); } } if ((chest = equipment.get(EquipmentConstants.CHEST)) != null) { playerProperties.put(DataType.SHORT, 0x200 + chest.getId()); } else { playerProperties.put(DataType.SHORT, 0x100 + style[2]); } if ((item = equipment.get(EquipmentConstants.SHIELD)) != null) { playerProperties.put(DataType.SHORT, 0x200 + item.getId()); } else { playerProperties.put(DataType.BYTE, 0); } if (chest != null) { EquipmentDefinition def = EquipmentDefinition.lookup(chest.getId()); if (def != null && !def.isFullBody()) { playerProperties.put(DataType.SHORT, 0x100 + style[3]); } else { playerProperties.put(DataType.BYTE, 0); } } else { playerProperties.put(DataType.SHORT, 0x100 + style[3]); } if ((item = equipment.get(EquipmentConstants.LEGS)) != null) { playerProperties.put(DataType.SHORT, 0x200 + item.getId()); } else { playerProperties.put(DataType.SHORT, 0x100 + style[5]); } if ((helm = equipment.get(EquipmentConstants.HAT)) != null) { EquipmentDefinition def = EquipmentDefinition.lookup(helm.getId()); if (def != null && !def.isFullHat() && !def.isFullMask()) { playerProperties.put(DataType.SHORT, 0x100 + style[0]); } else { playerProperties.put(DataType.BYTE, 0); } } else { playerProperties.put(DataType.SHORT, 0x100 + style[0]); } if ((item = equipment.get(EquipmentConstants.HANDS)) != null) { playerProperties.put(DataType.SHORT, 0x200 + item.getId()); } else { playerProperties.put(DataType.SHORT, 0x100 + style[4]); } if ((item = equipment.get(EquipmentConstants.FEET)) != null) { playerProperties.put(DataType.SHORT, 0x200 + item.getId()); } else { playerProperties.put(DataType.SHORT, 0x100 + style[6]); } EquipmentDefinition def = null; if (helm != null) { def = EquipmentDefinition.lookup(helm.getId()); } if (def != null && (def.isFullHat() || def.isFullMask()) || appearance.getGender() == Gender.FEMALE) { playerProperties.put(DataType.BYTE, 0); } else { playerProperties.put(DataType.SHORT, 0x100 + style[1]); } } int[] colors = appearance.getColors(); for (int color : colors) { playerProperties.put(DataType.BYTE, color); } playerProperties.put(DataType.SHORT, 0x328); // stand playerProperties.put(DataType.SHORT, 0x337); // stand turn playerProperties.put(DataType.SHORT, 0x333); // walk playerProperties.put(DataType.SHORT, 0x334); // turn 180 playerProperties.put(DataType.SHORT, 0x335); // turn 90 cw playerProperties.put(DataType.SHORT, 0x336); // turn 90 ccw playerProperties.put(DataType.SHORT, 0x338); // run playerProperties.put(DataType.LONG, block.getName()); playerProperties.put(DataType.BYTE, block.getCombatLevel()); playerProperties.put(DataType.SHORT, block.getSkillLevel()); builder.put(DataType.BYTE, playerProperties.getLength()); builder.putRawBuilderReverse(playerProperties); }
@Override public int hashCode() { final int prime = 31; return item.hashCode() * prime + positionOffset; }