/** * Clicks a tile on the minimap. * * @param mobile The mobile to click (global). * @return <tt>true</tt> if the mobile was clicked; otherwise <tt>false</tt>. */ public static boolean walk(final Locatable mobile) { Tile stepDirection = mobile.getLocation(); if (!stepDirection.isOnMap()) { stepDirection = getClosestOnMap(stepDirection); } final Tile tile = stepDirection; return Mouse.apply( new ViewportEntity() { public Point getCentralPoint() { return Calculations.worldToMap(tile.getX(), tile.getY()); } public Point getNextViewportPoint() { return getCentralPoint(); } public boolean contains(final Point point) { return getCentralPoint().distance(point) <= 2; } public boolean validate() { return tile.isOnMap(); } }, new Filter<Point>() { public boolean accept(final Point point) { Mouse.click(true); return true; } }); }
public static Tile getClosestOnMap(Tile tile) { if (tile.isOnMap()) { return tile; } final Tile location = Players.getLocal().getLocation(); tile = tile.derive(-location.getX(), -location.getY()); final double angle = Math.atan2(tile.getY(), tile.getX()); return new Tile( location.getX() + (int) (16d * Math.cos(angle)), location.getY() + (int) (16d * Math.sin(angle)), tile.getPlane()); }