use of org.apollo.game.model.Direction in project apollo by apollo-rsps.
the class PlayerSynchronizationMessageEncoder method putMovementUpdate.
/**
* Puts a movement update for the specified segment.
*
* @param seg The segment.
* @param message The message.
* @param builder The builder.
*/
private static void putMovementUpdate(SynchronizationSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) {
boolean updateRequired = seg.getBlockSet().size() > 0;
if (seg.getType() == SegmentType.TELEPORT) {
Position pos = ((TeleportSegment) seg).getDestination();
builder.putBits(1, 1);
builder.putBits(2, 3);
builder.putBits(1, message.hasRegionChanged() ? 0 : 1);
builder.putBits(2, pos.getHeight());
builder.putBits(7, pos.getLocalY(message.getLastKnownRegion()));
builder.putBits(7, pos.getLocalX(message.getLastKnownRegion()));
builder.putBits(1, updateRequired ? 1 : 0);
} else if (seg.getType() == SegmentType.RUN) {
Direction[] directions = ((MovementSegment) seg).getDirections();
builder.putBits(1, 1);
builder.putBits(2, 2);
builder.putBits(3, directions[0].toInteger());
builder.putBits(3, directions[1].toInteger());
builder.putBits(1, updateRequired ? 1 : 0);
} else if (seg.getType() == SegmentType.WALK) {
Direction[] directions = ((MovementSegment) seg).getDirections();
builder.putBits(1, 1);
builder.putBits(2, 1);
builder.putBits(3, directions[0].toInteger());
builder.putBits(1, updateRequired ? 1 : 0);
} else {
if (updateRequired) {
builder.putBits(1, 1);
builder.putBits(2, 0);
} else {
builder.putBits(1, 0);
}
}
}
use of org.apollo.game.model.Direction 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.Direction 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.Direction in project apollo by apollo-rsps.
the class PlayerSynchronizationMessageEncoder method putMovementUpdate.
/**
* Puts a movement update for the specified segment.
*
* @param seg The segment.
* @param message The message.
* @param builder The builder.
*/
private static void putMovementUpdate(SynchronizationSegment seg, PlayerSynchronizationMessage message, GamePacketBuilder builder) {
boolean updateRequired = seg.getBlockSet().size() > 0;
if (seg.getType() == SegmentType.TELEPORT) {
Position position = ((TeleportSegment) seg).getDestination();
builder.putBits(1, 1);
builder.putBits(2, 3);
builder.putBits(2, position.getHeight());
builder.putBits(1, message.hasRegionChanged() ? 0 : 1);
builder.putBits(1, updateRequired ? 1 : 0);
builder.putBits(7, position.getLocalY(message.getLastKnownRegion()));
builder.putBits(7, position.getLocalX(message.getLastKnownRegion()));
} else if (seg.getType() == SegmentType.RUN) {
Direction[] directions = ((MovementSegment) seg).getDirections();
builder.putBits(1, 1);
builder.putBits(2, 2);
builder.putBits(3, directions[0].toInteger());
builder.putBits(3, directions[1].toInteger());
builder.putBits(1, updateRequired ? 1 : 0);
} else if (seg.getType() == SegmentType.WALK) {
Direction[] directions = ((MovementSegment) seg).getDirections();
builder.putBits(1, 1);
builder.putBits(2, 1);
builder.putBits(3, directions[0].toInteger());
builder.putBits(1, updateRequired ? 1 : 0);
} else {
if (updateRequired) {
builder.putBits(1, 1);
builder.putBits(2, 0);
} else {
builder.putBits(1, 0);
}
}
}
use of org.apollo.game.model.Direction in project apollo by apollo-rsps.
the class CollisionManagerTests method assertUntraversable.
/**
* Helper test assertion that a position is untraversable in a given direction.
*
* @param collisionManager The {@link CollisionManager} to check.
* @param position The {@link Position}.
* @param directions The {@link Direction}s to assert.
*/
private static void assertUntraversable(CollisionManager collisionManager, Position position, Direction... directions) {
for (Direction direction : directions) {
boolean traversable = collisionManager.traversable(position, EntityType.NPC, direction);
String message = String.format("Can walk %s from tile at (%d,%d), should not be able to", direction.toString(), position.getX(), position.getY());
Assert.assertFalse(message, traversable);
}
}
Aggregations