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());
}
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);
}
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);
}
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);
}
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());
}
Aggregations