Search in sources :

Example 41 with Position

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

the class ItemOnObjectVerificationHandlerTests method terminateIfInvalidSlot.

@Test
public void terminateIfInvalidSlot() throws Exception {
    Position playerPosition = new Position(3200, 3200);
    Position objectPosition = new Position(3200, 3200);
    World world = mock(World.class);
    Region region = mock(Region.class);
    RegionRepository regionRepository = mock(RegionRepository.class);
    Player player = mock(Player.class);
    Set<Entity> entitySet = new HashSet<>();
    entitySet.add(new StaticGameObject(world, 4151, objectPosition, 0, 0));
    Inventory inventory = new Inventory(28);
    when(player.getInventory()).thenReturn(inventory);
    when(world.getRegionRepository()).thenReturn(regionRepository);
    when(regionRepository.fromPosition(objectPosition)).thenReturn(region);
    when(player.getPosition()).thenReturn(playerPosition);
    when(region.getEntities(objectPosition, EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT)).thenReturn(entitySet);
    ItemOnObjectMessage itemOnObjectMessage = new ItemOnObjectMessage(SynchronizationInventoryListener.INVENTORY_ID, 4151, 30, 1, objectPosition.getX(), objectPosition.getY());
    ItemOnObjectVerificationHandler itemOnObjectVerificationHandler = new ItemOnObjectVerificationHandler(world);
    itemOnObjectVerificationHandler.handle(player, itemOnObjectMessage);
    assertTrue("ObjectVerificationHandler: message not terminated when no valid slot given!", itemOnObjectMessage.terminated());
}
Also used : Entity(org.apollo.game.model.entity.Entity) Player(org.apollo.game.model.entity.Player) Position(org.apollo.game.model.Position) RegionRepository(org.apollo.game.model.area.RegionRepository) ItemOnObjectMessage(org.apollo.game.message.impl.ItemOnObjectMessage) Region(org.apollo.game.model.area.Region) StaticGameObject(org.apollo.game.model.entity.obj.StaticGameObject) World(org.apollo.game.model.World) Inventory(org.apollo.game.model.inv.Inventory) HashSet(java.util.HashSet) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 42 with Position

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

the class FirstObjectActionMessageDecoder method decode.

@Override
public ObjectActionMessage decode(GamePacket packet) {
    GamePacketReader reader = new GamePacketReader(packet);
    int x = (int) reader.getUnsigned(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD);
    int id = (int) reader.getUnsigned(DataType.SHORT);
    int y = (int) reader.getUnsigned(DataType.SHORT, DataTransformation.ADD);
    return new ObjectActionMessage(1, 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 43 with Position

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

the class PathfindingAlgorithm method inside.

/**
 * Returns whether or not the specified {@link Position} is inside the specified {@code boundary}.
 *
 * @param position The Position.
 * @param boundary The boundary Positions.
 * @return {@code true} if the specified Position is inside the boundary, {@code false} if not.
 */
private boolean inside(Position position, Position[] boundary) {
    int x = position.getX(), y = position.getY();
    Position min = boundary[0], max = boundary[1];
    return x >= min.getX() && y >= min.getY() && x <= max.getX() && y <= max.getY();
}
Also used : Position(org.apollo.game.model.Position)

Example 44 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() == 213) {
        // 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);
    boolean run = reader.getUnsigned(DataType.BYTE) == 1;
    int y = (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, DataTransformation.SUBTRACT);
    }
    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)

Example 45 with Position

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

the class PlayerSynchronizationMessageEncoder method putAddPlayerUpdate.

/**
 * Puts an add player update.
 *
 * @param seg The segment.
 * @param message The message.
 * @param builder The builder.
 */
private static void putAddPlayerUpdate(AddPlayerSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) {
    boolean updateRequired = seg.getBlockSet().size() > 0;
    Position player = message.getPosition();
    Position other = seg.getPosition();
    builder.putBits(11, seg.getIndex());
    builder.putBits(5, other.getX() - player.getX());
    builder.putBits(1, updateRequired ? 1 : 0);
    // discard walking queue?
    builder.putBits(1, 1);
    builder.putBits(5, other.getY() - player.getY());
}
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