From 8e72c90252befcf0b1e75ee8c31be3575a4e48b0 Mon Sep 17 00:00:00 2001 From: Yuri Moens Date: Wed, 20 Oct 2021 11:21:55 +0200 Subject: [PATCH] Handle misclicks --- .../cagility/tasks/HandleObstacle.java | 29 ++++++++++++++----- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/CAgility/src/io/reisub/dreambot/cagility/tasks/HandleObstacle.java b/CAgility/src/io/reisub/dreambot/cagility/tasks/HandleObstacle.java index b6b7c76..a1a135a 100644 --- a/CAgility/src/io/reisub/dreambot/cagility/tasks/HandleObstacle.java +++ b/CAgility/src/io/reisub/dreambot/cagility/tasks/HandleObstacle.java @@ -16,7 +16,6 @@ import org.dreambot.api.methods.walking.impl.Walking; import org.dreambot.api.methods.walking.path.impl.LocalPath; import org.dreambot.api.script.ScriptManager; import org.dreambot.api.script.TaskNode; -import org.dreambot.api.utilities.impl.Condition; import org.dreambot.api.wrappers.interactive.GameObject; import org.dreambot.api.wrappers.items.GroundItem; @@ -214,13 +213,7 @@ public class HandleObstacle extends TaskNode { MethodContext.sleepUntil(Util::playerIsIdle, Calculations.random(3000, 3500)); } - if (isWalking) { - Mouse.setAlwaysHop(true); - currentObject.interactForceLeft(currentObject.getActions()[0]); - Mouse.setAlwaysHop(false); - } else { - currentObject.interactForceLeft(currentObject.getActions()[0]); - } + interact(currentObject, isWalking); Rectangle hoverRect = hoverMap.get(current.getNext().getID()); if (hoverRect != null) { @@ -235,4 +228,24 @@ public class HandleObstacle extends TaskNode { return Calculations.random(180, 350); } + + public void interact(GameObject currentObject, boolean shouldHop) { + Mouse.setAlwaysHop(shouldHop); + currentObject.interactForceLeft(currentObject.getActions()[0]); + Mouse.setAlwaysHop(false); + + Tile dest = null; + + if (MethodProvider.sleepUntil(() -> { + Tile t = Walking.getDestination(); + return t != null; + }, Calculations.random(1000, 1100))) { + dest = Walking.getDestination(); + } + + if (!currentObject.getObjectTiles().contains(dest) && !currentObject.getInteractableFrom().contains(dest)) { + MethodProvider.log("Misclick, trying again"); + interact(currentObject, true); + } + } }