Search in sources :

Example 16 with Player

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

Example 17 with Player

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

the class ParallelClientSynchronizer method synchronize.

@Override
public void synchronize(MobRepository<Player> players, MobRepository<Npc> npcs) {
    int playerCount = players.size();
    int npcCount = npcs.size();
    Map<RegionCoordinates, Set<RegionUpdateMessage>> encodes = new ConcurrentHashMap<>();
    Map<RegionCoordinates, Set<RegionUpdateMessage>> updates = new ConcurrentHashMap<>();
    phaser.bulkRegister(playerCount);
    for (Player player : players) {
        SynchronizationTask task = new PrePlayerSynchronizationTask(player, encodes, updates);
        executor.submit(new PhasedSynchronizationTask(phaser, task));
    }
    phaser.arriveAndAwaitAdvance();
    phaser.bulkRegister(npcCount);
    for (Npc npc : npcs) {
        SynchronizationTask task = new PreNpcSynchronizationTask(npc);
        executor.submit(new PhasedSynchronizationTask(phaser, task));
    }
    phaser.arriveAndAwaitAdvance();
    phaser.bulkRegister(playerCount);
    for (Player player : players) {
        SynchronizationTask task = new PlayerSynchronizationTask(player);
        executor.submit(new PhasedSynchronizationTask(phaser, task));
    }
    phaser.arriveAndAwaitAdvance();
    phaser.bulkRegister(playerCount);
    for (Player player : players) {
        SynchronizationTask task = new NpcSynchronizationTask(player);
        executor.submit(new PhasedSynchronizationTask(phaser, task));
    }
    phaser.arriveAndAwaitAdvance();
    phaser.bulkRegister(playerCount);
    for (Player player : players) {
        SynchronizationTask task = new PostPlayerSynchronizationTask(player);
        executor.submit(new PhasedSynchronizationTask(phaser, task));
    }
    phaser.arriveAndAwaitAdvance();
    phaser.bulkRegister(npcCount);
    for (Npc npc : npcs) {
        SynchronizationTask task = new PostNpcSynchronizationTask(npc);
        executor.submit(new PhasedSynchronizationTask(phaser, task));
    }
    phaser.arriveAndAwaitAdvance();
}
Also used : Npc(org.apollo.game.model.entity.Npc) PhasedSynchronizationTask(org.apollo.game.sync.task.PhasedSynchronizationTask) Player(org.apollo.game.model.entity.Player) Set(java.util.Set) PlayerSynchronizationTask(org.apollo.game.sync.task.PlayerSynchronizationTask) PrePlayerSynchronizationTask(org.apollo.game.sync.task.PrePlayerSynchronizationTask) PostPlayerSynchronizationTask(org.apollo.game.sync.task.PostPlayerSynchronizationTask) PrePlayerSynchronizationTask(org.apollo.game.sync.task.PrePlayerSynchronizationTask) NpcSynchronizationTask(org.apollo.game.sync.task.NpcSynchronizationTask) PlayerSynchronizationTask(org.apollo.game.sync.task.PlayerSynchronizationTask) PrePlayerSynchronizationTask(org.apollo.game.sync.task.PrePlayerSynchronizationTask) SynchronizationTask(org.apollo.game.sync.task.SynchronizationTask) PostNpcSynchronizationTask(org.apollo.game.sync.task.PostNpcSynchronizationTask) PostPlayerSynchronizationTask(org.apollo.game.sync.task.PostPlayerSynchronizationTask) PreNpcSynchronizationTask(org.apollo.game.sync.task.PreNpcSynchronizationTask) PhasedSynchronizationTask(org.apollo.game.sync.task.PhasedSynchronizationTask) RegionCoordinates(org.apollo.game.model.area.RegionCoordinates) NpcSynchronizationTask(org.apollo.game.sync.task.NpcSynchronizationTask) PostNpcSynchronizationTask(org.apollo.game.sync.task.PostNpcSynchronizationTask) PreNpcSynchronizationTask(org.apollo.game.sync.task.PreNpcSynchronizationTask) PreNpcSynchronizationTask(org.apollo.game.sync.task.PreNpcSynchronizationTask) PostPlayerSynchronizationTask(org.apollo.game.sync.task.PostPlayerSynchronizationTask) PostNpcSynchronizationTask(org.apollo.game.sync.task.PostNpcSynchronizationTask) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

Player (org.apollo.game.model.entity.Player)17 Position (org.apollo.game.model.Position)7 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 Region (org.apollo.game.model.area.Region)6 RegionRepository (org.apollo.game.model.area.RegionRepository)6 HashSet (java.util.HashSet)5 World (org.apollo.game.model.World)5 Entity (org.apollo.game.model.entity.Entity)5 StaticGameObject (org.apollo.game.model.entity.obj.StaticGameObject)4 Inventory (org.apollo.game.model.inv.Inventory)4 ItemOnObjectMessage (org.apollo.game.message.impl.ItemOnObjectMessage)3 RegionCoordinates (org.apollo.game.model.area.RegionCoordinates)3 ArrayList (java.util.ArrayList)2 Set (java.util.Set)2 ObjectActionMessage (org.apollo.game.message.impl.ObjectActionMessage)2 Item (org.apollo.game.model.Item)2 Npc (org.apollo.game.model.entity.Npc)2 BufferedInputStream (java.io.BufferedInputStream)1 DataInputStream (java.io.DataInputStream)1