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

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 53.70 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import java.awt.Color;
  2. import java.awt.Font;
  3. import java.awt.Graphics;
  4. import java.awt.Point;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.io.BufferedReader;
  8. import java.io.InputStreamReader;
  9. import java.net.URL;
  10. import java.util.ArrayList;
  11. import java.util.LinkedList;
  12. import java.util.Map;
  13.  
  14. import javax.swing.DefaultComboBoxModel;
  15. import javax.swing.DefaultListModel;
  16. import javax.swing.JButton;
  17. import javax.swing.JCheckBox;
  18. import javax.swing.JComboBox;
  19. import javax.swing.JFrame;
  20. import javax.swing.JLabel;
  21. import javax.swing.JList;
  22. import javax.swing.JPanel;
  23. import javax.swing.JScrollPane;
  24. import javax.swing.JTabbedPane;
  25. import javax.swing.JTable;
  26. import javax.swing.JTextField;
  27. import javax.swing.ListSelectionModel;
  28. import javax.swing.SwingConstants;
  29. import javax.swing.UIManager;
  30. import javax.swing.border.EmptyBorder;
  31. import javax.swing.border.LineBorder;
  32. import javax.swing.border.TitledBorder;
  33. import javax.swing.table.DefaultTableModel;
  34.  
  35. import org.rsbot.accessors.Node;
  36. import org.rsbot.accessors.RSNPCNode;
  37. import org.rsbot.bot.Bot;
  38. import org.rsbot.bot.input.CanvasWrapper;
  39. import org.rsbot.event.listeners.PaintListener;
  40. import org.rsbot.script.Calculations;
  41. import org.rsbot.script.Methods;
  42. import org.rsbot.script.Script;
  43. import org.rsbot.script.ScriptManifest;
  44. import org.rsbot.script.wrappers.RSArea;
  45. import org.rsbot.script.wrappers.RSInterface;
  46. import org.rsbot.script.wrappers.RSInterfaceChild;
  47. import org.rsbot.script.wrappers.RSItemTile;
  48. import org.rsbot.script.wrappers.RSNPC;
  49. import org.rsbot.script.wrappers.RSObject;
  50. import org.rsbot.script.wrappers.RSPlayer;
  51. import org.rsbot.script.wrappers.RSTile;
  52.  
  53. /**
  54.  * Created by IntelliJ IDEA. User: Bool Date: 30-okt-2009 Time: 23:39:10
  55.  */
  56. @ScriptManifest(authors = { "Bool" }, category = "Combat", name = "BPestControlV2", version = 2.0, description = "<html><body style=\"font-family: Arial; padding: 10px;\">Select your account and press OK to show the GUI.</body></html>")
  57. public class BPestControlV2 extends Script implements PaintListener {
  58.         ScriptManifest sm = getClass().getAnnotation(ScriptManifest.class);
  59.         double version = sm.version();
  60.  
  61.         class animationChecker implements Runnable {
  62.                 public void run() {
  63.                         while (isActive) {
  64.                                 if (getMyPlayer().getAnimation() != -1) {
  65.                                         lastAniChange = System.currentTimeMillis();
  66.                                 }
  67.                                 try {
  68.                                         Thread.sleep(500);
  69.                                 } catch (Exception ignored) {
  70.                                 }
  71.                         }
  72.                 }
  73.  
  74.         }
  75.  
  76.         class BGUI extends JFrame implements ActionListener {
  77.                 private static final long serialVersionUID = 1L;
  78.                 private JPanel contentPane;
  79.                 private JTabbedPane tabbedPane;
  80.                 private JTable table;
  81.                 private JTextField textField;
  82.                 private JTextField textField_1;
  83.                 private JButton btnAddBreak;
  84.                 private DefaultTableModel model;
  85.                 private DefaultListModel jobmodel;
  86.  
  87.                 private JButton btnAddAntiban;
  88.                 private JComboBox comboBox_1;
  89.                 private JList list_1;
  90.                 private JButton btnAddJob;
  91.                 private JList list;
  92.                 private JComboBox comboBox;
  93.  
  94.                 public BGUI() {
  95.                         initGUI();
  96.                 }
  97.  
  98.                 private void initGUI() {
  99.                         setAlwaysOnTop(true);
  100.                         setResizable(false);
  101.                         try {
  102.                                 UIManager.setLookAndFeel(UIManager
  103.                                                 .getSystemLookAndFeelClassName());
  104.                         } catch (Exception ignored) {
  105.                         }
  106.                         setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  107.                         setBounds(100, 100, 450, 288);
  108.                         contentPane = new JPanel();
  109.                         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  110.                         setContentPane(contentPane);
  111.                         contentPane.setLayout(null);
  112.                         tabbedPane = new JTabbedPane(SwingConstants.LEFT);
  113.                         tabbedPane.setBounds(10, 10, 414, 218);
  114.                         contentPane.add(tabbedPane);
  115.  
  116.                         final JPanel panel = new JPanel();
  117.                         tabbedPane.addTab("Main", null, panel, null);
  118.  
  119.                         btnStartScript = new JButton("Start script");
  120.                         btnStartScript.addActionListener(this);
  121.                         btnStartScript.setBounds(327, 234, 97, 23);
  122.                         contentPane.add(btnStartScript);
  123.                         panel.setLayout(null);
  124.  
  125.                         final JPanel panel_2 = new JPanel();
  126.                         tabbedPane.addTab("Antiban", null, panel_2, null);
  127.  
  128.                         chckbxUseSpecialAttack = new JCheckBox("Use special attack");
  129.                         chckbxUseSpecialAttack.setBounds(10, 10, 126, 17);
  130.                         panel.add(chckbxUseSpecialAttack);
  131.  
  132.                         chckbxUseQuickPrayer = new JCheckBox("Use quick prayer");
  133.                         chckbxUseQuickPrayer.setBounds(10, 27, 126, 17);
  134.                         panel.add(chckbxUseQuickPrayer);
  135.  
  136.                         comboBox = new JComboBox();
  137.                         comboBox.setModel(new DefaultComboBoxModel(jobsStrings));
  138.                         comboBox.setBounds(10, 50, 126, 24);
  139.                         panel.add(comboBox);
  140.  
  141.                         btnAddJob = new JButton("Add Job");
  142.                         btnAddJob.setBounds(20, 80, 103, 23);
  143.                         btnAddJob.addActionListener(this);
  144.                         panel.add(btnAddJob);
  145.  
  146.                         final JScrollPane scrollPane = new JScrollPane();
  147.                         scrollPane.setBounds(180, 10, 126, 193);
  148.                         panel.add(scrollPane);
  149.  
  150.                         jobmodel = new DefaultListModel();
  151.                         list = new JList(jobmodel);
  152.                         scrollPane.setViewportView(list);
  153.                         list.setBorder(new TitledBorder(null, "", TitledBorder.LEADING,
  154.                                         TitledBorder.TOP, null, null));
  155.  
  156.                         final JPanel panel_7 = new JPanel();
  157.                         tabbedPane.addTab("Break handler", null, panel_7, null);
  158.                         panel_2.setLayout(null);
  159.                         m = new DefaultListModel();
  160.                         list_1 = new JList(m);
  161.                         list_1.setBorder(new LineBorder(new Color(0, 0, 0)));
  162.                         list_1.setBounds(10, 10, 307, 164);
  163.                         panel_2.add(list_1);
  164.  
  165.                         btnAddAntiban = new JButton("Add antiban");
  166.                         btnAddAntiban.addActionListener(this);
  167.                         btnAddAntiban.setBounds(10, 180, 97, 23);
  168.                         panel_2.add(btnAddAntiban);
  169.  
  170.                         comboBox_1 = new JComboBox();
  171.                         comboBox_1.setModel(new DefaultComboBoxModel(new String[] {
  172.                                         "rotate compass", "move mouse",
  173.                                         "move mouse and rotate compass", "rest",
  174.                                         "right click object", "right click npc",
  175.                                         "right click player" }));
  176.                         comboBox_1.setBounds(113, 180, 204, 23);
  177.                         panel_2.add(comboBox_1);
  178.                         panel_7.setLayout(null);
  179.  
  180.                         table = new JTable();
  181.                         table.setBorder(new LineBorder(new Color(0, 0, 0)));
  182.                         table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
  183.                         table.setBounds(10, 10, 301, 164);
  184.                         model = new DefaultTableModel();
  185.                         table.setModel(model);
  186.                         model.addColumn("");
  187.                         model.addColumn("");
  188.                         panel_7.add(table);
  189.  
  190.                         btnAddBreak = new JButton("Add break");
  191.                         btnAddBreak.addActionListener(this);
  192.                         btnAddBreak.setBounds(10, 180, 89, 23);
  193.                         panel_7.add(btnAddBreak);
  194.  
  195.                         final JLabel lblBreakFor = new JLabel("Break for");
  196.                         lblBreakFor.setBounds(105, 183, 52, 16);
  197.                         panel_7.add(lblBreakFor);
  198.  
  199.                         textField = new JTextField();
  200.                         textField.setBounds(158, 181, 27, 21);
  201.                         panel_7.add(textField);
  202.                         textField.setColumns(10);
  203.  
  204.                         final JLabel lblAfter = new JLabel("after ");
  205.                         lblAfter.setBounds(190, 183, 27, 16);
  206.                         panel_7.add(lblAfter);
  207.  
  208.                         textField_1 = new JTextField();
  209.                         textField_1.setBounds(218, 181, 26, 21);
  210.                         panel_7.add(textField_1);
  211.                         textField_1.setColumns(10);
  212.  
  213.                         btnRemove = new JButton("Delete");
  214.                         btnRemove.addActionListener(this);
  215.                         btnRemove.setBounds(248, 181, 65, 23);
  216.                         panel_7.add(btnRemove);
  217.  
  218.                         comboBox_2 = new JComboBox();
  219.                         comboBox_2.setModel(new DefaultComboBoxModel(new String[] {
  220.                                         "Novice", "Intermediate", "Veteran" }));
  221.                         comboBox_2.setBounds(10, 181, 141, 22);
  222.                         panel.add(comboBox_2);
  223.  
  224.                         chckbxAttackPortals = new JCheckBox("Attack portals");
  225.                         chckbxAttackPortals.setBounds(10, 148, 105, 17);
  226.                         panel.add(chckbxAttackPortals);
  227.  
  228.                         specialtxt = new JTextField();
  229.                         specialtxt.setText("  %");
  230.                         specialtxt.setBounds(137, 10, 31, 19);
  231.                         panel.add(specialtxt);
  232.                         specialtxt.setColumns(10);
  233.                         chckbxattackspinners = new JCheckBox("Attack spinners");
  234.                         chckbxattackspinners.setBounds(10, 160, 113, 17);
  235.                         panel.add(chckbxattackspinners);
  236.                 }
  237.  
  238.                 DefaultListModel m;
  239.                 private JButton btnRemove;
  240.  
  241.                 public void actionPerformed(final ActionEvent e) {
  242.                         if (e.getSource() == btnStartScript) {
  243.                                 start = true;
  244.                                 attackPortals = chckbxAttackPortals.isSelected();
  245.                                 attackSpinner = chckbxattackspinners.isSelected();
  246.                                 if (pickupArrows) {
  247.                                         if (getCurrentTab() != TAB_EQUIPMENT)
  248.                                                 openTab(TAB_EQUIPMENT);
  249.                                         arrowID = getEquipmentArray()[13];
  250.                                 }
  251.                                 if (DBaxe) {
  252.                                         if (getCurrentTab() != TAB_EQUIPMENT)
  253.                                                 openTab(TAB_EQUIPMENT);
  254.                                         oldID = getEquipmentArray()[3];
  255.                                 }
  256.                                 usePray = chckbxUseQuickPrayer.isSelected();
  257.                                 if (chckbxUseSpecialAttack.isSelected()) {
  258.                                         try {
  259.                                                 specialPercent = Integer.parseInt(specialtxt.getText());
  260.                                         } catch (Exception check) {
  261.                                                 specialPercent = 0;
  262.                                         }
  263.                                 } else {
  264.                                         specialPercent = 0;
  265.                                 }
  266.                                 for (int i = 0; i < jobmodel.getSize(); i++) {
  267.                                         int index = 0;
  268.                                         for (int j = 0; j < jobsStrings.length; j++)
  269.                                                 if (jobsStrings[j].equals(jobmodel.get(i).toString()))
  270.                                                         index = j;
  271.                                         jobQ.add(new Job(jobmodel.get(i).toString(),
  272.                                                         jobsPoints[index]));
  273.                                 }
  274.                                 for (int i = 0; i < m.getSize(); i++) {
  275.                                         antibanQ.add(m.get(i).toString());
  276.                                 }
  277.                                 int i = comboBox_2.getSelectedIndex();
  278.                                 log("" + i);
  279.                                 if (i == 0) {
  280.                                         plankID = 14315;
  281.                                         boatArea = new RSArea(2660, 2638, 3, 5);
  282.                                         Squire = 3802;
  283.                                 } else if (i == 1) {
  284.                                         plankID = 25631;
  285.                                         boatArea = new RSArea(2638, 2642, 3, 5);
  286.                                         Squire = 6140;
  287.                                 } else {
  288.                                         plankID = 25632;
  289.                                         boatArea = new RSArea(2632, 2649, 3, 5);
  290.                                         Squire = 6141;
  291.                                 }
  292.                                 dispose();
  293.                         }
  294.                         if (e.getSource() == btnAddJob) {
  295.                                 jobmodel.addElement(comboBox.getSelectedItem());
  296.                         }
  297.                         if (e.getSource() == btnRemove) {
  298.                                 if (table.getSelectedRow() != -1)
  299.                                         model.removeRow(table.getSelectedRow());
  300.                         }
  301.                         if (e.getSource() == btnAddAntiban) {
  302.                                 m.addElement(comboBox_1.getSelectedItem());
  303.                         }
  304.                         if (e.getSource() == btnAddBreak) {
  305.                                 model.addRow(new Object[] { textField.getText(),
  306.                                                 textField_1.getText() });
  307.                         }
  308.                 }
  309.  
  310.                 double version = 1.0;
  311.                 private JTextField specialtxt;
  312.                 private JButton btnStartScript;
  313.                 private JCheckBox chckbxUseSpecialAttack;
  314.                 private JCheckBox chckbxUseQuickPrayer;
  315.                 private JCheckBox chckbxAttackPortals;
  316.                 private JComboBox comboBox_2;
  317.                 private JCheckBox chckbxattackspinners;
  318.  
  319.         }
  320.  
  321.         private class Job {
  322.  
  323.                 private final String n;
  324.                 private boolean done = false;
  325.                 public int points;
  326.  
  327.                 public Job(final String name, int points) {
  328.                         n = name;
  329.                         this.points = points;
  330.                 }
  331.  
  332.                 public final String getName() {
  333.                         return n;
  334.                 }
  335.  
  336.                 public boolean isFinished() {
  337.                         return done;
  338.                 }
  339.  
  340.                 public String toString() {
  341.                         return "Name " + getName();
  342.                 }
  343.         }
  344.  
  345.         private class Portal {
  346.  
  347.                 private final RSTile Location;
  348.                 private final String Name;
  349.                 private final RSTile gateLoc;
  350.  
  351.                 public Portal(final RSTile t, final String name, final RSTile g) {
  352.                         Location = t;
  353.                         Name = name;
  354.                         gateLoc = g;
  355.                 }
  356.  
  357.                 public boolean equals(final Portal p) {
  358.                         return p.getLocation().getX() == getLocation().getX()
  359.                                         && p.getLocation().getY() == getLocation().getY();
  360.                 }
  361.  
  362.                 public RSArea getArea() {
  363.                         RSArea a = null;
  364.                         if (getName().equals("E")) {
  365.                                 a = new RSArea(voidLoc.getX() + 24, voidLoc.getY() - 20, 3, 5);
  366.                         } else if (getName().equals("W")) {
  367.                                 a = new RSArea(voidLoc.getX() - 25, voidLoc.getY() - 15, 4, 3);
  368.                         } else if (getName().contains("SE")) {
  369.                                 a = new RSArea(voidLoc.getX() + 16, voidLoc.getY() - 34, 4, 3);
  370.                         } else if (getName().contains("SW")) {
  371.                                 a = new RSArea(voidLoc.getX() - 8, voidLoc.getY() - 35, 5, 3);
  372.                         }
  373.                         return a;
  374.                 }
  375.  
  376.                 public RSObject getGate() {
  377.                         return getObjectAt(getGateLocation());
  378.                 }
  379.  
  380.                 public RSTile getGateLocation() {
  381.                         return gateLoc;
  382.                 }
  383.  
  384.                 public RSTile getLocation() {
  385.                         return Location;
  386.                 }
  387.  
  388.                 public String getName() {
  389.                         return Name;
  390.                 }
  391.  
  392.                 public RSNPC getNPC() {
  393.                         if (!attackPortals) {
  394.                                 return null;
  395.                         }
  396.                         final RSNPC portal = getNearestNPCByName("Portal");
  397.                         if (portal != null) {
  398.                                 if (portal.isInCombat()) {
  399.                                         return portal;
  400.                                 } else {
  401.                                         return null;
  402.                                 }
  403.                         }
  404.                         return null;
  405.                 }
  406.  
  407.                 public RSTile getRandom() {
  408.                         final RSTile[][] tiles = getArea().getTiles();
  409.                         final int y = random(0, tiles.length - 1);
  410.                         final int x = random(0, tiles[y].length - 1);
  411.                         try {
  412.                                 return tiles[x][y];
  413.                         } catch (final Exception e) {
  414.                                 return getRandom();
  415.                         }
  416.                 }
  417.  
  418.                 public RSArea getRealArea() {
  419.                         RSArea a = null;
  420.                         if (getName().equals("E")) {
  421.                                 a = new RSArea(voidLoc.getX() + 16, voidLoc.getY() - 23, 14, 14);
  422.                         } else if (getName().equals("W")) {
  423.                                 a = new RSArea(voidLoc.getX() - 30, voidLoc.getY() - 24, 16, 19);
  424.                         } else if (getName().contains("SE")) {
  425.                                 a = new RSArea(voidLoc.getX(), voidLoc.getY() - 45, 28, 21);
  426.                         } else if (getName().contains("SW")) {
  427.                                 a = new RSArea(voidLoc.getX() - 17, voidLoc.getY() - 44, 17, 20);
  428.                         }
  429.                         return a;
  430.                 }
  431.  
  432.                 public boolean isGateOpen() {
  433.                         return getGate() == null || getGate().getID() > 14240;
  434.                 }
  435.  
  436.                 public boolean isOpen() {
  437.                         try {
  438.                                 if (getName().equals("W")) {
  439.                                         if (Integer.parseInt(getInterface(408, 13).getText()) < 10) {
  440.                                                 return false;
  441.                                         }
  442.                                 }
  443.                                 if (getName().equals("E")) {
  444.                                         if (Integer.parseInt(getInterface(408, 14).getText()) < 10) {
  445.                                                 return false;
  446.                                         }
  447.                                 }
  448.                                 if (getName().equals("SE")) {
  449.                                         if (Integer.parseInt(getInterface(408, 15).getText()) < 10) {
  450.                                                 return false;
  451.                                         }
  452.                                 }
  453.                                 if (getName().equals("SW")) {
  454.                                         if (Integer.parseInt(getInterface(408, 16).getText()) < 10) {
  455.                                                 return false;
  456.                                         }
  457.                                 }
  458.                         } catch (final Exception e) {
  459.                                 return false;
  460.                         }
  461.                         return true;
  462.                 }
  463.  
  464.                 private void openGate() {
  465.                         while (inPest() && !isGateOpen()) {
  466.                                 if (getMyPlayer().isMoving()) {
  467.                                         try {
  468.                                                 Thread.sleep(random(500, 600));
  469.                                         } catch (Exception e) {
  470.  
  471.                                         }
  472.                                         continue;
  473.                                 }
  474.                                 final Point p = Calculations.tileToScreen(getGateLocation());
  475.                                 if (!pointOnScreen(p)) {
  476.                                         walkTileMM(getGateLocation());
  477.                                         try {
  478.                                                 Thread.sleep(random(500, 700));
  479.                                         } catch (InterruptedException ignored) {
  480.                                         }
  481.                                         continue;
  482.                                 }
  483.                                 doAction(p, "Open");
  484.                         }
  485.                 }
  486.  
  487.                 public void walkTo() {
  488.                         final Portal p = getNearestPortal();
  489.                         boolean died = false;
  490.                         final RSNPC npc = getNearestNPCByID(squire);
  491.                         if (npc != null) {
  492.                                 if (distanceTo(npc) < 10) {
  493.                                         died = true;
  494.                                 }
  495.                         }
  496.                         boolean atDoor = false;
  497.                         while (inPest() && distanceTo(getLocation()) > 10 && isOpen()) {
  498.                                 if (getMyPlayer().isInCombat()
  499.                                                 && getMyPlayer().getHPPercent() < 2
  500.                                                 && distanceTo(getNearestNPCByID(squire)) > 15) {
  501.                                         return;
  502.                                 }
  503.                                 if (died) {
  504.                                         try {
  505.                                                 enablePrayer();
  506.                                                 Thread.sleep(random(300, 800));
  507.                                                 setRun(true);
  508.                                                 Thread.sleep(random(300, 800));
  509.                                                 doDragonBattleAxe();
  510.                                                 Thread.sleep(random(300, 800));
  511.                                         } catch (Exception e) {
  512.                                         }
  513.                                         if (!atDoor) {
  514.                                                 walkPath(genPath(getGateLocation()));
  515.                                                 if (!isGateOpen() && tileOnScreen(getGateLocation())) {
  516.                                                         openGate();
  517.                                                         if (isGateOpen()) {
  518.                                                                 atDoor = true;
  519.                                                         }
  520.                                                 }
  521.                                                 if (distanceTo(getGateLocation()) < 10 && isGateOpen()) {
  522.                                                         atDoor = true;
  523.                                                 }
  524.                                         }
  525.                                         if (atDoor) {
  526.                                                 walkPath(genPath(getRandom()));
  527.                                         }
  528.                                 } else if (p.getName().equals("E") && getName().equals("W")) {
  529.                                         while (inPest() && getNearestPortal().getName().equals("E")) {
  530.                                                 final Portal se = getPortalByName("SE");
  531.                                                 if (!walkPath(genPath(se.getRandom()))) {
  532.                                                         wait(400, 700);
  533.                                                 }
  534.                                         }
  535.                                         while (inPest()
  536.                                                         && getNearestPortal().getName().equals("SE")) {
  537.                                                 final Portal sw = getPortalByName("SW");
  538.                                                 if (!walkPath(genPath(sw.getRandom()))) {
  539.                                                         wait(400, 700);
  540.                                                 }
  541.                                         }
  542.                                 } else if (p.getName().equals("W") && getName().equals("E")) {
  543.                                         while (inPest() && getNearestPortal().getName().equals("W")) {
  544.                                                 final Portal sw = getPortalByName("SW");
  545.                                                 if (!walkPath(genPath(sw.getRandom()))) {
  546.                                                         wait(400, 700);
  547.                                                 }
  548.                                         }
  549.                                         while (inPest()
  550.                                                         && getNearestPortal().getName().equals("SW")) {
  551.                                                 final Portal se = getPortalByName("SE");
  552.                                                 if (!walkPath(genPath(se.getRandom()))) {
  553.                                                         wait(400, 700);
  554.                                                 }
  555.                                         }
  556.                                         while (!walkPath(genPath(getRandom()))) {
  557.                                                 wait(400, 700);
  558.                                         }
  559.                                 } else if (p.getName().equals("E") && getName().equals("SE")) {
  560.                                         if (!walkPath(genPath(getLocation()))) {
  561.                                                 wait(400, 700);
  562.                                         }
  563.                                 } else if (p.getName().equals("SE") && getName().equals("E")) {
  564.                                         while (!walkPath(genPath(getLocation()))) {
  565.                                                 wait(400, 700);
  566.                                         }
  567.                                 } else if (p.getName().equals("E") && getName().equals("SW")) {
  568.                                         while (inPest() && getNearestPortal().getName().equals("E")) {
  569.                                                 final Portal se = getPortalByName("SE");
  570.                                                 if (!walkPath(genPath(se.getRandom()))) {
  571.                                                         wait(400, 700);
  572.                                                 }
  573.                                         }
  574.                                         while (!walkPath(genPath(getRandom()))) {
  575.                                                 wait(400, 700);
  576.                                         }
  577.                                 } else if (p.getName().equals("SW") && getName().equals("E")) {
  578.                                         while (inPest()
  579.                                                         && getNearestPortal().getName().equals("SW")) {
  580.                                                 final Portal se = getPortalByName("SE");
  581.                                                 if (!walkPath(genPath(se.getRandom()))) {
  582.                                                         wait(400, 700);
  583.                                                 }
  584.                                         }
  585.                                         while (!walkPath(genPath(getRandom()))) {
  586.                                                 wait(400, 700);
  587.                                         }
  588.                                 } else if (p.getName().equals("W") && getName().equals("SW")) {
  589.  
  590.                                         if (!walkPath(genPath(getLocation()))) {
  591.                                                 wait(400, 700);
  592.                                         }
  593.                                 } else if (p.getName().equals("SW") && getName().equals("W")) {
  594.  
  595.                                         if (!walkPath(genPath(getLocation()))) {
  596.                                                 wait(400, 700);
  597.                                         }
  598.                                 } else if (p.getName().equals("SE") && getName().equals("W")) {
  599.                                         while (inPest()
  600.                                                         && getNearestPortal().getName().equals("SE")) {
  601.                                                 final Portal se = getPortalByName("SW");
  602.                                                 if (!walkPath(genPath(se.getRandom()))) {
  603.                                                         wait(400, 700);
  604.                                                 }
  605.                                         }
  606.                                         while (!walkPath(genPath(getRandom()))) {
  607.                                                 wait(400, 700);
  608.                                         }
  609.                                 } else if (p.getName().equals("W") && getName().equals("SE")) {
  610.  
  611.                                         while (inPest() && getNearestPortal().getName().equals("W")) {
  612.                                                 final Portal se = getPortalByName("SW");
  613.                                                 if (!walkPath(genPath(se.getRandom()))) {
  614.                                                         wait(400, 700);
  615.                                                 }
  616.                                         }
  617.                                         while (!walkPath(genPath(getRandom()))) {
  618.                                                 wait(400, 700);
  619.                                         }
  620.                                 } else if (p.getName().equals("SW") && getName().equals("SE")) {
  621.  
  622.                                         if (!walkPath(genPath(getLocation()))) {
  623.                                                 wait(400, 700);
  624.                                         }
  625.                                 } else if (p.getName().equals("SE") && getName().equals("SW")) {
  626.                                         if (!walkPath(genPath(getLocation()))) {
  627.                                                 wait(400, 700);
  628.                                         }
  629.                                 }
  630.                         }
  631.                 }
  632.  
  633.                 public void wait(int min, int max) {
  634.                         try {
  635.                                 Thread.sleep(random(min, max));
  636.                         } catch (Exception ignored) {
  637.                         }
  638.                 }
  639.         }
  640.  
  641.         private final LinkedList<Job> jobQ = new LinkedList<Job>();
  642.         private final LinkedList<Portal> portalQ = new LinkedList<Portal>();
  643.         private final LinkedList<Break> breakQ = new LinkedList<Break>();
  644.         private final ArrayList<String> antibanQ = new ArrayList<String>();
  645.  
  646.         private Portal current;
  647.         private boolean start = false;
  648.  
  649.         private boolean attackPortals = false;
  650.  
  651.         private boolean usePray = false;
  652.         private boolean played = false;
  653.         private boolean got250 = false;
  654.         private boolean attackSpinner = false;
  655.         private boolean DBaxe = false;
  656.         private boolean pickupArrows = false;
  657.         private RSTile[] path;
  658.         private final int Interface_250 = 213;
  659.         private int plankID = 14315;
  660.         private final int squire = 3781;
  661.         private int Squire;
  662.         private int failsafe = 0;
  663.         private int points = 0;
  664.         private int specialPercent = 0;
  665.         private int arrowID = 0;
  666.         private int oldPoints = 0;
  667.         private int gainedPoints = 0;
  668.  
  669.         private int lost = 0;
  670.         private int won = 0;
  671.         private RSArea boatArea = null;
  672.         private RSTile voidLoc = null;
  673.         long lastNPC = 0;
  674.  
  675.         private long lastAniChange = 0;
  676.  
  677.         private long startTime = 0;
  678.  
  679.         private long gc = 0;
  680.         public final int ROTATE_COMPASS = 0;
  681.         public final int MOVE_MOUSE = 1;
  682.         public final int MOVE_MOUSE_AND_ROTATE_COMPASS = 2;
  683.         public final int RIGHT_CLICK_OBJECT = 3;
  684.         public final int RIGHT_CLICK_NPC = 4;
  685.         public final int RIGHT_CLICK_PLAYER = 5;
  686.         private final String[] jobsStrings = new String[] { "Attack", "Defence",
  687.                         "Magic", "Prayer", "Strength", "Ranged", "Hitpoints", "Top",
  688.                         "Robe", "Range Helm", "Melee Helm", "Mage Helm", "Glove" };
  689.         private final int[] jobsPoints = new int[] { 100, 100, 100, 100, 100, 100,
  690.                         100, 250, 250, 200, 200, 200, 150 };
  691.         private int width = 0;
  692.  
  693.         private int height = 0;
  694.  
  695.         private Break curBreak;
  696.  
  697.         Pathfinder pf;
  698.  
  699.         boolean allJobsFinished() {
  700.                 Job j = null;
  701.                 for (Job job : jobQ) {
  702.                         if (!(j = job).isFinished()) {
  703.                                 break;
  704.                         }
  705.                 }
  706.  
  707.                 return j == null;
  708.         }
  709.  
  710.         public void performAntiban(String antiban) throws InterruptedException {
  711.                 log("Doing : " + antiban.toLowerCase().replace('_', ' '));
  712.                 int ab = AntibanStringToInteger(antiban);
  713.                 switch (ab) {
  714.                 case ROTATE_COMPASS:
  715.                         char dir = 37;
  716.                         if (random(0, 3) == 2)
  717.                                 dir = 39;
  718.                         Bot.getInputManager().pressKey(dir);
  719.                         Thread.sleep(random(500, 2000));
  720.                         Bot.getInputManager().releaseKey(dir);
  721.                         break;
  722.                 case MOVE_MOUSE:
  723.                         moveMouse(random(0, CanvasWrapper.getGameWidth()), random(0,
  724.                                         CanvasWrapper.getGameHeight()));
  725.                         break;
  726.                 case MOVE_MOUSE_AND_ROTATE_COMPASS:
  727.                         Thread camera = new Thread() {
  728.                                 @Override
  729.                                 public void run() {
  730.                                         char dir = 37;
  731.                                         if (random(0, 3) == 2)
  732.                                                 dir = 39;
  733.                                         Bot.getInputManager().pressKey(dir);
  734.                                         try {
  735.                                                 Thread.sleep(random(500, 2000));
  736.                                         } catch (InterruptedException e) {
  737.                                                 e.printStackTrace();
  738.                                         }
  739.                                         Bot.getInputManager().releaseKey(dir);
  740.                                 }
  741.                         };
  742.  
  743.                         Thread mouse = new Thread() {
  744.                                 @Override
  745.                                 public void run() {
  746.                                         moveMouse(random(0, CanvasWrapper.getGameWidth()), random(
  747.                                                         0, CanvasWrapper.getGameHeight()));
  748.                                 }
  749.                         };
  750.                         camera.start();
  751.                         mouse.start();
  752.                         while (camera.isAlive() || mouse.isAlive())
  753.                                 wait(random(100, 300));
  754.                         break;
  755.                 case RIGHT_CLICK_OBJECT:
  756.                         RSObject obj = getObjOnScreen();
  757.                         if (obj != null) {
  758.                                 clickMouse(Calculations.tileToScreen(obj.getLocation()), false);
  759.                                 Thread.sleep(random(500, 2000));
  760.                                 while (isMenuOpen()) {
  761.                                         moveMouseRandomly(20);
  762.                                 }
  763.                         }
  764.                         break;
  765.                 case RIGHT_CLICK_NPC:
  766.                         RSNPC npc = getNPCOnScreen();
  767.                         if (npc != null) {
  768.                                 clickMouse(npc.getScreenLocation(), false);
  769.                                 Thread.sleep(random(500, 2000));
  770.                                 while (isMenuOpen()) {
  771.                                         moveMouseRandomly(20);
  772.                                 }
  773.                         }
  774.                         break;
  775.                 case RIGHT_CLICK_PLAYER:
  776.                         RSPlayer player = getPlayerOnScreen();
  777.                         if (player != null) {
  778.                                 clickMouse(player.getScreenLocation(), false);
  779.                                 Thread.sleep(random(500, 2000));
  780.                                 while (isMenuOpen()) {
  781.                                         moveMouseRandomly(20);
  782.                                 }
  783.                         }
  784.                         break;
  785.                 default:
  786.                         break;
  787.                 }
  788.         }
  789.  
  790.         public RSObject getObjOnScreen() {
  791.                 ArrayList<RSObject> result = new ArrayList<RSObject>();
  792.                 for (int x = 0; x < 104; x++) {
  793.                         for (int y = 0; y < 104; y++) {
  794.                                 RSObject obj = getObjectAt(x + Bot.getClient().getBaseX(), y
  795.                                                 + Bot.getClient().getBaseY());
  796.                                 if (obj != null) {
  797.                                         Point p = Calculations.tileToScreen(obj.getLocation());
  798.                                         if (p.x != -1)
  799.                                                 result.add(obj);
  800.                                 }
  801.                         }
  802.                 }
  803.                 if (result.size() == 0)
  804.                         return null;
  805.                 return result.get(random(0, result.size()));
  806.         }
  807.  
  808.         public RSNPC getNPCOnScreen() {
  809.                 final int[] validNpcs = Bot.getClient().getRSNPCIndexArray();
  810.                 final ArrayList<RSNPC> p = new ArrayList<RSNPC>();
  811.                 for (final int element : validNpcs) {
  812.                         Node node = Calculations.findNodeByID(Bot.getClient().getRSNPCNC(), element);
  813.                         if (node == null || !(node instanceof RSNPCNode)) {
  814.                                 continue;
  815.                         }
  816.                         final RSNPC player = new RSNPC(((RSNPCNode) node).getRSNPC());
  817.                         try {
  818.                                 if (!tileOnScreen(player.getLocation())) {
  819.                                         continue;
  820.                                 }
  821.                                 p.add(player);
  822.                         } catch (final Exception ignored) {
  823.                         }
  824.                 }
  825.                 if (p.size() == 0) {
  826.                         return null;
  827.                 } else if (p.size() == 1) {
  828.                         return p.get(0);
  829.                 }
  830.                 return p.get(random(0, p.size() - 1));
  831.         }
  832.  
  833.         public int AntibanStringToInteger(String a) {
  834.                 if (a.contains("rotate compass"))
  835.                         return ROTATE_COMPASS;
  836.                 else if (a.contains("move mouse"))
  837.                         return MOVE_MOUSE;
  838.                 else if (a.contains("MOVE_MOUSE_AND_ROTATE_COMPASS"
  839.                                 .replaceAll("_", " ").toLowerCase()))
  840.                         return MOVE_MOUSE_AND_ROTATE_COMPASS;
  841.                 else if (a.contains("RIGHT_CLICK_OBJECT".replaceAll("_", " ")
  842.                                 .toLowerCase()))
  843.                         return RIGHT_CLICK_OBJECT;
  844.                 else if (a.contains("RIGHT_CLICK_NPC".replaceAll("_", " ")
  845.                                 .toLowerCase()))
  846.                         return RIGHT_CLICK_NPC;
  847.                 else if (a.contains("RIGHT_CLICK_PLAYER".replaceAll("_", " ")
  848.                                 .toLowerCase()))
  849.                         return RIGHT_CLICK_PLAYER;
  850.                 return -1;
  851.         }
  852.  
  853.         public boolean arrayContains(final String[] array, final String option) {
  854.                 if (array == null) {
  855.                         return false;
  856.                 }
  857.                 for (final String s : array) {
  858.                         if (s.contains(option)) {
  859.                                 return true;
  860.                         }
  861.                 }
  862.                 return false;
  863.         }
  864.  
  865.         boolean atPortal() {
  866.                 for (final Portal p : portalQ) {
  867.                         if (p.getRealArea().contains(getMyPlayer().getLocation())) {
  868.                                 return true;
  869.                         }
  870.                 }
  871.                 return false;
  872.         }
  873.  
  874.         public Break getCurrentBreak() {
  875.                 if ((curBreak == null || curBreak.isDone) && breakQ.size() == 0)
  876.                         return null;
  877.                 if (curBreak == null || curBreak.isDone)
  878.                         curBreak = breakQ.remove();
  879.                 if (curBreak.Time == null)
  880.                         curBreak.init();
  881.                 return curBreak;
  882.         }
  883.  
  884.         boolean clickNPC(final RSNPC n, final String action) {
  885.                 if (!tileOnScreen(n.getLocation())) {
  886.                         while (inPest() && atPortal()
  887.                                         && !walkPath(genPath(n.getLocation()))) {
  888.                                 wait(random(200, 500));
  889.                         }
  890.                 }
  891.                 try {
  892.                         Point p = n.getScreenLocation();
  893.                         while ((p = n.getScreenLocation()) != null && p.x != -1
  894.                                         && getMouseLocation().distance(n.getScreenLocation()) > 8) {
  895.                                 moveMouse(p, 5, 5);
  896.                         }
  897.                         if (!pointOnScreen(getMouseLocation())) {
  898.                                 return false;
  899.                         }
  900.  
  901.                         if (getTopText().contains(action)) {
  902.                                 clickMouse(true);
  903.                         } else if (menuContains(action)) {
  904.                                 clickMouse(false);
  905.                                 return atMenu(action);
  906.                         } else {
  907.                                 return false;
  908.                         }
  909.                 } catch (final Exception ignored) {
  910.                 }
  911.                 return true;
  912.         }
  913.  
  914.         @Override
  915.         public int getMouseSpeed() {
  916.                 return random(5, 7);
  917.         }
  918.  
  919.         void clickRandomPlayer() {
  920.                 RSPlayer p;
  921.                 if ((p = getPlayerOnScreen()) != null) {
  922.                         if (p.getScreenLocation().x != -1 && p.getScreenLocation().y != -1) {
  923.                                 moveMouse(p.getScreenLocation());
  924.                                 clickMouse(false);
  925.                                 wait(random(800, 1000));
  926.                                 moveMouse(random(0, 763), random(0, 503));
  927.                         }
  928.                 }
  929.         }
  930.  
  931.         boolean doAction(final Point p, final String action) {
  932.                 if (p.x == -1 || p.y == -1) {
  933.                         return false;
  934.                 }
  935.                 while (p.x != -1 && getMouseLocation().distance(p) > 8) {
  936.                         moveMouse(p);
  937.                 }
  938.                 if (!pointOnScreen(getMouseLocation())) {
  939.                         return false;
  940.                 }
  941.                 if (getTopText().contains(action)) {
  942.                         clickMouse(true);
  943.                 } else if (menuContains(action)) {
  944.                         clickMouse(false);
  945.                         return atMenu(action);
  946.                 } else {
  947.                         return false;
  948.                 }
  949.                 return true;
  950.         }
  951.  
  952.         void doJob() {
  953.                 final Job j = getJob();
  954.                 if (j == null) {
  955.                         return;
  956.                 }
  957.                 if (j.points == 250 && !got250)
  958.                         return;
  959.                 if (j.points >= points)
  960.                         return;
  961.                 while (!getInterface(267).isValid() || getInterface(267).isValid()
  962.                                 && getInterface(267, 34).getAbsoluteX() < 10) {
  963.                         if (getMyPlayer().getInteracting() != null)
  964.                                 continue;
  965.                         if (getNearestNPCByID(3788) == null) {
  966.                                 walkPath(genPath(new RSTile(2661, 2650)), 2);
  967.                         } else if (distanceTo(getNearestNPCByID(3788)) > 3) {
  968.                                 walkPath(genPath(getNearestNPCByID(3788).getLocation()), 2);
  969.                         }
  970.                         if (clickNPC(getNearestNPCByID(3788), "Exchange")) {
  971.                                 wait(random(800, 1200));
  972.                         } else {
  973.                                 wait(random(300, 700));
  974.                         }
  975.                 }
  976.                 wait(random(800, 1000));
  977.                 int i = 0;
  978.                 boolean skip = false;
  979.                 ;
  980.                 if (j.getName().equals(jobsStrings[i])) {
  981.                         clickMouse(random(188, 223), random(67, 72), true);
  982.                         skip = true;
  983.                 }
  984.                 i++;
  985.                 if (j.getName().equals(jobsStrings[i])) {
  986.                         clickMouse(random(188, 223), random(104, 112), true);
  987.                         skip = true;
  988.                 }
  989.                 i++;
  990.                 if (j.getName().equals(jobsStrings[i])) {
  991.                         clickMouse(random(188, 223), random(144, 151), true);
  992.                         skip = true;
  993.                 }
  994.                 i++;
  995.                 if (j.getName().equals(jobsStrings[i])) {
  996.                         clickMouse(random(188, 223), random(180, 188), true);
  997.                         skip = true;
  998.                 }
  999.                 i++;
  1000.                 if (j.getName().equals(jobsStrings[i])) {
  1001.                         clickMouse(random(406, 444), random(67, 72), true);
  1002.                         skip = true;
  1003.                 }
  1004.                 i++;
  1005.                 if (j.getName().equals(jobsStrings[i])) {
  1006.                         clickMouse(random(406, 444), random(104, 112), true);
  1007.                         skip = true;
  1008.                 }
  1009.                 i++;
  1010.                 if (j.getName().equals(jobsStrings[i])) {
  1011.                         clickMouse(random(406, 444), random(144, 151), true);
  1012.                         skip = true;
  1013.                 }
  1014.                 if (!skip) {
  1015.                         clickMouse(481, 179, true);
  1016.                         wait(random(800, 900));
  1017.                 }
  1018.                 i++;
  1019.                 if (j.getName().equals(jobsStrings[i])) {
  1020.                         clickMouse(random(300, 340), random(111, 119), true);
  1021.                 }
  1022.                 i++;
  1023.                 if (j.getName().equals(jobsStrings[i])) {
  1024.                         clickMouse(random(80, 120), random(150, 155), true);
  1025.                 }
  1026.                 i++;
  1027.                 if (j.getName().equals(jobsStrings[i])) {
  1028.                         clickMouse(random(300, 340), random(190, 197), true);
  1029.                 }
  1030.                 i++;
  1031.  
  1032.                 if (j.getName().equals(jobsStrings[i])) {
  1033.                         clickMouse(random(80, 120), random(188, 193), true);
  1034.                 }
  1035.                 i++;
  1036.                 if (j.getName().equals(jobsStrings[i])) {
  1037.                         clickMouse(random(80, 120), random(225, 234), true);
  1038.                 }
  1039.                 i++;
  1040.                 if (j.getName().equals(jobsStrings[i])) {
  1041.                         clickMouse(random(300, 340), random(151, 156), true);
  1042.                 }
  1043.                 jobQ.remove(j);
  1044.                 wait(random(800, 1000));
  1045.                 clickMouse(random(190, 320), random(285, 320), true);
  1046.                 oldPoints = 0;
  1047.                 played = false;
  1048.                 points = 0;
  1049.                 got250 = false;
  1050.         }
  1051.  
  1052.         @Override
  1053.         public boolean tileOnMap(RSTile tile) {
  1054.                 Point center = tileToMinimap(getLocation());
  1055.                 return tileToMinimap(tile).distance(center) <= 70;
  1056.         }
  1057.  
  1058.         void enablePrayer() {
  1059.                 if (!PrayerEnabled() && usePray) {
  1060.                         clickMouse(random(715, 752), random(60, 80), true);
  1061.                 }
  1062.         }
  1063.  
  1064.         int enterBoat() {
  1065.                 portalQ.clear();
  1066.                 final RSObject o = getPlank();
  1067.                 if (o != null && !onBoat()) {
  1068.                         final RSTile t = o.getLocation();
  1069.                         final Point p = Calculations.tileToScreen(t);
  1070.                         if (p.x == -1 || p.y == -1) {
  1071.                                 walkTileMM(t);
  1072.                         }
  1073.                         if (doAction(p, "Cross")) {
  1074.                                 return random(1000, 1300);
  1075.                         }
  1076.                 }
  1077.                 return random(600, 800);
  1078.         }
  1079.  
  1080.         RSObject getPlank() {
  1081.                 for (int x = 0; x < 104; x++) {
  1082.                         for (int y = 0; y < 104; y++) {
  1083.                                 RSObject obj = getObjectAt(x + Bot.getClient().getBaseX(), y
  1084.                                                 + Bot.getClient().getBaseY());
  1085.                                 if (obj != null && obj.getID() == plankID)
  1086.                                         return obj;
  1087.                         }
  1088.                 }
  1089.                 return null;
  1090.         }
  1091.  
  1092.         void fillPortalList() {
  1093.                 if (portalQ.size() < 1) {
  1094.                         portalQ.add(new Portal(new RSTile(voidLoc.getX() - 26, voidLoc
  1095.                                         .getY() - 15), "W", new RSTile(voidLoc.getX() - 12, voidLoc
  1096.                                         .getY() - 15)));
  1097.                         portalQ.add(new Portal(new RSTile(voidLoc.getX() + 26, voidLoc
  1098.                                         .getY() - 18), "E", new RSTile(voidLoc.getX() + 15, voidLoc
  1099.                                         .getY() - 15)));
  1100.                         portalQ.add(new Portal(new RSTile(voidLoc.getX() + 15, voidLoc
  1101.                                         .getY() - 36), "SE", new RSTile(voidLoc.getX() + 1, voidLoc
  1102.                                         .getY() - 22)));
  1103.                         portalQ.add(new Portal(new RSTile(voidLoc.getX() - 9, voidLoc
  1104.                                         .getY() - 37), "SW", new RSTile(voidLoc.getX() + 1, voidLoc
  1105.                                         .getY() - 22)));
  1106.                 } else {
  1107.                         portalQ.clear();
  1108.                         fillPortalList();
  1109.                 }
  1110.         }
  1111.  
  1112.         RSTile[] genPath(final RSTile t) {
  1113.                 RSTile[] temp = pf.findPath(t);
  1114.                 if (temp != null)
  1115.                         return temp;
  1116.                 RSTile current = getMyPlayer().getLocation();
  1117.                 final ArrayList<RSTile> tiles = new ArrayList<RSTile>();
  1118.                 final ArrayList<RSTile> path = new ArrayList<RSTile>();
  1119.  
  1120.                 while (Methods.distanceBetween(t, current) > 2) {
  1121.                         final int x = current.getX();
  1122.                         final int y = current.getY();
  1123.                         tiles.add(new RSTile(x, y - 1));
  1124.                         tiles.add(new RSTile(x - 1, y));
  1125.                         tiles.add(new RSTile(x + 1, y));
  1126.                         tiles.add(new RSTile(x, y + 1));
  1127.                         tiles.add(new RSTile(x - 1, y - 1));
  1128.                         tiles.add(new RSTile(x + 1, y - 1));
  1129.                         tiles.add(new RSTile(x + 1, y + 1));
  1130.                         tiles.add(new RSTile(x - 1, y + 1));
  1131.                         final RSTile tile = getNearest(tiles, t);
  1132.                         path.add(tile);
  1133.                         this.path = path.toArray(new RSTile[path.size()]);
  1134.                         current = tile;
  1135.                         tiles.clear();
  1136.                 }
  1137.                 this.path = path.toArray(new RSTile[path.size()]);
  1138.                 return this.path;
  1139.         }
  1140.  
  1141.         Portal getCurrentPortal() {
  1142.                 return current;
  1143.         }
  1144.  
  1145.         Job getJob() {
  1146.                 if (jobQ.size() == 0)
  1147.                         return null;
  1148.                 return jobQ.getFirst();
  1149.         }
  1150.  
  1151.         RSTile getNearest(final ArrayList<RSTile> tiles, final RSTile t) {
  1152.                 RSTile nearest = tiles.get(0);
  1153.                 for (RSTile tile : tiles) {
  1154.                         if (Methods.distanceBetween(tile, t) < Methods.distanceBetween(
  1155.                                         nearest, t)) {
  1156.                                 nearest = tile;
  1157.                         }
  1158.                 }
  1159.                 return nearest;
  1160.         }
  1161.  
  1162.         Portal getNearestOpenPortal() {
  1163.                 if (portalQ.size() < 1) {
  1164.                         return null;
  1165.                 }
  1166.                 Portal winner = null;
  1167.                 for (final Portal p : portalQ) {
  1168.                         if (p.isOpen()) {
  1169.                                 winner = p;
  1170.                         }
  1171.                 }
  1172.                 if (winner == null) {
  1173.                         return null;
  1174.                 }
  1175.  
  1176.                 for (final Portal p : portalQ) {
  1177.                         if (!p.isOpen()) {
  1178.                                 continue;
  1179.                         }
  1180.                         if (distanceTo(p.getLocation()) < distanceTo(winner.getLocation())) {
  1181.                                 winner = p;
  1182.                         }
  1183.                 }
  1184.                 current = winner;
  1185.                 return winner;
  1186.         }
  1187.  
  1188.         Portal getNearestPortal() {
  1189.                 if (portalQ.size() < 1) {
  1190.                         return null;
  1191.                 }
  1192.                 Portal winner = portalQ.get(0);
  1193.                 for (final Portal p : portalQ) {
  1194.                         if (distanceTo(p.getLocation()) < distanceTo(winner.getLocation())) {
  1195.                                 winner = p;
  1196.                         }
  1197.                 }
  1198.                 return winner;
  1199.         }
  1200.  
  1201.         RSTile getNext(final RSTile[] path) {
  1202.                 RSTile nearest = path[0];
  1203.                 for (final RSTile element : path) {
  1204.                         if (Methods.distanceBetween(element, path[path.length - 1]) < Methods
  1205.                                         .distanceBetween(nearest, path[path.length - 1])) {
  1206.                                 if (tileOnMap(element)) {
  1207.                                         nearest = element;
  1208.                                 }
  1209.                         }
  1210.                 }
  1211.                 return nearest;
  1212.         }
  1213.  
  1214.         RSPlayer getPlayerOnScreen() {
  1215.                 final int[] validPlayers = Bot.getClient().getRSPlayerIndexArray();
  1216.                 final org.rsbot.accessors.RSPlayer[] players = Bot.getClient()
  1217.                                 .getRSPlayerArray();
  1218.                 final ArrayList<RSPlayer> p = new ArrayList<RSPlayer>();
  1219.                 for (final int element : validPlayers) {
  1220.                         if (players[element] == null) {
  1221.                                 continue;
  1222.                         }
  1223.                         final RSPlayer player = new RSPlayer(players[element]);
  1224.                         try {
  1225.                                 if (!tileOnScreen(player.getLocation())) {
  1226.                                         continue;
  1227.                                 }
  1228.                                 p.add(player);
  1229.                         } catch (final Exception ignored) {
  1230.                         }
  1231.                 }
  1232.                 if (p.size() == 0) {
  1233.                         return null;
  1234.                 } else if (p.size() == 1) {
  1235.                         return p.get(0);
  1236.                 }
  1237.                 return p.get(random(0, p.size() - 1));
  1238.         }
  1239.  
  1240.         Portal getPortalByName(final String name) {
  1241.                 if (portalQ.size() < 1) {
  1242.                         return null;
  1243.                 }
  1244.                 for (final Portal p : portalQ) {
  1245.                         if (p.getName().equalsIgnoreCase(name)) {
  1246.                                 return p;
  1247.                         }
  1248.                 }
  1249.                 return null;
  1250.         }
  1251.  
  1252.         public RSTile getRandom(final RSArea a) {
  1253.                 try {
  1254.                         final RSTile[][] tiles = a.getTiles();
  1255.                         final int y = random(0, tiles.length - 1);
  1256.                         final int x = random(0, tiles[y].length - 1);
  1257.                         return tiles[x][y];
  1258.                 } catch (final Exception ignored) {
  1259.                 }
  1260.                 return new RSTile(-1, -1);
  1261.         }
  1262.  
  1263.         Portal getRandomOpenPortal() {
  1264.                 if (portalQ.size() < 1) {
  1265.                         return null;
  1266.                 }
  1267.                 final ArrayList<Portal> po = new ArrayList<Portal>();
  1268.                 for (final Portal p : portalQ) {
  1269.                         if (p.isOpen()) {
  1270.                                 po.add(p);
  1271.                         }
  1272.                 }
  1273.                 current = po.get(random(0, po.size()));
  1274.                 return current;
  1275.         }
  1276.  
  1277.         String getTopText() {
  1278.                 try {
  1279.                         final long start = System.currentTimeMillis();
  1280.                         String[] menuItems = getMenuItems().toArray(
  1281.                                         new String[getMenuItems().size()]);
  1282.                         if (menuItems.length == 0) {
  1283.                                 return "Cancel";
  1284.                         }
  1285.                         while (menuItems[0].contains("Cancel")
  1286.                                         && pointOnScreen(getMouseLocation())
  1287.                                         && System.currentTimeMillis() - start < 700) {
  1288.                                 menuItems = getMenuItems().toArray(
  1289.                                                 new String[getMenuItems().size()]);
  1290.                         }
  1291.                         return menuItems[0];
  1292.                 } catch (Exception e) {
  1293.                         return getTopText();
  1294.                 }
  1295.         }
  1296.  
  1297.         boolean inPest() {
  1298.                 return getNearestNPCByID(Squire) == null;
  1299.         }
  1300.  
  1301.         @Override
  1302.         public int loop() {
  1303.                 try {
  1304.                         if (gc == 0)
  1305.                                 gc = System.currentTimeMillis();
  1306.  
  1307.                         if (!onBoat() && !inPest()) {
  1308.                                 Break b = getCurrentBreak();
  1309.                                 if (b != null && b.needsBreak())
  1310.                                         b.takeBreak();
  1311.                         }
  1312.  
  1313.                         if (this.getInterface(Interface_250).isValid()) {
  1314.                                 got250 = true;
  1315.                         }
  1316.  
  1317.                         if (getMyPlayer().isInCombat() && getMyPlayer().getHPPercent() < 2
  1318.                                         && distanceTo(getNearestNPCByID(squire)) > 15) {
  1319.                                 return random(600, 800);
  1320.                         }
  1321.  
  1322.                         if (!onBoat() && !inPest() && getJob() != null) {
  1323.                                 doJob();
  1324.                         }
  1325.  
  1326.                         if (getJob() == null && got250) {
  1327.                                 logout();
  1328.                                 log("Thanks for using BPestControll");
  1329.                                 log("Reached 250 points and out of jobs");
  1330.                         }
  1331.                         if (isMenuOpen()) {
  1332.                                 moveMouse(random(5, 760), random(5, 500));
  1333.                         }
  1334.                         if (!inPest() && !onBoat()) {
  1335.                                 return enterBoat();
  1336.                         }
  1337.                         if (onBoat()) {
  1338.                                 String s = "";
  1339.                                 if (getInterface(407, 16) != null) {
  1340.                                         s = getInterface(407, 16).getText();
  1341.                                 }
  1342.                                 points = Integer.parseInt(s.replace("Pest Points: ", ""));
  1343.                                 if (played) {
  1344.                                         if (points > oldPoints) {
  1345.                                                 gainedPoints += points - oldPoints;
  1346.                                         }
  1347.                                         if (points - oldPoints == 0) {
  1348.                                                 lost++;
  1349.                                         } else {
  1350.                                                 won++;
  1351.                                         }
  1352.                                 }
  1353.                                 oldPoints = points;
  1354.                                 played = false;
  1355.                                 return random(400, 700);
  1356.                         }
  1357.                         if (getNearestNPCByID(squire) != null) {
  1358.                                 voidLoc = getNearestNPCByID(squire).getLocation();
  1359.                                 fillPortalList();
  1360.                         }
  1361.                         if (inPest()) {
  1362.                                 return pestLoop();
  1363.                         }
  1364.                 } catch (Exception ignored) {
  1365.                 }
  1366.                 return random(100, 800);
  1367.         }
  1368.  
  1369.         boolean menuContains(final String a) {
  1370.                 try {
  1371.                         final long start = System.currentTimeMillis();
  1372.                         String[] menuItems = getMenuItems().toArray(
  1373.                                         new String[getMenuItems().size()]);
  1374.                         while (menuItems[0].contains("Cancel")
  1375.                                         && pointOnScreen(getMouseLocation())
  1376.                                         && System.currentTimeMillis() - start < 700) {
  1377.                                 menuItems = getMenuItems().toArray(
  1378.                                                 new String[getMenuItems().size()]);
  1379.                         }
  1380.                         for (final String element : menuItems) {
  1381.                                 if (element.contains(a)) {
  1382.                                         return true;
  1383.                                 }
  1384.                         }
  1385.                 } catch (final Exception ignored) {
  1386.  
  1387.                 }
  1388.                 return false;
  1389.         }
  1390.  
  1391.         @Override
  1392.         public void moveMouse(final int x, final int y) {
  1393.                 if (x != -1 && y != -1) {
  1394.                         moveMouse(x, y, 0, 0);
  1395.                 }
  1396.         }
  1397.  
  1398.         @Override
  1399.         public void moveMouse(final Point p) {
  1400.                 if (p.x != -1 && p.y != -1) {
  1401.                         moveMouse(p.x, p.y, 0, 0);
  1402.                 }
  1403.         }
  1404.  
  1405.         @Override
  1406.         public void moveMouse(final Point p, final int rX, final int rY) {
  1407.                 final int X = p.x + random(-(rX / 2), (rX / 2));
  1408.                 final int Y = p.y + random(-(rY / 2), (rY / 2));
  1409.                 moveMouse(X, Y);
  1410.         }
  1411.  
  1412.         boolean onBoat() {
  1413.                 return boatArea != null
  1414.                                 && boatArea.contains(getMyPlayer().getLocation());
  1415.         }
  1416.  
  1417.         @Override
  1418.         public void onFinish() {
  1419.                 log("Gained " + gainedPoints + " points.");
  1420.         }
  1421.  
  1422.         public void onRepaint(final Graphics g) {
  1423.                 if (getCurrentBreak() != null) {
  1424.                         g.drawString(getCurrentBreak().getTimeTillBreak(), 10, 400);
  1425.                         g.drawString("" + getCurrentBreak().needsBreak(), 10, 415);
  1426.                 }
  1427.                 int y = 120;
  1428.                 final int x = 20;
  1429.                 g.setColor(new Color(51, 153, 255, 170));
  1430.                 g.fillRoundRect(15, 120, width, height, 5, 5);
  1431.                 g.setColor(Color.WHITE);
  1432.                 g.drawRoundRect(15, 120, width, height, 5, 5);
  1433.                 width = 0;
  1434.                 height = 0;
  1435.                 if (startTime == 0) {
  1436.                         startTime = System.currentTimeMillis();
  1437.                 }
  1438.                 long millis = System.currentTimeMillis() - startTime;
  1439.                 try {
  1440.                         g.setColor(Color.WHITE);
  1441.                         g.setFont(new Font("Arial", Font.BOLD, 14));
  1442.                         g.drawString("BPestControlV2 made by Bool", x, y += g
  1443.                                         .getFontMetrics().getHeight());
  1444.                         height += g.getFontMetrics().getHeight();
  1445.                         width = (int) g.getFontMetrics().getStringBounds(
  1446.                                         "BPestControlV2 made by Bool", g).getWidth();
  1447.                         g.setFont(new Font("Arial", Font.PLAIN, 12));
  1448.                         g.drawString("Lost " + lost + " Games", x, y += g.getFontMetrics()
  1449.                                         .getHeight());
  1450.                         height += g.getFontMetrics().getHeight();
  1451.                         g.drawString("won " + won + " Games", x, y += g.getFontMetrics()
  1452.                                         .getHeight());
  1453.                         height += g.getFontMetrics().getHeight();
  1454.                         g.drawString("Gained " + gainedPoints + " points", x, y += g
  1455.                                         .getFontMetrics().getHeight());
  1456.                         height += g.getFontMetrics().getHeight();
  1457.                         g.drawString("Time running : " + timeToString(millis), x, y += g
  1458.                                         .getFontMetrics().getHeight());
  1459.                         height += g.getFontMetrics().getHeight();
  1460.                         if (getJob() != null) {
  1461.                                 if (g.getFontMetrics().getStringBounds(
  1462.                                                 "Spending points on " + getJob().getName(), g)
  1463.                                                 .getWidth() > width) {
  1464.                                         width = (int) g.getFontMetrics().getStringBounds(
  1465.                                                         "Spending points on " + getJob().getName(), g)
  1466.                                                         .getWidth();
  1467.                                 }
  1468.                                 g.drawString("Spending points on " + getJob().getName() + " "
  1469.                                                 + points, x, y += g.getFontMetrics().getHeight());
  1470.                                 height += g.getFontMetrics().getHeight();
  1471.                         }
  1472.                         height += 5;
  1473.                         width += 10;
  1474.                 } catch (final Exception ignored) {
  1475.  
  1476.                 }
  1477.         }
  1478.  
  1479.         @Override
  1480.         public boolean onStart(final Map<String, String> l) {
  1481.                 start = false;
  1482.                 final BGUI gui = new BGUI();
  1483.                 gui.setVisible(true);
  1484.                 while (gui.isVisible()) {
  1485.                         wait(random(500, 600));
  1486.                 }
  1487.                 if (!start) {
  1488.                         return false;
  1489.                 }
  1490.                 if (start) {
  1491.                         new Thread(new animationChecker()).start();
  1492.                         antiban.start();
  1493.                 }
  1494.                 log("starting script");
  1495.                 pf = new Pathfinder();
  1496.                 return start;
  1497.                 // return true;
  1498.         }
  1499.  
  1500.         int pestLoop() {
  1501.                 if (!played) {
  1502.                         played = true;
  1503.                 }
  1504.                 try {
  1505.                         if (!atPortal()) {
  1506.                                 final Portal p = getRandomOpenPortal();
  1507.                                 p.walkTo();
  1508.                                 return random(100, 600);
  1509.                         }
  1510.                         if (!getCurrentPortal().equals(getNearestPortal())) {
  1511.                                 if (getNearestOpenPortal() != null) {
  1512.                                         getNearestOpenPortal().walkTo();
  1513.                                 }
  1514.                                 return random(100, 600);
  1515.                         }
  1516.                         if (!getCurrentPortal().isOpen()) {
  1517.                                 if (getNearestOpenPortal() != null) {
  1518.                                         getNearestOpenPortal().walkTo();
  1519.                                 }
  1520.                                 return random(100, 600);
  1521.                         }
  1522.                         checkSpecial();
  1523.                         if (getMyPlayer().getInteracting() == null) {
  1524.                                 RSItemTile t = getGroundItem(arrowID);
  1525.                                 if (t != null && t.isValid()) {
  1526.                                         atTile(t, "Take");
  1527.                                         return random(600, 800);
  1528.                                 }
  1529.                                 path = null;
  1530.                                 if (!inPest()) {
  1531.                                         return random(100, 500);
  1532.                                 }
  1533.                                 failsafe = 0;
  1534.                                 RSNPC c;
  1535.                                 if (getCurrentPortal().getNPC() != null) {
  1536.                                         c = getCurrentPortal().getNPC();
  1537.                                 } else {
  1538.                                         c = getNPC(attackSpinner);
  1539.                                 }
  1540.                                 if (c != null) {
  1541.                                         if (clickNPC(c, "Attack")) {
  1542.                                                 return random(600, 1200);
  1543.                                         }
  1544.                                 }
  1545.                                 return random(400, 700);
  1546.                         } else {
  1547.                                 RSNPC n = getNPC(true);
  1548.                                 if (n != null && n.getName().contains("Spinner")) {
  1549.                                         RSNPC inter = (RSNPC) getMyPlayer().getInteracting();
  1550.                                         if ((inter != null && !inter.getName().equals(n.getName()))
  1551.                                                         || inter == null)
  1552.                                                 if (clickNPC(n, "Attack")) {
  1553.                                                         return random(600, 1200);
  1554.                                                 }
  1555.                                 }
  1556.                                 path = null;
  1557.                                 if (failsafe > 4) {
  1558.                                         walkTileMM(getNearestOpenPortal().getRandom());
  1559.                                 }
  1560.                                 final RSNPC npc = (RSNPC) getMyPlayer().getInteracting();
  1561.                                 if (getMyPlayer().isMoving()
  1562.                                                 || getMyPlayer().getInteracting() != null
  1563.                                                 || System.currentTimeMillis() - lastAniChange < 2000
  1564.                                                 || npc != null && npc.getName().contains("ortal")) {
  1565.                                         failsafe = 0;
  1566.                                 } else {
  1567.                                         failsafe++;
  1568.                                         wait(random(600, 800));
  1569.                                 }
  1570.                                 return random(400, 700);
  1571.                         }
  1572.                 } catch (final Exception ignored) {
  1573.                 }
  1574.                 return random(400, 700);
  1575.         }
  1576.  
  1577.         boolean PrayerEnabled() {
  1578.                 return getSetting(1395) > 0;
  1579.         }
  1580.  
  1581.         private int i = 0;
  1582.  
  1583.         boolean walkPath(final RSTile[] path) {
  1584.                 final char left = 37;
  1585.                 final char right = 39;
  1586.                 RSTile tile = getNext(path);
  1587.                 moveMouse(Calculations.worldToMinimap(tile.getX(), tile.getY()));
  1588.                 if (!inPest()) {
  1589.                         return true;
  1590.                 }
  1591.                 if (i == 7) {
  1592.                         char dir = random(0, 3) == 2 ? left : right;
  1593.                         Bot.getInputManager().pressKey(dir);
  1594.                         wait(random(800, 1200));
  1595.                         Bot.getInputManager().releaseKey(dir);
  1596.                         i = 0;
  1597.                         return false;
  1598.                 }
  1599.                 if (getTopText().contains("ancel")) {
  1600.                         i++;
  1601.                         return false;
  1602.                 }
  1603.                 try {
  1604.                         walkTileMM(getNext(path));
  1605.                         wait(random(200, 500));
  1606.                         while (getMyPlayer().isMoving() && distanceTo(getDestination()) > 7) {
  1607.                                 wait(random(600, 800));
  1608.                         }
  1609.                 } catch (final Exception ignored) {
  1610.                 }
  1611.                 return distanceTo(path[path.length - 1]) < 10 || !inPest();
  1612.         }
  1613.  
  1614.         void checkSpecial() {
  1615.                 if (specialPercent == 0 || isSpecialEnabled())
  1616.                         return;
  1617.                 int percent = (getSetting(300) / 10);
  1618.                 if (percent > specialPercent) {
  1619.                         RSInterfaceChild child = RSInterface.getChildInterface(884, 4);
  1620.                         if (getCurrentTab() != TAB_ATTACK)
  1621.                                 openTab(TAB_ATTACK);
  1622.                         atInterface(child);
  1623.                         wait(random(400, 700));
  1624.                 }
  1625.         }
  1626.  
  1627.         boolean isSpecialEnabled() {
  1628.                 return getSetting(301) == 1;
  1629.         }
  1630.  
  1631.         void walkPath(final RSTile[] path, final int i) {
  1632.                 try {
  1633.                         walkTileMM(getNext(path));
  1634.                         wait(random(200, 500));
  1635.                         while (getMyPlayer().isMoving() && distanceTo(getDestination()) > 7) {
  1636.                                 wait(random(600, 800));
  1637.                         }
  1638.                 } catch (final Exception ignored) {
  1639.                 }
  1640.         }
  1641.  
  1642.         int daxeID = 0;
  1643.         int oldID = 0;
  1644.  
  1645.         public void doDragonBattleAxe() {
  1646.                 if (!DBaxe)
  1647.                         return;
  1648.                 if (getCurrentTab() != TAB_INVENTORY)
  1649.                         openTab(TAB_INVENTORY);
  1650.                 atInventoryItem(daxeID, "");
  1651.                 if (getCurrentTab() != TAB_ATTACK)
  1652.                         openTab(TAB_ATTACK);
  1653.                 RSInterfaceChild child = RSInterface.getChildInterface(884, 4);
  1654.                 atInterface(child);
  1655.                 wait(random(1200, 1500));
  1656.                 if (getCurrentTab() != TAB_INVENTORY)
  1657.                         openTab(TAB_INVENTORY);
  1658.                 atInventoryItem(oldID, "");
  1659.  
  1660.         }
  1661.  
  1662.         RSNPC getNPC(boolean spinner) {
  1663.                 final String[] names = { "Shifter", "Defiler", "Torcher", "Brawler",
  1664.                                 "Ravager", "Spinner" };
  1665.                 RSNPC closest = null;
  1666.                 final int[] validNPCs = Bot.getClient().getRSNPCIndexArray();
  1667.                 ArrayList<RSNPC> result = new ArrayList<RSNPC>();
  1668.  
  1669.         for (final int element : validNPCs) {
  1670.                 Node node = Calculations.findNodeByID(Bot.getClient().getRSNPCNC(), element);
  1671.             if (node == null || !(node instanceof RSNPCNode)) {
  1672.                 continue;
  1673.             }
  1674.             final RSNPC Monster = new RSNPC(((RSNPCNode) node).getRSNPC());
  1675.                         try {
  1676.                                 for (final String name : names) {
  1677.                                         if (!name.equals(Monster.getName())
  1678.                                                         || distanceBetween(
  1679.                                                                         getCurrentPortal().getLocation(), Monster
  1680.                                                                                         .getLocation()) > 10
  1681.                                                         || Monster.isInCombat()
  1682.                                                         && Monster.getHPPercent() < 10) {
  1683.                                                 continue;
  1684.                                         }
  1685.                                         result.add(Monster);
  1686.                                 }
  1687.                         } catch (final Exception e) {
  1688.                                 e.printStackTrace();
  1689.                         }
  1690.                 }
  1691.                 if (result.size() == 0)
  1692.                         return null;
  1693.                 RSNPC s = null;
  1694.                 for (RSNPC npc : result) {
  1695.                         if (spinner) {
  1696.                                 if (npc.getName().equalsIgnoreCase("Spinner")) {
  1697.                                         if (s == null || distanceTo(s) > distanceTo(npc))
  1698.                                                 s = npc;
  1699.                                 }
  1700.                         }
  1701.                         if (closest == null || distanceTo(closest) > distanceTo(npc))
  1702.                                 closest = npc;
  1703.                 }
  1704.                 if (spinner && s != null) {
  1705.                         return s;
  1706.                 }
  1707.                 return closest;
  1708.         }
  1709.  
  1710.         class Break {
  1711.                 public boolean isDone = false;
  1712.                 int time, after;
  1713.                 public Timer Time;
  1714.                 long end;
  1715.  
  1716.                 public Break(int time, int after) {
  1717.                         this.time = time;
  1718.                         this.after = after;
  1719.                         end = System.currentTimeMillis() + after;
  1720.                 }
  1721.  
  1722.                 public void init() {
  1723.                         Time = new Timer(time);
  1724.                         end = System.currentTimeMillis() + after;
  1725.                 }
  1726.  
  1727.                 public void takeBreak() {
  1728.                         while (isLoggedIn())
  1729.                                 logout();
  1730.                         Time.reset();
  1731.                         log("Taking break for " + Time.toString());
  1732.                         while (!Time.isDone()) {
  1733.                                 try {
  1734.                                         Thread.sleep(random(500, 800));
  1735.                                 } catch (InterruptedException e) {
  1736.                                 }
  1737.                         }
  1738.                         isDone = true;
  1739.                 }
  1740.  
  1741.                 public String getTimeTillBreak() {
  1742.                         return timeToString(end - System.currentTimeMillis());
  1743.                 }
  1744.  
  1745.                 public boolean needsBreak() {
  1746.                         return System.currentTimeMillis() > end;
  1747.                 }
  1748.         }
  1749.  
  1750.         class Timer {
  1751.  
  1752.                 private long start;
  1753.                 private int time;
  1754.  
  1755.                 public Timer(int time) {
  1756.                         start = System.currentTimeMillis();
  1757.                         this.time = time;
  1758.                 }
  1759.  
  1760.                 public Timer() {
  1761.                         this(0);
  1762.                 }
  1763.  
  1764.                 public boolean isDone() {
  1765.                         return (System.currentTimeMillis() - start) > time;
  1766.                 }
  1767.  
  1768.                 public void reset() {
  1769.                         start = System.currentTimeMillis();
  1770.                 }
  1771.  
  1772.                 @Override
  1773.                 public String toString() {
  1774.                         return timeToString((System.currentTimeMillis() - start));
  1775.                 }
  1776.  
  1777.                 public String timeRemaining() {
  1778.                         return timeToString(((System.currentTimeMillis() - start) + time));
  1779.                 }
  1780.         }
  1781.  
  1782.         public String timeToString(long time) {
  1783.                 final long hours = time / (1000 * 60 * 60);
  1784.                 time -= hours * 1000 * 60 * 60;
  1785.                 final long minutes = time / (1000 * 60);
  1786.                 time -= minutes * 1000 * 60;
  1787.                 final long seconds = time / 1000;
  1788.                 String str = "";
  1789.                 if (hours < 10)
  1790.                         str += "0";
  1791.                 str += hours + ":";
  1792.                 if (minutes < 10)
  1793.                         str += "0";
  1794.                 str += minutes + ":";
  1795.                 if (seconds < 10)
  1796.                         str += "0";
  1797.                 str += seconds;
  1798.                 return str;
  1799.         }
  1800.  
  1801.         public boolean needUpdate() {
  1802.                 try {
  1803.                         URL url = new URL("http://boolscripts.site11.com/Scripts/version");
  1804.                         BufferedReader reader = new BufferedReader(new InputStreamReader(
  1805.                                         url.openStream()));
  1806.                         String line = reader.readLine();
  1807.                         double i = Double.parseDouble(line);
  1808.                         if (i > version)
  1809.                                 return true;
  1810.                 } catch (Exception e) {
  1811.                 }
  1812.                 return true;
  1813.         }
  1814.  
  1815.         Thread antiban = new Thread() {
  1816.                 @Override
  1817.                 public void run() {
  1818.                         setName("Antiban");
  1819.                         while (isActive) {
  1820.                                 try {
  1821.                                         if (!isLoggedIn()) {
  1822.                                                 Thread.sleep(300, 400);
  1823.                                                 continue;
  1824.                                         }
  1825.                                         int i = random(0, 150);
  1826.                                         if (i == 4 || i == 9)
  1827.                                                 performAntiban(antibanQ.get(random(0, antibanQ.size())));
  1828.                                         sleep(random(100, 2000));
  1829.                                 } catch (InterruptedException ignored) {
  1830.                                 }
  1831.                         }
  1832.                 }
  1833.         };
  1834.  
  1835.         class Pathfinder {
  1836.  
  1837.                 public int basex, basey;
  1838.                 public int[][] blocks;
  1839.  
  1840.                 public Pathfinder() {
  1841.                         reload();
  1842.                 }
  1843.  
  1844.                 public void reload() {
  1845.                         basex = Bot.getClient().getBaseX();
  1846.                         basey = Bot.getClient().getBaseY();
  1847.                         blocks = Bot.getClient().getRSGroundDataArray()[Bot.getClient()
  1848.                                         .getPlane()].getBlocks();
  1849.                 }
  1850.  
  1851.                 public RSTile[] findPath(RSTile dest) {
  1852.                         if (!isValid())
  1853.                                 reload();
  1854.                         return findPath(getLocation(), dest);
  1855.                 }
  1856.  
  1857.                 public RSTile[] findPath(RSTile start, RSTile dest) {
  1858.                         if (!isValid())
  1859.                                 reload();
  1860.                         return findPath(
  1861.                                         new Node(start.getX() - basex, start.getY() - basey),
  1862.                                         new Node(dest.getX() - basex, dest.getY() - basey));
  1863.                 }
  1864.  
  1865.                 public RSTile[] findPath(Node start, Node dest) {
  1866.                         if (!isValid())
  1867.                                 reload();
  1868.                         if (!canReach(new RSTile(dest.x + basex, dest.y + basey), false)) {
  1869.                                 return null;
  1870.                         }
  1871.                         ArrayList<Node> closed = new ArrayList<Node>();
  1872.                         ArrayList<Node> open = new ArrayList<Node>();
  1873.  
  1874.                         Node current = start;
  1875.                         open.add(current);
  1876.                         while (open.size() != 0) {
  1877.                                 current = getBestNode(open);
  1878.                                 closed.add(current);
  1879.                                 open.remove(current);
  1880.                                 for (Node node : getNodesAround(current)) {
  1881.                                         if (!closed.contains(node)) {
  1882.                                                 if (!open.contains(node)) {
  1883.                                                         node.parent = current;
  1884.                                                         node.cost = current.cost
  1885.                                                                         + getMovementCost(node, current);
  1886.                                                         node.heuristic = node.cost
  1887.                                                                         + getHeuristicCost(node, dest);
  1888.                                                         open.add(node);
  1889.                                                 } else {
  1890.                                                         if (current.cost + getMovementCost(node, current) < node.cost) {
  1891.                                                                 node.parent = current;
  1892.                                                                 node.cost = current.cost
  1893.                                                                                 + getMovementCost(node, current);
  1894.                                                                 node.heuristic = node.cost
  1895.                                                                                 + getHeuristicCost(node, dest);
  1896.                                                         }
  1897.                                                 }
  1898.                                         }
  1899.                                 }
  1900.                                 if (closed.contains(dest)) {
  1901.                                         final ArrayList<RSTile> result = new ArrayList<RSTile>();
  1902.                                         Node node = closed.get(closed.size() - 1);
  1903.                                         while (node.parent != null) {
  1904.                                                 result.add(new RSTile(node.x + basex, node.y + basey));
  1905.                                                 node = node.parent;
  1906.                                         }
  1907.                                         path = reversePath(result
  1908.                                                         .toArray(new RSTile[result.size()]));
  1909.                                         return path;
  1910.                                 }
  1911.                         }
  1912.                         return null;
  1913.                 }
  1914.  
  1915.                 public Node getBestNode(ArrayList<Node> nodes) {
  1916.                         Node winner = null;
  1917.                         for (Node node : nodes) {
  1918.                                 if (winner == null || node.cost < winner.cost) {
  1919.                                         winner = node;
  1920.                                 }
  1921.                         }
  1922.                         return winner;
  1923.                 }
  1924.  
  1925.                 public double getHeuristicCost(Node current, Node dest) {
  1926.                         float dx = dest.x - current.x;
  1927.                         float dy = dest.y - current.y;
  1928.                         return (double) (Math.sqrt((dx * dx) + (dy * dy)));
  1929.                 }
  1930.  
  1931.                 public double getMovementCost(Node current, Node dest) {
  1932.                         return (double) Math.hypot(dest.x - current.x, dest.y - current.y);
  1933.                 }
  1934.  
  1935.                 /**
  1936.                  * credits to jacmob
  1937.                  */
  1938.                 public ArrayList<Node> getNodesAround(Node node) {
  1939.                         final ArrayList<Node> tiles = new ArrayList<Node>();
  1940.                         final int curX = node.x, curY = node.y;
  1941.                         if (curX > 0 && curY < 103
  1942.                                         && (blocks[curX - 1][curY + 1] & 0x1280138) == 0
  1943.                                         && (blocks[curX - 1][curY] & 0x1280108) == 0
  1944.                                         && (blocks[curX][curY + 1] & 0x1280120) == 0) {
  1945.                                 tiles.add(new Node(curX - 1, curY + 1));
  1946.                         }
  1947.                         if (curY < 103 && (blocks[curX][curY + 1] & 0x1280120) == 0) {
  1948.                                 tiles.add(new Node(curX, curY + 1));
  1949.                         }
  1950.                         if (curX > 0 && curY < 103
  1951.                                         && (blocks[curX - 1][curY + 1] & 0x1280138) == 0
  1952.                                         && (blocks[curX - 1][curY] & 0x1280108) == 0
  1953.                                         && (blocks[curX][curY + 1] & 0x1280120) == 0) {
  1954.                                 tiles.add(new Node(curX + 1, curY + 1));
  1955.                         }
  1956.                         if (curX > 0 && (blocks[curX - 1][curY] & 0x1280108) == 0) {
  1957.                                 tiles.add(new Node(curX - 1, curY));
  1958.                         }
  1959.                         if (curX < 103 && (blocks[curX + 1][curY] & 0x1280180) == 0) {
  1960.                                 tiles.add(new Node(curX + 1, curY));
  1961.                         }
  1962.                         if (curX > 0 && curY > 0
  1963.                                         && (blocks[curX - 1][curY - 1] & 0x128010e) == 0
  1964.                                         && (blocks[curX - 1][curY] & 0x1280108) == 0
  1965.                                         && (blocks[curX][curY - 1] & 0x1280102) == 0) {
  1966.                                 tiles.add(new Node(curX - 1, curY - 1));
  1967.                         }
  1968.                         if (curY > 0 && (blocks[curX][curY - 1] & 0x1280102) == 0) {
  1969.                                 tiles.add(new Node(curX, curY - 1));
  1970.                         }
  1971.                         if (curX < 103 && curY > 0
  1972.                                         && (blocks[curX + 1][curY - 1] & 0x1280183) == 0
  1973.                                         && (blocks[curX + 1][curY] & 0x1280180) == 0
  1974.                                         && (blocks[curX][curY - 1] & 0x1280102) == 0) {
  1975.                                 tiles.add(new Node(curX + 1, curY - 1));
  1976.                         }
  1977.                         return tiles;
  1978.  
  1979.                 }
  1980.  
  1981.                 public boolean validTile(RSTile tile) {
  1982.                         if (!isValid())
  1983.                                 reload();
  1984.                         int x = tile.getX() - basex;
  1985.                         int y = tile.getY() - basey;
  1986.                         return x > 0 && x < 105 && y > 0 && y < 105;
  1987.                 }
  1988.  
  1989.                 public boolean isValid() {
  1990.                         return basex == Bot.getClient().getBaseX()
  1991.                                         && basey == Bot.getClient().getBaseY();
  1992.                 }
  1993.  
  1994.                 class Node {
  1995.  
  1996.                         public final int x, y;
  1997.                         public double cost = 0, heuristic = 0;
  1998.                         public Node parent;
  1999.  
  2000.                         public Node(int x, int y) {
  2001.                                 this.x = x;
  2002.                                 this.y = y;
  2003.                         }
  2004.  
  2005.                         public boolean equals(Object other) {
  2006.                                 if (other instanceof Node) {
  2007.                                         Node o = (Node) other;
  2008.                                         return x == o.x && y == o.y;
  2009.                                 }
  2010.                                 return false;
  2011.                         }
  2012.                 }
  2013.         }
  2014.  
  2015. }