PageRenderTime 51ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/scripts/BPestControlV2.java

http://d-linked.googlecode.com/
Java | 1988 lines | 1807 code | 174 blank | 7 comment | 570 complexity | 3c21ccbc9c065487543d7588a62ffb8c MD5 | raw file
Possible License(s): GPL-3.0

Large files files are truncated, but you can click here to view the full file

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

Large files files are truncated, but you can click here to view the full file