Search in sources :

Example 36 with Position

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

the class ItemOnObjectVerificationHandlerTests method terminateIfObjectOutOfRange.

@Test
public void terminateIfObjectOutOfRange() 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);
    inventory.set(1, new Item(4151, 1));
    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, 1, 1, objectPosition.getX(), objectPosition.getY());
    ItemOnObjectVerificationHandler itemOnObjectVerificationHandler = new ItemOnObjectVerificationHandler(world);
    itemOnObjectVerificationHandler.handle(player, itemOnObjectMessage);
    assertTrue("ObjectVerificationHandler: message not terminated when object out of range!", itemOnObjectMessage.terminated());
}
Also used : Entity(org.apollo.game.model.entity.Entity) Player(org.apollo.game.model.entity.Player) Position(org.apollo.game.model.Position) ItemOnObjectMessage(org.apollo.game.message.impl.ItemOnObjectMessage) StaticGameObject(org.apollo.game.model.entity.obj.StaticGameObject) World(org.apollo.game.model.World) Item(org.apollo.game.model.Item) RegionRepository(org.apollo.game.model.area.RegionRepository) Region(org.apollo.game.model.area.Region) Inventory(org.apollo.game.model.inv.Inventory) HashSet(java.util.HashSet) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 37 with Position

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

the class CollisionManagerTests method object.

/**
 * Tests that the tiles occupied by a 2x2 square object are not traversable.  When an interactable object is added
 * to a collision update, all tiles spanning its with and length from its origin position will be marked as completely
 * blocked off, which with a 2x2 object at (1,1) produces a grid like this:
 * <pre>
 * (0,3) |---------|---------|---------|---------|
 *       |         |xxxxxxxxx|xxxxxxxxx|         |
 *       |         |x       x|x       x|         |
 *       |         |xxxxxxxxx|xxxxxxxxx|         |
 * (0,2) |---------|---------|---------|---------|
 *       |         |xxxxxxxxx|xxxxxxxxx|         |
 *       |         |x       x|x       x|         |
 *       |         |xxxxxxxxx|xxxxxxxxx|         |
 * (0,1) |---------|---------|---------|---------|
 *       |         |         |         |         |
 *       |         |         |         |         |
 *       |         |         |         |         |
 * (0,0) |---------|---------|---------|---------|
 * 	   (0,0)     (1,0)     (2,0)     (3,0)     (4,0)
 * </pre>
 * <p>
 * Where every tile that is occupied by the object is untraversable in every direction.
 */
@Test
public void object() {
    Position origin = new Position(1, 1, 0);
    CollisionManager collisionManager = createCollisionManager(createMapObject(SQUARE_OBJECT, origin, ObjectType.INTERACTABLE, Direction.NORTH));
    Position west = origin.step(1, Direction.WEST);
    Position east = origin.step(2, Direction.EAST);
    Position northEast = origin.step(2, Direction.NORTH).step(1, Direction.EAST);
    Position southEast = origin.step(1, Direction.SOUTH_EAST);
    assertUntraversable(collisionManager, west, Direction.EAST);
    assertUntraversable(collisionManager, east, Direction.WEST);
    assertUntraversable(collisionManager, northEast, Direction.SOUTH_EAST, Direction.SOUTH_WEST);
    assertUntraversable(collisionManager, southEast, Direction.NORTH_EAST, Direction.NORTH_WEST);
}
Also used : Position(org.apollo.game.model.Position) Test(org.junit.Test)

Example 38 with Position

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

the class CollisionManagerTests method wall.

/**
 * Tests that a wall is untraversable from the front and back, for the facing direction and opposite facing direction
 * respectively. For a simple grid, with a wall on 0,1 we end up with a collision matrix looking like:
 * <pre>
 * (0,2) |---------|
 *       |         |
 *       |         |
 *       |   xxx   |
 * (0,1) |---------|
 *       |   xxx   |
 *       |         |
 *       |         |
 * (0,0) |---------|
 *       |         |
 *       |         |
 *       |         |
 *       |---------|
 * </pre>
 * <p>
 * Where {@code xxx} denotes that you cannot walk into that tile from that direction (in this case you south on
 * (0,2) and north on (0,1)). For the grid above you can't walk north into {@code (0, 2)} because {@code (0, 2)} is
 * untraversable from the south, and as expectred you can't walk south into {@code (0,1)} because ({@code (0, 1)} is
 * untraversable from the north.
 */
@Test
public void wall() {
    Position front = new Position(0, 1, 0);
    Position back = front.step(1, Direction.NORTH);
    CollisionManager collisionManager = createCollisionManager(createMapObject(WALL, front, ObjectType.LENGTHWISE_WALL, Direction.NORTH));
    assertUntraversable(collisionManager, front, Direction.NORTH);
    assertUntraversable(collisionManager, back, Direction.SOUTH);
    assertUntraversable(collisionManager, front, Direction.NORTH_EAST);
    assertUntraversable(collisionManager, back, Direction.SOUTH_EAST);
}
Also used : Position(org.apollo.game.model.Position) Test(org.junit.Test)

Example 39 with Position

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

the class CollisionManagerTests method cornerWall.

/**
 * Tests that a corner wall is untraversable from the sides that it blocks.  Corners are much like walls, with
 * the only difference being their orientation.  Instead of {@link Direction#WNES}, they have diagonal directions.
 * With a corner wall at (0, 1) facing to the north-east we end up with a grid looking like this:
 * <p>
 * <pre>
 * (0,2) |---------|---------|
 *       |         |         |
 *       |         |         |
 *       |         |xxx      |
 * (0,1) |---------|---------|
 *       |      xxx|         |
 *       |         |         |
 *       |         |         |
 * (0,0) |---------|---------|
 * 	   (1,0)     (2,0)     (3,0)
 * </pre>
 * <p>
 * Where you can walk north and east through the tile the corner occupies, as well as south and west through the
 * adjacent tile, but not north-east or south-west.
 */
@Test
public void cornerWall() {
    Position front = new Position(0, 1, 0);
    Position back = front.step(1, Direction.NORTH_EAST);
    CollisionManager collisionManager = createCollisionManager(createMapObject(WALL, front, ObjectType.TRIANGULAR_CORNER, Direction.NORTH_EAST));
    assertTraversable(collisionManager, front, Direction.NORTH, Direction.EAST);
    assertUntraversable(collisionManager, front, Direction.NORTH_EAST);
    assertTraversable(collisionManager, back, Direction.SOUTH, Direction.WEST);
    assertUntraversable(collisionManager, back, Direction.SOUTH_WEST);
}
Also used : Position(org.apollo.game.model.Position) Test(org.junit.Test)

Example 40 with Position

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

the class ItemOnObjectVerificationHandlerTests method terminateIfInvalidItem.

@Test
public void terminateIfInvalidItem() throws Exception {
    Position playerPosition = new Position(3200, 3200);
    Position objectPosition = new Position(3200, 3216);
    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, 1, 1, objectPosition.getX(), objectPosition.getY());
    ItemOnObjectVerificationHandler itemOnObjectVerificationHandler = new ItemOnObjectVerificationHandler(world);
    itemOnObjectVerificationHandler.handle(player, itemOnObjectMessage);
    assertTrue("ObjectVerificationHandler: message not terminated valid item 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)

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