package io.reisub.dreambot.cagility.tasks; import io.reisub.dreambot.cagility.Obstacle; import io.reisub.dreambot.util.Constants; import io.reisub.dreambot.util.Util; import org.dreambot.api.input.Mouse; import org.dreambot.api.input.mouse.destination.impl.MiniMapTileDestination; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.MethodContext; import org.dreambot.api.methods.interactive.Players; import org.dreambot.api.methods.item.GroundItems; import org.dreambot.api.methods.map.Area; import org.dreambot.api.methods.map.Tile; 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.wrappers.interactive.GameObject; import org.dreambot.api.wrappers.items.GroundItem; import java.awt.*; import java.util.HashMap; import java.util.Map; public class HandleObstacle extends TaskNode { public enum Course { CANIFIS( new Obstacle(14843, new Area(new Tile(3520, 3510, 0), new Tile(3465, 3465, 0))), new Obstacle(14844, new Area( new Tile(3503, 3488, 2), new Tile(3509, 3488, 2), new Tile(3508, 3492, 2), new Tile(3511, 3492, 2), new Tile(3512, 3496, 2), new Tile(3508, 3499, 2), new Tile(3504, 3498, 2))), new Obstacle(14845, new Area( new Tile(3496, 3502, 2), new Tile(3505, 3503, 2), new Tile(3505, 3507, 2), new Tile(3496, 3507, 2))), new Obstacle(14848, new Area( new Tile(3493, 3506, 2), new Tile(3488, 3506, 2), new Tile(3488, 3502, 2), new Tile(3485, 3502, 2), new Tile(3485, 3498, 2), new Tile(3491, 3498, 2), new Tile(3493, 3499, 2))), new Obstacle(14846, new Area( new Tile(3481, 3500, 3), new Tile(3474, 3500, 3), new Tile(3474, 3491, 3), new Tile(3481, 3491, 3))), new Obstacle(14894, new Area( new Tile(3485, 3488, 2), new Tile(3477, 3488, 2), new Tile(3476, 3481, 2), new Tile(3482, 3480, 2))), new Obstacle(14847, new Area( new Tile(3487, 3479, 3), new Tile(3486, 3468, 3), new Tile(3500, 3467, 3), new Tile(3505, 3471, 3), new Tile(3504, 3477, 3), new Tile(3497, 3480, 3))), new Obstacle(14897, new Area( new Tile(3508, 3473, 2), new Tile(3513, 3473, 2), new Tile(3516, 3476, 2), new Tile(3516, 3484, 2), new Tile(3507, 3484, 2))) ), SEERS( new Obstacle(14927, new Area( new Tile(2697, 3459, 0), new Tile(2735, 3459, 0), new Tile(2735, 3495, 0), new Tile(2698, 3494, 0)), new Tile(2720, 3470, 0), new Tile(2727, 3480, 0)), new Obstacle(14928, new Area( new Tile(2721, 3489, 3), new Tile(2730, 3489, 3), new Tile(2730, 3497, 3), new Tile(2721, 3497, 3))), new Obstacle(14932, new Area( new Tile(2715, 3487, 2), new Tile(2715, 3498, 2), new Tile(2704, 3498, 2), new Tile(2704, 3487, 2))), new Obstacle(14929, new Area( new Tile(2708, 3482, 2), new Tile(2717, 3482, 2), new Tile(2717, 3475, 2), new Tile(2708, 3475, 2))), new Obstacle(14930, new Area( new Tile(2716, 3468, 3), new Tile(2699, 3468, 3), new Tile(2699, 3476, 3), new Tile(2707, 3476, 3), new Tile(2708, 3474, 3), new Tile(2716, 3474, 3))), new Obstacle(14931, new Area( new Tile(2704, 3467, 2), new Tile(2693, 3467, 2), new Tile(2693, 3459, 2), new Tile(2704, 3459, 2))) ); private final Obstacle[] obstacles; Course(Obstacle... obstacles) { this.obstacles = obstacles; for (int i = 0; i < obstacles.length; i++) { if (i + 1 == obstacles.length) { obstacles[i].setNext(obstacles[0]); } else { obstacles[i].setNext(obstacles[i+1]); } } } public Obstacle getCurrentObstacle() { for (Obstacle o : obstacles) { if (o.isPlayerInArea()) return o; } return null; } } private final Course course; private final Map hoverMap; private int retries = 0; public HandleObstacle(Course course) { this.course = course; this.hoverMap = new HashMap<>(); } @Override public boolean accept() { GroundItem mark = GroundItems.closest(Constants.MARK_OF_GRACE); return Util.playerIsIdle() && (mark == null || !mark.canReach()); } @Override public int execute() { Obstacle current = course.getCurrentObstacle(); if (current == null) { if (retries >= 10) { MethodContext.logError("Player is in an unsupported area: " + Players.localPlayer().getTile().toString() + ". Stopping."); ScriptManager.getScriptManager().stop(); } else { retries++; } return Calculations.random(300, 400); } retries = 0; final GameObject currentObject = current.getGameObject(); if (currentObject == null) return Calculations.random(300, 500); boolean isWalking = false; LocalPath path = current.getPath(); if (path.size() > 0 && currentObject.distance() > 20) { isWalking = true; if (hoverMap.get(current.getID()) == null) { MiniMapTileDestination td = new MiniMapTileDestination(path.first()); hoverMap.put(current.getID(), td.getBoundingBox()); } for (Tile t : path) { final Tile target = t.getRandomizedTile(1); Walking.clickTileOnMinimap(target) MethodContext.sleepUntil(() -> target.distance(Players.localPlayer()) < Calculations.random(4, 7), Calculations.random(14000, 15000)); } } while (!currentObject.isOnScreen() || currentObject.distance() > 15) { isWalking = true; Walking.walk(currentObject); MethodContext.sleepUntil(() -> Players.localPlayer().distance(currentObject) < 3, Calculations.random(5000, 5500)); } if (hoverMap.get(current.getID()) == null) { hoverMap.put(current.getID(), currentObject.getBoundingBox()); } if (!isWalking) { MethodContext.sleepUntil(Util::playerIsIdle, Calculations.random(3000, 3500)); } currentObject.interact(); Rectangle hoverRect = hoverMap.get(current.getNext().getID()); if (hoverRect != null) { Mouse.move(hoverRect); } if (isWalking) { Util.sleepUntilMovingAndAnimating(Calculations.random(12000, 13000)); } else { Util.sleepUntilMovingAndAnimating(Calculations.random(6000, 7000)); } return Calculations.random(180, 350); } }