Retry area localisation and fix walking

This commit is contained in:
Yuri Moens 2021-10-18 18:35:25 +02:00
parent 34586a83f6
commit d094033e6c
Signed by: ymo
GPG Key ID: F6D51D6FE15BE924

View File

@ -97,6 +97,8 @@ public class HandleObstacle extends TaskNode {
private final Course course; private final Course course;
private final Map<Integer, Rectangle> hoverMap; private final Map<Integer, Rectangle> hoverMap;
private int retries = 0;
public HandleObstacle(Course course) { public HandleObstacle(Course course) {
this.course = course; this.course = course;
this.hoverMap = new HashMap<>(); this.hoverMap = new HashMap<>();
@ -113,16 +115,22 @@ public class HandleObstacle extends TaskNode {
public int execute() { public int execute() {
Obstacle current = course.getCurrentObstacle(); Obstacle current = course.getCurrentObstacle();
if (current == null) { if (current == null) {
MethodContext.logError("Player is in an unsupported area: " + Players.localPlayer().getTile().toString() + ". Stopping."); if (retries >= 10) {
ScriptManager.getScriptManager().stop(); MethodContext.logError("Player is in an unsupported area: " + Players.localPlayer().getTile().toString() + ". Stopping.");
return 0; ScriptManager.getScriptManager().stop();
} else {
retries++;
}
return Calculations.random(300, 400);
} }
retries = 0;
final GameObject currentObject = current.getGameObject(); final GameObject currentObject = current.getGameObject();
if (currentObject == null) return Calculations.random(300, 500); if (currentObject == null) return Calculations.random(300, 500);
if (!currentObject.isOnScreen()) { if (!currentObject.isOnScreen()) {
Walking.clickTileOnMinimap(currentObject.getTile()); Walking.walk(currentObject);
MethodContext.sleepUntil(() -> Players.localPlayer().distance(currentObject) < 3, Calculations.random(5000, 5500)); MethodContext.sleepUntil(() -> Players.localPlayer().distance(currentObject) < 3, Calculations.random(5000, 5500));
} }