Search in sources :

Example 6 with GamePacketBuilder

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

the class PositionHintIconMessageEncoder method encode.

@Override
public GamePacket encode(PositionHintIconMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(254);
    HintIconMessage.Type type = message.getType();
    if (type == Type.PLAYER || type == Type.NPC) {
        throw new IllegalStateException("Unsupported hint icon type " + type + ".");
    }
    builder.put(DataType.BYTE, type.getValue());
    Position position = message.getPosition();
    builder.put(DataType.SHORT, position.getX());
    builder.put(DataType.SHORT, position.getY());
    builder.put(DataType.BYTE, message.getHeight());
    return builder.toGamePacket();
}
Also used : Position(org.apollo.game.model.Position) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder) Type(org.apollo.game.message.impl.HintIconMessage.Type) HintIconMessage(org.apollo.game.message.impl.HintIconMessage) PositionHintIconMessage(org.apollo.game.message.impl.PositionHintIconMessage)

Example 7 with GamePacketBuilder

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

the class RegionChangeMessageEncoder method encode.

@Override
public GamePacket encode(RegionChangeMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(73);
    builder.put(DataType.SHORT, DataTransformation.ADD, message.getPosition().getCentralRegionX());
    builder.put(DataType.SHORT, message.getPosition().getCentralRegionY());
    return builder.toGamePacket();
}
Also used : GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder)

Example 8 with GamePacketBuilder

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

the class ForwardPrivateChatMessageEncoder method encode.

@Override
public GamePacket encode(ForwardPrivateChatMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(196, PacketType.VARIABLE_BYTE);
    builder.put(DataType.LONG, NameUtil.encodeBase37(message.getSenderUsername()));
    builder.put(DataType.INT, messageCounter.incrementAndGet());
    builder.put(DataType.BYTE, message.getSenderPrivilege().toInteger());
    builder.putBytes(message.getCompressedMessage());
    return builder.toGamePacket();
}
Also used : GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder)

Example 9 with GamePacketBuilder

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

the class GroupedRegionUpdateMessageEncoder method encode.

@Override
public GamePacket encode(GroupedRegionUpdateMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(60, PacketType.VARIABLE_SHORT);
    Position base = message.getLastKnownRegion(), region = message.getRegionPosition();
    builder.put(DataType.BYTE, region.getLocalY(base));
    builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(base));
    for (RegionUpdateMessage update : message.getMessages()) {
        @SuppressWarnings("unchecked") MessageEncoder<RegionUpdateMessage> encoder = (MessageEncoder<RegionUpdateMessage>) release.getMessageEncoder(update.getClass());
        GamePacket packet = encoder.encode(update);
        builder.put(DataType.BYTE, packet.getOpcode());
        builder.putBytes(packet.getPayload());
    }
    return builder.toGamePacket();
}
Also used : GamePacket(org.apollo.net.codec.game.GamePacket) Position(org.apollo.game.model.Position) RegionUpdateMessage(org.apollo.game.message.impl.RegionUpdateMessage) GroupedRegionUpdateMessage(org.apollo.game.message.impl.GroupedRegionUpdateMessage) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder) MessageEncoder(org.apollo.net.release.MessageEncoder)

Example 10 with GamePacketBuilder

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

the class IdAssignmentMessageEncoder method encode.

@Override
public GamePacket encode(IdAssignmentMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(249);
    builder.put(DataType.BYTE, DataTransformation.ADD, message.isMembers() ? 1 : 0);
    builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId());
    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