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());
}
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);
}
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);
}
}
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);
}
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);
}
Aggregations