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