Compare commits
6 Commits
97d34e4415
...
7b94322749
Author | SHA1 | Date | |
---|---|---|---|
7b94322749
|
|||
992f3ed17e
|
|||
1d8aaabdaa
|
|||
a7a172525c
|
|||
d094033e6c
|
|||
34586a83f6
|
@ -3,6 +3,7 @@ package io.reisub.dreambot.cagility;
|
||||
import io.reisub.dreambot.cagility.tasks.HandleObstacle;
|
||||
import io.reisub.dreambot.cagility.tasks.PickupMark;
|
||||
import io.reisub.dreambot.util.Constants;
|
||||
import io.reisub.dreambot.util.randomevents.GenieSolver;
|
||||
import io.reisub.dreambot.util.tasks.Eat;
|
||||
import io.reisub.dreambot.util.tasks.kitten.KittenTask;
|
||||
import org.dreambot.api.script.Category;
|
||||
@ -14,6 +15,8 @@ import org.dreambot.api.script.impl.TaskScript;
|
||||
public class CAgility extends TaskScript {
|
||||
@Override
|
||||
public void onStart() {
|
||||
getRandomManager().registerSolver(new GenieSolver(GenieSolver.Skill.HERBLORE));
|
||||
|
||||
addNodes(
|
||||
new Eat(),
|
||||
KittenTask.createKittenTask(),
|
||||
|
@ -97,6 +97,8 @@ public class HandleObstacle extends TaskNode {
|
||||
private final Course course;
|
||||
private final Map<Integer, Rectangle> hoverMap;
|
||||
|
||||
private int retries = 0;
|
||||
|
||||
public HandleObstacle(Course course) {
|
||||
this.course = course;
|
||||
this.hoverMap = new HashMap<>();
|
||||
@ -113,16 +115,22 @@ public class HandleObstacle extends TaskNode {
|
||||
public int execute() {
|
||||
Obstacle current = course.getCurrentObstacle();
|
||||
if (current == null) {
|
||||
MethodContext.logError("Player is in an unsupported area: " + Players.localPlayer().getTile().toString() + ". Stopping.");
|
||||
ScriptManager.getScriptManager().stop();
|
||||
return 0;
|
||||
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);
|
||||
|
||||
if (!currentObject.isOnScreen()) {
|
||||
Walking.clickTileOnMinimap(currentObject.getTile());
|
||||
Walking.walk(currentObject);
|
||||
MethodContext.sleepUntil(() -> Players.localPlayer().distance(currentObject) < 3, Calculations.random(5000, 5500));
|
||||
}
|
||||
|
||||
@ -137,7 +145,11 @@ public class HandleObstacle extends TaskNode {
|
||||
Mouse.move(hoverRect);
|
||||
}
|
||||
|
||||
Util.sleepUntilMovingAndAnimating(Calculations.random(9000, 10000));
|
||||
if (!Util.sleepUntilMoving(Calculations.random(1200, 1800))) {
|
||||
return Calculations.random( 180, 350);
|
||||
}
|
||||
|
||||
Util.sleepUntilMovingAndAnimating(Calculations.random(6000, 7000));
|
||||
|
||||
return Calculations.random(180, 350);
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ public class CNPC {
|
||||
for (NPC npc : npcs) {
|
||||
Character c = npc.getInteractingCharacter();
|
||||
|
||||
if (c != null && c.getName().equals(Players.localPlayer().getName())) {
|
||||
if (c != null && c.getName() != null && c.getName().equals(Players.localPlayer().getName())) {
|
||||
return npc;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ public class Constants {
|
||||
|
||||
// Items/GameObjects/NPCs
|
||||
public static final String KITTEN = "Kitten";
|
||||
public static final String KITTEN_INVENTORY = "Pet kitten";
|
||||
public static final String CAT = "Cat";
|
||||
public static final String[] KITTEN_FISH_NAMES = new String[]{
|
||||
"Shrimp",
|
||||
|
@ -21,69 +21,55 @@ public class Util {
|
||||
return !player.isMoving() && !player.isAnimating();
|
||||
}
|
||||
|
||||
public static int sleepUntilMoving() {
|
||||
public static boolean sleepUntilMoving() {
|
||||
return sleepUntilMoving(Calculations.random(3000, 3500));
|
||||
}
|
||||
|
||||
public static int sleepUntilMoving(long timeout) {
|
||||
public static boolean sleepUntilMoving(long timeout) {
|
||||
long start = System.currentTimeMillis();
|
||||
Player player = Players.localPlayer();
|
||||
|
||||
MethodContext.sleepUntil(() -> player.isMoving(), timeout);
|
||||
|
||||
return (int) (System.currentTimeMillis() - start);
|
||||
return MethodContext.sleepUntil(player::isMoving, timeout);
|
||||
}
|
||||
|
||||
public static int sleepUntilAnimating() {
|
||||
public static boolean sleepUntilAnimating() {
|
||||
return sleepUntilAnimating(Calculations.random(3000, 3500));
|
||||
}
|
||||
|
||||
public static int sleepUntilAnimating(long timeout) {
|
||||
public static boolean sleepUntilAnimating(long timeout) {
|
||||
long start = System.currentTimeMillis();
|
||||
Player player = Players.localPlayer();
|
||||
|
||||
MethodContext.sleepUntil(() -> player.isAnimating(), timeout);
|
||||
|
||||
return (int) (System.currentTimeMillis() - start);
|
||||
return MethodContext.sleepUntil(player::isAnimating, timeout);
|
||||
}
|
||||
|
||||
public static int sleepUntilMovingOrAnimating() {
|
||||
public static boolean sleepUntilMovingOrAnimating() {
|
||||
return sleepUntilMovingOrAnimating(Calculations.random(3000, 3500));
|
||||
}
|
||||
|
||||
public static int sleepUntilMovingOrAnimating(long timeout) {
|
||||
public static boolean sleepUntilMovingOrAnimating(long timeout) {
|
||||
long start = System.currentTimeMillis();
|
||||
Player player = Players.localPlayer();
|
||||
|
||||
MethodContext.sleepUntil(() -> player.isMoving() || player.isAnimating(), timeout);
|
||||
|
||||
return (int) (System.currentTimeMillis() - start);
|
||||
return MethodContext.sleepUntil(() -> player.isMoving() || player.isAnimating(), timeout);
|
||||
}
|
||||
|
||||
public static int sleepUntilMovingAndAnimating() {
|
||||
public static boolean sleepUntilMovingAndAnimating() {
|
||||
return sleepUntilMovingAndAnimating(Calculations.random(5000, 5500));
|
||||
}
|
||||
|
||||
public static int sleepUntilMovingAndAnimating(long timeout) {
|
||||
int elapsed = sleepUntilMovingOrAnimating(timeout);
|
||||
|
||||
public static boolean sleepUntilMovingAndAnimating(long timeout) {
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
if (timeout - elapsed < 0) {
|
||||
return elapsed;
|
||||
if (!sleepUntilMoving(timeout)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MethodContext.sleepWhile(() -> Players.localPlayer().isMoving(), timeout - elapsed);
|
||||
|
||||
elapsed += (System.currentTimeMillis() - start);
|
||||
|
||||
if (timeout - elapsed < 0) {
|
||||
return elapsed;
|
||||
if (!MethodContext.sleepWhile(() -> Players.localPlayer().isMoving(), timeout - (System.currentTimeMillis() - start))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
elapsed += sleepUntilAnimating(timeout - elapsed);
|
||||
|
||||
return elapsed;
|
||||
return sleepUntilAnimating(timeout - (System.currentTimeMillis() - start));
|
||||
}
|
||||
|
||||
public static int getCurrentHP() {
|
||||
|
@ -33,8 +33,8 @@ public class KittenTask extends TaskNodeParent {
|
||||
public static KittenTask createKittenTask() {
|
||||
KittenTask task = null;
|
||||
|
||||
if (Inventory.contains(Constants.KITTEN)) {
|
||||
Inventory.drop(Constants.KITTEN);
|
||||
if (Inventory.contains(Constants.KITTEN_INVENTORY)) {
|
||||
Inventory.drop(Constants.KITTEN_INVENTORY);
|
||||
|
||||
task = new KittenTask();
|
||||
}
|
||||
|
Reference in New Issue
Block a user