Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by Alexander on 2017-04-28.
- * Free for anyone to use or build upon.
- * Recuires OSbot API.
- */
- import org.osbot.rs07.api.map.Area;
- import org.osbot.rs07.api.map.constants.Banks;
- import org.osbot.rs07.api.model.Entity;
- import org.osbot.rs07.api.ui.Skill;
- import org.osbot.rs07.script.Script;
- import org.osbot.rs07.script.ScriptManifest;
- import java.awt.*;
- //Script information and publisher, you can add your name here instead.
- @ScriptManifest(author = "zer0", name = "zer0Chopper", info = "Free source woodcutter", version = 0.1, logo = "")
- //Main class, good to have.
- public class Main extends Script {
- private State currentState;
- public int logsChopped = 0;
- private static long startTime = System.currentTimeMillis();
- @Override
- public void onStart()
- {
- log("Welcome to zer0Chopper v0.1");
- currentState = State.WAIT;
- }
- public void onPaint(Graphics2D g)
- {
- long timeRan = System.currentTimeMillis() - startTime;
- g.setColor(Color.orange);
- g.drawString("Current state: " + currentState.name(), 5 , 300);
- g.drawString("Runtime: " + Timing.msToString(timeRan), 5, 315);
- g.drawString("XP gained: " + getExperienceTracker().getGainedXP(Skill.WOODCUTTING), 5,330);
- //g.drawString("TLL : " + getExperienceTracker().getTimeToLevel(Skill.WOODCUTTING),30, 75);
- g.drawString("Current level : " + getExperienceTracker().getGainedLevels(Skill.WOODCUTTING),5, 345);
- }
- @Override
- public void onExit()
- {
- log("Thanks for using zer0Chopper v0.1");
- }
- //Below we create our cutting zone, this case will be using West Varrock.
- //Feel free to make your own or expand this one.
- public int x1 = 3158;
- public int x2 = 3170;
- public int y1 = 3393;
- public int y2 = 3416;
- //Creating and setting the size of you active cuttingzone.
- private final Area westVarrock = new Area(x1,y1,x2,y2);
- //Used later in a Switch statement. The bot will have 3 states! To cut, to bank & to wait.
- private enum State
- {
- CUT, BANK, WAIT, WALKING_BANK, WALKING_CUT
- }
- private State getState() {
- //Looking for the cloest entity of the "Tree" sort.
- Entity tree = objects.closest("Tree");
- if(getInventory().isFull() && !Banks.VARROCK_WEST.contains(myPosition())) //Check for a full bag.
- {
- return State.WALKING_BANK;
- }
- if(getInventory().isFull() && Banks.VARROCK_WEST.contains(myPosition()))
- {
- return State.BANK;
- }
- if(!westVarrock.contains(myPosition()))
- {
- return State.WALKING_CUT;
- }
- if(tree != null && !myPlayer().isAnimating()) //Checking if there is a tree and my character is done chopping.
- {
- return State.CUT;
- }
- return State.WAIT; //This will wait until one of the others are true.
- }
- //The real shit goes down below, in the onLoop method.
- @Override
- public final int onLoop() throws InterruptedException {
- currentState = getState();
- switch (currentState)
- {
- case CUT:
- {
- Entity tree = objects.closest("Tree");
- if(tree != null)
- {
- tree.interact("Chop down");
- Sleep.sleepUntil(() -> myPlayer().isAnimating() || !tree.exists(), random(4000,5600));
- Sleep.sleepUntil(() -> !myPlayer().isAnimating() || !tree.exists(), random(4000,5600));
- }
- logsChopped++;
- break;
- }
- case BANK:
- {
- bank();
- break;
- }
- case WAIT:
- {
- sleep(random(2000,3500));
- break;
- }
- case WALKING_CUT:
- {
- getWalking().webWalk(westVarrock);
- break;
- }
- case WALKING_BANK:
- {
- getWalking().webWalk(Banks.VARROCK_WEST);
- break;
- }
- }
- return random(200,300);
- }
- //Banking method used to bank all the items.
- public void bank() throws InterruptedException {
- getBank().open();
- getBank().depositAll("Logs");
- }
- }
- import org.osbot.rs07.utility.ConditionalSleep;
- import java.util.function.BooleanSupplier;
- /**
- * Created by allerost on 2017-05-02.
- */
- class Sleep extends ConditionalSleep
- {
- private final BooleanSupplier condition;
- public Sleep(final BooleanSupplier condition, final int timeout) {
- super(timeout);
- this.condition = condition;
- }
- @Override
- public final boolean condition() throws InterruptedException {
- return condition.getAsBoolean();
- }
- public static boolean sleepUntil(final BooleanSupplier condition, final int timeout) {
- return new Sleep(condition, timeout).sleep();
- }
- }
- import java.util.concurrent.Callable;
- import java.util.concurrent.TimeUnit;
- import org.osbot.rs07.utility.ConditionalSleep;
- /**
- * Static utility class with various methods that are related
- * to time / timing.
- *
- * @author The Viking
- *
- */
- public class Timing
- {
- /**
- * Calculates the time, in ms, from a specific mark
- *
- * @param mark The initial time mark we're calculating from
- * @return The time, in ms, from the provided mark
- */
- public static long timeFromMark(long mark)
- {
- return System.currentTimeMillis() - mark;
- }
- /**
- * Returns the current time in ms. Essentially just a shorter
- * wrapper for System.currentTimeMillis()
- *
- * @return The current time, in ms
- */
- public static long currentMs()
- {
- return System.currentTimeMillis();
- }
- /**
- * Converts a time, in ms, to a pretty String in hh:mm:ss:SSS format
- *
- * @param ms The time, in ms, to convert
- * @return A string representing the current time
- */
- public static String msToString(long ms)
- {
- return String.format("%02d:%02d:%02d", TimeUnit.MILLISECONDS.toHours(ms),
- TimeUnit.MILLISECONDS.toMinutes(ms) % TimeUnit.HOURS.toMinutes(1),
- TimeUnit.MILLISECONDS.toSeconds(ms) % TimeUnit.MINUTES.toSeconds(1));
- }
- /**
- * This method waits for a specific condition
- * to be true within a maximum amount of time. Your
- * basic conditional sleep. This method uses the LCondition interface, so it provides lambda support
- *
- * @param condition the condition to wait for
- * @param cycleTime the time, in ms, between condition checks
- * @param timeout the maximum time to wait for the condition to be true
- * @return true if the condition was met within the threshold, or false if the timeout was exceeded
- */
- public static boolean waitCondition(Callable<Boolean> condition, int cycleTime, int timeout)
- {
- return new ConditionalSleep(timeout, cycleTime)
- {
- @Override
- public boolean condition()
- {
- try
- {
- return condition.call();
- }
- catch(Exception e)
- {
- e.printStackTrace();
- }
- return false;
- }
- }.sleep();
- }
- /**
- * This method waits for a specific condition to be true within a maximum amount of time. Your
- * basic conditional sleep. This method uses the LCondition interface, so it provides lambda support
- *
- * @param condition the condition to wait for
- * @param timeout the maximum time to wait for the condition to be true
- * @return true if the condition was met within the threshold, or false if the timeout was exceeded
- */
- public static boolean waitCondition(Callable<Boolean> condition, int timeout)
- {
- return waitCondition(condition, 20, timeout);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement