Search in sources :

Example 66 with GamePacketBuilder

use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.

the class UpdateItemsMessageEncoder method encode.

@Override
public GamePacket encode(UpdateItemsMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(206, PacketType.VARIABLE_SHORT);
    Item[] items = message.getItems();
    builder.put(DataType.SHORT, message.getInterfaceId());
    builder.put(DataType.SHORT, items.length);
    for (Item item : items) {
        int id = item == null ? -1 : item.getId();
        int amount = item == null ? 0 : item.getAmount();
        builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, id + 1);
        if (amount > 254) {
            builder.put(DataType.BYTE, DataTransformation.NEGATE, 255);
            builder.put(DataType.INT, DataOrder.LITTLE, amount);
        } else {
            builder.put(DataType.BYTE, DataTransformation.NEGATE, amount);
        }
    }
    return builder.toGamePacket();
}
Also used : Item(org.apollo.game.model.Item) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder)

Example 67 with GamePacketBuilder

use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.

the class SendProjectileMessageEncoder method encode.

@Override
public GamePacket encode(SendProjectileMessage message) {
    Projectile projectile = message.getProjectile();
    Position source = projectile.getPosition();
    Position destination = projectile.getDestination();
    GamePacketBuilder builder = new GamePacketBuilder(181);
    builder.put(DataType.BYTE, message.getPositionOffset());
    builder.put(DataType.BYTE, destination.getX() - source.getX());
    builder.put(DataType.BYTE, destination.getY() - source.getY());
    builder.put(DataType.SHORT, projectile.getTarget());
    builder.put(DataType.SHORT, projectile.getGraphic());
    builder.put(DataType.BYTE, projectile.getStartHeight());
    builder.put(DataType.BYTE, projectile.getEndHeight());
    builder.put(DataType.SHORT, projectile.getDelay());
    builder.put(DataType.SHORT, projectile.getLifetime());
    builder.put(DataType.BYTE, projectile.getPitch());
    builder.put(DataType.BYTE, projectile.getOffset());
    return builder.toGamePacket();
}
Also used : Position(org.apollo.game.model.Position) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder) Projectile(org.apollo.game.model.entity.Projectile)

Example 68 with GamePacketBuilder

use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.

the class SetWidgetTextMessageEncoder method encode.

@Override
public GamePacket encode(SetWidgetTextMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(232, PacketType.VARIABLE_SHORT);
    builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId());
    builder.putString(message.getText());
    return builder.toGamePacket();
}
Also used : GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder)

Example 69 with GamePacketBuilder

use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.

the class SwitchTabInterfaceMessageEncoder method encode.

@Override
public GamePacket encode(SwitchTabInterfaceMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(10);
    builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getTabId());
    builder.put(DataType.SHORT, DataTransformation.ADD, message.getInterfaceId());
    return builder.toGamePacket();
}
Also used : GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder)

Example 70 with GamePacketBuilder

use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.

the class UpdateRunEnergyMessageEncoder method encode.

@Override
public GamePacket encode(UpdateRunEnergyMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(125);
    builder.put(DataType.BYTE, message.getEnergy());
    return builder.toGamePacket();
}
Also used : GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder)

Aggregations

GamePacketBuilder (org.apollo.net.codec.game.GamePacketBuilder)93 Position (org.apollo.game.model.Position)9 Item (org.apollo.game.model.Item)6 HintIconMessage (org.apollo.game.message.impl.HintIconMessage)4 SegmentType (org.apollo.game.sync.seg.SegmentType)4 SynchronizationSegment (org.apollo.game.sync.seg.SynchronizationSegment)4 EquipmentDefinition (org.apollo.cache.def.EquipmentDefinition)2 GroupedRegionUpdateMessage (org.apollo.game.message.impl.GroupedRegionUpdateMessage)2 Type (org.apollo.game.message.impl.HintIconMessage.Type)2 MobHintIconMessage (org.apollo.game.message.impl.MobHintIconMessage)2 PositionHintIconMessage (org.apollo.game.message.impl.PositionHintIconMessage)2 RegionUpdateMessage (org.apollo.game.message.impl.RegionUpdateMessage)2 Appearance (org.apollo.game.model.Appearance)2 Skill (org.apollo.game.model.entity.Skill)2 Inventory (org.apollo.game.model.inv.Inventory)2 SlottedItem (org.apollo.game.model.inv.SlottedItem)2 AddNpcSegment (org.apollo.game.sync.seg.AddNpcSegment)2 AddPlayerSegment (org.apollo.game.sync.seg.AddPlayerSegment)2 GamePacket (org.apollo.net.codec.game.GamePacket)2 MessageEncoder (org.apollo.net.release.MessageEncoder)2