Search in sources :

Example 6 with RegionRepository

use of org.apollo.game.model.area.RegionRepository 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)

Example 7 with RegionRepository

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

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

the class StaticGameObject method viewableBy.

@Override
public boolean viewableBy(Player player, World world) {
    RegionRepository repository = world.getRegionRepository();
    RegionCoordinates coordinates = position.getRegionCoordinates();
    return repository.get(coordinates).contains(this);
}
Also used : RegionCoordinates(org.apollo.game.model.area.RegionCoordinates) RegionRepository(org.apollo.game.model.area.RegionRepository)

Example 9 with RegionRepository

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

the class PrePlayerSynchronizationTask method sendUpdates.

/**
 * Sends the updates for a {@link Region}
 *
 * @param position The {@link Position} of the last known region.
 * @param differences The {@link Set} of {@link RegionCoordinates} of Regions that changed.
 * @param full The {@link Set} of {@link RegionCoordinates} of Regions that require a full update.
 */
private void sendUpdates(Position position, Set<RegionCoordinates> differences, Set<RegionCoordinates> full) {
    RegionRepository repository = player.getWorld().getRegionRepository();
    int height = position.getHeight();
    for (RegionCoordinates coordinates : differences) {
        Set<RegionUpdateMessage> messages = updates.computeIfAbsent(coordinates, coords -> repository.get(coords).getUpdates(height));
        if (!messages.isEmpty()) {
            player.send(new GroupedRegionUpdateMessage(position, coordinates, messages));
        }
    }
    for (RegionCoordinates coordinates : full) {
        Set<RegionUpdateMessage> messages = encodes.computeIfAbsent(coordinates, coords -> repository.get(coords).encode(height));
        if (!messages.isEmpty()) {
            player.send(new ClearRegionMessage(position, coordinates));
            player.send(new GroupedRegionUpdateMessage(position, coordinates, messages));
        }
    }
}
Also used : RegionCoordinates(org.apollo.game.model.area.RegionCoordinates) GroupedRegionUpdateMessage(org.apollo.game.message.impl.GroupedRegionUpdateMessage) RegionRepository(org.apollo.game.model.area.RegionRepository) RegionUpdateMessage(org.apollo.game.message.impl.RegionUpdateMessage) GroupedRegionUpdateMessage(org.apollo.game.message.impl.GroupedRegionUpdateMessage) ClearRegionMessage(org.apollo.game.message.impl.ClearRegionMessage)

Example 10 with RegionRepository

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

the class ObjectActionVerificationHandlerTests method terminateIfOutOfRange.

@Test
public void terminateIfOutOfRange() 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));
    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);
    ObjectActionMessage objectActionMessage = new ObjectActionMessage(1, 4151, objectPosition);
    ObjectActionVerificationHandler objectActionVerificationHandler = new ObjectActionVerificationHandler(world);
    objectActionVerificationHandler.handle(player, objectActionMessage);
    assertTrue("ObjectVerificationHandler: message not terminated when out of range!", objectActionMessage.terminated());
}
Also used : Entity(org.apollo.game.model.entity.Entity) Player(org.apollo.game.model.entity.Player) ObjectActionMessage(org.apollo.game.message.impl.ObjectActionMessage) Position(org.apollo.game.model.Position) RegionRepository(org.apollo.game.model.area.RegionRepository) Region(org.apollo.game.model.area.Region) StaticGameObject(org.apollo.game.model.entity.obj.StaticGameObject) World(org.apollo.game.model.World) HashSet(java.util.HashSet) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

RegionRepository (org.apollo.game.model.area.RegionRepository)12 Position (org.apollo.game.model.Position)10 Region (org.apollo.game.model.area.Region)9 HashSet (java.util.HashSet)6 World (org.apollo.game.model.World)6 Player (org.apollo.game.model.entity.Player)6 RegionCoordinates (org.apollo.game.model.area.RegionCoordinates)5 Entity (org.apollo.game.model.entity.Entity)5 StaticGameObject (org.apollo.game.model.entity.obj.StaticGameObject)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 ItemOnObjectMessage (org.apollo.game.message.impl.ItemOnObjectMessage)3 Inventory (org.apollo.game.model.inv.Inventory)3 ArrayList (java.util.ArrayList)2 ObjectActionMessage (org.apollo.game.message.impl.ObjectActionMessage)2 MovementSegment (org.apollo.game.sync.seg.MovementSegment)2 RemoveMobSegment (org.apollo.game.sync.seg.RemoveMobSegment)2 SynchronizationSegment (org.apollo.game.sync.seg.SynchronizationSegment)2 MapObject (org.apollo.cache.map.MapObject)1 ClearRegionMessage (org.apollo.game.message.impl.ClearRegionMessage)1