Search in sources :

Example 1 with EntityType

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

the class CollisionUpdateListener method execute.

@Override
public void execute(Region region, Entity entity, EntityUpdateType type) {
    EntityType entityType = entity.getEntityType();
    if (entityType != EntityType.STATIC_OBJECT && entityType != EntityType.DYNAMIC_OBJECT) {
        return;
    }
    CollisionUpdate.Builder builder = new CollisionUpdate.Builder();
    if (type == EntityUpdateType.ADD) {
        builder.type(CollisionUpdateType.ADDING);
    } else {
        builder.type(CollisionUpdateType.REMOVING);
    }
    builder.object((GameObject) entity);
    collisionManager.apply(builder.build());
}
Also used : EntityType(org.apollo.game.model.entity.EntityType)

Example 2 with EntityType

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

the class World method spawn.

/**
 * Spawns the specified {@link Entity}, which must not be a {@link Player}
 * or an {@link Npc}, which have their own register methods.
 *
 * @param entity The Entity.
 */
public void spawn(Entity entity) {
    EntityType type = entity.getEntityType();
    Preconditions.checkArgument(type != EntityType.PLAYER && type != EntityType.NPC, "Cannot spawn a Mob.");
    Region region = regions.fromPosition(entity.getPosition());
    region.addEntity(entity);
}
Also used : EntityType(org.apollo.game.model.entity.EntityType) Region(org.apollo.game.model.area.Region)

Example 3 with EntityType

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

the class Region method addEntity.

/**
 * Adds a {@link Entity} to the Region. Note that this does not spawn the Entity, or do any other action other than
 * register it to this Region.
 *
 * @param entity The Entity.
 * @param notify Whether or not the {@link RegionListener}s for this Region should be notified.
 * @throws IllegalArgumentException If the Entity does not belong in this Region.
 */
public void addEntity(Entity entity, boolean notify) {
    EntityType type = entity.getEntityType();
    Position position = entity.getPosition();
    checkPosition(position);
    if (!type.isTransient()) {
        Set<Entity> local = entities.computeIfAbsent(position, key -> new HashSet<>(DEFAULT_LIST_SIZE));
        local.add(entity);
    }
    if (notify) {
        notifyListeners(entity, EntityUpdateType.ADD);
    }
}
Also used : EntityType(org.apollo.game.model.entity.EntityType) Entity(org.apollo.game.model.entity.Entity) GroupableEntity(org.apollo.game.model.area.update.GroupableEntity) Position(org.apollo.game.model.Position)

Example 4 with EntityType

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

the class Region method record.

/**
 * Records the specified {@link GroupableEntity} as being updated this pulse.
 *
 * @param entity The GroupableEntity.
 * @param update The {@link EntityUpdateType}.
 * @throws UnsupportedOperationException If the specified Entity cannot be operated on in this manner.
 */
private <T extends Entity & GroupableEntity> void record(T entity, EntityUpdateType update) {
    UpdateOperation<?> operation = entity.toUpdateOperation(this, update);
    RegionUpdateMessage message = operation.toMessage(), inverse = operation.inverse();
    int height = entity.getPosition().getHeight();
    Set<RegionUpdateMessage> updates = this.updates.get(height);
    EntityType type = entity.getEntityType();
    if (type == EntityType.STATIC_OBJECT) {
        // TODO set/clear collision matrix values
        if (update == EntityUpdateType.REMOVE) {
            removedObjects.get(height).add(message);
        } else {
            // TODO should this really be possible?
            removedObjects.get(height).remove(inverse);
        }
    } else if (update == EntityUpdateType.REMOVE && !type.isTransient()) {
        updates.remove(inverse);
    }
    updates.add(message);
}
Also used : EntityType(org.apollo.game.model.entity.EntityType) RegionUpdateMessage(org.apollo.game.message.impl.RegionUpdateMessage)

Example 5 with EntityType

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

the class Region method removeEntity.

/**
 * Removes an {@link Entity} from this Region.
 *
 * @param entity The Entity.
 * @throws IllegalArgumentException If the Entity does not belong in this Region, or if it was never added.
 */
public void removeEntity(Entity entity) {
    EntityType type = entity.getEntityType();
    if (type.isTransient()) {
        throw new IllegalArgumentException("Tried to remove a transient Entity (" + entity + ") from " + "(" + this + ").");
    }
    Position position = entity.getPosition();
    checkPosition(position);
    Set<Entity> local = entities.get(position);
    if (local == null || !local.remove(entity)) {
        throw new IllegalArgumentException("Entity (" + entity + ") belongs in (" + this + ") but does not exist.");
    }
    notifyListeners(entity, EntityUpdateType.REMOVE);
}
Also used : EntityType(org.apollo.game.model.entity.EntityType) Entity(org.apollo.game.model.entity.Entity) GroupableEntity(org.apollo.game.model.area.update.GroupableEntity) Position(org.apollo.game.model.Position)

Aggregations

EntityType (org.apollo.game.model.entity.EntityType)5 Position (org.apollo.game.model.Position)2 GroupableEntity (org.apollo.game.model.area.update.GroupableEntity)2 Entity (org.apollo.game.model.entity.Entity)2 RegionUpdateMessage (org.apollo.game.message.impl.RegionUpdateMessage)1 Region (org.apollo.game.model.area.Region)1