Search in sources :

Example 1 with GameObject

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

the class ObjectActionVerificationHandler method handle.

@Override
public void handle(Player player, ObjectActionMessage message) {
    int id = message.getId();
    if (id < 0 || id >= 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) || !containsObject(id, objects)) {
        message.terminate();
        return;
    }
    ObjectDefinition definition = ObjectDefinition.lookup(id);
    if (message.getOption() >= definition.getMenuActions().length) {
        message.terminate();
        return;
    }
}
Also used : Position(org.apollo.game.model.Position) GameObject(org.apollo.game.model.entity.obj.GameObject) Region(org.apollo.game.model.area.Region) ObjectDefinition(org.apollo.cache.def.ObjectDefinition)

Example 2 with GameObject

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

the class CollisionManager method build.

/**
 * Applies the initial {@link CollisionUpdate} to the {@link CollisionMatrix}es for all objects and tiles loaded
 * from the cache.
 *
 * @param rebuilding A flag indicating whether or not {@link CollisionMatrix}es are being rebuilt.
 */
public void build(boolean rebuilding) {
    if (rebuilding) {
        for (Region region : regions.getRegions()) {
            for (CollisionMatrix matrix : region.getMatrices()) {
                matrix.reset();
            }
        }
    }
    CollisionUpdate.Builder builder = new CollisionUpdate.Builder();
    builder.type(CollisionUpdateType.ADDING);
    for (Position tile : blocked) {
        int x = tile.getX(), y = tile.getY();
        int height = tile.getHeight();
        if (bridges.contains(new Position(x, y, 1))) {
            height--;
        }
        if (height >= 0) {
            builder.tile(new Position(x, y, height), false, Direction.NESW);
        }
    }
    apply(builder.build());
    for (Region region : regions.getRegions()) {
        CollisionUpdate.Builder objects = new CollisionUpdate.Builder();
        objects.type(CollisionUpdateType.ADDING);
        region.getEntities(STATIC_OBJECT, DYNAMIC_OBJECT).forEach(entity -> objects.object((GameObject) entity));
        apply(objects.build());
    }
}
Also used : Position(org.apollo.game.model.Position) GameObject(org.apollo.game.model.entity.obj.GameObject) Region(org.apollo.game.model.area.Region)

Example 3 with GameObject

use of org.apollo.game.model.entity.obj.GameObject 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;
    }
}
Also used : Item(org.apollo.game.model.Item) Position(org.apollo.game.model.Position) GameObject(org.apollo.game.model.entity.obj.GameObject) Region(org.apollo.game.model.area.Region) Inventory(org.apollo.game.model.inv.Inventory)

Aggregations

Position (org.apollo.game.model.Position)3 Region (org.apollo.game.model.area.Region)3 GameObject (org.apollo.game.model.entity.obj.GameObject)3 ObjectDefinition (org.apollo.cache.def.ObjectDefinition)1 Item (org.apollo.game.model.Item)1 Inventory (org.apollo.game.model.inv.Inventory)1