use of org.apollo.game.model.area.Region 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());
}
use of org.apollo.game.model.area.Region in project apollo by apollo-rsps.
the class GameService method finalizePlayerRegistration.
/**
* Finalizes the registration of a player.
*
* @param player The player.
*/
public synchronized void finalizePlayerRegistration(Player player) {
world.register(player);
Region region = world.getRegionRepository().fromPosition(player.getPosition());
region.addEntity(player);
if (!player.getSession().isReconnecting()) {
player.sendInitialMessages();
}
}
use of org.apollo.game.model.area.Region in project apollo by apollo-rsps.
the class ItemOnObjectVerificationHandler method handle.
@Override
public void handle(Player player, ItemOnObjectMessage message) {
if (message.getInterfaceId() != SynchronizationInventoryListener.INVENTORY_ID && message.getInterfaceId() != BankConstants.SIDEBAR_INVENTORY_ID) {
message.terminate();
return;
}
Inventory inventory = player.getInventory();
int slot = message.getSlot();
if (slot < 0 || slot >= inventory.capacity()) {
message.terminate();
return;
}
Item item = inventory.get(slot);
if (item == null || item.getId() != message.getId()) {
message.terminate();
return;
}
int objectId = message.getObjectId();
if (objectId < 0 || objectId >= ObjectDefinition.count()) {
message.terminate();
return;
}
Position position = message.getPosition();
Region region = world.getRegionRepository().fromPosition(position);
Set<GameObject> objects = region.getEntities(position, EntityType.STATIC_OBJECT, EntityType.DYNAMIC_OBJECT);
if (!player.getPosition().isWithinDistance(position, 15) || !ObjectActionVerificationHandler.containsObject(objectId, objects)) {
message.terminate();
return;
}
}
use of org.apollo.game.model.area.Region in project apollo by apollo-rsps.
the class World method registerNpcs.
/**
* Registers all of the {@link Npc}s in the {@link #queuedNpcs queue}.
*/
private void registerNpcs() {
while (!queuedNpcs.isEmpty()) {
Npc npc = queuedNpcs.poll();
boolean success = npcRepository.add(npc);
if (success) {
Region region = regions.fromPosition(npc.getPosition());
region.addEntity(npc);
if (npc.hasBoundaries()) {
npcMovement.addNpc(npc);
}
} else {
logger.warning("Failed to register npc (capacity reached): [count=" + npcRepository.size() + "]");
}
}
}
use of org.apollo.game.model.area.Region in project apollo by apollo-rsps.
the class World method unregister.
/**
* Unregisters the specified player.
*
* @param player The player.
*/
public void unregister(final Player player) {
Preconditions.checkNotNull(player, "Player may not be null.");
players.remove(NameUtil.encodeBase37(player.getUsername()));
Region region = regions.fromPosition(player.getPosition());
region.removeEntity(player);
playerRepository.remove(player);
logger.info("Unregistered player: " + player + " [count=" + playerRepository.size() + "]");
}
Aggregations