Search in sources :

Example 56 with Position

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

the class NpcSynchronizationMessageEncoder method putAddNpcUpdate.

/**
 * Puts an add npc update.
 *
 * @param seg The segment.
 * @param message The message.
 * @param builder The builder.
 */
private static void putAddNpcUpdate(AddNpcSegment seg, NpcSynchronizationMessage message, GamePacketBuilder builder) {
    boolean updateRequired = seg.getBlockSet().size() > 0;
    Position npc = message.getPosition();
    Position other = seg.getPosition();
    builder.putBits(14, seg.getIndex());
    builder.putBits(5, other.getY() - npc.getY());
    builder.putBits(5, other.getX() - npc.getX());
    // discard walking queue
    builder.putBits(1, 0);
    builder.putBits(12, seg.getNpcId());
    builder.putBits(1, updateRequired ? 1 : 0);
}
Also used : Position(org.apollo.game.model.Position)

Example 57 with Position

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

the class PlayerSynchronizationMessageEncoder method putMovementUpdate.

/**
 * Puts a movement update for the specified segment.
 *
 * @param seg The segment.
 * @param message The message.
 * @param builder The builder.
 */
private static void putMovementUpdate(SynchronizationSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) {
    boolean updateRequired = seg.getBlockSet().size() > 0;
    if (seg.getType() == SegmentType.TELEPORT) {
        Position position = ((TeleportSegment) seg).getDestination();
        builder.putBits(1, 1);
        builder.putBits(2, 3);
        builder.putBits(2, position.getHeight());
        builder.putBits(1, message.hasRegionChanged() ? 0 : 1);
        builder.putBits(1, updateRequired ? 1 : 0);
        builder.putBits(7, position.getLocalY(message.getLastKnownRegion()));
        builder.putBits(7, position.getLocalX(message.getLastKnownRegion()));
    } else if (seg.getType() == SegmentType.RUN) {
        Direction[] directions = ((MovementSegment) seg).getDirections();
        builder.putBits(1, 1);
        builder.putBits(2, 2);
        builder.putBits(3, directions[0].toInteger());
        builder.putBits(3, directions[1].toInteger());
        builder.putBits(1, updateRequired ? 1 : 0);
    } else if (seg.getType() == SegmentType.WALK) {
        Direction[] directions = ((MovementSegment) seg).getDirections();
        builder.putBits(1, 1);
        builder.putBits(2, 1);
        builder.putBits(3, directions[0].toInteger());
        builder.putBits(1, updateRequired ? 1 : 0);
    } else {
        if (updateRequired) {
            builder.putBits(1, 1);
            builder.putBits(2, 0);
        } else {
            builder.putBits(1, 0);
        }
    }
}
Also used : Position(org.apollo.game.model.Position) TeleportSegment(org.apollo.game.sync.seg.TeleportSegment) Direction(org.apollo.game.model.Direction) MovementSegment(org.apollo.game.sync.seg.MovementSegment)

Example 58 with Position

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

the class TakeTileItemMessageDecoder method decode.

@Override
public TakeTileItemMessage decode(GamePacket packet) {
    GamePacketReader reader = new GamePacketReader(packet);
    int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE);
    int id = (int) reader.getUnsigned(DataType.SHORT);
    int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE);
    return new TakeTileItemMessage(id, new Position(x, y));
}
Also used : GamePacketReader(org.apollo.net.codec.game.GamePacketReader) Position(org.apollo.game.model.Position) TakeTileItemMessage(org.apollo.game.message.impl.TakeTileItemMessage)

Example 59 with Position

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

the class ThirdObjectActionMessageDecoder method decode.

@Override
public ObjectActionMessage decode(GamePacket packet) {
    GamePacketReader reader = new GamePacketReader(packet);
    int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE);
    int y = (int) reader.getUnsigned(DataType.SHORT);
    int id = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD);
    return new ObjectActionMessage(3, id, new Position(x, y));
}
Also used : ObjectActionMessage(org.apollo.game.message.impl.ObjectActionMessage) GamePacketReader(org.apollo.net.codec.game.GamePacketReader) Position(org.apollo.game.model.Position)

Example 60 with Position

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

the class WalkMessageDecoder method decode.

@Override
public WalkMessage decode(GamePacket packet) {
    GamePacketReader reader = new GamePacketReader(packet);
    int length = packet.getLength();
    if (packet.getOpcode() == 248) {
        // strip off anti-cheat data
        length -= 14;
    }
    int steps = (length - 5) / 2;
    int[][] path = new int[steps][2];
    int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD);
    for (int i = 0; i < steps; i++) {
        path[i][0] = (int) reader.getSigned(DataType.BYTE);
        path[i][1] = (int) reader.getSigned(DataType.BYTE);
    }
    int y = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE);
    boolean run = reader.getUnsigned(DataType.BYTE, DataTransformation.NEGATE) == 1;
    Position[] positions = new Position[steps + 1];
    positions[0] = new Position(x, y);
    for (int i = 0; i < steps; i++) {
        positions[i + 1] = new Position(path[i][0] + x, path[i][1] + y);
    }
    return new WalkMessage(positions, run);
}
Also used : WalkMessage(org.apollo.game.message.impl.WalkMessage) GamePacketReader(org.apollo.net.codec.game.GamePacketReader) 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