diff --git a/CMiner/src/io/reisub/dreambot/cminer/CMiner.java b/CMiner/src/io/reisub/dreambot/cminer/CMiner.java index 48d943e..331c48c 100644 --- a/CMiner/src/io/reisub/dreambot/cminer/CMiner.java +++ b/CMiner/src/io/reisub/dreambot/cminer/CMiner.java @@ -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() ); } } diff --git a/CMiner/src/io/reisub/dreambot/cminer/tasks/GoToSpot.java b/CMiner/src/io/reisub/dreambot/cminer/tasks/GoToSpot.java index fbc40f1..ff019b3 100644 --- a/CMiner/src/io/reisub/dreambot/cminer/tasks/GoToSpot.java +++ b/CMiner/src/io/reisub/dreambot/cminer/tasks/GoToSpot.java @@ -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 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 getFreeSpots() { + List freeSpots = new ArrayList<>(); + List 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() { + @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)); + } }