Search in sources :

Example 1 with WalkingQueue

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

the class NpcMovementTask method execute.

@Override
public void execute() {
    int count = RANDOM.nextInt(npcs.size() / 50 + 5);
    for (int iterations = 0; iterations < count; iterations++) {
        Npc npc = npcs.poll();
        if (npc == null) {
            break;
        }
        Position[] boundary = npc.getBoundaries().get();
        Position current = npc.getPosition();
        Position min = boundary[0], max = boundary[1];
        int currentX = current.getX(), currentY = current.getY();
        boolean negativeX = RANDOM.nextBoolean(), negativeY = RANDOM.nextBoolean();
        int x = RANDOM.nextInt(negativeX ? currentX - min.getX() : max.getX() - currentX);
        int y = RANDOM.nextInt(negativeY ? currentY - min.getY() : max.getY() - currentY);
        int dx = negativeX ? -x : x;
        int dy = negativeY ? -y : y;
        Position next = new Position(currentX + dx, currentY + dy);
        Deque<Position> positions = algorithm.find(current, next, boundary);
        WalkingQueue queue = npc.getWalkingQueue();
        Position first = positions.pollFirst();
        if (first != null) {
            queue.addFirstStep(first);
            positions.forEach(queue::addStep);
        }
        npcs.offer(npc);
    }
}
Also used : Npc(org.apollo.game.model.entity.Npc) Position(org.apollo.game.model.Position) WalkingQueue(org.apollo.game.model.entity.WalkingQueue)

Example 2 with WalkingQueue

use of org.apollo.game.model.entity.WalkingQueue 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)

Aggregations

Position (org.apollo.game.model.Position)2 WalkingQueue (org.apollo.game.model.entity.WalkingQueue)2 Npc (org.apollo.game.model.entity.Npc)1