79 lines
2.5 KiB
Java
79 lines
2.5 KiB
Java
package io.reisub.dreambot.util;
|
|
|
|
import org.dreambot.api.methods.Calculations;
|
|
import org.dreambot.api.methods.MethodContext;
|
|
import org.dreambot.api.methods.interactive.Players;
|
|
import org.dreambot.api.methods.skills.Skill;
|
|
import org.dreambot.api.methods.skills.Skills;
|
|
import org.dreambot.api.wrappers.interactive.Player;
|
|
|
|
@SuppressWarnings("unused")
|
|
public class Util {
|
|
public static boolean playerIsIdle() {
|
|
return playerIsIdle(0);
|
|
}
|
|
|
|
public static boolean playerIsIdle(long timeout) {
|
|
Player player = Players.localPlayer();
|
|
|
|
MethodContext.sleepWhile(() -> !player.isMoving() && !player.isAnimating(), timeout);
|
|
|
|
return !player.isMoving() && !player.isAnimating();
|
|
}
|
|
|
|
public static boolean sleepUntilMoving() {
|
|
return sleepUntilMoving(Calculations.random(3000, 3500));
|
|
}
|
|
|
|
public static boolean sleepUntilMoving(long timeout) {
|
|
long start = System.currentTimeMillis();
|
|
Player player = Players.localPlayer();
|
|
|
|
return MethodContext.sleepUntil(player::isMoving, timeout);
|
|
}
|
|
|
|
public static boolean sleepUntilAnimating() {
|
|
return sleepUntilAnimating(Calculations.random(3000, 3500));
|
|
}
|
|
|
|
public static boolean sleepUntilAnimating(long timeout) {
|
|
long start = System.currentTimeMillis();
|
|
Player player = Players.localPlayer();
|
|
|
|
return MethodContext.sleepUntil(player::isAnimating, timeout);
|
|
}
|
|
|
|
public static boolean sleepUntilMovingOrAnimating() {
|
|
return sleepUntilMovingOrAnimating(Calculations.random(3000, 3500));
|
|
}
|
|
|
|
public static boolean sleepUntilMovingOrAnimating(long timeout) {
|
|
long start = System.currentTimeMillis();
|
|
Player player = Players.localPlayer();
|
|
|
|
return MethodContext.sleepUntil(() -> player.isMoving() || player.isAnimating(), timeout);
|
|
}
|
|
|
|
public static boolean sleepUntilMovingAndAnimating() {
|
|
return sleepUntilMovingAndAnimating(Calculations.random(5000, 5500));
|
|
}
|
|
|
|
public static boolean sleepUntilMovingAndAnimating(long timeout) {
|
|
long start = System.currentTimeMillis();
|
|
|
|
if (!sleepUntilMoving(timeout)) {
|
|
return false;
|
|
}
|
|
|
|
if (!MethodContext.sleepWhile(() -> Players.localPlayer().isMoving(), timeout - (System.currentTimeMillis() - start))) {
|
|
return false;
|
|
}
|
|
|
|
return sleepUntilAnimating(timeout - (System.currentTimeMillis() - start));
|
|
}
|
|
|
|
public static int getCurrentHP() {
|
|
return Skills.getBoostedLevels(Skill.HITPOINTS);
|
|
}
|
|
}
|