- import java.awt.BasicStroke;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.awt.Image;
- import java.awt.Point;
- import java.awt.RenderingHints;
- import java.io.IOException;
- import java.net.URL;
- import java.text.DecimalFormat;
- import java.util.Map;
- import java.util.logging.Logger;
- import java.util.logging.Level;
- import javax.imageio.ImageIO;
- import org.rsbot.Application;
- import org.rsbot.event.events.ServerMessageEvent;
- import org.rsbot.event.listeners.PaintListener;
- import org.rsbot.event.listeners.ServerMessageListener;
- import org.rsbot.script.*;
- import org.rsbot.script.methods.*;
- import org.rsbot.script.util.Timer;
- import org.rsbot.script.wrappers.*;
- @ScriptManifest(authors = "Barry", name = "bChop", category = "Woodcutting", version = 0.51, description =
- "<p>Settings coming here shortly. For now, just have an axe and stand kinda near the tree(s) you want to cut.</p>"
- + "<p><strong>Which trees should be chopped?</strong><br />"
- + "<select name='treeType'><option value='0'>Automatic</option><option value='1'>Normal trees</option>"
- + "<option value='2'>Oak trees</option><option value='3'>Willow trees</option><option value='4'>Maple trees</option>"
- + "<option value='5'>Yew trees</option></p>"
- + "<p><strong>Take screenshot on levelup?</strong><br />"
- + "<input type='radio' name='takeScreeny' value='true' checked='checked' /> Yes "
- + "<input type='radio' name='takeScreeny' value='false' /> No</p>"
- + "<p><strong>Obscure name on screenshot?</strong><br />"
- + "<input type='radio' name='obscureScreeny' value='true' checked='checked' /> Yes "
- + "<input type='radio' name='obscureScreeny' value='false' /> No</p>"
- )
- public class bChop extends Script implements PaintListener, ServerMessageListener
- {
- // Settings
- // 0: Drop / 1: Bank / 2: Burn
- private int whenFull = 0;
- // 0: AUTOMATIC / 1: Normal / 2: Oak / 3: Willow / 4: Maple / 5: Yew
- private boolean automaticTrees;
- private int treeType;
- // Screenshots
- private boolean takeScreeny;
- private boolean obscureScreeny;
- private String lastError = "An unknown error occurred.";
- // Tree detection
- private RSObject tree;
- private int currentTreeID;
- private RSArea wanderZone = null;
- private Timer noTreeTimer = null;
- // State handling
- protected static enum Status { INIT, FIND_TREE, WALK_TO_TREE, CHOP_TREE, CHOPPING, CHECK_TREE, WAIT, LEVELUP, INVEN_FULL, DROP_ALL, ERROR, RESET };
- private Status currState = Status.INIT;
- private Status lastState;
- // Items
- private final int[] id_hatchets = { 1351, 1349, 1353, 1361, 1355, 1357, 1359, 4031, 6739, 13470, 14108 };
- //private final int id_tinderbox = 0;
- private final int id_logs = 1511;
- private final int id_oakLogs = 1521;
- private final int id_willowLogs = 1519;
- private final int id_mapleLogs = 1517;
- private final int id_yewLogs = 1515;
- // Objects - trees - thanks to Epic_ for a "borrowed" set of IDs :)
- private int[] id_trees = null;
- private final int[] id_normalTrees = { 5004, 5005, 5045, 3879, 3881, 3882, 3883, 3885, 3886, 3887, 3888, 3889, 3890, 3891, 3892, 3893, 3928, 3967, 3968, 4048, 4049, 4050, 4051, 4052, 4053, 4054, 3033, 3034, 3035, 3036, 2409, 2447, 2448, 1330, 1331, 1332, 1310, 1305, 1304, 1303, 1301, 1276, 1277, 1278, 1279, 1280, 8742, 8743, 8973, 8974, 1315, 1316 };
- private final int[] id_oakTrees = { 1281, 3037, 8462, 8463, 8464, 8465, 8466, 8467 };
- private final int[] id_willowTrees = { 1308, 5551, 5552, 5553, 8481, 8482, 8483, 8484, 8485, 8486, 8487, 8488 };
- private final int[] id_mapleTrees = { 1307, 1308 };
- private final int[] id_yewTrees = { 1309, 8503, 8504, 8505, 8506, 8507, 8508, 8509, 8510, 8511, 8512, 8513 };
- // Animations
- private int anim_idle = -1;
- private int anim_chopping = 869;
- // Timer and experience maths
- private Timer runTimer;
- private int startExp = 0;
- private int startLevel = 0;
- private int logsChopped = 0;
- // Paint settings
- private boolean showPaint = false;
- private boolean canTogglePaint = true;
- // Positioning
- private int paintX0 = 0;
- private int paintY0 = 325;
- // Fonts
- private final Font fnt_label = new Font("SansSerif", 0, 15);
- private final Font fnt_value = new Font("SansSerif", 0, 14);
- private final Font fnt_antiban = new Font("SansSerif", 0, 12);
- // Colours
- private final Color clr_label = new Color(0, 0, 0);
- private final Color clr_value = new Color(121, 110, 91);
- private final Color clr_border = new Color(47, 43, 36);
- private final Color clr_background = new Color(255, 255, 255);
- private final Color clr_red = new Color(208, 0, 0);
- private final Color clr_yellow = new Color(208, 208, 0);
- private final Color clr_green = new Color(0, 208, 0);
- private final Color clr_darkRed = new Color(70, 0, 0);
- private final Color clr_darkYellow = new Color(70, 70, 0);
- private final Color clr_darkGreen = new Color(0, 70, 0);
- private final Color clr_black = new Color(0, 0, 0);
- private final Color clr_redSemi = new Color(208, 0, 0, 100);
- private final Color clr_yellowSemi = new Color(208, 208, 0, 100);
- private final Color clr_greenSemi = new Color(0, 208, 0, 100);
- // Images
- private static Image img_chatBackground;
- private static Image img_showPaint;
- private static Image img_hidePaint;
- private static Image img_antibanBackground;
- // Strokes
- private final BasicStroke stk_progBar = new BasicStroke(1);
- // Settings
- private final RenderingHints antialiasing = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- // Antiban
- private AntiBan antiBan;
- private boolean antiBanActive = false;
- static Logger antiBanLogger = Logger.getLogger("AntiBan");
- private static enum ABState { NOT_RUNNING, IDLE, READY, ACTIVE };
- private ABState antibanStatus = ABState.NOT_RUNNING;
- // Time to level - let's look a little sensible
- private String lastTimeToLevel = "Waiting 10s";
- private Timer updateTimeToLevel;
- // Misc stuff
- // Wait counter
- private int waitCounter = 0;
- /*
- *
- * End of settings and variables
- * Script setup follows
- *
- */
- // Constructor
- public bChop()
- { this.antiBan = new AntiBan(this); }
- // Starting script
- public boolean onStart(Map<String, String> args)
- {
- log("Starting bChop. Loading images...");
- // Get setup
- //log(args.get("location"));
- //args.get("takeScreeny");
- //args.get("obscureScreeny");
- // Load paint images
- img_chatBackground = getImage("http://img714.imageshack.us/img714/631/backgroundq.gif");
- img_showPaint = getImage("http://img833.imageshack.us/img833/6823/showpaint.gif");
- img_hidePaint = getImage("http://img441.imageshack.us/img441/6213/hidepaint.gif");
- img_antibanBackground = getImage("http://img828.imageshack.us/img828/102/antibanbackground.gif");
- log("...images loaded, starting script.");
- // Pull this in from GUI later
- treeType = Integer.parseInt(args.get("treeType"));
- takeScreeny = Boolean.parseBoolean(args.get("takeScreeny"));
- obscureScreeny = Boolean.parseBoolean(args.get("obscureScreeny"));
- // Handle automatic at start of script
- if (treeType == 0)
- { automaticTrees = true; }
- runTimer = new Timer(0);
- this.antiBan.start();
- return true;
- }
- // Stopping script
- public void onFinish()
- {
- log("Stopping bChop and logging out.");
- boolean twoStage = boolRandom();
- game.logout(twoStage);
- if (twoStage)
- { game.logout(false); }
- }
- /*
- *
- * End of script setup
- * Main loop and state handling follows
- *
- */
- // Main loop
- public int loop()
- {
- // If the antiban is running, just wait for it to finish
- if (antiBanActive)
- { return random(300,500); }
- // What do we need to do?
- determineState();
- switch (getState())
- {
- case FIND_TREE:
- // What kind of tree are we looking for?
- getTreeType();
- tree = objects.getNearest(id_trees);
- if (tree != null)
- {
- // Stop the clock
- noTreeTimer = null;
- // Log the tree's ID
- currentTreeID = tree.getDef().getID();
- // Check wander zone
- // Ignores this check if the noTreeTimer has waited 30s
- if ( (wanderZone != null && wanderZone.contains(tree.getLocation())) || wanderZone == null || (noTreeTimer != null && noTreeTimer.isUp()))
- {
- // Reset the noTreeTimer
- if (noTreeTimer != null)
- { noTreeTimer = null; }
- if (calc.distanceTo(tree.getLocation()) > 4)
- { setState(Status.WALK_TO_TREE); }
- else
- {
- if (getLastState() != Status.WAIT)
- {
- // Move on to chop it
- setState(Status.CHOP_TREE);
- }
- }
- }
- else
- {
- // Tree is outside wander zone, keep looking
- tree = null;
- return random(300,500);
- }
- // Tree is found, now set up a wander zone for it
- RSTile treeLoc = tree.getLocation();
- wanderZone = new RSArea
- (
- new RSTile
- (
- treeLoc.getX() - 10,
- treeLoc.getY() + 10
- ),
- new RSTile
- (
- treeLoc.getX() + 10,
- treeLoc.getY() - 10
- )
- );
- }
- else
- {
- // No trees found
- if (noTreeTimer == null)
- {
- // Start a new 30s timer
- noTreeTimer = new Timer(30000);
- }
- }
- break;
- case WALK_TO_TREE:
- if (treeStumped())
- { setState(Status.RESET); return random(300,500); }
- // Distance to
- if (!calc.tileOnMap(tree.getLocation()))
- { myWalkTo(tree.getLocation()); }
- else if (calc.distanceTo(tree.getLocation()) > 4)
- {
- if (!getMyPlayer().isMoving())
- { walking.walkTileMM(tree.getLocation(), 2, 2); }
- }
- // Camera rotation
- else if (!calc.tileOnScreen(tree.getLocation()))
- { camera.turnToObject(tree, 5); }
- // Chop tree
- else
- { setState(Status.CHOP_TREE); }
- break;
- case CHOP_TREE:
- // Problem, find another tree
- if (treeStumped())
- { setState(Status.RESET); }
- else
- {
- if (antiBan.usingMouse)
- { return random(300,500); }
- // Attempt the click. If it fails, find a new tree
- if (!clickTree(tree))
- { setState(Status.RESET); }
- setState(Status.WAIT);
- }
- break;
- case CHOPPING:
- if (treeStumped())
- { setState(Status.RESET); }
- break;
- case CHECK_TREE:
- if (treeStumped())
- { setState(Status.RESET); }
- break;
- case WAIT:
- if (treeStumped())
- { setState(Status.RESET); return random(300,500); }
- else if (getMyPlayer().getAnimation() == anim_chopping)
- { setState(Status.CHOPPING); }
- else if (!getMyPlayer().isMoving())
- {
- if (waitCounter > 5)
- { waitCounter = 0; setState(Status.RESET); }
- else
- { waitCounter++; }
- }
- break;
- case DROP_ALL:
- if (inventory.containsOneOf(id_logs, id_oakLogs, id_willowLogs, id_mapleLogs, id_yewLogs))
- { inventory.dropAllExcept(boolRandom(), id_hatchets); }
- else
- { setState(Status.ERROR); setError("Inventory full, but no logs in inventory."); }
- break;
- case LEVELUP:
- if (boolRandom()) { moveMouseSlightly(); }
- // Open stats menu for a screeny if needed
- if (takeScreeny)
- {
- game.openTab(Game.TAB_STATS);
- takeScreenshot(obscureScreeny);
- log("Levelup! " + skills.getRealLevel(Skills.WOODCUTTING) + " woodcutting. Screenshot taken.");
- }
- else
- { log("Levelup! " + skills.getRealLevel(Skills.WOODCUTTING) + " woodcutting."); }
- if (interfaces.canContinue())
- { interfaces.clickContinue(); }
- setState(Status.CHECK_TREE);
- break;
- case RESET:
- tree = null;
- currentTreeID = 0;
- setState(Status.FIND_TREE);
- break;
- case INIT:
- // Camera setup
- sleep(random(300,500));
- camera.setAltitude(true);
- sleep(random(500,900));
- camera.setAngle(random(camera.getAngle(), camera.getAngle() + 20));
- sleep(random(500,900));
- // Exp picking moved to the paint
- runTimer.reset();
- updateTimeToLevel = new Timer(10000);
- // Find a tree
- setState(Status.FIND_TREE);
- break;
- default:
- break;
- }
- return random(700,1000);
- }
- // Determine current state of script
- private void determineState()
- {
- Status currentState = getState();
- Status newState = null;
- // No need to check any criteria with these states
- Status[] fastReturn = { Status.INIT, Status.ERROR, Status.LEVELUP, Status.RESET };
- for (Status s : fastReturn)
- {
- if (s == currentState)
- { return; }
- }
- // Check if the inventory is open yet; if not, rely on serverMessageListener for a full notice
- // Inventory not full yet, keep chopping
- if (currentState != Status.INVEN_FULL || (game.getCurrentTab() == Game.TAB_INVENTORY && !inventory.isFull()) )
- {
- // If we're animated as chopping, continue chopping
- if (getMyPlayer().getAnimation() == anim_chopping)
- { newState = Status.CHOPPING; }
- // If we're animated idle and not WAITing, find a new tree
- else if (getMyPlayer().getAnimation() == anim_idle && currentState != Status.WAIT && currentState != Status.CHOP_TREE && currentState != Status.WALK_TO_TREE)
- { newState = Status.FIND_TREE; }
- }
- // Inventory is full - do we drop, bank or burn?
- else
- {
- /* if (OPT_LOGS_BANK)
- { newState = State.BANK_ALL; }
- if (OPT_LOGS_BURN)
- { newState = State.BURN_LOGS; }
- else
- { */newState = Status.DROP_ALL; /*}*/
- }
- if (newState != null)
- { setState(newState); }
- }
- private boolean treeStumped()
- {
- if (tree == null)
- { return true; }
- int treeID = tree.getDef().getID();
- if (treeID == currentTreeID)
- { return false; }
- else if (treeID == currentTreeID + 1)
- { return true; }
- return false;
- }
- // Setter for currState + lastState
- private void setState(Status newState)
- {
- lastState = currState;
- currState = newState;
- }
- // Getter for currState
- private Status getState()
- { return currState; }
- // Readable state for outputting
- private String getReadableState()
- {
- String state = currState.toString();
- state = state.replace("_", " ").toLowerCase();
- state = (state.length() > 0) ? Character.toUpperCase(state.charAt(0)) + state.substring(1) : "Wait";
- return state;
- }
- // Getter for lastState
- private Status getLastState()
- { return lastState; }
- // Setter for lastError
- private void setError(String e)
- {
- lastError = e;
- setState(Status.ERROR);
- }
- // Getter for lastError
- private String getError()
- { return lastError; }
- private void getTreeType()
- {
- int wcLevel = skills.getCurrentLevel(Skills.WOODCUTTING);
- // Automatic tree selection
- if (automaticTrees)
- {
- if (wcLevel > 60)
- { treeType = 5; }
- else if (wcLevel > 47)
- { treeType = 4; }
- else if (wcLevel > 33)
- { treeType = 3; }
- else if (wcLevel > 18)
- { treeType = 2; }
- else
- { treeType = 1; }
- }
- switch (treeType)
- {
- case 0:
- default:
- // Intentional fallthrough
- case 1:
- id_trees = id_normalTrees;
- break;
- case 2:
- id_trees = id_oakTrees;
- break;
- case 3:
- id_trees = id_willowTrees;
- break;
- case 4:
- id_trees = id_mapleTrees;
- break;
- case 5:
- id_trees = id_yewTrees;
- break;
- }
- }
- // Better method for clicking
- private boolean clickTree (RSObject tree)
- {
- if (tree == null)
- { return false; }
- // Move the mouse to hover the tree
- tree.doHover();
- sleep(random(500,750));
- String[] actions = tree.getDef().getActions();
- if (actions == null || actions.length == 0)
- { return false; }
- for (String action : actions)
- {
- if (action != null && action.equalsIgnoreCase("Chop down"));
- {
- if (tree.doAction("Chop down " + tree.getDef().getName()))
- { return true; }
- // Fall back to a generic chop
- else
- { return tree.doAction("Chop down"); }
- }
- }
- return false;
- }
- /*
- *
- * End of main loop and state handling
- * Unlabeled methods follow
- *
- */
- // Called when a log has been chopped
- private void logChopped()
- {
- // Increase counters for logs and exp
- logsChopped++;
- // Update state
- setState(Status.CHECK_TREE);
- }
- // Called when a level has been gained
- private void levelUp()
- {
- setState(Status.LEVELUP);
- }
- // Returns true/false randomly
- private boolean boolRandom()
- {
- int i = random(1,10);
- return (i < 6) ? false : true;
- }
- /*
- *
- * End of unlabeled methods
- * Custom logging follows
- *
- */
- // Log a message as AntiBan
- protected void abLog(String msg)
- { antiBanLogger.log(Level.INFO, msg); }
- /*
- *
- * End of custom logging
- * Walking, mouse and camera helpers follow
- *
- */
- private boolean myWalkTo(RSTile endTile)
- { return walk(walking.findPath(endTile)); }
- private final boolean walk(RSTile[] pathWalk)
- {
- RSTile[] path = walking.randomizePath(pathWalk, 2, 2);
- try
- {
- if (calc.distanceTo(walking.getDestination()) < random(3, 5) || calc.distanceTo(walking.getDestination()) > 40)
- {
- if (!walking.walkPathMM(path))
- {
- if (calc.distanceTo(walking.nextTile(path)) >= 7)
- {
- walkToClosestTile(path);
- moveMouseSlightly();
- }
- else
- { sleep(random(50, 150)); }
- }
- }
- }
- catch (final Exception e)
- { e.printStackTrace(); }
- sleep(50, 300);
- return false;
- }
- private boolean walkToClosestTile(RSTile[] path)
- {
- RSTile next = walking.nextTile(path, 16);
- return next != null && walking.walkTo(next);
- }
- private void moveMouseSlightly()
- { mouse.moveRandomly(random(0, 100)); }
- private void maybeMoveMouseSlightly()
- { if (boolRandom()) { moveMouseSlightly(); } }
- private void moveCameraSlightly()
- {
- moveCameraSlightly(false);
- }
- private void moveCameraSlightly(boolean changePitch)
- {
- int angle = camera.getAngle();
- if (angle == 0)
- { angle += random(1,90); }
- else if (angle < 45)
- { angle += random((0 - angle + 5), 45); }
- else if (angle > 315)
- { angle += random(-45, (360 - angle - 5)); }
- else
- { angle += random(-45, 45); }
- if (angle < 0)
- { angle = 0; }
- else if (angle > 360)
- { angle = 360; }
- camera.setAngle(angle);
- if (changePitch)
- {
- int pitch = camera.getPitch();
- if (pitch == 0)
- { pitch = random (40,60); }
- else if (pitch < 20)
- { pitch += random((0 - pitch), 20); }
- else if (pitch > 80)
- { pitch += random(-20, (100 - pitch)); }
- else
- { pitch += random (-20, 20); }
- camera.setPitch(pitch);
- }
- }
- /*
- *
- * Pretty much finished now
- * Server message listener and painter follow
- *
- */
- // Message listener
- public void serverMessageRecieved(ServerMessageEvent e)
- {
- String message = e.getMessage();
- // Log cut
- if (message.contains("You get some"))
- { logChopped(); }
- // Inventory full (and inventory not open)
- if (message.contains("inventory is too full"))
- { setState(Status.INVEN_FULL); }
- // Level up
- if (message.contains("just advanced"))
- { levelUp(); }
- }
- // Paint
- public void onRepaint(Graphics g)
- {
- Graphics2D G = (Graphics2D)g;
- G.setRenderingHints(antialiasing);
- // Pull in actual mouse
- org.rsbot.bot.input.Mouse m = Application.getGUI().getBot().getClient().getMouse();
- // Check to see if paint needs hiding/showing
- if (m.getRealX() >= 0 && m.getRealX() <= 0 + 81 && m.getRealY() >= 309 && m.getRealY() <= 309 + 31)
- { if (canTogglePaint) { showPaint = !showPaint; canTogglePaint = false; } }
- else
- { canTogglePaint = true; }
- // Bot-mouse overlay
- drawMouseLines(G);
- // No painting if not logged in
- if (game.isLoggedIn())
- {
- // Pull in starting exp and level
- // Moved this here so it bloody works :)
- if (startExp < 100)
- {
- startExp = skills.getCurrentExp(Skills.WOODCUTTING);
- startLevel = skills.getRealLevel(Skills.WOODCUTTING);
- }
- // Tile overlays
- overlayTile(G, getMyPlayer().getLocation(), new Color(0, 255, 0, 255), 1);
- if (tree != null)
- { overlayArea(G, tree.getArea(), new Color(255, 255, 0, 255), 2); }
- // Show the antiBan background
- G.drawImage(img_antibanBackground, paintX0 + 80, paintY0 - 16, null);
- G.setFont(fnt_antiban);
- // Paint the antiBan overlay
- ABState abStatus = antiBan.getStatus();
- if (abStatus == ABState.NOT_RUNNING)
- {
- // Paint red, not running
- G.setColor(clr_redSemi);
- G.fillRect(paintX0 + 88, paintY0 - 9, 424, 17);
- G.setColor(clr_darkRed);
- }
- else if (abStatus == ABState.IDLE)
- {
- // No paint, idling
- G.setColor(clr_black);
- }
- else if (abStatus == ABState.READY)
- {
- // Paint yellow, anti coming soon
- G.setColor(clr_yellowSemi);
- G.fillRect(paintX0 + 88, paintY0 - 9, 424, 17);
- G.setColor(clr_darkYellow);
- }
- else
- {
- // Paint green, active
- G.setColor(clr_greenSemi);
- G.fillRect(paintX0 + 88, paintY0 - 9, 424, 17);
- G.setColor(clr_darkGreen);
- }
- // Write the status of the antiBan
- G.drawString("AntiBan | " + antiBan.getReadableState(), paintX0 + 92, paintY0 + 4);
- // Show/hide paint
- if (!showPaint)
- { G.drawImage(img_showPaint, paintX0, paintY0 - 16, null); }
- else
- {
- G.drawImage(img_hidePaint, paintX0, paintY0 - 16, null);
- // Set up variables
- int intWcLevel = skills.getRealLevel(Skills.WOODCUTTING);
- String nextWcLevel = Integer.toString(intWcLevel + 1);
- String logsCut = Integer.toString(logsChopped);
- String wcLevel = Integer.toString(intWcLevel);
- int intExpGain = skills.getCurrentExp(Skills.WOODCUTTING)- startExp;
- boolean correctedExpGain = false;
- // Merry hell with divide by 0
- if (intExpGain == 0) { intExpGain = 1; }
- else if (!correctedExpGain) { --intExpGain; correctedExpGain = true; }
- String expGain = String.format("%,d", intExpGain);
- String lvlGain = Integer.toString(intWcLevel - startLevel);
- // MATHS: XP/hr
- // Time elapsed
- long millis = runTimer.getElapsed();
- long millis2 = millis;
- // Calculate hours, minutes and seconds
- long hours = millis / (60 * 60 * 1000);
- millis -= hours * (60 * 60 * 1000);
- long mins = millis / (60 * 1000);
- millis -= mins * (60 * 1000);
- long secs = millis / 1000;
- // Work out exp per second
- float expPerSec = 0;
- if ((mins > 0 || hours > 0 || secs > 0) && intExpGain > 0)
- { expPerSec = ( (float)intExpGain / (float)(secs + (mins * 60) + (hours * 60 * 60)) ); }
- // And multiply up to exp per hour
- float expPerHour = expPerSec * 60 * 60;
- // Exp per hour final var
- int expHour = (int) expPerHour;
- // MATHS: End of XP/hr, starting time to levelup
- int expToLevel = skills.getExpToNextLevel(Skills.WOODCUTTING);
- // God damn longs and floats. Long doesn't want to work here for me
- String timeToLevel;
- // Only update every 30s so you don't look like a pussy
- if (updateTimeToLevel.isUp())
- {
- updateTimeToLevel.reset();
- float msToLevel = Math.round(expToLevel / ( (float)intExpGain / millis2));
- long millisToLevel = (int) msToLevel;
- long hoursToLevel = (millisToLevel / (60 * 60 * 1000));
- millisToLevel -= hoursToLevel * (60 * 60 * 1000);
- long minsToLevel = millisToLevel / (60 * 1000);
- millisToLevel -= minsToLevel * (60 * 1000);
- long secsToLevel = millisToLevel / 1000;
- DecimalFormat nf = new DecimalFormat("00");
- timeToLevel = nf.format(hoursToLevel) + ":" + nf.format(minsToLevel) + ":" + nf.format(secsToLevel);
- lastTimeToLevel = timeToLevel;
- }
- else
- { timeToLevel = lastTimeToLevel; }
- // MATHS: Whew, done
- String pctToLvl = Integer.toString(skills.getPercentToNextLevel(Skills.WOODCUTTING)) + "%";
- double expKHour = expHour / 1000;
- DecimalFormat df = new DecimalFormat("###,###.#");
- String expHr = df.format(expKHour);
- // Progress bars at 101px possible height (100px bar, 1px separator)
- int greenBar = (intWcLevel == 99) ? 101 : skills.getPercentToNextLevel(Skills.WOODCUTTING);
- int redBar = (greenBar == 0) ? 101 : 100 - greenBar; redBar = (redBar < 0) ? 0 : redBar;
- // End of set up, start painting
- // Paint chatbox
- G.drawImage(img_chatBackground, paintX0, paintY0 + 9, null);
- // Labels
- G.setFont(fnt_label);
- G.setColor(clr_label);
- G.drawString("Time Running", paintX0 + 46, paintY0 + 46);
- G.drawString("Logs Cut", paintX0 + 162, paintY0 + 46);
- G.drawString("Status", paintX0 + 262, paintY0 + 46);
- G.drawString("Current Level", paintX0 + 46, paintY0 + 82);
- G.drawString("Exp Gained", paintX0 + 162, paintY0 + 82);
- G.drawString("Levels Gained", paintX0 + 262, paintY0 + 82);
- G.drawString("% to Level " + nextWcLevel, paintX0 + 46, paintY0 + 118);
- G.drawString("Exp/hr", paintX0 + 162, paintY0 + 118);
- G.drawString("Time to Level", paintX0 + 262, paintY0 + 118);
- // Values
- G.setFont(fnt_value);
- G.setColor(clr_value);
- G.drawString(runTimer.toStringElapsed(), paintX0 + 51, paintY0 + 63);
- G.drawString(logsCut, paintX0 + 167, paintY0 + 63);
- G.drawString(getReadableState(), paintX0 + 267, paintY0 + 63);
- G.drawString("Level " + wcLevel, paintX0 + 51, paintY0 + 100);
- G.drawString(expGain + " exp", paintX0 + 167, paintY0 + 100);
- G.drawString(lvlGain + " levels", paintX0 + 267, paintY0 + 100);
- G.drawString(pctToLvl, paintX0 + 51, paintY0 + 136);
- G.drawString(expHr + "k xp/hr", paintX0 + 167, paintY0 + 136);
- G.drawString(timeToLevel, paintX0 + 267, paintY0 + 136);
- // Progress bar
- G.setColor(clr_background);
- G.fillRect(paintX0 + 17, paintY0 + 31, 19, 107);
- G.setColor(clr_border);
- G.setStroke(stk_progBar);
- G.drawRect(paintX0 + 17, paintY0 + 31, 19, 107);
- // Progress
- G.setColor(clr_red);
- G.fillRect(paintX0 + 20, paintY0 + 34, 14, redBar);
- if (redBar != 101 && greenBar != 101)
- {
- G.setColor(clr_background);
- G.fillRect(paintX0 + 18, paintY0 + 34 + redBar, 16, 2);
- }
- G.setColor(clr_green);
- G.fillRect(paintX0 + 20, paintY0 + 36 + redBar, 14, greenBar);
- }
- }
- }
- private Image getImage(String url)
- {
- try
- { return ImageIO.read(new URL(url)); }
- catch (IOException e)
- { return null; }
- }
- /**
- * Modified method that draws a tile or tiles with the passed color on the passed instance of <code>Graphics</code>.
- *
- * @param g The instance of <code>Graphics</code> you want to draw on.
- * @param tile The instance of the tile you want to draw.
- * @param color The color you want the drawn tile to be.
- * @author Gnarly
- * @author BarryScript
- */
- private void overlayTile(Graphics g, RSTile t, Color c, int thingOnTile)
- {
- RSTile t2 = new RSTile(t.getX() + 1, t.getY());
- RSTile t3 = new RSTile(t.getX(), t.getY() + 1);
- RSTile t4 = new RSTile(t.getX() + 1, t.getY() + 1);
- Point p = calc.tileToScreen(t);
- Point pn = calc.tileToScreen(t, 0, 0, 0);
- Point px = calc.tileToScreen(t2, 0, 0, 0);
- Point py = calc.tileToScreen(t3, 0, 0, 0);
- Point pxy = calc.tileToScreen(t4, 0, 0, 0);
- Point[] points = { p, pn, px, py, pxy };
- for (Point point : points)
- {
- if (!calc.pointOnScreen(point))
- { return; }
- }
- g.setColor(c);
- g.drawPolygon(new int[] { py.x, pxy.x, px.x, pn.x }, new int[] { py.y, pxy.y, px.y, pn.y }, 4);
- // Paint labels
- overlayLabels(g, c, p, thingOnTile);
- }
- // TODO Paint outside borders only
- private void overlayArea(Graphics g, RSArea a, Color c, int thingOnTile)
- {
- // Get most distant tiles, assume rectangular RSArea
- RSTile[][] allTiles = a.getTiles();
- int xLen = allTiles.length - 1;
- int yLen = allTiles[0].length;
- RSTile base = allTiles[0][0];
- RSTile nw = new RSTile(base.getX(), base.getY() + yLen - 1);
- RSTile ne = new RSTile(base.getX() + xLen, base.getY() + yLen - 1);
- RSTile sw = new RSTile(base.getX(), base.getY());
- RSTile se = new RSTile(base.getX() + xLen, base.getY());
- overlayTile(g, sw, c, 2);
- overlayTile(g, se, c, 2);
- overlayTile(g, nw, c, 2);
- overlayTile(g, ne, c, 2);
- }
- private void overlayLabels(Graphics g, Color c, Point p, int thingOnTile)
- {
- g.setFont(new Font("sansserif", Font.BOLD, 12));
- g.setColor(new Color(0, 0, 0, 255));
- if (thingOnTile == 1)
- {
- g.drawString("Player", p.x, p.y);
- g.setColor(c);
- g.drawString("Player", p.x, p.y);
- }
- else if (thingOnTile == 2)
- {
- g.drawString("Tree", p.x, p.y);
- g.setColor(c);
- g.drawString("Tree", p.x, p.y);
- }
- }
- /**
- * Draws mouse lines on the passed instance of <code>Graphics</code>.
- *
- * @param render The instance of <code>Graphics</code> you want to draw on.
- * @author Gnarly
- */
- private void drawMouseLines(Graphics render)
- {
- if (!mouse.isClientPresent())
- { return; }
- render.setColor(new Color(0, 0, 0, 128));
- render.drawLine(0, (int) mouse.getClientLocation().getY(), game.getWidth(), (int) mouse.getClientLocation().getY());
- render.drawLine((int) mouse.getClientLocation().getX(), 0, (int) mouse.getClientLocation().getX(), game.getHeight());
- String texts[] =
- {
- "mx: " + (int) mouse.getClientLocation().getX(),
- "my: " + (int) mouse.getClientLocation().getY()
- };
- int width = 0;
- for (String text : texts)
- {
- int textWidth = render.getFontMetrics().stringWidth(text);
- if (textWidth > width)
- { width = textWidth; }
- }
- width += 10;
- int height = 2 + (texts.length * 15);
- render.setColor(new Color(0, 0, 0, 100));
- render.fillRect((int) mouse.getClientLocation().getX(), (int) mouse.getClientLocation().getY(), width, height);
- render.setColor(Color.BLACK);
- render.drawRect((int) mouse.getClientLocation().getX(), (int) mouse.getClientLocation().getY(), width, height);
- render.setColor(Color.WHITE);
- int fontY = (int) mouse.getClientLocation().getY() + 12;
- for (String text : texts)
- {
- render.drawString(text, (int) mouse.getClientLocation().getX() + 5, fontY);
- fontY += 15;
- }
- }
- class AntiBan extends Thread
- {
- // Parent
- private bChop b;
- // Is the antiban using the mouse?
- private boolean canUseMouse = false;
- protected boolean usingMouse = false;
- // Tabs to use
- private int[] tabs = {Game.TAB_STATS, Game.TAB_EQUIPMENT, Game.TAB_EQUIPMENT, Game.TAB_MAGIC, Game.TAB_FRIENDS};
- // Readable state
- private String[] basicStates = { "Idle", "Reset", "Move Mouse", "Move Camera", "Move Camera", "Open Tab", "Hover Stat", "Do Nothing", "Paused", "Off-Screen" };
- private String[] detailedStates =
- {
- "Waiting for {DURATION} {SECONDS} before running anti-ban again", // 0
- "Going back to the inventory", // 1
- "Moving mouse slightly from {INT1}, {INT2}", // 2
- "Moving camera slightly (angle {INT1} only)", // 3
- "Moving camera slightly (angle {INT1} and pitch {INT2})", // 4
- "Opening {TEXT1} tab for about {DURATION} {SECONDS}", // 5
- "Hovering over the {TEXT1} stat for about {DURATION} {SECONDS}", // 6
- "Deliberately doing nothing for about {DURATION} {SECONDS}", // 7
- "Script has been paused; anti-ban will resume with script", // 8
- "Moving mouse off screen until it's next needed" // 9
- };
- private String abState = "";
- private int sleepFor;
- public AntiBan(bChop parent)
- {
- this.b = parent;
- }
- // Main method
- public void run()
- {
- abLog("Started AntiBan");
- antibanStatus = ABState.IDLE;
- // Settings variables
- int tabToOpen, duration;
- try { while(b.isActive) {
- if(!b.isPaused)
- {
- antibanStatus = ABState.ACTIVE;
- // Determine if we have mouse control
- setHasMouse();
- int[] noMouse = { 1, 2, 3 };
- int allowedSnippets = (canUseMouse) ? 6 : noMouse.length;
- int rand = random(1, allowedSnippets);
- boolean needsMouse = true;
- for (int nmSnip : noMouse)
- { if (nmSnip == rand) { needsMouse = false; } }
- usingMouse = needsMouse;
- switch(rand)
- {
- // Deliberately do nothing
- case 1:
- duration = random(750,3000);
- setReadableState(7, duration);
- b.maybeMoveMouseSlightly();
- break;
- // Move the camera angle slightly -> RESET
- case 2:
- duration = random(200,400);
- setReadableState(3, -1, b.camera.getAngle());
- b.maybeMoveMouseSlightly();
- b.moveCameraSlightly();
- break;
- // Move the camera angle and pitch slightly -> RESET
- case 3:
- duration = random(200,400);
- setReadableState(4, -1, b.camera.getAngle(), b.camera.getPitch());
- b.maybeMoveMouseSlightly();
- b.moveCameraSlightly(true);
- break;
- // Move the mouse slightly -> RESET
- case 4:
- duration = random(200,400);
- setReadableState(2, -1, b.mouse.getClientLocation().x, b.mouse.getClientLocation().y);
- b.moveMouseSlightly();
- break;
- // Open a tab -> Wait for a few seconds -> RESET
- case 5:
- tabToOpen = random(0, tabs.length);
- duration = random(1500,3000);
- setReadableState(5, duration, Game.TAB_NAMES[tabs[tabToOpen]], tabs[tabToOpen]);
- b.maybeMoveMouseSlightly();
- // Open a tab
- b.game.openTab(tabs[tabToOpen]);
- break;
- // Move mouse off screen -> Wait -> Bring back to screen
- case 6:
- duration = random(3500,5000);
- setReadableState(9, duration);
- b.maybeMoveMouseSlightly();
- // Send it off-screen
- b.mouse.moveOffScreen();
- break;
- default:
- duration = random(100,200);
- break;
- }
- // Wait a little
- sleep(duration);
- // Go back to the inventory if needed
- if (b.game.getCurrentTab() != Game.TAB_INVENTORY)
- { b.game.openTab(Game.TAB_INVENTORY); }
- while (b.game.getCurrentTab() != Game.TAB_INVENTORY)
- { sleep(random(500,750)); }
- usingMouse = false;
- // Change state back to default after a little
- sleep(2000);
- setReadableState(1);
- antibanStatus = ABState.IDLE;
- // Sleep nicely
- sleepFor = random(8000,15000);
- while (sleepFor > 0)
- {
- if (sleepFor < 3000)
- { antibanStatus = ABState.READY; }
- setReadableState(0, (int) Math.ceil(sleepFor), null, -1, -1, -1);
- if (sleepFor % 1000 == 0)
- {
- sleepFor -= 1000;
- sleep(1000);
- }
- else
- {
- sleepFor -= sleepFor % 1000;
- sleep(sleepFor % 1000);
- }
- }
- }
- // Coming out of sleep and finding it paused
- else
- { setReadableState(8); }
- }
- }
- catch(InterruptedException e)
- {
- antibanStatus = ABState.NOT_RUNNING;
- abLog(e.getMessage());
- }
- }
- private String getReadableState()
- { return abState; }
- public ABState getStatus()
- { return antibanStatus; }
- private void setHasMouse()
- { canUseMouse = (getMyPlayer().getAnimation() == -1 && b.getState() != Status.CHOP_TREE && b.getState() != Status.WALK_TO_TREE) ? false : true; }
- // Set readable state for paint to use
- private void setReadableState(int stateID, int duration, String text1, int num1, int num2, int num3)
- {
- // Text replacement
- String detail = detailedStates[stateID];
- duration = Math.round(duration / 1000);
- if (duration != -1 && detail.contains("{DURATION}"))
- { detail = detail.replace("{DURATION}", Integer.toString(duration)); }
- if (text1 != null && detail.contains("{TEXT1}"))
- { detail = detail.replace("{TEXT1}", text1); }
- if (num1 != -1 && detail.contains("{INT1}"))
- { detail = detail.replace("{INT1}", Integer.toString(num1)); }
- if (num2 != -1 && detail.contains("{INT2}"))
- { detail = detail.replace("{INT2}", Integer.toString(num2)); }
- if (num3 != -1 && detail.contains("{INT3}"))
- { detail = detail.replace("{INT3}", Integer.toString(num3)); }
- if (detail.contains("{TAB_TOTAL}"))
- { detail = detail.replace("{TAB_TOTAL}", Integer.toString(tabs.length)); }
- if (detail.contains("{SECONDS}"))
- { detail = (duration == 1) ? detail.replace("{SECONDS}", "second") : detail.replace("{SECONDS}", "seconds"); }
- abState = basicStates[stateID] + " - " + detail;
- }
- private void setReadableState(int stateID)
- { setReadableState(stateID, 0, null, -1, -1, -1); }
- private void setReadableState(int stateID, int duration)
- { setReadableState(stateID, duration, null, -1, -1, -1); }
- private void setReadableState(int stateID, int duration, int num1)
- { setReadableState(stateID, duration, null, num1, -1, -1); }
- private void setReadableState(int stateID, int duration, int num1, int num2)
- { setReadableState(stateID, duration, null, num1, num2, -1); }
- private void setReadableState(int stateID, int duration, int num1, int num2, int num3)
- { setReadableState(stateID, duration, null, num1, num2, num3); }
- private void setReadableState(int stateID, int duration, String text1)
- { setReadableState(stateID, duration, text1, -1, -1, -1); }
- private void setReadableState(int stateID, int duration, String text1, int num1)
- { setReadableState(stateID, duration, text1, num1, -1, -1); }
- private void setReadableState(int stateID, int duration, String text1, int num1, int num2)
- { setReadableState(stateID, duration, text1, num1, num2, -1); }
- }
- }