Advertisement
Guest User

Untitled

a guest
Feb 12th, 2012
505
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 67.52 KB | None | 0 0
  1. import com.rarebot.event.listeners.PaintListener;
  2.  
  3. import com.rarebot.script.Script;
  4. import com.rarebot.script.ScriptManifest;
  5. import com.rarebot.script.methods.Equipment;
  6. import com.rarebot.script.methods.Game;
  7. import com.rarebot.script.util.Filter;
  8. import com.rarebot.script.wrappers.*;
  9.  
  10. import javax.swing.*;
  11. import javax.swing.border.EmptyBorder;
  12. import javax.swing.border.LineBorder;
  13. import javax.swing.border.TitledBorder;
  14. import javax.swing.table.DefaultTableModel;
  15. import java.awt.*;
  16. import java.awt.event.ActionEvent;
  17. import java.awt.event.ActionListener;
  18. import java.util.ArrayList;
  19. import java.util.LinkedList;
  20.  
  21.  
  22. import java.io.BufferedReader;
  23.  
  24. import java.io.IOException;
  25. import java.io.InputStreamReader;
  26. import java.lang.reflect.Method;
  27. import java.net.URL;
  28. import java.net.URLConnection;
  29.  
  30. import com.rarebot.script.wrappers.RSNPC;
  31. import com.rarebot.script.wrappers.RSObject;
  32. import com.rarebot.script.wrappers.RSTile;
  33.  
  34. @ScriptManifest(authors = {"Bool & Gravemindx"}, keywords = {"Minigames", "Combat"}, name = "BPestControl", version = 1.65, description = "Select options in the GUI.")
  35. public class BPestControl extends Script implements PaintListener {
  36.  
  37.     ScriptManifest sm = getClass().getAnnotation(ScriptManifest.class);
  38.     double version = sm.version();
  39.    
  40.  
  41.     class AnimationChecker implements Runnable {
  42.         public void run() {
  43.             while (isActive()) {
  44.                 if (getMyPlayer().getAnimation() != -1) {
  45.                     lastAniChange = System.currentTimeMillis();
  46.                 }
  47.                 try {
  48.                     Thread.sleep(500);
  49.                 } catch (Exception ignored) {
  50.                 }
  51.             }
  52.         }
  53.     }
  54.  
  55.    
  56.     private class Job {
  57.  
  58.         private final String n;
  59.         private boolean done = false;
  60.         public int points;
  61.        
  62.  
  63.         public Job(final String name, int points) {
  64.             n = name;
  65.             this.points = points;
  66.         }
  67.  
  68.         public final String getName() {
  69.             return n;
  70.         }
  71.  
  72.         public boolean isFinished() {
  73.             return done;
  74.         }
  75.  
  76.         public String toString() {
  77.             return "Name " + getName();
  78.         }
  79.     }
  80.  
  81.     private class Portal {
  82.  
  83.         private final RSTile Location;
  84.         private final String Name;
  85.         private final RSTile gateLoc;
  86.  
  87.         public Portal(final RSTile t, final String name, final RSTile g) {
  88.             Location = t;
  89.             Name = name;
  90.             gateLoc = g;
  91.         }
  92.  
  93.         public boolean equals(final Portal p) {
  94.             return p.getLocation().getX() == getLocation().getX()
  95.                     && p.getLocation().getY() == getLocation().getY();
  96.         }
  97.  
  98.         public RSArea getArea() {
  99.             RSArea a = null;
  100.             if (getName().equals("E")) {
  101.                 a = new RSArea(voidLoc.getX() + 24, voidLoc.getY() - 20, voidLoc.getX() + 27, voidLoc.getY() - 15);
  102.             } else if (getName().equals("W")) {
  103.                 a = new RSArea(voidLoc.getX() - 25, voidLoc.getY() - 15, voidLoc.getX() - 21, voidLoc.getY() - 12);
  104.             } else if (getName().contains("SE")) {
  105.                 a = new RSArea(voidLoc.getX() + 16, voidLoc.getY() - 34, voidLoc.getX() + 20, voidLoc.getY() - 31);
  106.             } else if (getName().contains("SW")) {
  107.                 a = new RSArea(voidLoc.getX() - 8, voidLoc.getY() - 35, voidLoc.getX() - 3, voidLoc.getY() - 32);
  108.             }
  109.             return a;
  110.         }
  111.  
  112.         public RSObject getGate() {
  113.             return objects.getTopAt(getGateLocation());
  114.         }
  115.  
  116.         public RSTile getGateLocation() {
  117.             return gateLoc;
  118.         }
  119.  
  120.         public RSTile getLocation() {
  121.             return Location;
  122.         }
  123.  
  124.         public String getName() {
  125.             return Name;
  126.         }
  127.  
  128.         public RSNPC getNPC() {
  129.             if (!attackPortals) {
  130.                 return null;
  131.             }
  132.             final RSNPC portal = npcs.getNearest("Portal");
  133.             if (portal != null) {
  134.                 if (portal.isInCombat()) {
  135.                     return portal;
  136.                 } else {
  137.                     return null;
  138.                 }
  139.             }
  140.             return null;
  141.         }
  142.  
  143.         public RSTile getRandom() {
  144.             final RSTile[][] tiles = getArea().getTiles();
  145.             final int y = random(0, tiles.length - 1);
  146.             final int x = random(0, tiles[y].length - 1);
  147.             try {
  148.                 return tiles[x][y];
  149.             } catch (final Exception e) {
  150.                 return getRandom();
  151.             }
  152.         }
  153.  
  154.         public RSArea getRealArea() {
  155.             RSArea a = null;
  156.             if (getName().equals("E")) {
  157.                 a = new RSArea(voidLoc.getX() + 16, voidLoc.getY() - 23, voidLoc.getX() + 30, voidLoc.getY() - 9);
  158.             } else if (getName().equals("W")) {
  159.                 a = new RSArea(voidLoc.getX() - 30, voidLoc.getY() - 24, voidLoc.getX() - 14, voidLoc.getY() - 5);
  160.             } else if (getName().contains("SE")) {
  161.                 a = new RSArea(voidLoc.getX(), voidLoc.getY() - 45, voidLoc.getX() + 28, voidLoc.getY() - 24);
  162.             } else if (getName().contains("SW")) {
  163.                 a = new RSArea(voidLoc.getX() - 17, voidLoc.getY() - 44, voidLoc.getX(), voidLoc.getY() - 24);
  164.             }
  165.             return a;
  166.         }
  167.  
  168.         public boolean isGateOpen() {
  169.             return getGate() == null || getGate().getID() > 14240;
  170.         }
  171.  
  172.         public boolean isOpen() {
  173.             try {
  174.                 if (getName().equals("W")) {
  175.                     if (Integer.parseInt(interfaces.getComponent(408, 13).getText()) < 10) {
  176.                         return false;
  177.                     }
  178.                 }
  179.                 if (getName().equals("E")) {
  180.                     if (Integer.parseInt(interfaces.getComponent(408, 14).getText()) < 10) {
  181.                         return false;
  182.                     }
  183.                 }
  184.                 if (getName().equals("SE")) {
  185.                     if (Integer.parseInt(interfaces.getComponent(408, 15).getText()) < 10) {
  186.                         return false;
  187.                     }
  188.                 }
  189.                 if (getName().equals("SW")) {
  190.                     if (Integer.parseInt(interfaces.getComponent(408, 16).getText()) < 10) {
  191.                         return false;
  192.                     }
  193.                 }
  194.             } catch (final Exception e) {
  195.                 return false;
  196.             }
  197.             return true;
  198.         }
  199.  
  200.         private void openGate() {
  201.             while (inPest() && !isGateOpen()) {
  202.                 if (getMyPlayer().isMoving()) {
  203.                     sleep(random(500, 600));
  204.                     continue;
  205.                 }
  206.                 final Point p = calc.tileToScreen(getGateLocation());
  207.                 if (!calc.pointOnScreen(p)) {
  208.                     walking.walkTileMM(getGateLocation());
  209.                     try {
  210.                         Thread.sleep(random(500, 700));
  211.                     } catch (InterruptedException ignored) {
  212.                     }
  213.                     continue;
  214.                 }
  215.                 moveMouse (p, 375, 165);
  216.                 mouse.clickSlightly();
  217.                 sleep (random (2500,3000));
  218.                 doAction(p, "Open");
  219.             }
  220.         }
  221.  
  222.         public void walkTo() {
  223.             final Portal p = getNearestPortal();
  224.             boolean died = false;
  225.             final RSNPC npc = npcs.getNearest(squire);
  226.             if (npc != null) {
  227.                 if (calc.distanceTo(npc) < 10) {
  228.                     died = true;
  229.                 }
  230.             }
  231.             boolean atDoor = false;
  232.             while (inPest() && calc.distanceTo(getLocation()) > 10 && isOpen()) {
  233.                 if (getMyPlayer().isInCombat()
  234.                         && getMyPlayer().getHPPercent() < 2
  235.                         && calc.distanceTo(npcs.getNearest(squire)) > 15) {
  236.                     return;
  237.                 }
  238.                 if (died) {
  239.                     try {
  240.                         enablePrayer();
  241.                         Thread.sleep(random(300, 800));
  242.                         walking.setRun(true);
  243.                         Thread.sleep(random(300, 800));
  244.                         doDragonBattleAxe();
  245.                         Thread.sleep(random(300, 800));
  246.                     } catch (Exception ignored) {
  247.                     }
  248.                     if (!atDoor) {
  249.                         walkPath(genPath(getGateLocation()));
  250.                         if (!isGateOpen() && calc.tileOnScreen(getGateLocation())) {
  251.                             openGate();
  252.                             if (isGateOpen()) {
  253.                                 atDoor = true;
  254.                             }
  255.                         }
  256.                         if (calc.distanceTo(getGateLocation()) < 10 && isGateOpen()) {
  257.                             atDoor = true;
  258.                         }
  259.                     }
  260.                     if (atDoor) {
  261.                         walkPath(genPath(getRandom()));
  262.                     }
  263.                 } else if (p.getName().equals("E") && getName().equals("W")) {
  264.                     while (inPest() && getNearestPortal().getName().equals("E")) {
  265.                         final Portal se = getPortalByName("SE");
  266.                         if (!walkPath(genPath(se.getRandom()))) {
  267.                             wait(400, 700);
  268.                         }
  269.                     }
  270.                     while (inPest()
  271.                             && getNearestPortal().getName().equals("SE")) {
  272.                         final Portal sw = getPortalByName("SW");
  273.                         if (!walkPath(genPath(sw.getRandom()))) {
  274.                             wait(400, 700);
  275.                         }
  276.                     }
  277.                 } else if (p.getName().equals("W") && getName().equals("E")) {
  278.                     while (inPest() && getNearestPortal().getName().equals("W")) {
  279.                         final Portal sw = getPortalByName("SW");
  280.                         if (!walkPath(genPath(sw.getRandom()))) {
  281.                             wait(400, 700);
  282.                         }
  283.                     }
  284.                     while (inPest()
  285.                             && getNearestPortal().getName().equals("SW")) {
  286.                         final Portal se = getPortalByName("SE");
  287.                         if (!walkPath(genPath(se.getRandom()))) {
  288.                             wait(400, 700);
  289.                         }
  290.                     }
  291.                     while (!walkPath(genPath(getRandom()))) {
  292.                         wait(400, 700);
  293.                     }
  294.                 } else if (p.getName().equals("E") && getName().equals("SE")) {
  295.                     if (!walkPath(genPath(getLocation()))) {
  296.                         wait(400, 700);
  297.                     }
  298.                 } else if (p.getName().equals("SE") && getName().equals("E")) {
  299.                     while (!walkPath(genPath(getLocation()))) {
  300.                         wait(400, 700);
  301.                     }
  302.                 } else if (p.getName().equals("E") && getName().equals("SW")) {
  303.                     while (inPest() && getNearestPortal().getName().equals("E")) {
  304.                         final Portal se = getPortalByName("SE");
  305.                         if (!walkPath(genPath(se.getRandom()))) {
  306.                             wait(400, 700);
  307.                         }
  308.                     }
  309.                     while (!walkPath(genPath(getRandom()))) {
  310.                         wait(400, 700);
  311.                     }
  312.                 } else if (p.getName().equals("SW") && getName().equals("E")) {
  313.                     while (inPest()
  314.                             && getNearestPortal().getName().equals("SW")) {
  315.                         final Portal se = getPortalByName("SE");
  316.                         if (!walkPath(genPath(se.getRandom()))) {
  317.                             wait(400, 700);
  318.                         }
  319.                     }
  320.                     while (!walkPath(genPath(getRandom()))) {
  321.                         wait(400, 700);
  322.                     }
  323.                 } else if (p.getName().equals("W") && getName().equals("SW")) {
  324.  
  325.                     if (!walkPath(genPath(getLocation()))) {
  326.                         wait(400, 700);
  327.                     }
  328.                 } else if (p.getName().equals("SW") && getName().equals("W")) {
  329.  
  330.                     if (!walkPath(genPath(getLocation()))) {
  331.                         wait(400, 700);
  332.                     }
  333.                 } else if (p.getName().equals("SE") && getName().equals("W")) {
  334.                     while (inPest()
  335.                             && getNearestPortal().getName().equals("SE")) {
  336.                         final Portal se = getPortalByName("SW");
  337.                         if (!walkPath(genPath(se.getRandom()))) {
  338.                             wait(400, 700);
  339.                         }
  340.                     }
  341.                     while (!walkPath(genPath(getRandom()))) {
  342.                         wait(400, 700);
  343.                     }
  344.                 } else if (p.getName().equals("W") && getName().equals("SE")) {
  345.  
  346.                     while (inPest() && getNearestPortal().getName().equals("W")) {
  347.                         final Portal se = getPortalByName("SW");
  348.                         if (!walkPath(genPath(se.getRandom()))) {
  349.                             wait(400, 700);
  350.                         }
  351.                     }
  352.                     while (!walkPath(genPath(getRandom()))) {
  353.                         wait(400, 700);
  354.                     }
  355.                 } else if (p.getName().equals("SW") && getName().equals("SE")) {
  356.  
  357.                     if (!walkPath(genPath(getLocation()))) {
  358.                         wait(400, 700);
  359.                     }
  360.                 } else if (p.getName().equals("SE") && getName().equals("SW")) {
  361.                     if (!walkPath(genPath(getLocation()))) {
  362.                         wait(400, 700);
  363.                     }
  364.                 }
  365.             }
  366.         }
  367.  
  368.         public void wait(int min, int max) {
  369.             try {
  370.                 Thread.sleep(random(min, max));
  371.             } catch (Exception ignored) {
  372.             }
  373.         }
  374.     }
  375.  
  376.     //private static final int INTERFACE_250_PTS = 213;
  377.    
  378.  
  379.  
  380.     private final LinkedList<Job> jobQ = new LinkedList<Job>();
  381.     private final LinkedList<Portal> portalQ = new LinkedList<Portal>();
  382.     private final LinkedList<Break> breakQ = new LinkedList<Break>();
  383.     private final ArrayList<String> antibanQ = new ArrayList<String>();
  384.  
  385.     private Portal current;
  386.     private boolean start = false;
  387.  
  388.  
  389.     private boolean attackPortals = false;
  390.  
  391.     private boolean usePray = false;
  392.     private boolean played = false;
  393.     private boolean got250 = false;
  394.     private boolean attackSpinner = false;
  395.     private boolean DBaxe = false;
  396.     private boolean pickupArrows = false;
  397.     private RSTile[] path;
  398.     private int plankID = 14315;
  399.     private final int squire = 3781;
  400.     private int Squire;
  401.     private int failsafe = 0;
  402.     private int points = 0;
  403.     //private int points = 0;
  404.     private int specialPercent = 0;
  405.     private int spendwhenpoints = 0;
  406.     private int arrowID = 0;
  407.     private int oldPoints = 0;
  408.     private int gainedPoints = 0;
  409.     private int AttState = 0;
  410.     private int VarAttState = 0;
  411.    
  412.     private int lost = 0;
  413.     private int won = 0;
  414.     private RSArea boatArea = null;
  415.     private RSArea BuyArea = null;
  416.     private RSTile voidLoc = null;
  417.     private RSTile standingTile = null;
  418.     private RSTile standingTile2 = null;
  419.  
  420.     private long lastAniChange = 0;
  421.  
  422.     private long startTime = 0;
  423.    
  424.    
  425.  
  426.     private long gc = 0;
  427.     public final int ROTATE_COMPASS = 0;
  428.     public final int MOVE_MOUSE = 1;
  429.     public final int MOVE_MOUSE_AND_ROTATE_COMPASS = 2;
  430.     public final int RIGHT_CLICK_OBJECT = 3;
  431.     public final int RIGHT_CLICK_NPC = 4;
  432.     public final int RIGHT_CLICK_PLAYER = 5;
  433.     private final String[] jobsStrings = new String[]{"Attack", "Defence",
  434.             "Magic", "Prayer", "Strength", "Ranged", "Hitpoints",
  435.             "melee helm", "ranger helm", "mage helm", "top", "robes",
  436.             "gloves", "mace", "deflector", //"seal"
  437.             };
  438.             //"Robe", "Range Helm", "Melee Helm", "Mage Helm", "Glove"};
  439.     private final int[] jobsPoints = new int[]{100, 100, 100, 100, 100, 100,
  440.             100, 250, 250, 200, 200, 200, 150};
  441.     private int width = 0;
  442.  
  443.     private int height = 0;
  444.  
  445.     private Break curBreak;
  446.    
  447.     Pathfinder pf;
  448.  
  449.     Runnable antiban = new Runnable() {
  450.         public void run() {
  451.             while (isActive()) {
  452.                 try {
  453.                     if (!game.isLoggedIn()) {
  454.                         Thread.sleep(300, 400);
  455.                         continue;
  456.                     }
  457.                     int i = random(0, 150);
  458.                     if (i == 4 || i == 9)
  459.                         performAntiban(antibanQ.get(random(0, antibanQ.size())));
  460.                     Thread.sleep(random(100, 2000));
  461.                 } catch (InterruptedException ignored) {
  462.                 }
  463.             }
  464.         }
  465.     };
  466.    
  467.    
  468.    
  469.     public void performAntiban(String antiban) throws InterruptedException {
  470.         log("Doing : " + antiban.toLowerCase().replace('_', ' '));
  471.         int ab = AntibanStringToInteger(antiban);
  472.         switch (ab) {
  473.             case ROTATE_COMPASS:
  474.                 char dir = 37;
  475.                 if (random(0, 3) == 2)
  476.                     dir = 39;
  477.                 keyboard.pressKey(dir);
  478.                 Thread.sleep(random(500, 2000));
  479.                 keyboard.releaseKey(dir);
  480.                 break;
  481.             case MOVE_MOUSE:
  482.                 mouse.move(random(0, game.getWidth()), random(0,
  483.                         game.getHeight()));
  484.                 break;
  485.             case MOVE_MOUSE_AND_ROTATE_COMPASS:
  486.                 Thread camera = new Thread() {
  487.                     @Override
  488.                     public void run() {
  489.                         char dir = 37;
  490.                         if (random(0, 3) == 2)
  491.                             dir = 39;
  492.                         keyboard.pressKey(dir);
  493.                         try {
  494.                             Thread.sleep(random(500, 2000));
  495.                         } catch (InterruptedException e) {
  496.                             e.printStackTrace();
  497.                         }
  498.                         keyboard.releaseKey(dir);
  499.                     }
  500.                 };
  501.  
  502.                 Thread mouseThread = new Thread() {
  503.                     @Override
  504.                     public void run() {
  505.                         mouse.move(random(0, game.getWidth()), random(
  506.                                 0, game.getHeight()));
  507.                     }
  508.                 };
  509.                 camera.start();
  510.                 mouseThread.start();
  511.                 while (camera.isAlive() || mouseThread.isAlive())
  512.                     Thread.sleep(random(100, 300));
  513.                 break;
  514.             case RIGHT_CLICK_OBJECT:
  515.                 RSObject obj = getObjOnScreen();
  516.                 if (obj != null) {
  517.                     mouse.click(calc.tileToScreen(obj.getLocation()), false);
  518.                     Thread.sleep(random(500, 2000));
  519.                     while (menu.isOpen()) {
  520.                         mouse.moveRandomly(20);
  521.                     }
  522.                 }
  523.                 break;
  524.             case RIGHT_CLICK_NPC:
  525.                 RSNPC npc = getNPCOnScreen();
  526.                 if (npc != null) {
  527.                     mouse.click(npc.getScreenLocation(), false);
  528.                     Thread.sleep(random(500, 2000));
  529.                     while (menu.isOpen()) {
  530.                         mouse.moveRandomly(20);
  531.                     }
  532.                 }
  533.                 break;
  534.             case RIGHT_CLICK_PLAYER:
  535.                 RSPlayer player = getPlayerOnScreen();
  536.                 if (player != null) {
  537.                     mouse.click(player.getScreenLocation(), false);
  538.                     Thread.sleep(random(500, 2000));
  539.                     while (menu.isOpen()) {
  540.                         mouse.moveRandomly(20);
  541.                     }
  542.                 }
  543.                 break;
  544.             default:
  545.                 break;
  546.         }
  547.     }
  548.  
  549.     public RSObject getObjOnScreen() {
  550.         ArrayList<RSObject> result = new ArrayList<RSObject>();
  551.         for (int x = 0; x < 104; x++) {
  552.             for (int y = 0; y < 104; y++) {
  553.                 RSObject obj = objects.getTopAt(
  554.                         new RSTile(x + game.getBaseX(), y + game.getBaseY()));
  555.                 if (obj != null) {
  556.                     Point p = calc.tileToScreen(obj.getLocation());
  557.                     if (p.x != -1)
  558.                         result.add(obj);
  559.                 }
  560.             }
  561.         }
  562.         if (result.size() == 0)
  563.             return null;
  564.         return result.get(random(0, result.size()));
  565.     }
  566.  
  567.     public RSNPC getNPCOnScreen() {
  568.         RSNPC[] screen = npcs.getAll(new Filter<RSNPC>() {
  569.             public boolean accept(RSNPC npc) {
  570.                 return npc.isOnScreen();
  571.             }
  572.         });
  573.         if (screen.length > 0) {
  574.             return screen[random(0, screen.length)];
  575.         }
  576.         return null;
  577.     }
  578.  
  579.     public int AntibanStringToInteger(String a) {
  580.         if (a.contains("rotate compass"))
  581.             return ROTATE_COMPASS;
  582.         else if (a.contains("move mouse"))
  583.             return MOVE_MOUSE;
  584.         else if (a.contains("MOVE_MOUSE_AND_ROTATE_COMPASS"
  585.                 .replaceAll("_", " ").toLowerCase()))
  586.             return MOVE_MOUSE_AND_ROTATE_COMPASS;
  587.         else if (a.contains("RIGHT_CLICK_OBJECT".replaceAll("_", " ")
  588.                 .toLowerCase()))
  589.             return RIGHT_CLICK_OBJECT;
  590.         else if (a.contains("RIGHT_CLICK_NPC".replaceAll("_", " ")
  591.                 .toLowerCase()))
  592.             return RIGHT_CLICK_NPC;
  593.         else if (a.contains("RIGHT_CLICK_PLAYER".replaceAll("_", " ")
  594.                 .toLowerCase()))
  595.             return RIGHT_CLICK_PLAYER;
  596.         return -1;
  597.     }
  598.  
  599.     boolean atPortal() {
  600.         for (final Portal p : portalQ) {
  601.             if (p.getRealArea().contains(getMyPlayer().getLocation())) {
  602.                 return true;
  603.             }
  604.         }
  605.         return false;
  606.     }
  607.  
  608.     public Break getCurrentBreak() {
  609.         if ((curBreak == null || curBreak.isDone) && breakQ.size() == 0)
  610.             return null;
  611.         if (curBreak == null || curBreak.isDone)
  612.             curBreak = breakQ.remove();
  613.         if (curBreak.Time == null)
  614.             curBreak.init();
  615.         return curBreak;
  616.     }
  617.  
  618.    
  619.    
  620.  
  621.  
  622.  
  623.    
  624.     boolean clickNPC(final RSNPC n, final String action) {
  625.         if (!calc.tileOnScreen(n.getLocation())) {
  626.             while (inPest() && atPortal()
  627.                     && !walkPath(genPath(n.getLocation()))) {
  628.                 sleep(random(200, 500));
  629.             }
  630.         }
  631.         try {
  632.             Point p;
  633.             while ((p = n.getScreenLocation()) != null && p.x != -1
  634.                     && mouse.getLocation().distance(n.getScreenLocation()) > 8) {
  635.                 moveMouse ( p , 1 , 1);
  636.             }
  637.             if (!calc.pointOnScreen(mouse.getLocation())) {
  638.                 return false;
  639.             }
  640.  
  641.             if (getTopText().contains(action)) {
  642.                 mouse.click(true);
  643.             } else if (menu.contains(action)) {
  644.                 mouse.click(false);
  645.                 return menu.doAction(action);
  646.             } else {
  647.                 return false;
  648.             }
  649.         } catch (final Exception ignored) {
  650.         }
  651.         return true;
  652.     }
  653.  
  654.     boolean doAction(final Point p, final String action) {
  655.         if (p.x == -1 || p.y == -1) {
  656.             return false;
  657.         }
  658.         while (p.x != -1 && mouse.getLocation().distance(p) > 8) {
  659.            
  660.             mouse.move(p);
  661.         }
  662.         if (!calc.pointOnScreen(mouse.getLocation())) {
  663.             return false;
  664.         }
  665.         if (getTopText().contains(action)) {
  666.             mouse.click(true);
  667.         } else if (menu.contains(action)) {
  668.             mouse.click(false);
  669.             return menu.doAction(action);
  670.         } else {
  671.             return false;
  672.         }
  673.         return true;
  674.     }
  675.  
  676.    
  677.  
  678.     public boolean tileOnMap(RSTile tile) {
  679.         Point center = calc.tileToMinimap(getMyPlayer().getLocation());
  680.         return calc.tileToMinimap(tile).distance(center) <= 70;
  681.     }
  682.  
  683.     void enablePrayer() {
  684.         if (!PrayerEnabled() && usePray) {
  685.             mouse.click(random(715, 752), random(60, 80), true);
  686.         }
  687.     }
  688.  
  689.     int enterBoat() {
  690.         portalQ.clear();
  691.         final RSObject o = objects.getNearest(plankID);
  692.         if (o != null && !onBoat()) {
  693.             //camera.setAngle(random(1, 360));
  694.             camera.turnTo(o);
  695.             if (interfaces.get(242).isValid() ) {
  696.                 lost++;
  697.                 interfaces.get(242).getComponent(6).doClick();
  698.             }
  699.             if (interfaces.get(243).isValid() ) {
  700.                 won++;
  701.                 interfaces.get(243).getComponent(7).doClick();
  702.             }
  703.             o.doAction("Cross");
  704.             sleep(random(1500,2000));
  705.         }
  706.         return random(600, 800);
  707.     }
  708.  
  709.     void fillPortalList() {
  710.         if (portalQ.size() < 1) {
  711.             portalQ.add(new Portal(new RSTile(voidLoc.getX() - 26, voidLoc
  712.                     .getY() - 15), "W", new RSTile(voidLoc.getX() - 12, voidLoc
  713.                     .getY() - 15)));
  714.             portalQ.add(new Portal(new RSTile(voidLoc.getX() + 26, voidLoc
  715.                     .getY() - 18), "E", new RSTile(voidLoc.getX() + 15, voidLoc
  716.                     .getY() - 15)));
  717.             portalQ.add(new Portal(new RSTile(voidLoc.getX() + 15, voidLoc
  718.                     .getY() - 36), "SE", new RSTile(voidLoc.getX() + 1, voidLoc
  719.                     .getY() - 22)));
  720.             portalQ.add(new Portal(new RSTile(voidLoc.getX() - 9, voidLoc
  721.                     .getY() - 37), "SW", new RSTile(voidLoc.getX() + 1, voidLoc
  722.                     .getY() - 22)));
  723.         } else {
  724.             portalQ.clear();
  725.             fillPortalList();
  726.         }
  727.     }
  728.  
  729.     RSTile[] genPath(final RSTile t) {
  730.         RSTile[] temp = pf.findPath(t);
  731.         if (temp != null)
  732.             return temp;
  733.         RSTile current = getMyPlayer().getLocation();
  734.         final ArrayList<RSTile> tiles = new ArrayList<RSTile>();
  735.         final ArrayList<RSTile> path = new ArrayList<RSTile>();
  736.  
  737.         while (calc.distanceBetween(t, current) > 2) {
  738.             final int x = current.getX();
  739.             final int y = current.getY();
  740.             tiles.add(new RSTile(x, y - 1));
  741.             tiles.add(new RSTile(x - 1, y));
  742.             tiles.add(new RSTile(x + 1, y));
  743.             tiles.add(new RSTile(x, y + 1));
  744.             tiles.add(new RSTile(x - 1, y - 1));
  745.             tiles.add(new RSTile(x + 1, y - 1));
  746.             tiles.add(new RSTile(x + 1, y + 1));
  747.             tiles.add(new RSTile(x - 1, y + 1));
  748.             final RSTile tile = getNearest(tiles, t);
  749.             path.add(tile);
  750.             this.path = path.toArray(new RSTile[path.size()]);
  751.             current = tile;
  752.             tiles.clear();
  753.         }
  754.         this.path = path.toArray(new RSTile[path.size()]);
  755.         return this.path;
  756.     }
  757.  
  758.     Portal getCurrentPortal() {
  759.         return current;
  760.     }
  761.  
  762.     Job getJob() {
  763.         if (jobQ.size() == 0)
  764.             return null;
  765.         return jobQ.getFirst();
  766.     }
  767.  
  768.     RSTile getNearest(final ArrayList<RSTile> tiles, final RSTile t) {
  769.         RSTile nearest = tiles.get(0);
  770.         for (RSTile tile : tiles) {
  771.             if (calc.distanceBetween(tile, t) < calc.distanceBetween(
  772.                     nearest, t)) {
  773.                 nearest = tile;
  774.             }
  775.         }
  776.         return nearest;
  777.     }
  778.  
  779.     Portal getNearestOpenPortal() {
  780.         if (portalQ.size() < 1) {
  781.             return null;
  782.         }
  783.         Portal winner = null;
  784.         for (final Portal p : portalQ) {
  785.             if (p.isOpen()) {
  786.                 winner = p;
  787.             }
  788.         }
  789.         if (winner == null) {
  790.             return null;
  791.         }
  792.  
  793.         for (final Portal p : portalQ) {
  794.             if (!p.isOpen()) {
  795.                 continue;
  796.             }
  797.             if (calc.distanceTo(p.getLocation()) < calc.distanceTo(winner.getLocation())) {
  798.                 winner = p;
  799.             }
  800.         }
  801.         current = winner;
  802.         return winner;
  803.     }
  804.  
  805.     Portal getNearestPortal() {
  806.         if (portalQ.size() < 1) {
  807.             return null;
  808.         }
  809.         Portal winner = portalQ.get(0);
  810.         for (final Portal p : portalQ) {
  811.             if (calc.distanceTo(p.getLocation()) < calc.distanceTo(winner.getLocation())) {
  812.                 winner = p;
  813.             }
  814.         }
  815.         return winner;
  816.     }
  817.  
  818.     RSTile getNext(final RSTile[] path) {
  819.         RSTile nearest = path[0];
  820.         for (final RSTile element : path) {
  821.             if (calc.distanceBetween(element, path[path.length - 1]) < calc
  822.                     .distanceBetween(nearest, path[path.length - 1])) {
  823.                 if (tileOnMap(element)) {
  824.                     nearest = element;
  825.                 }
  826.             }
  827.         }
  828.         return nearest;
  829.     }
  830.  
  831.     RSPlayer getPlayerOnScreen() {
  832.         RSPlayer[] screen = players.getAll(new Filter<RSPlayer>() {
  833.             public boolean accept(RSPlayer p) {
  834.                 return p.isOnScreen();
  835.             }
  836.         });
  837.         if (screen.length > 0) {
  838.             return screen[random(0, screen.length)];
  839.         }
  840.         return null;
  841.     }
  842.  
  843.     Portal getPortalByName(final String name) {
  844.         if (portalQ.size() < 1) {
  845.             return null;
  846.         }
  847.         for (final Portal p : portalQ) {
  848.             if (p.getName().equalsIgnoreCase(name)) {
  849.                 return p;
  850.             }
  851.         }
  852.         return null;
  853.     }
  854.  
  855.     Portal getRandomOpenPortal() {
  856.         if (portalQ.size() < 1) {
  857.             return null;
  858.         }
  859.         final ArrayList<Portal> po = new ArrayList<Portal>();
  860.         for (final Portal p : portalQ) {
  861.             if (p.isOpen()) {
  862.                 po.add(p);
  863.             }
  864.         }
  865.         current = po.get(random(0, po.size()));
  866.         return current;
  867.     }
  868.  
  869.     String getTopText() {
  870.         try {
  871.             final long start = System.currentTimeMillis();
  872.             String[] menuItems = menu.getItems();
  873.             if (menuItems.length == 0) {
  874.                 return "Cancel";
  875.             }
  876.             while (menuItems[0].contains("Cancel")
  877.                     && calc.pointOnScreen(mouse.getLocation())
  878.                     && System.currentTimeMillis() - start < 700) {
  879.                 menuItems = menu.getItems();
  880.             }
  881.             return menuItems[0];
  882.         } catch (Exception e) {
  883.             return getTopText();
  884.         }
  885.     }
  886.  
  887.     boolean inPest() {
  888.         return npcs.getNearest(Squire) == null;
  889.     }
  890.    
  891.     public void exchange() {
  892.         if (getJob().getName().equals("Attack")) {
  893.             sleep (random(6000,8000));
  894.             sleep(random(5000, 6500));
  895.             log ("we're gonna click on 100x");
  896.             interfaces.get(1011).getComponent(87).doClick();
  897.             sleep(random(4000, 5000));
  898.             log ("we clicked 100x, now confirm");
  899.             sleep(random(5000, 6500));
  900.             interfaces.get(1011).getComponent(382).doClick();
  901.             log ("we confirmed");
  902.             oldPoints = 0;
  903.             played = false;
  904.             points = 0;
  905.             got250 = false;
  906.             interfaces.get(1011).getComponent(51).doClick();
  907.             sleep (2000, 3500);
  908.             walkPath(genPath(new RSTile (2657, 2639)), 2);
  909.         }
  910.         if (getJob().getName().equals("Defence")) {
  911.             sleep (random(6000,8000));
  912.             sleep(random(5000, 6500));
  913.             log ("we're gonna click on 100x");
  914.             interfaces.get(1011).getComponent(119).doClick();
  915.             sleep(random(4000, 5000));
  916.             log ("we clicked 100x, now confirm");
  917.             sleep(random(5000, 6500));
  918.             interfaces.get(1011).getComponent(382).doClick();
  919.             log ("we confirmed");
  920.             oldPoints = 0;
  921.             played = false;
  922.             points = 0;
  923.             got250 = false;
  924.             interfaces.get(1011).getComponent(51).doClick();
  925.             sleep (2000, 3500);
  926.             walkPath(genPath(new RSTile (2657, 2639)), 2);
  927.        
  928.         }
  929.         if (getJob().getName().equals("Magic")) {
  930.             sleep (random(6000,8000));
  931.             sleep(random(5000, 6500));
  932.             log ("we're gonna click on 100x");
  933.             interfaces.get(1011).getComponent(167).doClick();
  934.             sleep(random(4000, 5000));
  935.             log ("we clicked 100x, now confirm");
  936.             sleep(random(5000, 6500));
  937.             interfaces.get(1011).getComponent(382).doClick();
  938.             log ("we confirmed");
  939.             oldPoints = 0;
  940.             played = false;
  941.             points = 0;
  942.             got250 = false;
  943.             interfaces.get(1011).getComponent(51).doClick();
  944.             sleep (2000, 3500);
  945.              walkPath(genPath(new RSTile (2657, 2639)), 2);
  946.         }
  947.         if (getJob().getName().equals("Prayer")) {
  948.             sleep (random(6000,8000));
  949.             sleep(random(5000, 6500));
  950.             log ("we're gonna click on 100x");
  951.             interfaces.get(1011).getComponent(183).doClick();
  952.             sleep(random(4000, 5000));
  953.             log ("we clicked 100x, now confirm");
  954.             sleep(random(5000, 6500));
  955.             interfaces.get(1011).getComponent(382).doClick();
  956.             log ("we confirmed");
  957.             oldPoints = 0;
  958.             played = false;
  959.             points = 0;
  960.             got250 = false;
  961.             interfaces.get(1011).getComponent(51).doClick();
  962.             sleep (2000, 3500);
  963.             walkPath(genPath(new RSTile (2657, 2639)), 2);
  964.         }
  965.        
  966.         if (getJob().getName().equals("Strength")) {
  967.                 sleep (random(6000,8000));
  968.                 sleep(random(5000, 6500));
  969.                 log ("we're gonna click on 100x");
  970.                 interfaces.get(1011).getComponent(103).doClick();
  971.                 sleep(random(4000, 5000));
  972.                 log ("we clicked 100x, now confirm");
  973.                 sleep(random(5000, 6500));
  974.                 interfaces.get(1011).getComponent(382).doClick();
  975.                 log ("we confirmed");
  976.                 oldPoints = 0;
  977.                 played = false;
  978.                 points = 0;
  979.                 got250 = false;
  980.                 interfaces.get(1011).getComponent(51).doClick();
  981.                 sleep (2000, 3500);
  982.                 walkPath(genPath(new RSTile (2657, 2639)), 2);
  983.                
  984.         }
  985.            
  986.         if (getJob().getName().equals("Ranged")) {
  987.             sleep (random(6000,8000));
  988.             sleep(random(5000, 6500));
  989.             log ("we're gonna click on 100x");
  990.             interfaces.get(1011).getComponent(151).doClick();
  991.             sleep(random(4000, 5000));
  992.             log ("we clicked 100x, now confirm");
  993.             sleep(random(5000, 6500));
  994.             interfaces.get(1011).getComponent(382).doClick();
  995.             log ("we confirmed");
  996.             oldPoints = 0;
  997.             played = false;
  998.             points = 0;
  999.             got250 = false;
  1000.             interfaces.get(1011).getComponent(51).doClick();
  1001.             sleep (2000, 3500);
  1002.             walkPath(genPath(new RSTile (2657, 2639)), 2);
  1003.            
  1004.         }
  1005.         if (getJob().getName().equals("Hitpoints")) {
  1006.             sleep (random(6000,8000));
  1007.             sleep(random(5000, 6500));
  1008.             log ("we're gonna click on 100x");
  1009.             interfaces.get(1011).getComponent(135).doClick();
  1010.             sleep(random(4000, 5000));
  1011.             log ("we clicked 100x, now confirm");
  1012.             sleep(random(5000, 6500));
  1013.             interfaces.get(1011).getComponent(382).doClick();
  1014.             log ("we confirmed");
  1015.             oldPoints = 0;
  1016.             played = false;
  1017.             points = 0;
  1018.             got250 = false;
  1019.             interfaces.get(1011).getComponent(51).doClick();
  1020.             sleep (2000, 3500);
  1021.             walkPath(genPath(new RSTile (2657, 2639)), 2);
  1022.            
  1023.         }
  1024.        
  1025.         //the void armor
  1026.        
  1027.        
  1028.        
  1029.        
  1030.        
  1031.         //if (getJob().getName().equals("seal")) {
  1032.             //sleep (random(6000,8000));
  1033.             //sleep(random(5000, 6500));
  1034.         //  log ("we're gonna the tab");
  1035.             ///interfaces.get(1011).getComponent(28).doClick();
  1036.          //   sleep(random(4000, 5000));
  1037.            // log ("we clicked the tab, now click exchange..");
  1038.          //   sleep(random(3500,4600));
  1039.           //  interfaces.get(1011).getComponent(279).doClick();
  1040.           //  log ("we clicked exchange, now confirm");
  1041.           //  sleep(random(5000, 6500));
  1042.           //  interfaces.get(1011).getComponent(382).doClick();
  1043.           //  log ("we confirmed");
  1044.           //  walkPath(genPath(new RSTile (2657, 2639)), 2);
  1045.         //}
  1046.         if (getJob().getName().equals("deflector")) {
  1047.             sleep (random(6000,8000));
  1048.             sleep(random(5000, 6500));
  1049.             log ("we're gonna the tab");
  1050.             interfaces.get(1011).getComponent(28).doClick();
  1051.             sleep(random(4000, 5000));
  1052.             log ("we clicked the tab, now click exchange..");
  1053.             sleep(random(3500,4600));
  1054.             interfaces.get(1011).getComponent(266).doClick();
  1055.             log ("we clicked exchange, now confirm");
  1056.             sleep(random(5000, 6500));
  1057.             interfaces.get(1011).getComponent(382).doClick();
  1058.             log ("we confirmed");
  1059.             oldPoints = 0;
  1060.             played = false;
  1061.             points = 0;
  1062.             got250 = false;
  1063.             interfaces.get(1011).getComponent(51).doClick();
  1064.             sleep (2000, 3500);
  1065.             walkPath(genPath(new RSTile (2657, 2639)), 2);
  1066.  
  1067.             jobQ.remove();
  1068.         }      
  1069.         if (getJob().getName().equals("mace")) {
  1070.             sleep (random(6000,8000));
  1071.             sleep(random(5000, 6500));
  1072.             log ("we're gonna the tab");
  1073.             interfaces.get(1011).getComponent(28).doClick();
  1074.             sleep(random(4000, 5000));
  1075.             log ("we clicked the tab, now click exchange..");
  1076.             sleep(random(3500,4600));
  1077.             interfaces.get(1011).getComponent(254).doClick();
  1078.             log ("we clicked exchange, now confirm");
  1079.             sleep(random(5000, 6500));
  1080.             interfaces.get(1011).getComponent(382).doClick();
  1081.             log ("we confirmed");
  1082.             oldPoints = 0;
  1083.             played = false;
  1084.             points = 0;
  1085.             got250 = false;
  1086.             interfaces.get(1011).getComponent(51).doClick();
  1087.             sleep (2000, 3500);
  1088.             walkPath(genPath(new RSTile (2657, 2639)), 2);
  1089.            
  1090.             jobQ.remove();
  1091.         }
  1092.         if (getJob().getName().equals("gloves")) {
  1093.             sleep (random(6000,8000));
  1094.             sleep(random(5000, 6500));
  1095.             log ("we're gonna the tab");
  1096.             interfaces.get(1011).getComponent(28).doClick();
  1097.             sleep(random(4000, 5000));
  1098.             log ("we clicked the tab, now click exchange..");
  1099.             sleep(random(3500,4600));
  1100.             interfaces.get(1011).getComponent(243).doClick();
  1101.             log ("we clicked exchange, now confirm");
  1102.             sleep(random(5000, 6500));
  1103.             interfaces.get(1011).getComponent(382).doClick();
  1104.             log ("we confirmed");
  1105.             oldPoints = 0;
  1106.             played = false;
  1107.             points = 0;
  1108.             got250 = false;
  1109.             interfaces.get(1011).getComponent(51).doClick();
  1110.             sleep (2000, 3500);
  1111.             walkPath(genPath(new RSTile (2657, 2639)), 2);
  1112.            
  1113.             jobQ.remove();
  1114.         }
  1115.  
  1116.         if (getJob().getName().equals("robes")) {
  1117.             sleep (random(6000,8000));
  1118.             sleep(random(5000, 6500));
  1119.             log ("we're gonna the tab");
  1120.             interfaces.get(1011).getComponent(28).doClick();
  1121.             sleep(random(4000, 5000));
  1122.             log ("we clicked the tab, now click exchange..");
  1123.             sleep(random(3500,4600));
  1124.             interfaces.get(1011).getComponent(231).doClick();
  1125.             log ("we clicked exchange, now confirm");
  1126.             sleep(random(5000, 6500));
  1127.             interfaces.get(1011).getComponent(382).doClick();
  1128.             log ("we confirmed");
  1129.             oldPoints = 0;
  1130.             played = false;
  1131.             points = 0;
  1132.             got250 = false;
  1133.             interfaces.get(1011).getComponent(51).doClick();
  1134.             sleep (2000, 3500);
  1135.             walkPath(genPath(new RSTile (2657, 2639)), 2);
  1136.            
  1137.             jobQ.remove();
  1138.         }
  1139.         if (getJob().getName().equals("top")) {
  1140.             sleep (random(6000,8000));
  1141.             sleep(random(5000, 6500));
  1142.             log ("we're gonna the tab");
  1143.             interfaces.get(1011).getComponent(28).doClick();
  1144.             sleep(random(4000, 5000));
  1145.             log ("we clicked the tab, now click exchange..");
  1146.             sleep(random(3500,4600));
  1147.             interfaces.get(1011).getComponent(219).doClick();
  1148.             log ("we clicked exchange, now confirm");
  1149.             sleep(random(5000, 6500));
  1150.             interfaces.get(1011).getComponent(382).doClick();
  1151.             log ("we confirmed");
  1152.             oldPoints = 0;
  1153.             played = false;
  1154.             points = 0;
  1155.             got250 = false;
  1156.             interfaces.get(1011).getComponent(51).doClick();
  1157.             sleep (2000, 3500);
  1158.             walkPath(genPath(new RSTile (2657, 2639)), 2);
  1159.            
  1160.             jobQ.remove();
  1161.         }
  1162.         if (getJob().getName().equals("mage helm")) {
  1163.             sleep (random(6000,8000));
  1164.             sleep(random(5000, 6500));
  1165.             log ("we're gonna the tab");
  1166.             interfaces.get(1011).getComponent(28).doClick();
  1167.             sleep(random(4000, 5000));
  1168.             log ("we clicked the tab, now click exchange..");
  1169.             sleep(random(3500,4600));
  1170.             interfaces.get(1011).getComponent(207).doClick();
  1171.             log ("we clicked exchange, now confirm");
  1172.             sleep(random(5000, 6500));
  1173.             interfaces.get(1011).getComponent(382).doClick();
  1174.             log ("we confirmed");
  1175.             oldPoints = 0;
  1176.             played = false;
  1177.             points = 0;
  1178.             got250 = false;
  1179.             interfaces.get(1011).getComponent(51).doClick();
  1180.             sleep (2000, 3500);
  1181.             walkPath(genPath(new RSTile (2657, 2639)), 2);
  1182.            
  1183.             jobQ.remove();
  1184.         }
  1185.         if (getJob().getName().equals("ranger helm")) {
  1186.             sleep (random(6000,8000));
  1187.             sleep(random(5000, 6500));
  1188.             log ("we're gonna the tab");
  1189.             interfaces.get(1011).getComponent(28).doClick();
  1190.             sleep(random(4000, 5000));
  1191.             log ("we clicked the tab, now click exchange..");
  1192.             sleep(random(3500,4600));
  1193.             interfaces.get(1011).getComponent(195).doClick();
  1194.             log ("we clicked exchange, now confirm");
  1195.             sleep(random(5000, 6500));
  1196.             interfaces.get(1011).getComponent(382).doClick();
  1197.             log ("we confirmed");
  1198.             oldPoints = 0;
  1199.             played = false;
  1200.             points = 0;
  1201.             got250 = false;
  1202.             interfaces.get(1011).getComponent(51).doClick();
  1203.             sleep (2000, 3500);
  1204.             walkPath(genPath(new RSTile (2657, 2639)), 2);
  1205.            
  1206.             jobQ.remove();
  1207.         }
  1208.         if (getJob().getName().equals("melee helm")) {
  1209.             sleep (random(6000,8000));
  1210.             sleep(random(5000, 6500));
  1211.             log ("we're gonna the tab");
  1212.             interfaces.get(1011).getComponent(28).doClick();
  1213.             sleep(random(4000, 5000));
  1214.             log ("we clicked the tab, now click exchange..");
  1215.             sleep(random(3500,4600));
  1216.             interfaces.get(1011).getComponent(290).doClick();
  1217.             log ("we clicked exchange, now confirm");
  1218.             sleep(random(5000, 6500));
  1219.             interfaces.get(1011).getComponent(382).doClick();
  1220.             log ("we confirmed");
  1221.             oldPoints = 0;
  1222.             played = false;
  1223.             points = 0;
  1224.             got250 = false;
  1225.             interfaces.get(1011).getComponent(51).doClick();
  1226.             sleep (2000, 3500);
  1227.             walkPath(genPath(new RSTile (2657, 2639)), 2);
  1228.             jobQ.remove();
  1229.         }
  1230.        
  1231.        
  1232.         //equipment: 21 & 28
  1233.         //melee helm: 66 290
  1234.         //ranger helm: 98 195
  1235.         //mage helm: 114 207
  1236.         //top: 130 219
  1237.         //robes: 146 231
  1238.         //gloves: 162  243
  1239.         //mace: 254
  1240.         //deflector: 178 266
  1241.         //seal: 279
  1242.        
  1243.        
  1244.        
  1245.        
  1246.     //      "Attack", "Defence",
  1247.     //      "Magic", "Prayer", "Strength", "Ranged", "Hitpoints", "Top",
  1248.     //      "Robe", "Range Helm", "Melee Helm", "Mage Helm", "Glove"
  1249.        
  1250.            
  1251.  
  1252.     //jobQ.remove(j);
  1253.     }
  1254.    
  1255.  
  1256.     @Override
  1257.     public int loop() {
  1258.         VarAttState = GetAttState();
  1259.         if (!(VarAttState == AttState))
  1260.             {
  1261.             RSComponent set1 = interfaces.getComponent(884, 11);
  1262.             RSComponent set2 = interfaces.getComponent(884, 12);
  1263.             RSComponent set3 = interfaces.getComponent(884, 13);
  1264.             RSComponent set4 = interfaces.getComponent(884, 14);
  1265.             if (game.getCurrentTab() != Game.TAB_ATTACK)
  1266.                 game.openTab(Game.TAB_ATTACK);
  1267.             if (AttState == 0)
  1268.             {
  1269.                 set1.doClick();
  1270.             }
  1271.             if (AttState == 1)
  1272.             {
  1273.                 set2.doClick();
  1274.             }
  1275.             if (AttState == 2)
  1276.             {
  1277.                 set3.doClick();
  1278.             }
  1279.             if (AttState == 3)
  1280.             {
  1281.                 set4.doClick();
  1282.             }
  1283.             }
  1284.         try {
  1285.             mouse.setSpeed(random(5, 8));
  1286.             if (gc == 0)
  1287.                 gc = System.currentTimeMillis();
  1288.  
  1289.             if (!onBoat() && !inPest()) {
  1290.                 Break b = getCurrentBreak();
  1291.                 if (b != null && b.needsBreak())
  1292.                     b.takeBreak();
  1293.             }
  1294.             //if (interfaces.get(INTERFACE_250_PTS).isValid()) {
  1295.             //  got250 = true;
  1296.             //}
  1297.  
  1298.             if (points >= spendwhenpoints && !inPest()) {
  1299.                 log ("We have (more than) the required number of points!");
  1300.                 got250 = true;
  1301.             }
  1302.            
  1303.             if (getMyPlayer().isInCombat() && getMyPlayer().getHPPercent() < 2
  1304.                     && calc.distanceTo(npcs.getNearest(squire)) > 15) {
  1305.                 return random(600, 800);
  1306.             }
  1307.            
  1308.  
  1309.            
  1310.            
  1311.         //  if (!(getMyPlayer().isInCombat()) && inPest() && standStill() == true) {
  1312.         //      log ("fixing standing still");
  1313.         //  } adding later
  1314.            
  1315.             RSNPC changer = npcs.getNearest(3788);
  1316.             RSNPC changer2 = npcs.getNearest(3789);
  1317.             if (!onBoat() && !inPest() && getJob() != null && got250 == true && !interfaces.get(1011).isValid()) {
  1318.            
  1319.                 log ("we're gonna buy (dojob)");
  1320.                 //doJob();
  1321.                 final Job j = getJob();
  1322.                 if (j == null) {
  1323.                     log ("we returned");
  1324.                     //return;
  1325.                 }
  1326.                 if (j.points == 100 && !got250)
  1327.                 {
  1328.                     log ("we returned 2");
  1329.                     //return;
  1330.                 }
  1331.                 //if (npcs.getNearest(3788) == null && !inBuyArea()) {
  1332.                 //  log ("the void is null");
  1333.                 //  walkPath(genPath(new RSTile(9545, 10657)), 2);
  1334.                 //  walkPath(genPath(npcs.getNearest(3788).getLocation()), 2);
  1335.                 //  sleep(random(5000, 6500));
  1336.                 //  clickNPC(npcs.getNearest(3788), "Exchange");
  1337.                 //  } else if (calc.distanceTo(npcs.getNearest(3788)) > 3) {
  1338.                 //} else if (npcs.getNearest(3788) != null && !inBuyArea()){
  1339.                 //      log ("the void is not null");
  1340.                 //      walkPath(genPath(new RSTile(2662, 2650)), 2);
  1341.                 //      walkPath(genPath(npcs.getNearest(3788).getLocation()), 2);
  1342.                 //      clickNPC(npcs.getNearest(3788), "Exchange");
  1343.                 //  }
  1344.            
  1345.                
  1346.                 //RSNPC changer = npcs.getNearest(3788);
  1347.                 //RSNPC changer2 = npcs.getNearest(3789);
  1348.                 //if (changer.isOnScreen()) {
  1349.                 //  clickNPC(npcs.getNearest(3788), "Exchange");
  1350.                     //log ("we clicked the void");
  1351.                 //  exchange();
  1352.                 ///}    else {
  1353.                 //      walkPath(genPath(npcs.getNearest(3788).getLocation()), 2);
  1354.                 //}
  1355.                
  1356.                 //if (changer2.isOnScreen()) {
  1357.                 //  clickNPC(npcs.getNearest(3789), "Exchange");
  1358.                 //  log ("we clicked the void");
  1359.                 //  exchange();
  1360.                 //} else {
  1361.                 //      walkPath(genPath(npcs.getNearest(3788).getLocation()), 2);
  1362.                 //}
  1363.                 if (changer.isOnScreen()&& !(interfaces.get(1011).isValid())) {
  1364.                     log ("the changer is on screen");
  1365.                     clickNPC(npcs.getNearest(3788), "Exchange");
  1366.                     sleep (random(3000,4000)); 
  1367.                     } else {
  1368.                         walkPath(genPath(npcs.getNearest(3788).getLocation()), 2);
  1369.                         camera.turnTo(changer);
  1370.                         sleep (random(1000,2000));
  1371.                         if (changer.isOnScreen()&& !(interfaces.get(1011).isValid())) {
  1372.                         clickNPC(npcs.getNearest(3788), "Exchange");
  1373.                         sleep (random(3000,4000));
  1374.                         }
  1375.                         else
  1376.                             {
  1377.                             if (changer2.isOnScreen() && !(interfaces.get(1011).isValid())) {
  1378.                                 log ("the changer is on screen");
  1379.                                 clickNPC(npcs.getNearest(3789), "Exchange");
  1380.                                 sleep (random(3000,4000)); 
  1381.                                 } else {
  1382.                                     walkPath(genPath(npcs.getNearest(3789).getLocation()), 2);
  1383.                                     sleep (random(3000,4000));
  1384.                                     clickNPC(npcs.getNearest(3789), "Exchange");
  1385.                                     sleep (random(3000,4000));
  1386.                                 } return 3000;
  1387.                            
  1388.                             }
  1389.                         }
  1390.                     }
  1391.            
  1392.        
  1393.             if (interfaces.get(1011).isValid()) {
  1394.                 exchange();
  1395.             }
  1396.                     //if (inBuyArea()) {
  1397.                     //  log ("we're in the buy area");
  1398.                     //  camera.turnToCharacter(changer);   
  1399.                     //  } else {
  1400.                     //      log ("the changer is NOT on screen");
  1401.                     //      walkPath(genPath(npcs.getNearest(3789).getLocation()), 2);
  1402.                     //      camera.turnToCharacter(changer);
  1403.                     //      clickNPC(npcs.getNearest(3789), "Exchange");
  1404.                     //      sleep (random(3000,4000));
  1405.                     //      if (interfaces.get(1011).isValid()) {
  1406.                     //          log ("interface is valid");
  1407.                     //          exchange();
  1408.                     //      } else {
  1409.                     //          walkPath(genPath(npcs.getNearest(3789).getLocation()), 2);
  1410.                     //          sleep (random(3000,4000));
  1411.                     //          clickNPC(npcs.getNearest(3788), "Exchange");
  1412.                     //          sleep (random(3000,4000));
  1413.                     //      }
  1414.                     //  }  
  1415.                     //  } return 4000;
  1416.                     //}
  1417.  
  1418.             if (getJob() == null && got250) {
  1419.                 game.logout(false);
  1420.                 log("Thanks for using BPestControl");
  1421.                 log("Reached 250 points and out of jobs");
  1422.             }
  1423.             if (menu.isOpen()) {
  1424.                 mouse.move(random(5, 760), random(5, 500));
  1425.             }
  1426.             if (!inPest() && !onBoat() && !inBuyArea() && !got250) {
  1427.                 return enterBoat();
  1428.             }
  1429.             if (onBoat()) {
  1430.                 String s = "";
  1431.                 if (interfaces.getComponent(407, 16) != null) {
  1432.                     s = interfaces.getComponent(407, 16).getText();
  1433.                 }
  1434.                 points = Integer.parseInt(s.replace("Commendations: ", ""));
  1435.                 if (played) {
  1436.                     if (points > oldPoints) {
  1437.                         gainedPoints += points - oldPoints;
  1438.                     }
  1439.                     //if (points - oldPoints == 0) {
  1440.                     //  lost++;
  1441.                     //} else {
  1442.                     //  won++;
  1443.                     //}
  1444.                    
  1445.                    
  1446.                 }
  1447.                 oldPoints = points;
  1448.                 played = false;
  1449.                 return random(400, 700);
  1450.             }
  1451.             if (npcs.getNearest(squire) != null) {
  1452.                 voidLoc = npcs.getNearest(squire).getLocation();
  1453.                 fillPortalList();
  1454.             }
  1455.             if (inPest()) {
  1456.                 return pestLoop();
  1457.             }
  1458.         } catch (Exception ignored) {
  1459.         }
  1460.         return random(100, 800);
  1461.     }
  1462.  
  1463.     public void moveMouse(final Point p, final int rX, final int rY) {
  1464.         final int X = p.x + random(-(rX / 1), (rX / 1));
  1465.         final int Y = p.y + random(-(rY / 1), (rY / 1));
  1466.         mouse.move(X, Y);
  1467.     }
  1468.  
  1469.     boolean onBoat() {
  1470.         return boatArea != null && boatArea.contains(getMyPlayer().getLocation());
  1471.     }
  1472.    
  1473.     boolean inBuyArea() {
  1474.         //int[] BuyArea = {2658, 2646, 2671, 2658};
  1475.         BuyArea = new RSArea (2658, 2647, 2667, 2659);
  1476.         return BuyArea != null && BuyArea.contains(getMyPlayer().getLocation());
  1477.  
  1478.     }
  1479.  
  1480.     int GetAttState() {
  1481.         return settings.getSetting(43);
  1482.     }
  1483.  
  1484.    
  1485.    
  1486.  
  1487.     @Override
  1488.     public boolean onStart() {
  1489.         if (game.isLoggedIn()) {
  1490.         start = false;
  1491.         URLConnection url = null;
  1492.         BufferedReader in = null;
  1493.         JOptionPane.showMessageDialog(null, "Checking for updates... Click OK to continue!");
  1494.         try {
  1495.             url = new URL("http://myrsdatabase.x10.mx/bpestcontrolversion.txt").openConnection();
  1496.             in = new BufferedReader(new InputStreamReader(url.getInputStream()));
  1497.             if (Double.parseDouble(in.readLine()) > getClass().getAnnotation(ScriptManifest.class).version()) {
  1498.                 if (JOptionPane.showConfirmDialog(null, "Update found, want to know where to get the new version?", "Update", 2) == 0) {
  1499.                     JOptionPane.showMessageDialog(null, "Please to go the powerbot forum (powerbot.org), go to the thread and update the script! (powerbot -> scripts -> minigames -> BPestcontrol [Fix(ing/ed)] - pest control script");
  1500.                 } else
  1501.                     log("Canceled");
  1502.             } else
  1503.                 JOptionPane.showMessageDialog(null,
  1504.                 "You have the latest version.");
  1505.             if (in != null)
  1506.                 in.close();
  1507.         } catch (IOException e) {
  1508.             return false;
  1509.         }
  1510.         final BGUI gui = new BGUI();
  1511.         gui.setVisible(true);
  1512.        
  1513.         while (gui.isVisible()) {
  1514.             sleep(random(500, 600));
  1515.         }
  1516.         if (!start) {
  1517.             return false;
  1518.         }
  1519.         new Thread(new AnimationChecker()).start();
  1520.         new Thread(antiban).start();
  1521.         log("starting script");
  1522.         pf = new Pathfinder();
  1523.         } else {
  1524.             log("Login before starting this script.");
  1525.             stopScript(false);
  1526.             return false;
  1527.         }
  1528.         return true;
  1529.     }
  1530.    
  1531.     @Override
  1532.     public void onFinish() {
  1533.         log("BPestControl original by Bool; remake by Gravemindx.");
  1534.         log("Gained " + gainedPoints + " points.");
  1535.     }
  1536.  
  1537.     public void onRepaint(final Graphics g) {
  1538.         Point mLoc = mouse.getLocation();
  1539.         g.setColor(Color.blue);
  1540.         g.drawLine(mLoc.x, 0, mLoc.x, 502);
  1541.         g.drawLine(0, mLoc.y, 764, mLoc.y);
  1542.         if (getCurrentBreak() != null) {
  1543.             g.drawString(getCurrentBreak().getTimeTillBreak(), 10, 400);
  1544.             g.drawString("" + getCurrentBreak().needsBreak(), 10, 415);
  1545.         }
  1546.         int y = 120;
  1547.         final int x = 20;
  1548.         g.setColor(new Color(51, 153, 255, 170));
  1549.         g.fillRoundRect(15, 120, width, height, 5, 5);
  1550.         g.setColor(Color.WHITE);
  1551.         g.drawRoundRect(15, 120, width, height, 5, 5);
  1552.         width = 0;
  1553.         height = 0;
  1554.         if (startTime == 0) {
  1555.             startTime = System.currentTimeMillis();
  1556.         }
  1557.         long millis = System.currentTimeMillis() - startTime;
  1558.         try {
  1559.             g.setColor(Color.WHITE);
  1560.             g.setFont(new Font("Arial", Font.BOLD, 14));
  1561.             g.drawString("BPestControl by GrAVeMinDx v1.65", x, y += g
  1562.                     .getFontMetrics().getHeight());
  1563.             height += g.getFontMetrics().getHeight();
  1564.             width = (int) g.getFontMetrics().getStringBounds(
  1565.                     "BPestControl by GrAVeMinDx v1.51", g).getWidth();
  1566.             g.setFont(new Font("Arial", Font.PLAIN, 12));
  1567.             g.drawString("Lost " + lost + " Games", x, y += g.getFontMetrics()
  1568.                     .getHeight());
  1569.             height += g.getFontMetrics().getHeight();
  1570.             g.drawString("won " + won + " Games", x, y += g.getFontMetrics()
  1571.                     .getHeight());
  1572.             height += g.getFontMetrics().getHeight();
  1573.             g.drawString("Gained " + gainedPoints + " points", x, y += g
  1574.                     .getFontMetrics().getHeight());
  1575.             height += g.getFontMetrics().getHeight();
  1576.             g.drawString("Time running : " + timeToString(millis), x, y += g
  1577.                     .getFontMetrics().getHeight());
  1578.             height += g.getFontMetrics().getHeight();
  1579.             if (getJob() != null) {
  1580.                 if (g.getFontMetrics().getStringBounds(
  1581.                         "Spending points on " + getJob().getName(), g)
  1582.                         .getWidth() > width) {
  1583.                     width = (int) g.getFontMetrics().getStringBounds(
  1584.                             "Spending points on " + getJob().getName(), g)
  1585.                             .getWidth();
  1586.                 }
  1587.                 g.drawString("Spending points on " + getJob().getName() + " "
  1588.                         + points, x, y += g.getFontMetrics().getHeight());
  1589.                 height += g.getFontMetrics().getHeight();
  1590.             }
  1591.             height += 5;
  1592.             width += 10;
  1593.         } catch (final Exception ignored) {
  1594.  
  1595.         }
  1596.     }
  1597.  
  1598.     int pestLoop() {
  1599.        
  1600.        
  1601.         if (!played) {
  1602.             played = true;
  1603.         }
  1604.         try {
  1605.             if (!atPortal()) {
  1606.                 final Portal p = getRandomOpenPortal();
  1607.                 p.walkTo();
  1608.                 return random(100, 600);
  1609.             }
  1610.             if (!getCurrentPortal().equals(getNearestPortal())) {
  1611.                 if (getNearestOpenPortal() != null) {
  1612.                     getNearestOpenPortal().walkTo();
  1613.                 }
  1614.                 return random(100, 600);
  1615.             }
  1616.             if (!getCurrentPortal().isOpen()) {
  1617.                 if (getNearestOpenPortal() != null) {
  1618.                     getNearestOpenPortal().walkTo();
  1619.                 }
  1620.                 return random(100, 600);
  1621.             }
  1622.             checkSpecial();
  1623.             if (getMyPlayer().getInteracting() == null) {
  1624.                 RSGroundItem t = groundItems.getNearest(arrowID);
  1625.                 if (t != null && t.isOnScreen()) {
  1626.                     t.doAction("Take");
  1627.                     return random(600, 800);
  1628.                 }
  1629.                 path = null;
  1630.                 if (!inPest()) {
  1631.                     return random(100, 500);
  1632.                 }
  1633.                 failsafe = 0;
  1634.                 RSNPC c;
  1635.                 if (getCurrentPortal().getNPC() != null) {
  1636.                     c = getCurrentPortal().getNPC();
  1637.                 } else {
  1638.                     c = getNPC(attackSpinner);
  1639.                 }
  1640.                 //if (c != null) {
  1641.                 //  if (clickNPC(c, "Attack")) {
  1642.                 //      return random(600, 1200);
  1643.                 //  }
  1644.                 //}
  1645.                 if (c != null) {
  1646.                     clickNPC(c, "Attack");
  1647.                     //return random(10000, 13000);
  1648.                 }
  1649.                 //return random(400, 700);
  1650.             } else {
  1651.                 RSNPC n = getNPC(true);
  1652.                 if (n != null && n.getName().contains("Spinner")) {
  1653.                     RSNPC inter = (RSNPC) getMyPlayer().getInteracting();
  1654.                     if ((inter != null && !inter.getName().equals(n.getName()))
  1655.                             || inter == null)
  1656.                         if (clickNPC(n, "Attack Spinner")) {
  1657.                             //return random(600, 1200);
  1658.                         }
  1659.                 }
  1660.                 path = null;
  1661.                 if (failsafe > 4) {
  1662.                     walking.walkTileMM(getNearestOpenPortal().getRandom());
  1663.                 }
  1664.                 final RSNPC npc = (RSNPC) getMyPlayer().getInteracting();
  1665.                 if (getMyPlayer().isMoving()
  1666.                         || getMyPlayer().getInteracting() != null
  1667.                         || System.currentTimeMillis() - lastAniChange < 2000
  1668.                         || npc != null && npc.getName().contains("ortal")) {
  1669.                     failsafe = 0;
  1670.                 } else {
  1671.                     failsafe++;
  1672.                     sleep(random(600, 800));
  1673.                 }
  1674.                 return random(400, 700);
  1675.             }
  1676.         } catch (final Exception ignored) {
  1677.         }
  1678.         return random(400, 700);
  1679.     }
  1680.  
  1681.     boolean PrayerEnabled() {
  1682.         return settings.getSetting(1395) > 0;
  1683.     }
  1684.  
  1685.     private int i = 0;
  1686.  
  1687.     boolean walkPath(final RSTile[] path) {
  1688.         final char left = 37;
  1689.         final char right = 39;
  1690.         RSTile tile = getNext(path);
  1691.         mouse.move(calc.worldToMinimap(tile.getX(), tile.getY()));
  1692.         if (!inPest()) {
  1693.             return true;
  1694.         }
  1695.         if (i == 7) {
  1696.             char dir = random(0, 3) == 2 ? left : right;
  1697.             keyboard.pressKey(dir);
  1698.             sleep(random(800, 1200));
  1699.             keyboard.releaseKey(dir);
  1700.             i = 0;
  1701.             return false;
  1702.         }
  1703.         if (getTopText().contains("Cancel")) {
  1704.             i++;
  1705.             return false;
  1706.         }
  1707.         try {
  1708.             walking.walkTileMM(getNext(path));
  1709.             sleep(random(200, 500));
  1710.             while (getMyPlayer().isMoving() && calc.distanceTo(walking.getDestination()) > 7) {
  1711.                 sleep(random(600, 800));
  1712.             }
  1713.         } catch (final Exception ignored) {
  1714.         }
  1715.         return calc.distanceTo(path[path.length - 1]) < 10 || !inPest();
  1716.     }
  1717.  
  1718.     void checkSpecial() {
  1719.         if (specialPercent == 0 ) {
  1720.             return;
  1721.         }
  1722.         int percent = (settings.getSetting(300) / 10);
  1723.         if (percent >= specialPercent && settings.getSetting(301) == 0) {
  1724.             RSComponent child = interfaces.getComponent(884, 4);
  1725.             if (game.getCurrentTab() != Game.TAB_ATTACK)
  1726.                 game.openTab(Game.TAB_ATTACK);
  1727.             child.doClick();
  1728.             sleep(random(2000, 3000));
  1729.         }
  1730.     }
  1731.    
  1732.  
  1733.  
  1734.     void walkPath(final RSTile[] path, final int i) {
  1735.         try {
  1736.             walking.walkTileMM(getNext(path));
  1737.             sleep(random(200, 500));
  1738.             while (getMyPlayer().isMoving() && calc.distanceTo(walking.getDestination()) > 7) {
  1739.                 sleep(random(600, 800));
  1740.             }
  1741.         } catch (final Exception ignored) {
  1742.         }
  1743.     }
  1744.  
  1745.     int daxeID = 0;
  1746.     int oldID = 0;
  1747.  
  1748.     public void doDragonBattleAxe() {
  1749.         if (!DBaxe)
  1750.             return;
  1751.         if (game.getCurrentTab() != Game.TAB_INVENTORY)
  1752.             game.openTab(Game.TAB_INVENTORY);
  1753.         inventory.getItem(daxeID).doClick(true);
  1754.         game.openTab(Game.TAB_ATTACK);
  1755.         RSComponent child = interfaces.getComponent(884, 4);
  1756.         child.doClick();
  1757.         sleep(random(1200, 1500));
  1758.         if (game.getCurrentTab() != Game.TAB_INVENTORY)
  1759.             game.openTab(Game.TAB_INVENTORY);
  1760.         inventory.getItem(oldID).doClick(true);
  1761.  
  1762.     }
  1763.  
  1764.     RSNPC getNPC(boolean spinner) {
  1765.         final String[] names = {"Shifter", "Defiler", "Torcher", "Brawler", "Ravager", "Spinner"};
  1766.         RSNPC closest = null;
  1767.         RSNPC[] result = npcs.getAll(new Filter<RSNPC>() {
  1768.             public boolean accept(RSNPC monster) {
  1769.                 for (String name : names) {
  1770.                     if (!name.equals(monster.getName())
  1771.                             || calc.distanceBetween(getCurrentPortal().getLocation(), monster.getLocation()) > 10
  1772.                             || monster.isInCombat() && monster.getHPPercent() < 10) {
  1773.                         continue;
  1774.                     }
  1775.                     return true;
  1776.                 }
  1777.                 return false;
  1778.             }
  1779.         });
  1780.         if (result.length == 0)
  1781.             return null;
  1782.         RSNPC s = null;
  1783.         for (RSNPC npc : result) {
  1784.             if (spinner) {
  1785.                 if (npc.getName().equalsIgnoreCase("Spinner")) {
  1786.                     if (s == null || calc.distanceTo(s) > calc.distanceTo(npc))
  1787.                         s = npc;
  1788.                 }
  1789.             }
  1790.             if (closest == null || calc.distanceTo(closest) > calc.distanceTo(npc))
  1791.                 closest = npc;
  1792.         }
  1793.         if (spinner && s != null) {
  1794.             return s;
  1795.         }
  1796.         return closest;
  1797.     }
  1798.  
  1799.     public String timeToString(long time) {
  1800.         final long hours = time / (1000 * 60 * 60);
  1801.         time -= hours * 1000 * 60 * 60;
  1802.         final long minutes = time / (1000 * 60);
  1803.         time -= minutes * 1000 * 60;
  1804.         final long seconds = time / 1000;
  1805.         String str = "";
  1806.         if (hours < 10)
  1807.             str += "0";
  1808.         str += hours + ":";
  1809.         if (minutes < 10)
  1810.             str += "0";
  1811.         str += minutes + ":";
  1812.         if (seconds < 10)
  1813.             str += "0";
  1814.         str += seconds;
  1815.         return str;
  1816.     }
  1817.  
  1818.     class Break {
  1819.         public boolean isDone = false;
  1820.         int time, after;
  1821.         public Timer Time;
  1822.         long end;
  1823.  
  1824.         public Break(int time, int after) {
  1825.             this.time = time;
  1826.             this.after = after;
  1827.             end = System.currentTimeMillis() + after;
  1828.         }
  1829.  
  1830.         public void init() {
  1831.             Time = new Timer(time);
  1832.             end = System.currentTimeMillis() + after;
  1833.         }
  1834.  
  1835.         public void takeBreak() {
  1836.             while (game.isLoggedIn())
  1837.                 game.logout(false);
  1838.             Time.reset();
  1839.             log("Taking break for " + Time.toString());
  1840.             while (!Time.isDone()) {
  1841.                 try {
  1842.                     Thread.sleep(random(500, 800));
  1843.                 } catch (InterruptedException ignored) {
  1844.                 }
  1845.             }
  1846.             isDone = true;
  1847.         }
  1848.  
  1849.         public String getTimeTillBreak() {
  1850.             return timeToString(end - System.currentTimeMillis());
  1851.         }
  1852.  
  1853.         public boolean needsBreak() {
  1854.             return System.currentTimeMillis() > end;
  1855.         }
  1856.     }
  1857.  
  1858.     // ----------
  1859.  
  1860.     class Timer {
  1861.  
  1862.         private long start;
  1863.         private int time;
  1864.  
  1865.         public Timer(int time) {
  1866.             start = System.currentTimeMillis();
  1867.             this.time = time;
  1868.         }
  1869.  
  1870.         public Timer() {
  1871.             this(0);
  1872.         }
  1873.  
  1874.         public boolean isDone() {
  1875.             return (System.currentTimeMillis() - start) > time;
  1876.         }
  1877.  
  1878.         public void reset() {
  1879.             start = System.currentTimeMillis();
  1880.         }
  1881.  
  1882.         @Override
  1883.         public String toString() {
  1884.             return timeToString((System.currentTimeMillis() - start));
  1885.         }
  1886.     }
  1887.  
  1888.     // ----------
  1889.  
  1890.     class Pathfinder {
  1891.  
  1892.         public int basex, basey;
  1893.         public int[][] blocks;
  1894.  
  1895.         public Pathfinder() {
  1896.             reload();
  1897.         }
  1898.  
  1899.         public void reload() {
  1900.             basex = game.getBaseX();
  1901.             basey = game.getBaseY();
  1902.             blocks = walking.getCollisionFlags(game.getPlane());
  1903.         }
  1904.  
  1905.         public RSTile[] findPath(RSTile dest) {
  1906.             if (!isValid())
  1907.                 reload();
  1908.             return findPath(getMyPlayer().getLocation(), dest);
  1909.         }
  1910.  
  1911.         public RSTile[] findPath(RSTile start, RSTile dest) {
  1912.             if (!isValid())
  1913.                 reload();
  1914.             return findPath(
  1915.                     new Node(start.getX() - basex, start.getY() - basey),
  1916.                     new Node(dest.getX() - basex, dest.getY() - basey));
  1917.         }
  1918.  
  1919.         public RSTile[] findPath(Node start, Node dest) {
  1920.             if (!isValid())
  1921.                 reload();
  1922.             if (!calc.canReach(new RSTile(dest.x + basex, dest.y + basey), false)) {
  1923.                 return null;
  1924.             }
  1925.             ArrayList<Node> closed = new ArrayList<Node>();
  1926.             ArrayList<Node> open = new ArrayList<Node>();
  1927.  
  1928.             Node current = start;
  1929.             open.add(current);
  1930.             while (open.size() != 0) {
  1931.                 current = getBestNode(open);
  1932.                 closed.add(current);
  1933.                 open.remove(current);
  1934.                 for (Node node : getNodesAround(current)) {
  1935.                     if (!closed.contains(node)) {
  1936.                         if (!open.contains(node)) {
  1937.                             node.parent = current;
  1938.                             node.cost = current.cost
  1939.                                     + getMovementCost(node, current);
  1940.                             node.heuristic = node.cost
  1941.                                     + getHeuristicCost(node, dest);
  1942.                             open.add(node);
  1943.                         } else {
  1944.                             if (current.cost + getMovementCost(node, current) < node.cost) {
  1945.                                 node.parent = current;
  1946.                                 node.cost = current.cost
  1947.                                         + getMovementCost(node, current);
  1948.                                 node.heuristic = node.cost
  1949.                                         + getHeuristicCost(node, dest);
  1950.                             }
  1951.                         }
  1952.                     }
  1953.                 }
  1954.                 if (closed.contains(dest)) {
  1955.                     final ArrayList<RSTile> result = new ArrayList<RSTile>();
  1956.                     Node node = closed.get(closed.size() - 1);
  1957.                     while (node.parent != null) {
  1958.                         result.add(new RSTile(node.x + basex, node.y + basey));
  1959.                         node = node.parent;
  1960.                     }
  1961.                     path = reversePath(result
  1962.                             .toArray(new RSTile[result.size()]));
  1963.                     return path;
  1964.                 }
  1965.             }
  1966.             return null;
  1967.         }
  1968.        
  1969.         /**
  1970.          * Reverses an array of tiles.
  1971.          *
  1972.          * @param other The <tt>RSTile</tt> path array to reverse.
  1973.          * @return The reverse <tt>RSTile</tt> path for the given <tt>RSTile</tt>
  1974.          *         path.
  1975.          */
  1976.         @Deprecated
  1977.         public RSTile[] reversePath(RSTile[] other) {
  1978.             RSTile[] t = new RSTile[other.length];
  1979.             for (int i = 0; i < t.length; i++) {
  1980.                 t[i] = other[other.length - i - 1];
  1981.             }
  1982.             return t;
  1983.         }
  1984.  
  1985.         public Node getBestNode(ArrayList<Node> nodes) {
  1986.             Node winner = null;
  1987.             for (Node node : nodes) {
  1988.                 if (winner == null || node.cost < winner.cost) {
  1989.                     winner = node;
  1990.                 }
  1991.             }
  1992.             return winner;
  1993.         }
  1994.  
  1995.         public double getHeuristicCost(Node current, Node dest) {
  1996.             float dx = dest.x - current.x;
  1997.             float dy = dest.y - current.y;
  1998.             return Math.sqrt((dx * dx) + (dy * dy));
  1999.         }
  2000.  
  2001.         public double getMovementCost(Node current, Node dest) {
  2002.             return Math.hypot(dest.x - current.x, dest.y - current.y);
  2003.         }
  2004.  
  2005.         /* (non-Javadoc)
  2006.          * credits to Jacmob
  2007.          */
  2008.         public ArrayList<Node> getNodesAround(Node node) {
  2009.             final ArrayList<Node> tiles = new ArrayList<Node>();
  2010.             final int curX = node.x, curY = node.y;
  2011.             if (curX > 0 && curY < 103
  2012.                     && (blocks[curX - 1][curY + 1] & 0x1280138) == 0
  2013.                     && (blocks[curX - 1][curY] & 0x1280108) == 0
  2014.                     && (blocks[curX][curY + 1] & 0x1280120) == 0) {
  2015.                 tiles.add(new Node(curX - 1, curY + 1));
  2016.             }
  2017.             if (curY < 103 && (blocks[curX][curY + 1] & 0x1280120) == 0) {
  2018.                 tiles.add(new Node(curX, curY + 1));
  2019.             }
  2020.             if (curX > 0 && curY < 103
  2021.                     && (blocks[curX - 1][curY + 1] & 0x1280138) == 0
  2022.                     && (blocks[curX - 1][curY] & 0x1280108) == 0
  2023.                     && (blocks[curX][curY + 1] & 0x1280120) == 0) {
  2024.                 tiles.add(new Node(curX + 1, curY + 1));
  2025.             }
  2026.             if (curX > 0 && (blocks[curX - 1][curY] & 0x1280108) == 0) {
  2027.                 tiles.add(new Node(curX - 1, curY));
  2028.             }
  2029.             if (curX < 103 && (blocks[curX + 1][curY] & 0x1280180) == 0) {
  2030.                 tiles.add(new Node(curX + 1, curY));
  2031.             }
  2032.             if (curX > 0 && curY > 0
  2033.                     && (blocks[curX - 1][curY - 1] & 0x128010e) == 0
  2034.                     && (blocks[curX - 1][curY] & 0x1280108) == 0
  2035.                     && (blocks[curX][curY - 1] & 0x1280102) == 0) {
  2036.                 tiles.add(new Node(curX - 1, curY - 1));
  2037.             }
  2038.             if (curY > 0 && (blocks[curX][curY - 1] & 0x1280102) == 0) {
  2039.                 tiles.add(new Node(curX, curY - 1));
  2040.             }
  2041.             if (curX < 103 && curY > 0
  2042.                     && (blocks[curX + 1][curY - 1] & 0x1280183) == 0
  2043.                     && (blocks[curX + 1][curY] & 0x1280180) == 0
  2044.                     && (blocks[curX][curY - 1] & 0x1280102) == 0) {
  2045.                 tiles.add(new Node(curX + 1, curY - 1));
  2046.             }
  2047.             return tiles;
  2048.  
  2049.         }
  2050.  
  2051.         public boolean isValid() {
  2052.             return basex == game.getBaseX()
  2053.                     && basey == game.getBaseY();
  2054.         }
  2055.  
  2056.         class Node {
  2057.  
  2058.             public final int x, y;
  2059.             public double cost = 0, heuristic = 0;
  2060.             public Node parent;
  2061.  
  2062.             public Node(int x, int y) {
  2063.                 this.x = x;
  2064.                 this.y = y;
  2065.             }
  2066.  
  2067.             public boolean equals(Object other) {
  2068.                 if (other instanceof Node) {
  2069.                     Node o = (Node) other;
  2070.                     return x == o.x && y == o.y;
  2071.                 }
  2072.                 return false;
  2073.             }
  2074.         }
  2075.     }
  2076.  
  2077.     // ----------
  2078.  
  2079.     class BGUI extends JFrame implements ActionListener {
  2080.         private static final long serialVersionUID = 1L;
  2081.         private JPanel contentPane;
  2082.         private JTabbedPane tabbedPane;
  2083.         private JTable table;
  2084.         private JTextField textField;
  2085.         private JTextField textField_1;
  2086.         private JButton btnAddBreak;
  2087.         private DefaultTableModel model;
  2088.         private DefaultListModel jobmodel;
  2089.  
  2090.         private JButton btnAddAntiban;
  2091.         private JComboBox comboBox_1;
  2092.         private JList list_1;
  2093.         private JButton btnAddJob;
  2094.         private JButton btnDelJob;
  2095.        
  2096.        
  2097.  
  2098.         private JList list;
  2099.         private JComboBox comboBox;
  2100.  
  2101.        
  2102.         public BGUI() {
  2103.             super("BPestControl");
  2104.             initGUI();
  2105.         }
  2106.  
  2107.         private void initGUI() {
  2108.             setAlwaysOnTop(true);
  2109.             setResizable(false);
  2110.             try {
  2111.                 UIManager.setLookAndFeel(UIManager
  2112.                         .getSystemLookAndFeelClassName());
  2113.             } catch (Exception ignored) {
  2114.             }
  2115.             setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  2116.             setBounds(100, 100, 450, 300);
  2117.             contentPane = new JPanel();
  2118.             contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  2119.             setContentPane(contentPane);
  2120.             contentPane.setLayout(null);
  2121.             tabbedPane = new JTabbedPane(SwingConstants.LEFT);
  2122.             tabbedPane.setBounds(10, 10, 414, 218);
  2123.             contentPane.add(tabbedPane);
  2124.  
  2125.             final JPanel panel = new JPanel();
  2126.             tabbedPane.addTab("Main", null, panel, null);
  2127.            
  2128.             final JLabel lblnote = new JLabel("note: fill in how much precent special it needs to be");
  2129.             lblnote.setBounds(10, 232, 300, 16);
  2130.             contentPane.add(lblnote);
  2131.            
  2132.             final JLabel lblnote2 = new JLabel("to do a special attack (example: 80) no % symbol");
  2133.             lblnote2.setBounds(43, 243, 300, 16);
  2134.             contentPane.add(lblnote2);
  2135.  
  2136.             btnStartScript = new JButton("Start script");
  2137.             btnStartScript.addActionListener(this);
  2138.             btnStartScript.setBounds(327, 234, 97, 23);
  2139.             contentPane.add(btnStartScript);
  2140.             panel.setLayout(null);
  2141.  
  2142.             final JPanel panel_2 = new JPanel();
  2143.             tabbedPane.addTab("Antiban", null, panel_2, null);
  2144.  
  2145.             chckbxUseSpecialAttack = new JCheckBox("Use special attack when at (fill in how much precent)");
  2146.             chckbxUseSpecialAttack.setBounds(10, 10, 126, 17);
  2147.             panel.add(chckbxUseSpecialAttack);
  2148.  
  2149.             chckbxUseQuickPrayer = new JCheckBox("Use quick prayer");
  2150.             chckbxUseQuickPrayer.setBounds(10, 27, 126, 17);
  2151.             panel.add(chckbxUseQuickPrayer);
  2152.  
  2153.            
  2154.             final JLabel spendnote = new JLabel("spend if we have");
  2155.             spendnote.setBounds(28, 44, 126, 17);
  2156.             panel.add(spendnote);
  2157.            
  2158.             spendwhen = new JTextField();
  2159.             spendwhen.setText("250");
  2160.             spendwhen.setBounds(137, 43, 31, 19);
  2161.             panel.add(spendwhen);
  2162.            
  2163.             comboBox = new JComboBox();
  2164.             comboBox.setModel(new DefaultComboBoxModel(jobsStrings));
  2165.             comboBox.setBounds(10, 70, 126, 24);
  2166.             panel.add(comboBox);
  2167.  
  2168.             btnAddJob = new JButton("Add Job");
  2169.             btnAddJob.setBounds(20, 95, 103, 23);
  2170.             btnAddJob.addActionListener(this);
  2171.             panel.add(btnAddJob);
  2172.            
  2173.             btnDelJob = new JButton("Delete Job");
  2174.             btnDelJob.setBounds(20, 120, 103, 23);
  2175.             btnDelJob.addActionListener(this);
  2176.             panel.add(btnDelJob);
  2177.  
  2178.             final JScrollPane scrollPane = new JScrollPane();
  2179.             scrollPane.setBounds(180, 10, 126, 193);
  2180.             panel.add(scrollPane);
  2181.  
  2182.             jobmodel = new DefaultListModel();
  2183.             list = new JList(jobmodel);
  2184.             scrollPane.setViewportView(list);
  2185.             list.setBorder(new TitledBorder(null, "", TitledBorder.LEADING,
  2186.                     TitledBorder.TOP, null, null));
  2187.  
  2188.             final JPanel panel_7 = new JPanel();
  2189.             tabbedPane.addTab("Break handler", null, panel_7, null);
  2190.             panel_2.setLayout(null);
  2191.             m = new DefaultListModel();
  2192.             list_1 = new JList(m);
  2193.             list_1.setBorder(new LineBorder(new Color(0, 0, 0)));
  2194.             list_1.setBounds(10, 10, 307, 164);
  2195.             panel_2.add(list_1);
  2196.  
  2197.             btnAddAntiban = new JButton("Add antiban");
  2198.             btnAddAntiban.addActionListener(this);
  2199.             btnAddAntiban.setBounds(10, 180, 97, 23);
  2200.             panel_2.add(btnAddAntiban);
  2201.  
  2202.             comboBox_1 = new JComboBox();
  2203.             comboBox_1.setModel(new DefaultComboBoxModel(new String[]{
  2204.                     "rotate compass", "move mouse",
  2205.                     "move mouse and rotate compass", "rest",
  2206.                     "right click object", "right click npc",
  2207.                     "right click player"}));
  2208.             comboBox_1.setBounds(113, 180, 204, 23);
  2209.             panel_2.add(comboBox_1);
  2210.             panel_7.setLayout(null);
  2211.  
  2212.             table = new JTable();
  2213.             table.setBorder(new LineBorder(new Color(0, 0, 0)));
  2214.             table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  2215.             table.setBounds(10, 10, 301, 164);
  2216.             model = new DefaultTableModel();
  2217.             table.setModel(model);
  2218.             model.addColumn("");
  2219.             model.addColumn("");
  2220.             panel_7.add(table);
  2221.  
  2222.             btnAddBreak = new JButton("Add break");
  2223.             btnAddBreak.addActionListener(this);
  2224.             btnAddBreak.setBounds(10, 180, 89, 23);
  2225.             panel_7.add(btnAddBreak);
  2226.  
  2227.             final JLabel lblBreakFor = new JLabel("Break for");
  2228.             lblBreakFor.setBounds(105, 183, 52, 16);
  2229.             panel_7.add(lblBreakFor);
  2230.  
  2231.             textField = new JTextField();
  2232.             textField.setBounds(158, 181, 27, 21);
  2233.             panel_7.add(textField);
  2234.             textField.setColumns(10);
  2235.  
  2236.             final JLabel lblAfter = new JLabel("after ");
  2237.             lblAfter.setBounds(190, 183, 27, 16);
  2238.             panel_7.add(lblAfter);
  2239.  
  2240.             textField_1 = new JTextField();
  2241.             textField_1.setBounds(218, 181, 26, 21);
  2242.             panel_7.add(textField_1);
  2243.             textField_1.setColumns(10);
  2244.  
  2245.             btnRemove = new JButton("Delete");
  2246.             btnRemove.addActionListener(this);
  2247.             btnRemove.setBounds(248, 181, 65, 23);
  2248.             panel_7.add(btnRemove);
  2249.  
  2250.             comboBox_2 = new JComboBox();
  2251.             comboBox_2.setModel(new DefaultComboBoxModel(new String[]{
  2252.                     "Novice", "Intermediate", "Veteran"}));
  2253.             comboBox_2.setBounds(10, 181, 141, 22);
  2254.             panel.add(comboBox_2);
  2255.  
  2256.             chckbxAttackPortals = new JCheckBox("Attack portals");
  2257.             chckbxAttackPortals.setBounds(10, 145, 105, 17);
  2258.             panel.add(chckbxAttackPortals);
  2259.        
  2260.             specialtxt = new JTextField();
  2261.             specialtxt.setText("");
  2262.             specialtxt.setBounds(137, 10, 31, 19);
  2263.             panel.add(specialtxt);
  2264.            
  2265.             specialtxt.setColumns(10);
  2266.             chckbxattackspinners = new JCheckBox("Attack spinners");
  2267.             chckbxattackspinners.setBounds(10, 160, 113, 17);
  2268.             panel.add(chckbxattackspinners);
  2269.            
  2270.         }
  2271.  
  2272.         DefaultListModel m;
  2273.         private JButton btnRemove;
  2274.        
  2275.  
  2276.  
  2277.         public void actionPerformed(final ActionEvent e) {
  2278.             if (e.getSource() == btnStartScript) {
  2279.                 AttState = GetAttState();
  2280.                 start = true;
  2281.                 attackPortals = chckbxAttackPortals.isSelected();
  2282.                 attackSpinner = chckbxattackspinners.isSelected();
  2283.                 spendwhenpoints = Integer.parseInt(spendwhen.getText());
  2284.                 if (pickupArrows) {
  2285.                     if (game.getCurrentTab() != Game.TAB_EQUIPMENT)
  2286.                         game.openTab(Game.TAB_EQUIPMENT);
  2287.                     arrowID = equipment.getItem(Equipment.AMMO).getID();
  2288.                 }
  2289.                 if (DBaxe) {
  2290.                     if (game.getCurrentTab() != Game.TAB_EQUIPMENT)
  2291.                         game.openTab(Game.TAB_EQUIPMENT);
  2292.                     oldID = equipment.getItem(Equipment.WEAPON).getID();
  2293.                 }
  2294.                 usePray = chckbxUseQuickPrayer.isSelected();
  2295.                 if (chckbxUseSpecialAttack.isSelected()) {
  2296.                     try {
  2297.                         specialPercent = Integer.parseInt(specialtxt.getText());
  2298.                     } catch (Exception check) {
  2299.                         specialPercent = 0;
  2300.                     }
  2301.                 } else {
  2302.                     specialPercent = 0;
  2303.                 }
  2304.                 for (int i = 0; i < jobmodel.getSize(); i++) {
  2305.                     int index = 0;
  2306.                     for (int j = 0; j < jobsStrings.length; j++)
  2307.                         if (jobsStrings[j].equals(jobmodel.get(i).toString()))
  2308.                             index = j;
  2309.                     jobQ.add(new Job(jobmodel.get(i).toString(),
  2310.                             jobsPoints[index]));
  2311.                    
  2312.                 }
  2313.                 for (int i = 0; i < m.getSize(); i++) {
  2314.                     antibanQ.add(m.get(i).toString());
  2315.                 }
  2316.                 int i = comboBox_2.getSelectedIndex();
  2317.                 log("" + i);
  2318.                 if (i == 0) {
  2319.                     plankID = 14315;
  2320.                     boatArea = new RSArea(2660, 2638, 2663, 2643);
  2321.                     Squire = 3802;
  2322.                 } else if (i == 1) {
  2323.                     plankID = 25631;
  2324.                     boatArea = new RSArea(2638, 2642, 2641, 2647);
  2325.                     Squire = 6140;
  2326.                 } else {
  2327.                     plankID = 25632;
  2328.                     boatArea = new RSArea(2632, 2649, 2635, 2654);
  2329.                     Squire = 6141;
  2330.                 }
  2331.                 dispose();
  2332.             }
  2333.             if (e.getSource() == btnAddJob) {
  2334.                 jobmodel.addElement(comboBox.getSelectedItem());
  2335.             }
  2336.                    
  2337.             if (e.getSource() == btnDelJob) {
  2338.                 jobmodel.removeElement(comboBox.getSelectedItem());
  2339.             }
  2340.        
  2341.             if (e.getSource() == btnRemove) {
  2342.                 if (table.getSelectedRow() != -1)
  2343.                     model.removeRow(table.getSelectedRow());
  2344.             }
  2345.             if (e.getSource() == btnAddAntiban) {
  2346.                 m.addElement(comboBox_1.getSelectedItem());
  2347.             }
  2348.             if (e.getSource() == btnAddBreak) {
  2349.                 model.addRow(new Object[]{textField.getText(),
  2350.                         textField_1.getText()});
  2351.             }
  2352.            
  2353.         }
  2354.  
  2355.         double version = 1.0;
  2356.         private JTextField specialtxt;
  2357.         private JTextField spendwhen;
  2358.         private JButton btnStartScript;
  2359.         private JCheckBox chckbxUseSpecialAttack;
  2360.         private JCheckBox chckbxUseQuickPrayer;
  2361.         private JCheckBox chckbxAttackPortals;
  2362.         private JComboBox comboBox_2;
  2363.         private JCheckBox chckbxattackspinners;
  2364.  
  2365.     }
  2366.  
  2367. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement