Search in sources :

Example 6 with Position

use of org.apollo.game.model.Position in project apollo by apollo-rsps.

the class PlayerSynchronizationMessageEncoder method putTurnToPositionBlock.

/**
 * Puts a Turn To Position block into the specified builder.
 *
 * @param block The block.
 * @param builder The builder.
 */
private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) {
    Position pos = block.getPosition();
    builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, pos.getX() * 2 + 1);
    builder.put(DataType.SHORT, DataOrder.LITTLE, pos.getY() * 2 + 1);
}
Also used : Position(org.apollo.game.model.Position)

Example 7 with Position

use of org.apollo.game.model.Position 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 8 with Position

use of org.apollo.game.model.Position 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 9 with Position

use of org.apollo.game.model.Position in project apollo by apollo-rsps.

the class ClearRegionMessageEncoder method encode.

@Override
public GamePacket encode(ClearRegionMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(64);
    Position player = message.getPlayerPosition(), region = message.getRegionPosition();
    builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(player));
    builder.put(DataType.BYTE, DataTransformation.SUBTRACT, region.getLocalY(player));
    return builder.toGamePacket();
}
Also used : Position(org.apollo.game.model.Position) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder)

Example 10 with Position

use of org.apollo.game.model.Position in project apollo by apollo-rsps.

the class PlayerSynchronizationMessageEncoder method putTurnToPositionBlock.

/**
 * Puts a turn to position block into the specified builder.
 *
 * @param block The block.
 * @param builder The builder.
 */
private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) {
    Position position = block.getPosition();
    builder.put(DataType.SHORT, position.getX() * 2 + 1);
    builder.put(DataType.SHORT, position.getY() * 2 + 1);
}
Also used : Position(org.apollo.game.model.Position)

Aggregations

Position (org.apollo.game.model.Position)66 Region (org.apollo.game.model.area.Region)14 RegionRepository (org.apollo.game.model.area.RegionRepository)10 GamePacketReader (org.apollo.net.codec.game.GamePacketReader)10 GamePacketBuilder (org.apollo.net.codec.game.GamePacketBuilder)9 ObjectActionMessage (org.apollo.game.message.impl.ObjectActionMessage)8 Direction (org.apollo.game.model.Direction)8 Entity (org.apollo.game.model.entity.Entity)8 HashSet (java.util.HashSet)7 World (org.apollo.game.model.World)7 Player (org.apollo.game.model.entity.Player)7 Test (org.junit.Test)7 StaticGameObject (org.apollo.game.model.entity.obj.StaticGameObject)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 ArrayList (java.util.ArrayList)3 ItemOnObjectMessage (org.apollo.game.message.impl.ItemOnObjectMessage)3 RegionCoordinates (org.apollo.game.model.area.RegionCoordinates)3 GroupableEntity (org.apollo.game.model.area.update.GroupableEntity)3 Inventory (org.apollo.game.model.inv.Inventory)3 MovementSegment (org.apollo.game.sync.seg.MovementSegment)3