Optimize walking and add custom starting condition
This commit is contained in:
parent
7cae9e07d0
commit
0cb56342ee
@ -8,8 +8,11 @@ import io.reisub.dreambot.util.Constants;
|
|||||||
import io.reisub.dreambot.util.randomevents.GenieSolver;
|
import io.reisub.dreambot.util.randomevents.GenieSolver;
|
||||||
import io.reisub.dreambot.util.tasks.Eat;
|
import io.reisub.dreambot.util.tasks.Eat;
|
||||||
import io.reisub.dreambot.util.tasks.kitten.KittenTask;
|
import io.reisub.dreambot.util.tasks.kitten.KittenTask;
|
||||||
|
import org.dreambot.api.methods.MethodProvider;
|
||||||
|
import org.dreambot.api.methods.interactive.Players;
|
||||||
import org.dreambot.api.methods.skills.Skill;
|
import org.dreambot.api.methods.skills.Skill;
|
||||||
import org.dreambot.api.script.Category;
|
import org.dreambot.api.script.Category;
|
||||||
|
import org.dreambot.api.script.ScriptManager;
|
||||||
import org.dreambot.api.script.ScriptManifest;
|
import org.dreambot.api.script.ScriptManifest;
|
||||||
import org.dreambot.api.script.TaskNode;
|
import org.dreambot.api.script.TaskNode;
|
||||||
|
|
||||||
|
@ -1,16 +1,19 @@
|
|||||||
package io.reisub.dreambot.cagility;
|
package io.reisub.dreambot.cagility;
|
||||||
|
|
||||||
|
import io.reisub.dreambot.util.Util;
|
||||||
import org.dreambot.api.methods.interactive.GameObjects;
|
import org.dreambot.api.methods.interactive.GameObjects;
|
||||||
import org.dreambot.api.methods.interactive.Players;
|
import org.dreambot.api.methods.interactive.Players;
|
||||||
import org.dreambot.api.methods.map.Area;
|
import org.dreambot.api.methods.map.Area;
|
||||||
import org.dreambot.api.methods.map.Tile;
|
import org.dreambot.api.methods.map.Tile;
|
||||||
import org.dreambot.api.methods.walking.path.impl.LocalPath;
|
import org.dreambot.api.methods.walking.path.impl.LocalPath;
|
||||||
|
import org.dreambot.api.utilities.impl.Condition;
|
||||||
import org.dreambot.api.wrappers.interactive.GameObject;
|
import org.dreambot.api.wrappers.interactive.GameObject;
|
||||||
|
|
||||||
public class Obstacle {
|
public class Obstacle {
|
||||||
private final int id;
|
private final int id;
|
||||||
private final Area area;
|
private final Area area;
|
||||||
private final LocalPath<Tile> path;
|
private final LocalPath<Tile> path;
|
||||||
|
private Condition startCondition;
|
||||||
private Obstacle next;
|
private Obstacle next;
|
||||||
|
|
||||||
public Obstacle(int id, Area area, Tile... walkingTiles) {
|
public Obstacle(int id, Area area, Tile... walkingTiles) {
|
||||||
@ -18,6 +21,14 @@ public class Obstacle {
|
|||||||
this.area = area;
|
this.area = area;
|
||||||
path = new LocalPath<>();
|
path = new LocalPath<>();
|
||||||
path.addAll(walkingTiles);
|
path.addAll(walkingTiles);
|
||||||
|
|
||||||
|
startCondition = Util::playerIsIdle;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Obstacle(int id, Area area, Condition startCondition, Tile... walkingTiles) {
|
||||||
|
this(id, area, walkingTiles);
|
||||||
|
|
||||||
|
this.startCondition = startCondition;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getID() {
|
public int getID() {
|
||||||
@ -43,4 +54,8 @@ public class Obstacle {
|
|||||||
public LocalPath<Tile> getPath() {
|
public LocalPath<Tile> getPath() {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean canStart() {
|
||||||
|
return startCondition.verify();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import org.dreambot.api.input.Mouse;
|
|||||||
import org.dreambot.api.input.mouse.destination.impl.MiniMapTileDestination;
|
import org.dreambot.api.input.mouse.destination.impl.MiniMapTileDestination;
|
||||||
import org.dreambot.api.methods.Calculations;
|
import org.dreambot.api.methods.Calculations;
|
||||||
import org.dreambot.api.methods.MethodContext;
|
import org.dreambot.api.methods.MethodContext;
|
||||||
|
import org.dreambot.api.methods.MethodProvider;
|
||||||
import org.dreambot.api.methods.interactive.Players;
|
import org.dreambot.api.methods.interactive.Players;
|
||||||
import org.dreambot.api.methods.item.GroundItems;
|
import org.dreambot.api.methods.item.GroundItems;
|
||||||
import org.dreambot.api.methods.map.Area;
|
import org.dreambot.api.methods.map.Area;
|
||||||
@ -15,6 +16,7 @@ import org.dreambot.api.methods.walking.impl.Walking;
|
|||||||
import org.dreambot.api.methods.walking.path.impl.LocalPath;
|
import org.dreambot.api.methods.walking.path.impl.LocalPath;
|
||||||
import org.dreambot.api.script.ScriptManager;
|
import org.dreambot.api.script.ScriptManager;
|
||||||
import org.dreambot.api.script.TaskNode;
|
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.interactive.GameObject;
|
||||||
import org.dreambot.api.wrappers.items.GroundItem;
|
import org.dreambot.api.wrappers.items.GroundItem;
|
||||||
|
|
||||||
@ -90,10 +92,17 @@ public class HandleObstacle extends TaskNode {
|
|||||||
new Tile(2704, 3498, 2),
|
new Tile(2704, 3498, 2),
|
||||||
new Tile(2704, 3487, 2))),
|
new Tile(2704, 3487, 2))),
|
||||||
new Obstacle(14929, new Area(
|
new Obstacle(14929, new Area(
|
||||||
new Tile(2708, 3482, 2),
|
new Tile(2708, 3475, 2),
|
||||||
new Tile(2717, 3482, 2),
|
new Tile(2716, 3475, 2),
|
||||||
new Tile(2717, 3475, 2),
|
new Tile(2716, 3484, 2),
|
||||||
new Tile(2708, 3475, 2))),
|
new Tile(2708, 3484, 2)),
|
||||||
|
() -> {
|
||||||
|
Area startArea = new Area(
|
||||||
|
new Tile(2710, 3482, 2),
|
||||||
|
new Tile(2710, 3481, 2)
|
||||||
|
);
|
||||||
|
return startArea.contains(Players.localPlayer());
|
||||||
|
}),
|
||||||
new Obstacle(14930, new Area(
|
new Obstacle(14930, new Area(
|
||||||
new Tile(2716, 3468, 3),
|
new Tile(2716, 3468, 3),
|
||||||
new Tile(2699, 3468, 3),
|
new Tile(2699, 3468, 3),
|
||||||
@ -136,6 +145,7 @@ 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 Obstacle current;
|
||||||
private int retries = 0;
|
private int retries = 0;
|
||||||
|
|
||||||
public HandleObstacle(Course course) {
|
public HandleObstacle(Course course) {
|
||||||
@ -147,24 +157,24 @@ public class HandleObstacle extends TaskNode {
|
|||||||
public boolean accept() {
|
public boolean accept() {
|
||||||
GroundItem mark = GroundItems.closest(Constants.MARK_OF_GRACE);
|
GroundItem mark = GroundItems.closest(Constants.MARK_OF_GRACE);
|
||||||
|
|
||||||
return Util.playerIsIdle() && (mark == null || !mark.canReach());
|
current = course.getCurrentObstacle();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int execute() {
|
|
||||||
Obstacle current = course.getCurrentObstacle();
|
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
if (retries >= 10) {
|
if (retries >= 20) {
|
||||||
MethodContext.logError("Player is in an unsupported area: " + Players.localPlayer().getTile().toString() + ". Stopping.");
|
MethodContext.logError("Player is in an unsupported area: " + Players.localPlayer().getTile().toString() + ". Stopping.");
|
||||||
ScriptManager.getScriptManager().stop();
|
ScriptManager.getScriptManager().stop();
|
||||||
} else {
|
} else {
|
||||||
retries++;
|
retries++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Calculations.random(300, 400);
|
return false;
|
||||||
}
|
}
|
||||||
retries = 0;
|
retries = 0;
|
||||||
|
|
||||||
|
return (current.canStart() || Util.playerIsIdle()) && (mark == null || !mark.canReach());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int execute() {
|
||||||
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);
|
||||||
|
|
||||||
@ -180,10 +190,13 @@ public class HandleObstacle extends TaskNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (Tile t : path) {
|
for (Tile t : path) {
|
||||||
final Tile target = t.getRandomizedTile(1);
|
Tile target = t.getRandomizedTile(1);
|
||||||
Walking.clickTileOnMinimap(target);
|
while (!Walking.clickTileOnMinimap(target)) {
|
||||||
|
target = t.getRandomizedTile(2);
|
||||||
|
}
|
||||||
|
|
||||||
MethodContext.sleepUntil(() -> target.distance(Players.localPlayer()) < Calculations.random(4, 7), Calculations.random(14000, 15000));
|
Tile finalTarget = target;
|
||||||
|
MethodContext.sleepUntil(() -> finalTarget.distance(Players.localPlayer()) < Calculations.random(4, 7), Calculations.random(14000, 15000));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,11 +210,17 @@ public class HandleObstacle extends TaskNode {
|
|||||||
hoverMap.put(current.getID(), currentObject.getBoundingBox());
|
hoverMap.put(current.getID(), currentObject.getBoundingBox());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isWalking) {
|
if (!isWalking && !current.canStart()) {
|
||||||
MethodContext.sleepUntil(Util::playerIsIdle, Calculations.random(3000, 3500));
|
MethodContext.sleepUntil(Util::playerIsIdle, Calculations.random(3000, 3500));
|
||||||
}
|
}
|
||||||
|
|
||||||
currentObject.interact();
|
if (isWalking) {
|
||||||
|
Mouse.setAlwaysHop(true);
|
||||||
|
currentObject.interactForceLeft(currentObject.getActions()[0]);
|
||||||
|
Mouse.setAlwaysHop(false);
|
||||||
|
} else {
|
||||||
|
currentObject.interactForceLeft(currentObject.getActions()[0]);
|
||||||
|
}
|
||||||
|
|
||||||
Rectangle hoverRect = hoverMap.get(current.getNext().getID());
|
Rectangle hoverRect = hoverMap.get(current.getNext().getID());
|
||||||
if (hoverRect != null) {
|
if (hoverRect != null) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user