93 lines
2.8 KiB
Java
93 lines
2.8 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 int sleepUntilMoving() {
|
|
return sleepUntilMoving(Calculations.random(3000, 3500));
|
|
}
|
|
|
|
public static int sleepUntilMoving(long timeout) {
|
|
long start = System.currentTimeMillis();
|
|
Player player = Players.localPlayer();
|
|
|
|
MethodContext.sleepUntil(() -> player.isMoving(), timeout);
|
|
|
|
return (int) (System.currentTimeMillis() - start);
|
|
}
|
|
|
|
public static int sleepUntilAnimating() {
|
|
return sleepUntilAnimating(Calculations.random(3000, 3500));
|
|
}
|
|
|
|
public static int sleepUntilAnimating(long timeout) {
|
|
long start = System.currentTimeMillis();
|
|
Player player = Players.localPlayer();
|
|
|
|
MethodContext.sleepUntil(() -> player.isAnimating(), timeout);
|
|
|
|
return (int) (System.currentTimeMillis() - start);
|
|
}
|
|
|
|
public static int sleepUntilMovingOrAnimating() {
|
|
return sleepUntilMovingOrAnimating(Calculations.random(3000, 3500));
|
|
}
|
|
|
|
public static int sleepUntilMovingOrAnimating(long timeout) {
|
|
long start = System.currentTimeMillis();
|
|
Player player = Players.localPlayer();
|
|
|
|
MethodContext.sleepUntil(() -> player.isMoving() || player.isAnimating(), timeout);
|
|
|
|
return (int) (System.currentTimeMillis() - start);
|
|
}
|
|
|
|
public static int sleepUntilMovingAndAnimating() {
|
|
return sleepUntilMovingAndAnimating(Calculations.random(5000, 5500));
|
|
}
|
|
|
|
public static int sleepUntilMovingAndAnimating(long timeout) {
|
|
int elapsed = sleepUntilMovingOrAnimating(timeout);
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
if (timeout - elapsed < 0) {
|
|
return elapsed;
|
|
}
|
|
|
|
MethodContext.sleepWhile(() -> Players.localPlayer().isMoving(), timeout - elapsed);
|
|
|
|
elapsed += (System.currentTimeMillis() - start);
|
|
|
|
if (timeout - elapsed < 0) {
|
|
return elapsed;
|
|
}
|
|
|
|
elapsed += sleepUntilAnimating(timeout - elapsed);
|
|
|
|
return elapsed;
|
|
}
|
|
|
|
public static int getCurrentHP() {
|
|
return Skills.getBoostedLevels(Skill.HITPOINTS);
|
|
}
|
|
}
|