Optimize walking to spot

This commit is contained in:
Yuri Moens 2021-10-21 00:20:47 +02:00
parent 415e6bf211
commit 4c3cde1647
Signed by: ymo
GPG Key ID: F6D51D6FE15BE924
2 changed files with 74 additions and 7 deletions

View File

@ -27,13 +27,13 @@ public class CMiner extends CTaskScript {
addNodes(
new Run(),
new GoToSpot(),
new Superheat(),
new Mine(true),
new GoToBank(),
new OpenBank(),
new DoBank(),
new Teleport(),
new GoToSpot()
new Teleport()
);
}
}

View File

@ -1,12 +1,24 @@
package io.reisub.dreambot.cminer.tasks;
import org.dreambot.api.Client;
import org.dreambot.api.data.GameState;
import org.dreambot.api.methods.Calculations;
import org.dreambot.api.methods.MethodProvider;
import org.dreambot.api.methods.container.impl.Inventory;
import org.dreambot.api.methods.filter.Filter;
import org.dreambot.api.methods.interactive.Players;
import org.dreambot.api.methods.map.Tile;
import org.dreambot.api.methods.skills.Skills;
import org.dreambot.api.methods.walking.impl.Walking;
import org.dreambot.api.methods.world.Location;
import org.dreambot.api.methods.world.World;
import org.dreambot.api.methods.world.Worlds;
import org.dreambot.api.methods.worldhopper.WorldHopper;
import org.dreambot.api.script.TaskNode;
import org.dreambot.api.wrappers.interactive.Player;
import java.util.ArrayList;
import java.util.List;
public class GoToSpot extends TaskNode {
private final Tile[] SPOTS = new Tile[]{
@ -25,12 +37,19 @@ public class GoToSpot extends TaskNode {
closestDist = Math.min(t.distance(), closestDist);
}
return !Inventory.isFull() && closestDist < 15;
return !Inventory.isFull() && closestDist < 20;
}
@Override
public int execute() {
Tile target = SPOTS[Calculations.random(SPOTS.length)];
List<Tile> freeSpots = getFreeSpots();
if (freeSpots.isEmpty()) {
hop();
return Calculations.random(250, 400);
}
Tile target = freeSpots.get(Calculations.random(0, freeSpots.size()));
while (target.distance() > 8) {
if (Walking.shouldWalk(Calculations.random(3, 5))) {
@ -40,12 +59,60 @@ public class GoToSpot extends TaskNode {
MethodProvider.sleep(300, 500);
}
MethodProvider.sleepUntil(() -> !Players.localPlayer().isMoving(), Calculations.random(4000, 5000));
if (!MethodProvider.sleepUntil(() -> !Players.localPlayer().isMoving(), Calculations.random(4500, 5500))) {
return Calculations.random(250, 400);
}
Walking.walkExact(target);
MethodProvider.sleepUntil(() -> Players.localPlayer().getTile().equals(target), Calculations.random(4000, 5000));
if (!Players.localPlayer().getTile().equals(target)) {
Walking.walkExact(target);
if (!MethodProvider.sleepUntil(() -> Players.localPlayer().isMoving(), Calculations.random(1000, 1500))) {
return Calculations.random(250, 400);
}
MethodProvider.sleepUntil(() -> Players.localPlayer().getTile().equals(target), Calculations.random(3500, 4500));
}
return Calculations.random(250, 400);
}
private List<Tile> getFreeSpots() {
List<Tile> freeSpots = new ArrayList<>();
List<Player> otherPlayers = Players.all(player -> !player.getName().equals(Players.localPlayer().getName()));
for (Tile t : SPOTS) {
boolean taken = false;
for (Player p : otherPlayers) {
if (p.getTile().equals(t)) {
taken = true;
break;
}
}
if (!taken) {
freeSpots.add(t);
}
}
return freeSpots;
}
private void hop() {
World world = Worlds.getRandomWorld(new Filter<World>() {
@Override
public boolean match(World world) {
return world.isMembers() &&
world.isNormal() &&
!world.isHighRisk() &&
!world.isPVP() &&
world.getMinimumLevel() <= Skills.getTotalLevel() &&
(world.getLocation().equals(Location.UK) || world.getLocation().equals(Location.GERMANY));
}
});
if (world != null) {
WorldHopper.hopWorld(world);
}
MethodProvider.sleepUntil(() -> Client.getGameState() == GameState.LOGGED_IN, Calculations.random(10000, 11000));
}
}