Search in sources :

Example 51 with Position

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();
    }
}
Also used : Position(org.apollo.game.model.Position) WalkingQueue(org.apollo.game.model.entity.WalkingQueue)

Example 52 with Position

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]);
        }
    }
}
Also used : Position(org.apollo.game.model.Position) DirectionFlag(org.apollo.game.model.area.collision.CollisionUpdate.DirectionFlag) Direction(org.apollo.game.model.Direction) Region(org.apollo.game.model.area.Region) Collection(java.util.Collection) Map(java.util.Map)

Example 53 with Position

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);
}
Also used : CollisionManager(org.apollo.game.model.area.collision.CollisionManager) Position(org.apollo.game.model.Position) World(org.apollo.game.model.World) Direction(org.apollo.game.model.Direction)

Example 54 with 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);
}
Also used : Entity(org.apollo.game.model.entity.Entity) GroupableEntity(org.apollo.game.model.area.update.GroupableEntity) Position(org.apollo.game.model.Position)

Example 55 with Position

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);
}
Also used : Position(org.apollo.game.model.Position)

Aggregations

Position (org.apollo.game.model.Position)66 Region (org.apollo.game.model.area.Region)14 RegionRepository (org.apollo.game.model.area.RegionRepository)10 GamePacketReader (org.apollo.net.codec.game.GamePacketReader)10 GamePacketBuilder (org.apollo.net.codec.game.GamePacketBuilder)9 ObjectActionMessage (org.apollo.game.message.impl.ObjectActionMessage)8 Direction (org.apollo.game.model.Direction)8 Entity (org.apollo.game.model.entity.Entity)8 HashSet (java.util.HashSet)7 World (org.apollo.game.model.World)7 Player (org.apollo.game.model.entity.Player)7 Test (org.junit.Test)7 StaticGameObject (org.apollo.game.model.entity.obj.StaticGameObject)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 ArrayList (java.util.ArrayList)3 ItemOnObjectMessage (org.apollo.game.message.impl.ItemOnObjectMessage)3 RegionCoordinates (org.apollo.game.model.area.RegionCoordinates)3 GroupableEntity (org.apollo.game.model.area.update.GroupableEntity)3 Inventory (org.apollo.game.model.inv.Inventory)3 MovementSegment (org.apollo.game.sync.seg.MovementSegment)3