package pathwalking.Botrepreneur;
import java.util.LinkedList;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.util.LocalPathFinder;
import org.osbot.rs07.input.mouse.MiniMapTileDestination;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.script.Script;
import sleep.Botrepreneur.SleepMethods;
import time.Botrepreneur.Timer;
import energy.Botrepreneur.RunMethods;
public class PathWalkMethods {
/**
* @author Botrepreneur
* @Version: 00.41 *Deux*
*/
public static boolean traversePath(Script script, Position[] path, boolean reversed, int toggleRunOnAt, int toggleRunOffAt, boolean toggleRunOnInCombat, long timeout) throws InterruptedException {
Timer timer = new Timer();
int attempts = 0;
while ((!reversed ? !script.myPosition().equals(path[path.length - 1]) : !script.myPosition().equals(path[0])) && timer.getElapsed() < timeout && attempts <= 10) {
RunMethods.manage(script, toggleRunOnAt, toggleRunOffAt, toggleRunOnInCombat);
Position bestPosition = null;
if (!reversed) {
for (int i = 1; i < path.length; i++) {
MiniMapTileDestination mmtd;
if (script.getMap().canReach(path) && (mmtd = new MiniMapTileDestination(script.getBot(), path)) != null && mmtd.isVisible()) {
bestPosition = path;
}
}
} else {
for (int i = path.length - 1; i > 0; i--) {
MiniMapTileDestination mmtd;
if (script.getMap().canReach(path) && (mmtd = new MiniMapTileDestination(script.getBot(), path)) != null && mmtd.isVisible()) {
bestPosition = path;
}
}
}
if (bestPosition != null) {
boolean clicked = false;
if (script.getMap().distance(bestPosition) <= 5 && bestPosition.isVisible(script.getBot())) {
clicked = bestPosition.interact(script.getBot(), "Walk here");
} else {
clicked = script.getMouse().click(new MiniMapTileDestination(script.getBot(), bestPosition));
}
if (clicked) {
SleepMethods.untilMoving(script, 900L);
if (script.myPlayer().isMoving()) {
int speed = MethodProvider.gRandom(script.getSettings().isRunning() ? 250 : 500, 100);
MethodProvider.sleep(script.getMap().distance(bestPosition) * speed);
}
}
else {
script.getCamera().moveYaw(script.getCamera().getYawAngle() + MethodProvider.gRandom(50, 20));
attempts++;
}
} else {
script.getCamera().moveYaw(script.getCamera().getYawAngle() + MethodProvider.gRandom(50, 20));
attempts++;
}
}
return !reversed ? script.myPosition().equals(path[path.length - 1]) : script.myPosition().equals(path[0]);
}
public static boolean traversePath(Script script, Position position, boolean reversed, int toggleRunOnAt, int toggleRunOffAt, boolean toggleRunOnInCombat, long timeout) throws InterruptedException {
if (position == null || !script.getMap().canReach(position)) {
return false;
}
LinkedList<Position> pathList;
Position[] path = null;
if ((pathList = new LocalPathFinder(script.getBot()).findPath(position)) != null) {
path = (Position[]) pathList.toArray(new Position[pathList.size()]);
}
return path != null ? traversePath(script, path, reversed, toggleRunOnAt, toggleRunOffAt, toggleRunOnInCombat, timeout) : false;
}
public static boolean traversePath(Script script, Entity entity, boolean reversed, int toggleRunOnAt, int toggleRunOffAt, boolean toggleRunOnInCombat, long timeout) throws InterruptedException {
Position position;
LinkedList<Position> pathList;
Position[] path = null;
if (entity != null && entity.exists() && (position = entity.getPosition()) != null && script.getMap().canReach(position) && (pathList = new LocalPathFinder(script.getBot()).findPath(position)) != null) {
path = (Position[]) pathList.toArray(new Position[pathList.size()]);
}
else {
return false;
}
return traversePath(script, path, reversed, toggleRunOnAt, toggleRunOffAt, toggleRunOnInCombat, timeout);
}
}