use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class WalkMessageHandler method handle.
@Override
public void handle(Player player, WalkMessage message) {
WalkingQueue queue = player.getWalkingQueue();
Position[] steps = message.getSteps();
for (int index = 0; index < steps.length; index++) {
Position step = steps[index];
if (index == 0) {
queue.addFirstStep(step);
} else {
queue.addStep(step);
}
}
queue.setRunning(message.isRunning() || player.isRunning());
player.getInterfaceSet().close();
if (queue.size() > 0) {
player.stopAction();
}
if (player.getInteractingMob() != null) {
player.resetInteractingMob();
}
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class CollisionManager method apply.
/**
* Apply a {@link CollisionUpdate} to the game world.
*
* @param update The update to apply.
*/
public void apply(CollisionUpdate update) {
Region prev = null;
CollisionUpdateType type = update.getType();
Map<Position, Collection<DirectionFlag>> map = update.getFlags().asMap();
for (Map.Entry<Position, Collection<DirectionFlag>> entry : map.entrySet()) {
Position position = entry.getKey();
int height = position.getHeight();
if (bridges.contains(new Position(position.getX(), position.getY(), 1))) {
if (--height < 0) {
continue;
}
}
if (prev == null || !prev.contains(position)) {
prev = regions.fromPosition(position);
}
int localX = position.getX() % Region.SIZE;
int localY = position.getY() % Region.SIZE;
CollisionMatrix matrix = prev.getMatrix(height);
CollisionFlag[] mobs = CollisionFlag.mobs();
CollisionFlag[] projectiles = CollisionFlag.projectiles();
for (DirectionFlag flag : entry.getValue()) {
Direction direction = flag.getDirection();
if (direction == Direction.NONE) {
continue;
}
int orientation = direction.toInteger();
if (flag.isImpenetrable()) {
flag(type, matrix, localX, localY, projectiles[orientation]);
}
flag(type, matrix, localX, localY, mobs[orientation]);
}
}
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class WalkingQueue method pulse.
/**
* Pulses this WalkingQueue.
*/
public void pulse() {
Position position = mob.getPosition();
int height = position.getHeight();
Direction firstDirection = Direction.NONE;
Direction secondDirection = Direction.NONE;
World world = mob.getWorld();
CollisionManager collisionManager = world.getCollisionManager();
Position next = points.poll();
if (next != null) {
firstDirection = Direction.between(position, next);
if (!collisionManager.traversable(position, EntityType.NPC, firstDirection)) {
clear();
firstDirection = Direction.NONE;
} else {
previousPoints.add(next);
position = new Position(next.getX(), next.getY(), height);
mob.setLastDirection(firstDirection);
if (running) {
next = points.poll();
if (next != null) {
secondDirection = Direction.between(position, next);
if (!collisionManager.traversable(position, EntityType.NPC, secondDirection)) {
clear();
secondDirection = Direction.NONE;
} else {
previousPoints.add(next);
position = new Position(next.getX(), next.getY(), height);
mob.setLastDirection(secondDirection);
}
}
}
}
}
mob.setDirections(firstDirection, secondDirection);
mob.setPosition(position);
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class Region method contains.
/**
* Checks if this Region contains the specified Entity.
*
* This method operates in constant time.
*
* @param entity The Entity.
* @return {@code true} if this Region contains the Entity, otherwise {@code false}.
*/
public boolean contains(Entity entity) {
Position position = entity.getPosition();
Set<Entity> local = entities.get(position);
return local != null && local.contains(entity);
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class NpcSynchronizationMessageEncoder method putTurnToPositionBlock.
/**
* Puts a turn to position block into the specified builder.
*
* @param block The block.
* @param builder The builder.
*/
private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) {
Position position = block.getPosition();
builder.put(DataType.SHORT, DataOrder.LITTLE, position.getX() * 2 + 1);
builder.put(DataType.SHORT, DataOrder.LITTLE, position.getY() * 2 + 1);
}
Aggregations