Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 37.88 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.awt.BasicStroke;
  2. import java.awt.Color;
  3. import java.awt.Font;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.Image;
  7. import java.awt.Point;
  8. import java.awt.RenderingHints;
  9. import java.io.IOException;
  10. import java.net.URL;
  11. import java.text.DecimalFormat;
  12. import java.util.Map;
  13.  
  14. import java.util.logging.Logger;
  15. import java.util.logging.Level;
  16.  
  17. import javax.imageio.ImageIO;
  18.  
  19. import org.rsbot.Application;
  20.  
  21. import org.rsbot.event.events.ServerMessageEvent;
  22. import org.rsbot.event.listeners.PaintListener;
  23. import org.rsbot.event.listeners.ServerMessageListener;
  24.  
  25. import org.rsbot.script.*;
  26. import org.rsbot.script.methods.*;
  27. import org.rsbot.script.util.Timer;
  28. import org.rsbot.script.wrappers.*;
  29.  
  30.  
  31. @ScriptManifest(authors = "Barry", name = "bChop", category = "Woodcutting", version = 0.51, description =
  32.         "<p>Settings coming here shortly. For now, just have an axe and stand kinda near the tree(s) you want to cut.</p>"
  33.         + "<p><strong>Which trees should be chopped?</strong><br />"
  34.         + "<select name='treeType'><option value='0'>Automatic</option><option value='1'>Normal trees</option>"
  35.         + "<option value='2'>Oak trees</option><option value='3'>Willow trees</option><option value='4'>Maple trees</option>"
  36.         + "<option value='5'>Yew trees</option></p>"
  37.         + "<p><strong>Take screenshot on levelup?</strong><br />"
  38.         + "<input type='radio' name='takeScreeny' value='true' checked='checked' /> Yes &nbsp;&nbsp;&nbsp; "
  39.         + "<input type='radio' name='takeScreeny' value='false' /> No</p>"
  40.         + "<p><strong>Obscure name on screenshot?</strong><br />"
  41.         + "<input type='radio' name='obscureScreeny' value='true' checked='checked' /> Yes &nbsp;&nbsp;&nbsp; "
  42.         + "<input type='radio' name='obscureScreeny' value='false' /> No</p>"
  43.         )
  44. public class bChop extends Script implements PaintListener, ServerMessageListener
  45.         {
  46.         // Settings
  47.                 // 0: Drop / 1: Bank / 2: Burn
  48.                 private int whenFull = 0;
  49.                 // 0: AUTOMATIC / 1: Normal / 2: Oak / 3: Willow / 4: Maple / 5: Yew
  50.                 private boolean automaticTrees;
  51.                 private int treeType;
  52.                 // Screenshots
  53.                 private boolean takeScreeny;
  54.                 private boolean obscureScreeny;
  55.                
  56.                 private String lastError = "An unknown error occurred.";
  57.                
  58.         // Tree detection
  59.         private RSObject tree;
  60.         private int currentTreeID;
  61.         private RSArea wanderZone = null;
  62.         private Timer noTreeTimer = null;
  63.        
  64.         // State handling
  65.         protected static enum Status { INIT, FIND_TREE, WALK_TO_TREE, CHOP_TREE, CHOPPING, CHECK_TREE, WAIT, LEVELUP, INVEN_FULL, DROP_ALL, ERROR, RESET };
  66.         private Status currState = Status.INIT;
  67.         private Status lastState;
  68.        
  69.         // Items
  70.         private final int[] id_hatchets = { 1351, 1349, 1353, 1361, 1355, 1357, 1359, 4031, 6739, 13470, 14108 };
  71.         //private final int id_tinderbox = 0;
  72.                
  73.         private final int id_logs = 1511;
  74.         private final int id_oakLogs = 1521;
  75.         private final int id_willowLogs = 1519;
  76.         private final int id_mapleLogs = 1517;
  77.         private final int id_yewLogs = 1515;
  78.        
  79.         // Objects - trees - thanks to Epic_ for a "borrowed" set of IDs :)
  80.         private int[] id_trees = null;
  81.         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 };
  82.         private final int[] id_oakTrees = { 1281, 3037, 8462, 8463, 8464, 8465, 8466, 8467 };
  83.         private final int[] id_willowTrees = { 1308, 5551, 5552, 5553, 8481, 8482, 8483, 8484, 8485, 8486, 8487, 8488 };
  84.         private final int[] id_mapleTrees = { 1307, 1308 };
  85.         private final int[] id_yewTrees = { 1309, 8503, 8504, 8505, 8506, 8507, 8508, 8509, 8510, 8511, 8512, 8513 };
  86.        
  87.         // Animations
  88.         private int anim_idle = -1;
  89.         private int anim_chopping = 869;
  90.        
  91.         // Timer and experience maths
  92.         private Timer runTimer;
  93.        
  94.         private int startExp = 0;
  95.         private int startLevel = 0;
  96.         private int logsChopped = 0;
  97.  
  98.         // Paint settings
  99.                 private boolean showPaint = false;
  100.                 private boolean canTogglePaint = true;
  101.                
  102.                 // Positioning
  103.                 private int paintX0 = 0;
  104.                 private int paintY0 = 325;
  105.                
  106.                 // Fonts
  107.                 private final Font fnt_label = new Font("SansSerif", 0, 15);
  108.                 private final Font fnt_value = new Font("SansSerif", 0, 14);
  109.                 private final Font fnt_antiban = new Font("SansSerif", 0, 12);
  110.                
  111.                 // Colours
  112.                 private final Color clr_label = new Color(0, 0, 0);
  113.                 private final Color clr_value = new Color(121, 110, 91);
  114.  
  115.                 private final Color clr_border = new Color(47, 43, 36);
  116.                 private final Color clr_background = new Color(255, 255, 255);
  117.  
  118.                 private final Color clr_red = new Color(208, 0, 0);
  119.                 private final Color clr_yellow = new Color(208, 208, 0);
  120.                 private final Color clr_green = new Color(0, 208, 0);
  121.                 private final Color clr_darkRed = new Color(70, 0, 0);
  122.                 private final Color clr_darkYellow = new Color(70, 70, 0);
  123.                 private final Color clr_darkGreen = new Color(0, 70, 0);
  124.                 private final Color clr_black = new Color(0, 0, 0);
  125.  
  126.                 private final Color clr_redSemi = new Color(208, 0, 0, 100);
  127.                 private final Color clr_yellowSemi = new Color(208, 208, 0, 100);
  128.                 private final Color clr_greenSemi = new Color(0, 208, 0, 100);
  129.                
  130.                 // Images
  131.                 private static Image img_chatBackground;
  132.                 private static Image img_showPaint;
  133.                 private static Image img_hidePaint;
  134.                 private static Image img_antibanBackground;
  135.        
  136.                 // Strokes
  137.                 private final BasicStroke stk_progBar = new BasicStroke(1);
  138.                
  139.                 // Settings
  140.                 private final RenderingHints antialiasing = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  141.                
  142.         // Antiban
  143.         private AntiBan antiBan;
  144.         private boolean antiBanActive = false;
  145.         static Logger antiBanLogger = Logger.getLogger("AntiBan");
  146.  
  147.         private static enum ABState { NOT_RUNNING, IDLE, READY, ACTIVE };
  148.         private ABState antibanStatus = ABState.NOT_RUNNING;
  149.        
  150.         // Time to level - let's look a little sensible
  151.         private String lastTimeToLevel = "Waiting 10s";
  152.         private Timer updateTimeToLevel;
  153.        
  154.         // Misc stuff
  155.                 // Wait counter
  156.                 private int waitCounter = 0;
  157.                        
  158.                
  159.         /*
  160.          *
  161.          *      End of settings and variables
  162.          *      Script setup follows
  163.          *
  164.          */
  165.        
  166.         // Constructor
  167.         public bChop()
  168.                 { this.antiBan = new AntiBan(this); }
  169.                
  170.         // Starting script
  171.         public boolean onStart(Map<String, String> args)
  172.                 {
  173.                 log("Starting bChop. Loading images...");
  174.  
  175.                 // Get setup
  176.                 //log(args.get("location"));
  177.                 //args.get("takeScreeny");
  178.                 //args.get("obscureScreeny");
  179.                
  180.                 // Load paint images
  181.                 img_chatBackground = getImage("http://img714.imageshack.us/img714/631/backgroundq.gif");
  182.                 img_showPaint = getImage("http://img833.imageshack.us/img833/6823/showpaint.gif");
  183.                 img_hidePaint = getImage("http://img441.imageshack.us/img441/6213/hidepaint.gif");
  184.                 img_antibanBackground = getImage("http://img828.imageshack.us/img828/102/antibanbackground.gif");
  185.                
  186.                 log("...images loaded, starting script.");
  187.                
  188.                 // Pull this in from GUI later
  189.                 treeType = Integer.parseInt(args.get("treeType"));
  190.                 takeScreeny = Boolean.parseBoolean(args.get("takeScreeny"));
  191.                 obscureScreeny = Boolean.parseBoolean(args.get("obscureScreeny"));
  192.                
  193.                 // Handle automatic at start of script
  194.                 if (treeType == 0)
  195.                         { automaticTrees = true; }
  196.                
  197.                 runTimer = new Timer(0);
  198.                 this.antiBan.start();
  199.  
  200.                 return true;
  201.                 }
  202.  
  203.         // Stopping script
  204.         public void onFinish()
  205.                 {
  206.                 log("Stopping bChop and logging out.");
  207.                
  208.                 boolean twoStage = boolRandom();
  209.                 game.logout(twoStage);
  210.                
  211.                 if (twoStage)
  212.                         { game.logout(false); }
  213.                 }
  214.        
  215.         /*
  216.          *
  217.          *      End of script setup
  218.          *      Main loop and state handling follows
  219.          *
  220.          */
  221.        
  222.         // Main loop
  223.         public int loop()
  224.                 {
  225.                 // If the antiban is running, just wait for it to finish
  226.                 if (antiBanActive)
  227.                         { return random(300,500); }
  228.                
  229.                 // What do we need to do?
  230.                 determineState();
  231.                
  232.                 switch (getState())
  233.                         {
  234.                         case FIND_TREE:
  235.                                 // What kind of tree are we looking for?
  236.                                 getTreeType();
  237.  
  238.                                 tree = objects.getNearest(id_trees);
  239.                                
  240.                                 if (tree != null)
  241.                                         {
  242.                                         // Stop the clock
  243.                                         noTreeTimer = null;
  244.                                        
  245.                                         // Log the tree's ID
  246.                                         currentTreeID = tree.getDef().getID();
  247.                                        
  248.                                         // Check wander zone
  249.                                         // Ignores this check if the noTreeTimer has waited 30s
  250.                                         if ( (wanderZone != null && wanderZone.contains(tree.getLocation())) || wanderZone == null || (noTreeTimer != null && noTreeTimer.isUp()))
  251.                                                 {
  252.                                                 // Reset the noTreeTimer
  253.                                                 if (noTreeTimer != null)
  254.                                                         { noTreeTimer = null; }
  255.                                                
  256.                                                 if (calc.distanceTo(tree.getLocation()) > 4)
  257.                                                         { setState(Status.WALK_TO_TREE); }
  258.                                                 else
  259.                                                         {
  260.                                                         if (getLastState() != Status.WAIT)
  261.                                                                 {
  262.                                                                 // Move on to chop it
  263.                                                                 setState(Status.CHOP_TREE);
  264.                                                                 }
  265.                                                         }
  266.                                                 }
  267.                                         else
  268.                                                 {
  269.                                                 // Tree is outside wander zone, keep looking
  270.                                                 tree = null;
  271.                                                 return random(300,500);
  272.                                                 }
  273.                                        
  274.                                         // Tree is found, now set up a wander zone for it
  275.                                         RSTile treeLoc = tree.getLocation();
  276.                                         wanderZone = new RSArea
  277.                                                 (
  278.                                                 new RSTile
  279.                                                         (
  280.                                                         treeLoc.getX() - 10,
  281.                                                         treeLoc.getY() + 10
  282.                                                         ),
  283.                                                 new RSTile
  284.                                                         (
  285.                                                         treeLoc.getX() + 10,
  286.                                                         treeLoc.getY() - 10
  287.                                                         )
  288.                                                 );
  289.                                         }
  290.                                 else
  291.                                         {
  292.                                         // No trees found
  293.                                         if (noTreeTimer == null)
  294.                                                 {
  295.                                                 // Start a new 30s timer
  296.                                                 noTreeTimer = new Timer(30000);
  297.                                                 }
  298.                                         }
  299.                                 break;
  300.  
  301.                         case WALK_TO_TREE:
  302.                                 if (treeStumped())
  303.                                         { setState(Status.RESET); return random(300,500); }
  304.                                
  305.                                 // Distance to
  306.                                 if (!calc.tileOnMap(tree.getLocation()))
  307.                                         { myWalkTo(tree.getLocation()); }
  308.                                 else if (calc.distanceTo(tree.getLocation()) > 4)
  309.                                         {
  310.                                         if (!getMyPlayer().isMoving())
  311.                                                 { walking.walkTileMM(tree.getLocation(), 2, 2); }
  312.                                         }
  313.                                 // Camera rotation
  314.                                 else if (!calc.tileOnScreen(tree.getLocation()))
  315.                                         { camera.turnToObject(tree, 5); }
  316.                                 // Chop tree
  317.                                 else
  318.                                         { setState(Status.CHOP_TREE); }
  319.                                 break;
  320.                                
  321.                         case CHOP_TREE:
  322.                                 // Problem, find another tree
  323.                                 if (treeStumped())
  324.                                         { setState(Status.RESET); }
  325.                                 else
  326.                                         {
  327.                                         if (antiBan.usingMouse)
  328.                                                 { return random(300,500); }
  329.                                        
  330.                                         // Attempt the click. If it fails, find a new tree
  331.                                         if (!clickTree(tree))
  332.                                                 { setState(Status.RESET); }
  333.  
  334.                                         setState(Status.WAIT);
  335.                                         }
  336.                                 break;
  337.                                
  338.                         case CHOPPING:
  339.                                 if (treeStumped())
  340.                                         { setState(Status.RESET); }
  341.                                 break;
  342.                        
  343.                         case CHECK_TREE:
  344.                                 if (treeStumped())
  345.                                         { setState(Status.RESET); }
  346.                                 break;
  347.  
  348.                         case WAIT:
  349.                                 if (treeStumped())
  350.                                         { setState(Status.RESET); return random(300,500); }
  351.  
  352.                                 else if (getMyPlayer().getAnimation() == anim_chopping)
  353.                                         { setState(Status.CHOPPING); }
  354.                                 else if (!getMyPlayer().isMoving())
  355.                                         {
  356.                                         if (waitCounter > 5)
  357.                                                 { waitCounter = 0; setState(Status.RESET); }
  358.                                         else
  359.                                                 { waitCounter++; }
  360.                                         }
  361.                                 break;
  362.                                
  363.                         case DROP_ALL:
  364.                                 if (inventory.containsOneOf(id_logs, id_oakLogs, id_willowLogs, id_mapleLogs, id_yewLogs))
  365.                                         { inventory.dropAllExcept(boolRandom(), id_hatchets); }
  366.                                 else
  367.                                         { setState(Status.ERROR); setError("Inventory full, but no logs in inventory."); }
  368.                                 break;
  369.                        
  370.                         case LEVELUP:                          
  371.                                 if (boolRandom()) { moveMouseSlightly(); }
  372.                                
  373.                                 // Open stats menu for a screeny if needed
  374.                                 if (takeScreeny)
  375.                                         {
  376.                                         game.openTab(Game.TAB_STATS);
  377.                                         takeScreenshot(obscureScreeny);
  378.                                        
  379.                                         log("Levelup! " + skills.getRealLevel(Skills.WOODCUTTING) + " woodcutting. Screenshot taken.");
  380.                                         }
  381.                                 else
  382.                                         { log("Levelup! " + skills.getRealLevel(Skills.WOODCUTTING) + " woodcutting."); }
  383.                                
  384.                                 if (interfaces.canContinue())
  385.                                         { interfaces.clickContinue(); }
  386.                                                        
  387.                                 setState(Status.CHECK_TREE);
  388.                                 break;
  389.                                
  390.                         case RESET:
  391.                                 tree = null;
  392.                                 currentTreeID = 0;
  393.                                 setState(Status.FIND_TREE);
  394.                                 break;
  395.                                
  396.                         case INIT:
  397.                                 // Camera setup
  398.                                 sleep(random(300,500));
  399.                                 camera.setAltitude(true);
  400.                                 sleep(random(500,900));
  401.                                 camera.setAngle(random(camera.getAngle(), camera.getAngle() + 20));
  402.                                 sleep(random(500,900));
  403.                                
  404.                                 // Exp picking moved to the paint
  405.                                
  406.                                 runTimer.reset();
  407.                                 updateTimeToLevel = new Timer(10000);
  408.                                
  409.                                 // Find a tree
  410.                                 setState(Status.FIND_TREE);
  411.                                 break;
  412.                                
  413.                         default:
  414.                                 break;
  415.                         }
  416.                
  417.                 return random(700,1000);
  418.                 }
  419.  
  420.         // Determine current state of script
  421.         private void determineState()
  422.                 {
  423.                 Status currentState = getState();
  424.                 Status newState = null;
  425.  
  426.                 // No need to check any criteria with these states
  427.                 Status[] fastReturn = { Status.INIT, Status.ERROR, Status.LEVELUP, Status.RESET };
  428.                 for (Status s : fastReturn)
  429.                         {
  430.                         if (s == currentState)
  431.                                 { return; }
  432.                         }
  433.                
  434.                 // Check if the inventory is open yet; if not, rely on serverMessageListener for a full notice
  435.                 // Inventory not full yet, keep chopping
  436.                 if (currentState != Status.INVEN_FULL || (game.getCurrentTab() == Game.TAB_INVENTORY && !inventory.isFull()) )
  437.                         {
  438.                         // If we're animated as chopping, continue chopping
  439.                         if (getMyPlayer().getAnimation() == anim_chopping)
  440.                                 { newState = Status.CHOPPING; }
  441.                         // If we're animated idle and not WAITing, find a new tree
  442.                         else if (getMyPlayer().getAnimation() == anim_idle && currentState != Status.WAIT && currentState != Status.CHOP_TREE && currentState != Status.WALK_TO_TREE)
  443.                                 { newState = Status.FIND_TREE; }
  444.                         }
  445.                 // Inventory is full - do we drop, bank or burn?
  446.                 else
  447.                         {
  448.         /*              if (OPT_LOGS_BANK)
  449.                                 { newState = State.BANK_ALL; }
  450.                         if (OPT_LOGS_BURN)
  451.                                 { newState = State.BURN_LOGS; }
  452.                         else
  453.                                 { */newState = Status.DROP_ALL; /*}*/
  454.                         }
  455.  
  456.                 if (newState != null)
  457.                         { setState(newState); }
  458.                 }
  459.  
  460.         private boolean treeStumped()
  461.                 {
  462.                 if (tree == null)
  463.                         { return true; }
  464.                
  465.                 int treeID = tree.getDef().getID();
  466.                 if (treeID == currentTreeID)
  467.                         { return false; }
  468.                 else if (treeID == currentTreeID + 1)
  469.                         { return true; }
  470.                
  471.                 return false;
  472.                 }
  473.        
  474.         // Setter for currState + lastState
  475.         private void setState(Status newState)
  476.                 {
  477.                 lastState = currState;
  478.                 currState = newState;
  479.                 }
  480.        
  481.         // Getter for currState
  482.         private Status getState()
  483.                 { return currState; }
  484.        
  485.         // Readable state for outputting
  486.         private String getReadableState()
  487.                 {
  488.                 String state = currState.toString();
  489.                 state = state.replace("_", " ").toLowerCase();
  490.                 state = (state.length() > 0) ? Character.toUpperCase(state.charAt(0)) + state.substring(1) : "Wait";
  491.                 return state;
  492.                 }
  493.        
  494.         // Getter for lastState
  495.         private Status getLastState()
  496.                 { return lastState; }
  497.        
  498.         // Setter for lastError
  499.         private void setError(String e)
  500.                 {
  501.                 lastError = e;
  502.                 setState(Status.ERROR);
  503.                 }
  504.  
  505.         // Getter for lastError
  506.         private String getError()
  507.                 { return lastError; }
  508.  
  509.         private void getTreeType()
  510.                 {
  511.                 int wcLevel = skills.getCurrentLevel(Skills.WOODCUTTING);
  512.                
  513.                 // Automatic tree selection
  514.                 if (automaticTrees)
  515.                         {
  516.                         if (wcLevel > 60)
  517.                                 { treeType = 5; }
  518.                         else if (wcLevel > 47)
  519.                                 { treeType = 4; }
  520.                         else if (wcLevel > 33)
  521.                                 { treeType = 3; }
  522.                         else if (wcLevel > 18)
  523.                                 { treeType = 2; }
  524.                         else
  525.                                 { treeType = 1; }
  526.                         }
  527.                
  528.                 switch (treeType)
  529.                         {
  530.                         case 0:
  531.                         default:
  532.                         // Intentional fallthrough
  533.                                
  534.                         case 1:
  535.                                 id_trees = id_normalTrees;
  536.                                 break;
  537.                                
  538.                         case 2:
  539.                                 id_trees = id_oakTrees;
  540.                                 break;
  541.                                
  542.                         case 3:
  543.                                 id_trees = id_willowTrees;
  544.                                 break;
  545.                                
  546.                         case 4:
  547.                                 id_trees = id_mapleTrees;
  548.                                 break;
  549.                                
  550.                         case 5:
  551.                                 id_trees = id_yewTrees;
  552.                                 break;
  553.                         }
  554.                 }
  555.        
  556.         // Better method for clicking
  557.         private boolean clickTree (RSObject tree)
  558.                 {
  559.                 if (tree == null)
  560.                         { return false; }
  561.  
  562.                 // Move the mouse to hover the tree
  563.                 tree.doHover();
  564.                 sleep(random(500,750));
  565.  
  566.                 String[] actions = tree.getDef().getActions();
  567.                
  568.                 if (actions == null || actions.length == 0)
  569.                         { return false; }
  570.                
  571.                 for (String action : actions)
  572.                         {
  573.                         if (action != null && action.equalsIgnoreCase("Chop down"));
  574.                                 {
  575.                                 if (tree.doAction("Chop down " + tree.getDef().getName()))
  576.                                         { return true; }
  577.                                 // Fall back to a generic chop
  578.                                 else
  579.                                         { return tree.doAction("Chop down"); }
  580.                                 }
  581.                         }
  582.                 return false;
  583.                 }
  584.        
  585.         /*
  586.          *
  587.          *      End of main loop and state handling
  588.          *      Unlabeled methods follow
  589.          *
  590.          */
  591.        
  592.         // Called when a log has been chopped
  593.         private void logChopped()
  594.                 {
  595.                 // Increase counters for logs and exp
  596.                 logsChopped++;
  597.                
  598.                 // Update state
  599.                 setState(Status.CHECK_TREE);
  600.                 }
  601.        
  602.         // Called when a level has been gained
  603.         private void levelUp()
  604.                 {
  605.                 setState(Status.LEVELUP);
  606.                 }
  607.        
  608.         // Returns true/false randomly
  609.         private boolean boolRandom()
  610.                 {
  611.                 int i = random(1,10);
  612.                 return (i < 6) ? false : true;
  613.                 }
  614.  
  615.         /*
  616.          *
  617.          *      End of unlabeled methods
  618.          *      Custom logging follows
  619.          *
  620.          */
  621.        
  622.         // Log a message as AntiBan
  623.         protected void abLog(String msg)
  624.                 { antiBanLogger.log(Level.INFO, msg); }
  625.        
  626.         /*
  627.          *
  628.          *      End of custom logging
  629.          *      Walking, mouse and camera helpers follow
  630.          *
  631.          */
  632.        
  633.         private boolean myWalkTo(RSTile endTile)
  634.                 { return walk(walking.findPath(endTile)); }
  635.        
  636.         private final boolean walk(RSTile[] pathWalk)
  637.                 {
  638.                 RSTile[] path = walking.randomizePath(pathWalk, 2, 2);
  639.                 try
  640.                         {
  641.                         if (calc.distanceTo(walking.getDestination()) < random(3, 5) || calc.distanceTo(walking.getDestination()) > 40)
  642.                                 {
  643.                                 if (!walking.walkPathMM(path))
  644.                                         {
  645.                                         if (calc.distanceTo(walking.nextTile(path)) >= 7)
  646.                                                 {
  647.                                                 walkToClosestTile(path);
  648.                                                 moveMouseSlightly();
  649.                                                 }
  650.                                         else
  651.                                                 { sleep(random(50, 150)); }
  652.                                         }
  653.                                 }
  654.                         }
  655.                 catch (final Exception e)
  656.                         { e.printStackTrace(); }
  657.  
  658.                 sleep(50, 300);
  659.                 return false;
  660.                 }
  661.  
  662.         private boolean walkToClosestTile(RSTile[] path)
  663.                 {
  664.                 RSTile next = walking.nextTile(path, 16);
  665.                 return next != null && walking.walkTo(next);
  666.                 }
  667.        
  668.         private void moveMouseSlightly()
  669.                 { mouse.moveRandomly(random(0, 100)); }
  670.        
  671.         private void maybeMoveMouseSlightly()
  672.                 { if (boolRandom()) { moveMouseSlightly(); } }
  673.        
  674.         private void moveCameraSlightly()
  675.                 {
  676.                 moveCameraSlightly(false);
  677.                 }
  678.  
  679.         private void moveCameraSlightly(boolean changePitch)
  680.                 {
  681.                 int angle = camera.getAngle();
  682.                
  683.                 if (angle == 0)
  684.                         { angle += random(1,90); }
  685.                 else if (angle < 45)
  686.                         { angle += random((0 - angle + 5), 45); }
  687.                 else if (angle > 315)
  688.                         { angle += random(-45, (360 - angle - 5)); }
  689.                 else
  690.                         { angle += random(-45, 45); }
  691.                
  692.                 if (angle < 0)
  693.                         { angle = 0; }
  694.                 else if (angle > 360)
  695.                         { angle = 360; }
  696.                
  697.                 camera.setAngle(angle);
  698.                
  699.                 if (changePitch)
  700.                         {
  701.                         int pitch = camera.getPitch();
  702.                        
  703.                         if (pitch == 0)
  704.                                 { pitch = random (40,60); }
  705.                         else if (pitch < 20)
  706.                                 { pitch += random((0 - pitch), 20); }
  707.                         else if (pitch > 80)
  708.                                 { pitch += random(-20, (100 - pitch)); }
  709.                         else
  710.                                 { pitch += random (-20, 20); }
  711.                        
  712.                         camera.setPitch(pitch);
  713.                         }
  714.                 }
  715.        
  716.        
  717.         /*
  718.          *
  719.          *      Pretty much finished now
  720.          *      Server message listener and painter follow
  721.          *
  722.          */
  723.        
  724.         // Message listener
  725.         public void serverMessageRecieved(ServerMessageEvent e)
  726.                 {
  727.                 String message = e.getMessage();
  728.  
  729.                 // Log cut
  730.                 if (message.contains("You get some"))
  731.                         { logChopped(); }
  732.                 // Inventory full (and inventory not open)
  733.                 if (message.contains("inventory is too full"))
  734.                         { setState(Status.INVEN_FULL); }
  735.                 // Level up
  736.                 if (message.contains("just advanced"))
  737.                         { levelUp(); }
  738.                 }
  739.  
  740.         // Paint
  741.         public void onRepaint(Graphics g)
  742.                 {
  743.                 Graphics2D G = (Graphics2D)g;
  744.                 G.setRenderingHints(antialiasing);
  745.                
  746.                 // Pull in actual mouse
  747.                 org.rsbot.bot.input.Mouse m = Application.getGUI().getBot().getClient().getMouse();
  748.                 // Check to see if paint needs hiding/showing
  749.                 if (m.getRealX() >= 0 && m.getRealX() <= 0 + 81         &&              m.getRealY() >= 309 && m.getRealY() <= 309 + 31)
  750.                         { if (canTogglePaint) { showPaint = !showPaint; canTogglePaint = false; } }
  751.                 else
  752.                         { canTogglePaint = true; }
  753.                
  754.                 // Bot-mouse overlay
  755.                 drawMouseLines(G);
  756.                
  757.                 // No painting if not logged in
  758.                 if (game.isLoggedIn())
  759.                         {
  760.                         // Pull in starting exp and level
  761.                         // Moved this here so it bloody works :)
  762.                         if (startExp < 100)
  763.                                 {
  764.                                 startExp = skills.getCurrentExp(Skills.WOODCUTTING);
  765.                                 startLevel = skills.getRealLevel(Skills.WOODCUTTING);
  766.                                 }
  767.  
  768.                         // Tile overlays
  769.                         overlayTile(G, getMyPlayer().getLocation(), new Color(0, 255, 0, 255), 1);
  770.                         if (tree != null)
  771.                                 { overlayArea(G, tree.getArea(), new Color(255, 255, 0, 255), 2); }
  772.  
  773.                         // Show the antiBan background
  774.                         G.drawImage(img_antibanBackground, paintX0 + 80, paintY0 - 16, null);
  775.                         G.setFont(fnt_antiban);
  776.                        
  777.                         // Paint the antiBan overlay
  778.                                 ABState abStatus = antiBan.getStatus();
  779.                                 if (abStatus == ABState.NOT_RUNNING)
  780.                                         {
  781.                                         // Paint red, not running
  782.                                         G.setColor(clr_redSemi);
  783.                                         G.fillRect(paintX0 + 88, paintY0 - 9, 424, 17);
  784.                                         G.setColor(clr_darkRed);
  785.                                         }
  786.                                 else if (abStatus == ABState.IDLE)
  787.                                         {
  788.                                         // No paint, idling
  789.                                         G.setColor(clr_black);
  790.                                         }
  791.                                 else if (abStatus == ABState.READY)
  792.                                         {
  793.                                         // Paint yellow, anti coming soon
  794.                                         G.setColor(clr_yellowSemi);
  795.                                         G.fillRect(paintX0 + 88, paintY0 - 9, 424, 17);
  796.                                         G.setColor(clr_darkYellow);
  797.                                         }
  798.                                 else
  799.                                         {
  800.                                         // Paint green, active
  801.                                         G.setColor(clr_greenSemi);
  802.                                         G.fillRect(paintX0 + 88, paintY0 - 9, 424, 17);
  803.                                         G.setColor(clr_darkGreen);
  804.                                         }
  805.                         // Write the status of the antiBan
  806.                         G.drawString("AntiBan | " + antiBan.getReadableState(), paintX0 + 92, paintY0 + 4);
  807.                        
  808.                         // Show/hide paint
  809.                         if (!showPaint)
  810.                                 { G.drawImage(img_showPaint, paintX0, paintY0 - 16, null); }
  811.                         else
  812.                                 {
  813.                                 G.drawImage(img_hidePaint, paintX0, paintY0 - 16, null);
  814.                                
  815.                                 // Set up variables
  816.                                 int intWcLevel = skills.getRealLevel(Skills.WOODCUTTING);
  817.                                 String nextWcLevel = Integer.toString(intWcLevel + 1);
  818.                                 String logsCut = Integer.toString(logsChopped);
  819.                                
  820.                                 String wcLevel = Integer.toString(intWcLevel);
  821.                                 int intExpGain = skills.getCurrentExp(Skills.WOODCUTTING)- startExp;
  822.                                 boolean correctedExpGain = false;
  823.                                         // Merry hell with divide by 0
  824.                                         if (intExpGain == 0) { intExpGain = 1; }
  825.                                         else if (!correctedExpGain) { --intExpGain; correctedExpGain = true; }
  826.                                        
  827.                                 String expGain = String.format("%,d", intExpGain);
  828.                                 String lvlGain = Integer.toString(intWcLevel - startLevel);
  829.  
  830.                                         // MATHS: XP/hr
  831.                                                 // Time elapsed
  832.                                                 long millis = runTimer.getElapsed();
  833.                                                 long millis2 = millis;
  834.                                                 // Calculate hours, minutes and seconds
  835.                                                 long hours = millis / (60 * 60 * 1000);
  836.                                                         millis -= hours * (60 * 60 * 1000);
  837.                                                 long mins = millis / (60 * 1000);
  838.                                                         millis -= mins * (60 * 1000);
  839.                                                 long secs = millis / 1000;
  840.                                                
  841.                                                 // Work out exp per second
  842.                                                 float expPerSec = 0;
  843.                                                 if ((mins > 0 || hours > 0 || secs > 0) && intExpGain > 0)
  844.                                                         { expPerSec = ( (float)intExpGain / (float)(secs + (mins * 60) + (hours * 60 * 60)) ); }
  845.                                                 // And multiply up to exp per hour
  846.                                                 float expPerHour = expPerSec * 60 * 60;
  847.                                                 // Exp per hour final var
  848.                                                         int expHour = (int) expPerHour;
  849.                                         // MATHS: End of XP/hr, starting time to levelup
  850.                                                 int expToLevel = skills.getExpToNextLevel(Skills.WOODCUTTING);
  851.  
  852.                                                 // God damn longs and floats. Long doesn't want to work here for me
  853.                                                 String timeToLevel;
  854.                                                 // Only update every 30s so you don't look like a pussy
  855.                                                 if (updateTimeToLevel.isUp())
  856.                                                         {
  857.                                                         updateTimeToLevel.reset();
  858.                                                         float msToLevel = Math.round(expToLevel / ( (float)intExpGain / millis2));
  859.                                                         long millisToLevel = (int) msToLevel;
  860.                                                         long hoursToLevel = (millisToLevel / (60 * 60 * 1000));
  861.                                                                 millisToLevel -= hoursToLevel * (60 * 60 * 1000);
  862.                                                         long minsToLevel = millisToLevel / (60 * 1000);
  863.                                                                 millisToLevel -= minsToLevel * (60 * 1000);
  864.                                                         long secsToLevel = millisToLevel / 1000;
  865.                                                         DecimalFormat nf = new DecimalFormat("00");
  866.                                                         timeToLevel = nf.format(hoursToLevel) + ":" + nf.format(minsToLevel) + ":" + nf.format(secsToLevel);
  867.                                                         lastTimeToLevel = timeToLevel;
  868.                                                         }
  869.                                                 else
  870.                                                         { timeToLevel = lastTimeToLevel; }
  871.                                                
  872.                                         // MATHS: Whew, done
  873.  
  874.                                         String pctToLvl = Integer.toString(skills.getPercentToNextLevel(Skills.WOODCUTTING)) + "%";
  875.                                         double expKHour = expHour / 1000;
  876.                                         DecimalFormat df = new DecimalFormat("###,###.#");
  877.                                         String expHr = df.format(expKHour);
  878.                                        
  879.                                         // Progress bars at 101px possible height (100px bar, 1px separator)
  880.                                         int greenBar = (intWcLevel == 99) ? 101 : skills.getPercentToNextLevel(Skills.WOODCUTTING);
  881.                                         int redBar = (greenBar == 0) ? 101 : 100 - greenBar; redBar = (redBar < 0) ? 0 : redBar;
  882.                                 // End of set up, start painting
  883.                                
  884.                                 // Paint chatbox
  885.                                 G.drawImage(img_chatBackground, paintX0, paintY0 + 9, null);
  886.                                
  887.                                 // Labels
  888.                                 G.setFont(fnt_label);
  889.                                 G.setColor(clr_label);
  890.                                
  891.                                 G.drawString("Time Running", paintX0 + 46, paintY0 + 46);
  892.                                 G.drawString("Logs Cut", paintX0 + 162, paintY0 + 46);
  893.                                 G.drawString("Status", paintX0 + 262, paintY0 + 46);
  894.                                
  895.                                 G.drawString("Current Level", paintX0 + 46, paintY0 + 82);
  896.                                 G.drawString("Exp Gained", paintX0 + 162, paintY0 + 82);
  897.                                 G.drawString("Levels Gained", paintX0 + 262, paintY0 + 82);
  898.                                
  899.                                 G.drawString("% to Level " + nextWcLevel, paintX0 + 46, paintY0 + 118);
  900.                                 G.drawString("Exp/hr", paintX0 + 162, paintY0 + 118);
  901.                                 G.drawString("Time to Level", paintX0 + 262, paintY0 + 118);
  902.  
  903.                                 // Values
  904.                                 G.setFont(fnt_value);
  905.                                 G.setColor(clr_value);
  906.                                
  907.                                 G.drawString(runTimer.toStringElapsed(), paintX0 + 51, paintY0 + 63);
  908.                                 G.drawString(logsCut, paintX0 + 167, paintY0 + 63);
  909.                                 G.drawString(getReadableState(), paintX0 + 267, paintY0 + 63);
  910.                                
  911.                                 G.drawString("Level " + wcLevel, paintX0 + 51, paintY0 + 100);
  912.                                 G.drawString(expGain + " exp", paintX0 + 167, paintY0 + 100);
  913.                                 G.drawString(lvlGain + " levels", paintX0 + 267, paintY0 + 100);
  914.                                
  915.                                 G.drawString(pctToLvl, paintX0 + 51, paintY0 + 136);
  916.                                 G.drawString(expHr + "k xp/hr", paintX0 + 167, paintY0 + 136);
  917.                                 G.drawString(timeToLevel, paintX0 + 267, paintY0 + 136);
  918.  
  919.                                 // Progress bar
  920.                                 G.setColor(clr_background);
  921.                                 G.fillRect(paintX0 + 17, paintY0 + 31, 19, 107);
  922.                                 G.setColor(clr_border);
  923.                                 G.setStroke(stk_progBar);
  924.                                 G.drawRect(paintX0 + 17, paintY0 + 31, 19, 107);
  925.  
  926.                                 // Progress
  927.                                 G.setColor(clr_red);
  928.                                 G.fillRect(paintX0 + 20, paintY0 + 34, 14, redBar);
  929.                                 if (redBar != 101 && greenBar != 101)
  930.                                         {
  931.                                         G.setColor(clr_background);
  932.                                         G.fillRect(paintX0 + 18, paintY0 + 34 + redBar, 16, 2);
  933.                                         }
  934.                                 G.setColor(clr_green);
  935.                                 G.fillRect(paintX0 + 20, paintY0 + 36 + redBar, 14, greenBar);
  936.                                 }
  937.                                
  938.                         }
  939.                 }
  940.  
  941.         private Image getImage(String url)
  942.                 {
  943.                 try
  944.                         { return ImageIO.read(new URL(url)); }
  945.                 catch (IOException e)
  946.                         { return null; }
  947.                 }
  948.  
  949.        
  950.         /**
  951.          * Modified method that draws a tile or tiles with the passed color on the passed instance of <code>Graphics</code>.
  952.          *
  953.          * @param g The instance of <code>Graphics</code> you want to draw on.
  954.          * @param tile The instance of the tile you want to draw.
  955.          * @param color The color you want the drawn tile to be.
  956.          * @author Gnarly
  957.          * @author BarryScript
  958.          */
  959.         private void overlayTile(Graphics g, RSTile t, Color c, int thingOnTile)
  960.                 {
  961.                 RSTile t2 = new RSTile(t.getX() + 1, t.getY());
  962.                 RSTile t3 = new RSTile(t.getX(), t.getY() + 1);
  963.                 RSTile t4 = new RSTile(t.getX() + 1, t.getY() + 1);
  964.                
  965.                 Point p = calc.tileToScreen(t);
  966.                
  967.                 Point pn = calc.tileToScreen(t, 0, 0, 0);
  968.                 Point px = calc.tileToScreen(t2, 0, 0, 0);
  969.                 Point py = calc.tileToScreen(t3, 0, 0, 0);
  970.                 Point pxy = calc.tileToScreen(t4, 0, 0, 0);
  971.                
  972.                 Point[] points = { p, pn, px, py, pxy };
  973.                
  974.                 for (Point point : points)
  975.                         {
  976.                         if (!calc.pointOnScreen(point))
  977.                                 { return; }
  978.                         }
  979.        
  980.                 g.setColor(c);
  981.                 g.drawPolygon(new int[] { py.x, pxy.x, px.x, pn.x }, new int[] { py.y, pxy.y, px.y, pn.y }, 4);
  982.        
  983.                 // Paint labels
  984.                 overlayLabels(g, c, p, thingOnTile);
  985.                 }
  986.  
  987.         // TODO Paint outside borders only
  988.         private void overlayArea(Graphics g, RSArea a, Color c, int thingOnTile)
  989.                 {
  990.                 // Get most distant tiles, assume rectangular RSArea
  991.                 RSTile[][] allTiles = a.getTiles();
  992.                 int xLen = allTiles.length - 1;
  993.                 int yLen = allTiles[0].length;
  994.                 RSTile base = allTiles[0][0];
  995.                
  996.                 RSTile nw = new RSTile(base.getX(), base.getY() + yLen - 1);
  997.                 RSTile ne = new RSTile(base.getX() + xLen, base.getY() + yLen - 1);
  998.                 RSTile sw = new RSTile(base.getX(), base.getY());
  999.                 RSTile se = new RSTile(base.getX() + xLen, base.getY());
  1000.                
  1001.                 overlayTile(g, sw, c, 2);
  1002.                 overlayTile(g, se, c, 2);
  1003.                 overlayTile(g, nw, c, 2);
  1004.                 overlayTile(g, ne, c, 2);
  1005.                 }
  1006.  
  1007.         private void overlayLabels(Graphics g, Color c, Point p, int thingOnTile)
  1008.                 {
  1009.                 g.setFont(new Font("sansserif", Font.BOLD, 12));
  1010.                 g.setColor(new Color(0, 0, 0, 255));
  1011.                 if (thingOnTile == 1)
  1012.                         {
  1013.                         g.drawString("Player", p.x, p.y);
  1014.                         g.setColor(c);
  1015.                         g.drawString("Player", p.x, p.y);
  1016.                         }
  1017.                 else if (thingOnTile == 2)
  1018.                         {
  1019.                         g.drawString("Tree", p.x, p.y);
  1020.                         g.setColor(c);
  1021.                         g.drawString("Tree", p.x, p.y);
  1022.                         }
  1023.                 }
  1024.        
  1025.         /**
  1026.          * Draws mouse lines on the passed instance of <code>Graphics</code>.
  1027.          *
  1028.          * @param render The instance of <code>Graphics</code> you want to draw on.
  1029.          * @author Gnarly
  1030.          */
  1031.         private void drawMouseLines(Graphics render)
  1032.                 {
  1033.                 if (!mouse.isClientPresent())
  1034.                         { return; }
  1035.                
  1036.                 render.setColor(new Color(0, 0, 0, 128));
  1037.                 render.drawLine(0, (int) mouse.getClientLocation().getY(), game.getWidth(), (int) mouse.getClientLocation().getY());
  1038.                 render.drawLine((int) mouse.getClientLocation().getX(), 0, (int) mouse.getClientLocation().getX(), game.getHeight());
  1039.                
  1040.                 String texts[] =
  1041.                         {
  1042.                                 "mx: " + (int) mouse.getClientLocation().getX(),
  1043.                                 "my: " + (int) mouse.getClientLocation().getY()
  1044.                         };
  1045.                
  1046.                 int width = 0;
  1047.                
  1048.                 for (String text : texts)
  1049.                         {
  1050.                         int textWidth = render.getFontMetrics().stringWidth(text);
  1051.                         if (textWidth > width)
  1052.                                 { width = textWidth; }
  1053.                         }
  1054.                
  1055.                 width += 10;
  1056.                
  1057.                 int height = 2 + (texts.length * 15);
  1058.                
  1059.                 render.setColor(new Color(0, 0, 0, 100));
  1060.                 render.fillRect((int) mouse.getClientLocation().getX(), (int) mouse.getClientLocation().getY(), width, height);
  1061.                 render.setColor(Color.BLACK);
  1062.                 render.drawRect((int) mouse.getClientLocation().getX(), (int) mouse.getClientLocation().getY(), width, height);
  1063.                
  1064.                 render.setColor(Color.WHITE);
  1065.                
  1066.                 int fontY = (int) mouse.getClientLocation().getY() + 12;
  1067.                 for (String text : texts)
  1068.                         {
  1069.                         render.drawString(text, (int) mouse.getClientLocation().getX() + 5, fontY);
  1070.                         fontY += 15;
  1071.                         }
  1072.                 }
  1073.        
  1074.        
  1075.        
  1076.        
  1077.        
  1078.        
  1079.        
  1080.         class AntiBan extends Thread
  1081.                 {
  1082.                 // Parent
  1083.                 private bChop b;
  1084.  
  1085.                 // Is the antiban using the mouse?
  1086.                 private boolean canUseMouse = false;
  1087.                 protected boolean usingMouse = false;
  1088.                
  1089.                 // Tabs to use
  1090.                 private int[] tabs = {Game.TAB_STATS, Game.TAB_EQUIPMENT, Game.TAB_EQUIPMENT, Game.TAB_MAGIC, Game.TAB_FRIENDS};
  1091.  
  1092.                 // Readable state
  1093.                 private String[] basicStates = { "Idle", "Reset", "Move Mouse", "Move Camera", "Move Camera", "Open Tab", "Hover Stat", "Do Nothing", "Paused", "Off-Screen" };
  1094.                 private String[] detailedStates =
  1095.                         {
  1096.                         "Waiting for {DURATION} {SECONDS} before running anti-ban again", // 0
  1097.                         "Going back to the inventory", // 1
  1098.                         "Moving mouse slightly from {INT1}, {INT2}", // 2
  1099.                         "Moving camera slightly (angle {INT1} only)", // 3
  1100.                         "Moving camera slightly (angle {INT1} and pitch {INT2})", // 4
  1101.                         "Opening {TEXT1} tab for about {DURATION} {SECONDS}", // 5
  1102.                         "Hovering over the {TEXT1} stat for about {DURATION} {SECONDS}", // 6
  1103.                         "Deliberately doing nothing for about {DURATION} {SECONDS}", // 7
  1104.                         "Script has been paused; anti-ban will resume with script", // 8
  1105.                         "Moving mouse off screen until it's next needed" // 9
  1106.                         };
  1107.                 private String abState = "";
  1108.                
  1109.                 private int sleepFor;
  1110.                
  1111.                 public AntiBan(bChop parent)
  1112.                         {
  1113.                         this.b = parent;
  1114.                         }
  1115.  
  1116.                 // Main method
  1117.                 public void run()
  1118.                         {
  1119.                         abLog("Started AntiBan");
  1120.                         antibanStatus = ABState.IDLE;
  1121.                        
  1122.                         // Settings variables
  1123.                         int tabToOpen, duration;
  1124.  
  1125.                         try { while(b.isActive) {
  1126.                                 if(!b.isPaused)
  1127.                                         {
  1128.                                         antibanStatus = ABState.ACTIVE;
  1129.                                        
  1130.                                         // Determine if we have mouse control
  1131.                                         setHasMouse();
  1132.        
  1133.                                         int[] noMouse = { 1, 2, 3 };
  1134.                                         int allowedSnippets = (canUseMouse) ? 6 : noMouse.length;
  1135.                                         int rand = random(1, allowedSnippets);
  1136.                                        
  1137.                                         boolean needsMouse = true;
  1138.                                         for (int nmSnip : noMouse)
  1139.                                                 { if (nmSnip == rand) { needsMouse = false; } }
  1140.                                         usingMouse = needsMouse;       
  1141.                                        
  1142.                                         switch(rand)
  1143.                                                 {
  1144.                                                 // Deliberately do nothing
  1145.                                                         case 1:
  1146.                                                                 duration = random(750,3000);
  1147.                                                                 setReadableState(7, duration);
  1148.                                                                
  1149.                                                                 b.maybeMoveMouseSlightly();
  1150.                                                                 break;
  1151.                                                        
  1152.                                                 // Move the camera angle slightly -> RESET
  1153.                                                 case 2:
  1154.                                                         duration = random(200,400);
  1155.                                                         setReadableState(3, -1, b.camera.getAngle());
  1156.                                                        
  1157.                                                         b.maybeMoveMouseSlightly();
  1158.                                                         b.moveCameraSlightly();
  1159.                                                         break;
  1160.                                                
  1161.                                                 // Move the camera angle and pitch slightly -> RESET
  1162.                                                 case 3:
  1163.                                                         duration = random(200,400);
  1164.                                                         setReadableState(4, -1, b.camera.getAngle(), b.camera.getPitch());
  1165.  
  1166.                                                         b.maybeMoveMouseSlightly();
  1167.                                                         b.moveCameraSlightly(true);
  1168.                                                         break;
  1169.                                                
  1170.                                                 // Move the mouse slightly -> RESET
  1171.                                                 case 4:
  1172.                                                         duration = random(200,400);
  1173.                                                         setReadableState(2, -1, b.mouse.getClientLocation().x, b.mouse.getClientLocation().y);
  1174.                                                        
  1175.                                                         b.moveMouseSlightly();
  1176.                                                         break;
  1177.                                                
  1178.                                                 // Open a tab -> Wait for a few seconds -> RESET
  1179.                                                 case 5:
  1180.                                                         tabToOpen = random(0, tabs.length);
  1181.                                                         duration = random(1500,3000);
  1182.                                                         setReadableState(5, duration, Game.TAB_NAMES[tabs[tabToOpen]], tabs[tabToOpen]);
  1183.                                                        
  1184.                                                         b.maybeMoveMouseSlightly();
  1185.                                                         // Open a tab
  1186.                                                         b.game.openTab(tabs[tabToOpen]);
  1187.                                                         break;
  1188.                                                        
  1189.                                                 // Move mouse off screen -> Wait -> Bring back to screen
  1190.                                                 case 6:
  1191.                                                         duration = random(3500,5000);
  1192.                                                         setReadableState(9, duration);
  1193.                                                        
  1194.                                                         b.maybeMoveMouseSlightly();
  1195.                                                         // Send it off-screen
  1196.                                                         b.mouse.moveOffScreen();
  1197.                                                         break;
  1198.                                                        
  1199.                                                 default:
  1200.                                                         duration = random(100,200);
  1201.                                                         break;
  1202.                                                 }
  1203.                                        
  1204.                                         // Wait a little
  1205.                                         sleep(duration);
  1206.        
  1207.                                         // Go back to the inventory if needed
  1208.                                         if (b.game.getCurrentTab() != Game.TAB_INVENTORY)
  1209.                                                 { b.game.openTab(Game.TAB_INVENTORY); }
  1210.                                         while (b.game.getCurrentTab() != Game.TAB_INVENTORY)
  1211.                                                 { sleep(random(500,750)); }
  1212.                                         usingMouse = false;
  1213.                                        
  1214.                                         // Change state back to default after a little
  1215.                                         sleep(2000);
  1216.                                         setReadableState(1);
  1217.                                         antibanStatus = ABState.IDLE;
  1218.        
  1219.                                         // Sleep nicely
  1220.                                         sleepFor = random(8000,15000);
  1221.                                         while (sleepFor > 0)
  1222.                                                 {
  1223.                                                 if (sleepFor < 3000)
  1224.                                                         { antibanStatus = ABState.READY; }
  1225.                                                 setReadableState(0, (int) Math.ceil(sleepFor), null, -1, -1, -1);
  1226.                                                 if (sleepFor % 1000 == 0)
  1227.                                                         {
  1228.                                                         sleepFor -= 1000;
  1229.                                                         sleep(1000);
  1230.                                                         }
  1231.                                                 else
  1232.                                                         {
  1233.                                                         sleepFor -= sleepFor % 1000;
  1234.                                                         sleep(sleepFor % 1000);
  1235.                                                         }
  1236.                                                 }
  1237.                                         }
  1238.                                 // Coming out of sleep and finding it paused
  1239.                                 else
  1240.                                         { setReadableState(8); }
  1241.                         }
  1242.                        
  1243.                         }
  1244.                         catch(InterruptedException e)
  1245.                                 {
  1246.                                 antibanStatus = ABState.NOT_RUNNING;
  1247.                                 abLog(e.getMessage());
  1248.                                 }
  1249.                         }
  1250.  
  1251.                 private String getReadableState()
  1252.                         { return abState; }
  1253.  
  1254.                 public ABState getStatus()
  1255.                         { return antibanStatus; }
  1256.                
  1257.                 private void setHasMouse()
  1258.                         { canUseMouse = (getMyPlayer().getAnimation() == -1 && b.getState() != Status.CHOP_TREE && b.getState() != Status.WALK_TO_TREE) ? false : true; }
  1259.                
  1260.                 // Set readable state for paint to use
  1261.                 private void setReadableState(int stateID, int duration, String text1, int num1, int num2, int num3)
  1262.                         {
  1263.                         // Text replacement
  1264.                         String detail = detailedStates[stateID];
  1265.                         duration = Math.round(duration / 1000);
  1266.  
  1267.                         if (duration != -1 && detail.contains("{DURATION}"))
  1268.                                 { detail = detail.replace("{DURATION}", Integer.toString(duration)); }
  1269.                         if (text1 != null && detail.contains("{TEXT1}"))
  1270.                                 { detail = detail.replace("{TEXT1}", text1); }
  1271.                         if (num1 != -1 && detail.contains("{INT1}"))
  1272.                                 { detail = detail.replace("{INT1}", Integer.toString(num1)); }
  1273.                         if (num2 != -1 && detail.contains("{INT2}"))
  1274.                                 { detail = detail.replace("{INT2}", Integer.toString(num2)); }
  1275.                         if (num3 != -1 && detail.contains("{INT3}"))
  1276.                                 { detail = detail.replace("{INT3}", Integer.toString(num3)); }
  1277.                        
  1278.                         if (detail.contains("{TAB_TOTAL}"))
  1279.                                 { detail = detail.replace("{TAB_TOTAL}", Integer.toString(tabs.length)); }
  1280.                
  1281.                         if (detail.contains("{SECONDS}"))
  1282.                                 { detail = (duration == 1) ? detail.replace("{SECONDS}", "second") : detail.replace("{SECONDS}", "seconds"); }
  1283.                        
  1284.                         abState = basicStates[stateID] + " - " + detail;
  1285.                         }
  1286.  
  1287.                 private void setReadableState(int stateID)
  1288.                         { setReadableState(stateID, 0, null, -1, -1, -1); }
  1289.                
  1290.                 private void setReadableState(int stateID, int duration)
  1291.                         { setReadableState(stateID, duration, null, -1, -1, -1); }
  1292.  
  1293.                 private void setReadableState(int stateID, int duration, int num1)
  1294.                         { setReadableState(stateID, duration, null, num1, -1, -1); }
  1295.  
  1296.                 private void setReadableState(int stateID, int duration, int num1, int num2)
  1297.                         { setReadableState(stateID, duration, null, num1, num2, -1); }
  1298.                
  1299.                 private void setReadableState(int stateID, int duration, int num1, int num2, int num3)
  1300.                         { setReadableState(stateID, duration, null, num1, num2, num3); }
  1301.  
  1302.                 private void setReadableState(int stateID, int duration, String text1)
  1303.                         { setReadableState(stateID, duration, text1, -1, -1, -1); }
  1304.  
  1305.                 private void setReadableState(int stateID, int duration, String text1, int num1)
  1306.                         { setReadableState(stateID, duration, text1, num1, -1, -1); }
  1307.  
  1308.                 private void setReadableState(int stateID, int duration, String text1, int num1, int num2)
  1309.                         { setReadableState(stateID, duration, text1, num1, num2, -1); }
  1310.                
  1311.                 }
  1312.         }