sp3cpk Posted May 10, 2017 Posted May 10, 2017 Hello! I was wondering if anyone could help with the following: Say my player is less than 3 coordinates from an NPC, how would approach this situation so my bot will walk to a coordinate 3 tiles away (a reachable coordinate).
Isolate Posted May 10, 2017 Posted May 10, 2017 (edited) Area small = entity.getArea(2); Area big = entity.getArea(3); List<Position> positions = big.getPositions(); if(positions.removeAll(small.getPositions())) { Position position = positions.get(new Random().nextInt((positions.size() - 1))); if (position != null) { WalkingEvent event = new WalkingEvent(position); event.setMiniMapDistanceThreshold(0); event.setMinDistanceThreshold(0); event.setBreakCondition(new Condition() { @Override public boolean evaluate() { return entity.getPosition().distance(myPosition()) >= 3; } }); execute(event); } } ? I think... ? I have a hunch I over complicated it Edited May 10, 2017 by Isolate
Alek Posted May 10, 2017 Posted May 10, 2017 40 minutes ago, Isolate said: Area small = entity.getArea(2); Area big = entity.getArea(3); List<Position> positions = big.getPositions(); if(positions.removeAll(small.getPositions())) { Position position = positions.get(new Random().nextInt((positions.size() - 1))); if (position != null) { WalkingEvent event = new WalkingEvent(position); event.setMiniMapDistanceThreshold(0); event.setMinDistanceThreshold(0); event.setBreakCondition(new Condition() { @Override public boolean evaluate() { return entity.getPosition().distance(myPosition()) >= 3; } }); execute(event); } } ? I think... ? I have a hunch I over complicated it It will fail if the position which was chosen at random is unreachable; in both WebWalkEvent or WalkingEvent. WalkingEvent event = new WalkingEvent(Entity entity).setDistanceThreshold(1); execute(event);