Search in sources :

Example 1 with SegmentType

use of org.apollo.game.sync.seg.SegmentType in project apollo by apollo-rsps.

the class PlayerSynchronizationMessageEncoder method encode.

@Override
public GamePacket encode(PlayerSynchronizationMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(81, PacketType.VARIABLE_SHORT);
    builder.switchToBitAccess();
    GamePacketBuilder blockBuilder = new GamePacketBuilder();
    putMovementUpdate(message.getSegment(), message, builder);
    putBlocks(message.getSegment(), blockBuilder);
    builder.putBits(8, message.getLocalPlayers());
    for (SynchronizationSegment segment : message.getSegments()) {
        SegmentType type = segment.getType();
        if (type == SegmentType.REMOVE_MOB) {
            putRemovePlayerUpdate(builder);
        } else if (type == SegmentType.ADD_MOB) {
            putAddPlayerUpdate((AddPlayerSegment) segment, message, builder);
            putBlocks(segment, blockBuilder);
        } else {
            putMovementUpdate(segment, message, builder);
            putBlocks(segment, blockBuilder);
        }
    }
    if (blockBuilder.getLength() > 0) {
        builder.putBits(11, 2047);
        builder.switchToByteAccess();
        builder.putRawBuilder(blockBuilder);
    } else {
        builder.switchToByteAccess();
    }
    return builder.toGamePacket();
}
Also used : SegmentType(org.apollo.game.sync.seg.SegmentType) AddPlayerSegment(org.apollo.game.sync.seg.AddPlayerSegment) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder) SynchronizationSegment(org.apollo.game.sync.seg.SynchronizationSegment)

Example 2 with SegmentType

use of org.apollo.game.sync.seg.SegmentType in project apollo by apollo-rsps.

the class NpcSynchronizationMessageEncoder method encode.

@Override
public GamePacket encode(NpcSynchronizationMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(65, PacketType.VARIABLE_SHORT);
    builder.switchToBitAccess();
    GamePacketBuilder blockBuilder = new GamePacketBuilder();
    builder.putBits(8, message.getLocalNpcCount());
    for (SynchronizationSegment segment : message.getSegments()) {
        SegmentType type = segment.getType();
        if (type == SegmentType.REMOVE_MOB) {
            putRemoveMobUpdate(builder);
        } else if (type == SegmentType.ADD_MOB) {
            putAddNpcUpdate((AddNpcSegment) segment, message, builder);
            putBlocks(segment, blockBuilder);
        } else {
            putMovementUpdate(segment, message, builder);
            putBlocks(segment, blockBuilder);
        }
    }
    if (blockBuilder.getLength() > 0) {
        builder.putBits(14, 16383);
        builder.switchToByteAccess();
        builder.putRawBuilder(blockBuilder);
    } else {
        builder.switchToByteAccess();
    }
    return builder.toGamePacket();
}
Also used : SegmentType(org.apollo.game.sync.seg.SegmentType) AddNpcSegment(org.apollo.game.sync.seg.AddNpcSegment) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder) SynchronizationSegment(org.apollo.game.sync.seg.SynchronizationSegment)

Example 3 with SegmentType

use of org.apollo.game.sync.seg.SegmentType in project apollo by apollo-rsps.

the class PlayerSynchronizationMessageEncoder method encode.

@Override
public GamePacket encode(PlayerSynchronizationMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(90, PacketType.VARIABLE_SHORT);
    builder.switchToBitAccess();
    GamePacketBuilder blockBuilder = new GamePacketBuilder();
    putMovementUpdate(message.getSegment(), message, builder);
    putBlocks(message.getSegment(), blockBuilder);
    builder.putBits(8, message.getLocalPlayers());
    for (SynchronizationSegment segment : message.getSegments()) {
        SegmentType type = segment.getType();
        if (type == SegmentType.REMOVE_MOB) {
            putRemovePlayerUpdate(builder);
        } else if (type == SegmentType.ADD_MOB) {
            putAddPlayerUpdate((AddPlayerSegment) segment, message, builder);
            putBlocks(segment, blockBuilder);
        } else {
            putMovementUpdate(segment, message, builder);
            putBlocks(segment, blockBuilder);
        }
    }
    if (blockBuilder.getLength() > 0) {
        builder.putBits(11, 2047);
        builder.switchToByteAccess();
        builder.putRawBuilder(blockBuilder);
    } else {
        builder.switchToByteAccess();
    }
    return builder.toGamePacket();
}
Also used : SegmentType(org.apollo.game.sync.seg.SegmentType) AddPlayerSegment(org.apollo.game.sync.seg.AddPlayerSegment) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder) SynchronizationSegment(org.apollo.game.sync.seg.SynchronizationSegment)

Example 4 with SegmentType

use of org.apollo.game.sync.seg.SegmentType in project apollo by apollo-rsps.

the class NpcSynchronizationMessageEncoder method encode.

@Override
public GamePacket encode(NpcSynchronizationMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(71, PacketType.VARIABLE_SHORT);
    builder.switchToBitAccess();
    GamePacketBuilder blockBuilder = new GamePacketBuilder();
    builder.putBits(8, message.getLocalNpcCount());
    for (SynchronizationSegment segment : message.getSegments()) {
        SegmentType type = segment.getType();
        if (type == SegmentType.REMOVE_MOB) {
            putRemoveNpcUpdate(builder);
        } else if (type == SegmentType.ADD_MOB) {
            putAddNpcUpdate((AddNpcSegment) segment, message, builder);
            putBlocks(segment, blockBuilder);
        } else {
            putMovementUpdate(segment, message, builder);
            putBlocks(segment, blockBuilder);
        }
    }
    if (blockBuilder.getLength() > 0) {
        builder.putBits(14, 16383);
        builder.switchToByteAccess();
        builder.putRawBuilder(blockBuilder);
    } else {
        builder.switchToByteAccess();
    }
    return builder.toGamePacket();
}
Also used : SegmentType(org.apollo.game.sync.seg.SegmentType) AddNpcSegment(org.apollo.game.sync.seg.AddNpcSegment) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder) SynchronizationSegment(org.apollo.game.sync.seg.SynchronizationSegment)

Aggregations

SegmentType (org.apollo.game.sync.seg.SegmentType)4 SynchronizationSegment (org.apollo.game.sync.seg.SynchronizationSegment)4 GamePacketBuilder (org.apollo.net.codec.game.GamePacketBuilder)4 AddNpcSegment (org.apollo.game.sync.seg.AddNpcSegment)2 AddPlayerSegment (org.apollo.game.sync.seg.AddPlayerSegment)2