Zalgo2462

TFighterEE (Stable) RSBot

Apr 5th, 2011
1,423
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 106.37 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import java.awt.event.MouseEvent;
  5. import java.awt.event.MouseListener;
  6. import java.awt.image.BufferedImage;
  7. import java.io.*;
  8. import java.text.DecimalFormat;
  9. import java.text.NumberFormat;
  10. import java.util.*;
  11. import java.net.*;
  12. import java.util.List;
  13.  
  14. import javax.imageio.ImageIO;
  15. import javax.swing.*;
  16. import javax.tools.DiagnosticCollector;
  17. import javax.tools.*;
  18.  
  19. import org.rsbot.event.events.MessageEvent;
  20. import org.rsbot.script.Script;
  21. import org.rsbot.event.listeners.MessageListener;
  22. import org.rsbot.event.listeners.PaintListener;
  23. import org.rsbot.script.ScriptManifest;
  24. import org.rsbot.script.methods.*;
  25. import org.rsbot.script.util.Filter;
  26. import org.rsbot.script.util.Timer;
  27. import org.rsbot.script.wrappers.*;
  28. import org.rsbot.Configuration;
  29. import org.rsbot.util.io.HttpClient;
  30.  
  31. /**
  32. * Change log:
  33. * v2.70: MOAR CODE OPTIMIZATIONS!!111, Screenshot sender
  34. * v2.60: Added Garbage Collector, loot above X value, improved GE checker, code optimization, fixed prayer potions, fix for 2.6.23
  35. * v2.53: Fixed AutoUpdater
  36. * v2.52: Fixed LootLoop Error for like the gazillionth time >.<
  37. * v2.51: Fixed LootLoop Error.... again!
  38. * v2.50: Room Generation, fixed paint
  39. * v2.30: Arrow Equipping, Explorers Ring, Expanded anti ban, bunyip summoning, pbot DDoS protection
  40. * v2.20: New GUI, added amount of food to withdraw, fixed prayer pot double clicking, fixed? stats panel freezing for some
  41. * v2.10: Fixed InCombatLoop NPE, added staffs to alching
  42. * v2.02: Finally fixed prayer pots.... hopefully , rewrote bonesLoop, bug fixes
  43. * v2.01: Fixed LootLoop Error.
  44. * v2.00: Milestone release:
  45. * Added:
  46. * -new autoupdater
  47. * -changed new paint
  48. * -multithreading
  49. * -disable specs
  50. * -fixed? prayer pots
  51. * -automatic banking (Experimental)
  52. * -Secondary Loot Method
  53. * -Bad Tile Checking
  54. * -Code optimization
  55. * v1.80: Stable: Fixed click to continue issue, Added autoupdater, Added new paint
  56. * v1.75: Unstable: Added autoupdater, new paint, may freeze a bit, looking to improve with multithreading next version.
  57. * v1.70: Stable: Fixed GUI, Added: B2B, alching, prayer pot support, and special attacks codings. (Please tell me if you have any issues with this.)
  58. * v1.66: Unstable: Removed "can reach" checking, improved Prayer pot support, added Special Attacks Codings
  59. * v1.65: Unstable: Added: B2B, alching, and item/npc "can reach" checking.
  60. * v1.61: Made SDN compatible.
  61. * v1.60: Stable: Potions and ssh scattering added.
  62. * v1.55: Unstable: Potions and ash scattering added.
  63. * v1.50: Project branched by Zalgo2462. Bone burial added.
  64. * v1.02: Includes click here to continue hotfix.
  65. * v1.01: Prioritize looting over combat. Safespotting + looting is now possible. Implemented new LoopAction structure internally.
  66. * v1.00: Milestone release.
  67. * Added:
  68. * -Safespot ability
  69. * -Central clicking
  70. * -Clicking continue
  71. * -Antiban - performs camera + mouse at same time! (sometimes)
  72. * -Declared stable
  73. * v0.96: Hopefully finally fixed food
  74. * v0.95: Small error, caused null pointer
  75. * v0.94: Fixed eating.
  76. * v0.93: Hide paint by clicking it.
  77. * v0.92: Loot support, mainly. Many small changes.
  78. * v0.91: Oops, forgot to add mouse speed settings!
  79. * v0.9: Initial release
  80. */
  81. @ScriptManifest(name = "TFighterEE", authors = "!@!@! And Zalgo2462", keywords = {"combat", "money", "universal", "fighter", "!@!@!", "Zalgo2462"}, version = 2.70,
  82. description = "TFighter by !@!@! with additions by Zalgo2462", website = "http://www.powerbot.org/community/topic/444458-tfighteree-the-original-tfighter-but-with-enhancements-approved-by/")
  83. public class TFighterEE extends Script implements PaintListener, MouseListener, MessageListener {
  84. private final String branch = "Stable";
  85. private final static ScriptManifest mani = TFighterEE.class.getAnnotation(ScriptManifest.class);
  86.  
  87. private final Util u = new Util();
  88.  
  89. private RSTile startTile;
  90.  
  91. private long nextAntiban = 0;
  92.  
  93. private int badFoodCount = 0;
  94. private int startTime = 0;
  95. private int mouseSpeedMin = 4, mouseSpeedMax = 7;
  96.  
  97. private boolean startScript;
  98. private boolean onlyInRadius = false;
  99. private boolean utilizeMultiwayCombat = false;
  100. private boolean useSafespot = false;
  101. private boolean useCentralClicking = true;
  102. private boolean prioritizeLoot = false;
  103. private boolean buryBones = false;
  104.  
  105. private ZUI zui = new ZUI();
  106.  
  107. private List<LoopAction> loopActions = new LinkedList<LoopAction>();
  108.  
  109. private RSWeb webToBank;
  110.  
  111. private RSWeb webToStart;
  112.  
  113. private Timer gcTimer;
  114.  
  115. public boolean onStart() {
  116. if (!game.isLoggedIn()) {
  117. log("Start logged in.");
  118. return false;
  119. }
  120.  
  121. u.vChecker.start();
  122.  
  123. u.paint.showPaint = true;
  124. u.paint.showMain = true;
  125.  
  126. try {
  127. SwingUtilities.invokeAndWait(new Runnable() {
  128. public void run() {
  129. zui.setResizable(false);
  130. zui.setVisible(true);
  131. }
  132. });
  133. } catch (Exception ignored) { }
  134.  
  135. startScript = false;
  136.  
  137. while (!startScript) {
  138. if (!zui.isVisible())
  139. return false;
  140. sleep(100);
  141. }
  142. u.sw.poll();
  143. startTime = (int) System.currentTimeMillis();
  144. startTile = getMyPlayer().getLocation();
  145.  
  146. if(u.bank.bankingEnabled) {
  147. if(startTile.getZ() == 0){
  148. RSTile bankTile = web.getNearestBank();
  149. if(bankTile.getX() == 3382 && bankTile.getY() == 3270) {
  150. bankTile = new RSTile(3269, 3167);
  151. }
  152. webToBank = web.getWeb(startTile, bankTile);
  153. webToStart = web.getWeb(bankTile, startTile);
  154. } else {
  155. log("Banking only works on ground level.");
  156. u.bank.bankingEnabled = false;
  157. }
  158. }
  159.  
  160. if(u.rooms.instantiateGenerator())
  161. u.rooms.generator.start();
  162.  
  163. LoopAction[] actions;
  164. if(prioritizeLoot) {
  165. actions = new LoopAction[] {new SummoningLoop(), new AlchLoop(), (buryBones ? new BonesLoop() : null), new LootLoop(),
  166. (useSafespot ? new SafespotLoop() : null), new InCombatLoop(), new AttackLoop() };
  167. }
  168. else {
  169. actions = new LoopAction[] { (useSafespot ? new SafespotLoop() : null), new InCombatLoop(), new SummoningLoop(), new AlchLoop(),
  170. (buryBones ? new BonesLoop() : null), new LootLoop(), new AttackLoop() };
  171. }
  172. loopActions.addAll(Arrays.asList(actions));
  173. System.gc();
  174. gcTimer = new Timer(1000 * 60 * 5);
  175. return true;
  176. }
  177.  
  178. public void onFinish() {
  179. sendScreenShot();
  180. if(u.rooms.generator != null) {
  181. if(u.rooms.generator.isAlive()) {
  182. u.rooms.generator.safeStop();
  183. }
  184. }
  185. }
  186.  
  187. @Override
  188. public int loop() {
  189. if (!gcTimer.isRunning()) {
  190. System.gc();
  191. gcTimer.reset();
  192. }
  193. if (random(0, 3) == 0 || mouse.getSpeed() < mouseSpeedMin || mouse.getSpeed() > mouseSpeedMax) {
  194. mouse.setSpeed(random(mouseSpeedMin, mouseSpeedMax));
  195. }
  196. if (camera.getPitch() < 90) {
  197. camera.setPitch(true);
  198. return random(50, 100);
  199. }
  200. if (!walking.isRunEnabled() && walking.getEnergy() > random(60, 90)) {
  201. walking.setRun(true);
  202. return random(1200, 1600);
  203. } else if(u.npcs.ring.contains("Explorer's Ring") && u.npcs.rechargeAvailable) {
  204. game.openTab(Game.Tab.EQUIPMENT);
  205. equipment.getItem(Equipment.RING).interact("Run-replenish");
  206. long millis = System.currentTimeMillis();
  207. int run = walking.getEnergy();
  208. while(System.currentTimeMillis() - millis < 5000 && run == walking.getEnergy()) {
  209. sleep(random (50, 70));
  210. }
  211. if(interfaces.getComponent(211, 1) != null &&
  212. interfaces.getComponent(211, 1).getText().contains("Your ring appears")) {
  213. u.npcs.rechargeAvailable = false;
  214. }
  215. }
  216.  
  217. if (interfaces.canContinue()) {
  218. interfaces.clickContinue();
  219. return random(1200, 1600);
  220. }
  221.  
  222. if (game.getTab() != Game.Tab.INVENTORY) {
  223. game.openTab(Game.Tab.INVENTORY);
  224. return random(700, 1500);
  225. }
  226.  
  227. //banking
  228. if (u.bank.bankingEnabled) {
  229. if (u.bank.shouldWalkHome) {
  230. if(calc.distanceTo(startTile) > 5) {
  231. if(webToStart != null) {
  232. webToStart.step();
  233. sleep(random(1500, 2000));
  234. if(!players.getMyPlayer().isMoving()) {
  235. walking.walkTileOnScreen(webToStart.getEnd());
  236. sleep(random(500, 1000));
  237. webToStart.update();
  238. }
  239. } else {
  240. log("Web is null");
  241. }
  242. } else {
  243. u.bank.shouldWalkHome = false;
  244. }
  245. return (random(500, 750));
  246. }
  247.  
  248. if (u.bank.isInBank && u.bank.needsBank()) {
  249. while(!bank.isOpen()) {
  250. bank.open();
  251. sleep(random(2000, 3000));
  252. }
  253. if(u.bank.depositLoot) {
  254. u.bank.deposit();
  255. }
  256. if(u.bank.withdrawFood && u.eat.foodOfChoice != null) {
  257. u.bank.withdraw();
  258. }
  259. u.bank.shouldWalkHome = true;
  260. u.bank.isInBank = false;
  261. return (random(500, 750));
  262. }
  263.  
  264. if (u.bank.needsBank()) {
  265. if(calc.distanceTo(web.getNearestBank()) > 5 ) {
  266. if(webToBank != null) {
  267. webToBank.step();
  268. sleep(random(1500, 2000));
  269. if(!players.getMyPlayer().isMoving()) {
  270. walking.walkTileOnScreen(webToBank.getEnd());
  271. sleep(random(500, 1000));
  272. webToBank.update();
  273. }
  274. } else {
  275. log("Web is null");
  276. }
  277. } else {
  278. u.bank.isInBank = true;
  279. }
  280. return (random(500, 750));
  281. }
  282. }
  283.  
  284. //eating
  285. if (u.eat.needEat()) {
  286. if (u.eat.haveFood()) {
  287. badFoodCount = 0;
  288. u.eat.eatFood();
  289. } else if (u.eat.haveB2pTab() && u.eat.haveBones()) {
  290. u.eat.breakB2pTab();
  291. return random(2600, 3000);
  292. } else if (u.eat.haveB2bRunes() && u.eat.haveBones() && skills.getCurrentLevel(Skills.MAGIC) >= 15) {
  293. u.eat.castB2b();
  294. return random(2600, 3000);
  295. } else if (u.bank.bankingEnabled && u.bank.withdrawFood){
  296. u.bank.needBankForFood = true;
  297. } else {
  298. badFoodCount++;
  299. if (badFoodCount > 5) {
  300. log("You ran out of food! Stopping.");
  301. stopScript();
  302. }
  303. }
  304. return random(1200, 1600);
  305. }
  306.  
  307. //potions and prayer
  308. u.pot.usePotions();
  309.  
  310. if(u.pot.getPotions().get("PRAYER").length != 0 && !prayer.isQuickPrayerOn() && u.pot.setQuickPrayer) {
  311. prayer.setQuickPrayer(true);
  312. }
  313.  
  314. //arrow equipping
  315. if(u.npcs.weapon != null && u.npcs.ammo != null) {
  316. if(u.npcs.weapon.toLowerCase().contains("bow")) {
  317. for(RSItem item : inventory.getItems()) {
  318. if(item != null) {
  319. if(item.getID() != -1 && item.getName().equals(u.npcs.ammo)) {
  320. int n = inventory.getCount(true);
  321. if(item.interact("Wield")) {
  322. waitForInvChange(n, 3000);
  323. }
  324. }
  325. }
  326. }
  327. }
  328. }
  329.  
  330. if(u.loot.onlyTakeLootFromKilled && u.npcs.lastClickedNPC != null) {
  331. u.npcs.sleepWhileNpcIsDying(u.npcs.lastClickedNPC);
  332. }
  333.  
  334. for(LoopAction a : loopActions)
  335. if(a != null && a.activate())
  336. return a.loop();
  337. return random(50, 200);
  338. }
  339.  
  340. private interface LoopAction {
  341. public int loop();
  342. public boolean activate();
  343. }
  344.  
  345. private class InCombatLoop implements LoopAction {
  346. private RSNPC interacting;
  347. public int loop() {
  348. if( u.npcs.useSpecial() && !combat.isSpecialEnabled() && !interacting.isDead()) {
  349. sleep(random(500, 1000));
  350. combat.setSpecialAttack(true);
  351. }
  352.  
  353. if(u.loot.onlyTakeLootFromKilled) {
  354. if(!u.npcs.tilesFoughtOn.contains(interacting.getLocation())
  355. && !interacting.isMoving()) {
  356. u.npcs.tilesFoughtOn.add(interacting.getLocation());
  357. }
  358. }
  359. antiban();
  360. return random(50, 200);
  361. }
  362.  
  363. public boolean activate() {
  364. return u.npcs.isInCombat() && (interacting = u.npcs.getInteracting()) != null;
  365. }
  366.  
  367. }
  368.  
  369. private class AttackLoop implements LoopAction {
  370. public int loop() {
  371. RSNPC inter = u.npcs.getInteracting();
  372. RSNPC n = inter != null ? inter : u.npcs.getNPC();
  373. if (n != null) {
  374. if(random(0, 4) == 3 )
  375. camera.turnTo(n);
  376. int result = u.npcs.clickNPC(n, "Attack " + n.getName());
  377. if (result == 0) {
  378. if(!useSafespot) {
  379. waitWhileMoving();
  380. } else {
  381. waitForAnim();
  382. }
  383. return random(300, 500);
  384. } else if (result == 1) {
  385. waitWhileMoving();
  386. return random(0, 200);
  387. }
  388. } else {
  389. if (calc.distanceTo(startTile) > 5) {
  390. walking.walkTileMM(walking.getClosestTileOnMap(startTile));
  391. waitWhileMoving();
  392. } else {
  393. antiban();
  394. }
  395. }
  396. return random(50, 200);
  397. }
  398.  
  399. public boolean activate() {
  400. return !u.npcs.isInCombat();
  401. }
  402.  
  403. }
  404.  
  405. private class SafespotLoop implements LoopAction {
  406. public int loop() {
  407. if (!calc.tileOnScreen(startTile) ? walking.walkTileMM(startTile) : tiles.interact(startTile, "Walk")) {
  408. waitWhileMoving();
  409. return random(200, 500);
  410. }
  411. return random(80, 120);
  412. }
  413.  
  414. public boolean activate() {
  415. return useSafespot && calc.distanceTo(startTile) > 0;
  416. }
  417.  
  418. }
  419.  
  420. private class LootLoop implements LoopAction {
  421. private RSGroundItem loot = null;
  422.  
  423. public int loop() {
  424. int origCount = inventory.getCount(true);
  425. String name = loot.getItem().getName();
  426. int count = loot.getItem().getStackSize();
  427. int result = u.loot.takeItem(loot);
  428. if (result == 0) {
  429. waitWhileMoving();
  430. if (waitForInvChange(origCount)) {
  431. u.loot.addItem(name, count);
  432. if(u.loot.onlyTakeLootFromKilled && u.npcs.tilesFoughtOn.contains(loot.getLocation())) {
  433. u.npcs.tilesFoughtOn.remove(loot.getLocation());
  434. }
  435. }
  436. } else if (result == 1) {
  437. waitWhileMoving();
  438. }
  439. return random(50, 200);
  440. }
  441.  
  442. public boolean activate() {
  443. return (loot = u.loot.getLoot()) != null;
  444. }
  445. }
  446.  
  447. private class AlchLoop implements LoopAction {
  448. public int loop() {
  449. for(RSItem i : inventory.getItems()) {
  450. for ( String s : u.alch.alchNames) {
  451. if ( i.getID() != -1 && i.getName().toLowerCase().contains(s)) {
  452. u.alch.alch(i.getComponent());
  453. return random(2500, 3000);
  454. }
  455. }
  456. for ( int n : u.alch.alchIDs) {
  457. if( n == i.getID()) {
  458. u.alch.alch(i.getComponent());
  459. return random(2500, 3000);
  460. }
  461. }
  462. }
  463.  
  464. return random(50, 200);
  465. }
  466.  
  467. public boolean activate() {
  468. return u.alch.canAlch() && u.alch.hasAlchItems();
  469. }
  470. }
  471.  
  472. private class BonesLoop implements LoopAction {
  473. private final int[] BONE_IDS = new int[] { 526, 528, 530, 532, 534, 536, 2859, 3123, 3125, 3183, 6182 , 20268, 20266, 20264};
  474.  
  475. public int loop() {
  476. RSItem bone = inventory.getItem(BONE_IDS);
  477. if(bone != null) {
  478. if(bone.getID() != -1) {
  479. int n = inventory.getCount(true);
  480. bone.doClick(true);
  481. waitForInvChange(n);
  482. }
  483. }
  484. return random(50, 200);
  485. }
  486.  
  487. public boolean activate() {
  488. return inventory.getCount(BONE_IDS) != 0;
  489. }
  490. }
  491.  
  492. //TODO: Add support for other familiars
  493. private class SummoningLoop implements LoopAction {
  494. private int BUNYIP_POUCH = 12029;
  495. public int loop() {
  496. inventory.getItem(BUNYIP_POUCH).interact("Summon");
  497. return random(3000, 5000);
  498. }
  499.  
  500. public boolean activate() {
  501. return !summoning.isFamiliarSummoned() && inventory.contains(BUNYIP_POUCH) && summoning.getSummoningPoints() > 0;
  502. }
  503. }
  504.  
  505. private void waitWhileMoving() {
  506. long start = System.currentTimeMillis();
  507. while (System.currentTimeMillis() - start < 1500 && !getMyPlayer().isMoving()) {
  508. sleep(random(50, 200));
  509. }
  510. while (getMyPlayer().isMoving()) {
  511. sleep(random(20, 50));
  512. }
  513. }
  514.  
  515. /**
  516. * Waits until the inventory count changes
  517. * @param origCount the original count of rsitems inventory.getCount(true)
  518. * @return True when inventory has changed
  519. */
  520. private boolean waitForInvChange(int origCount) {
  521. long start = System.currentTimeMillis();
  522. while (inventory.getCount(true) == origCount && System.currentTimeMillis() - start < 2000) {
  523. sleep(random(20, 70));
  524. }
  525. return inventory.getCount(true) != origCount;
  526. }
  527.  
  528. private boolean waitForInvChange(int origCount, int bound) {
  529. long start = System.currentTimeMillis();
  530. while (inventory.getCount(true) == origCount && System.currentTimeMillis() - start < bound) {
  531. sleep(random(20, 70));
  532. }
  533. return inventory.getCount(true) != origCount;
  534. }
  535.  
  536. /**
  537. * Used in safe spotting. Waits for an animation.
  538. */
  539. private void waitForAnim() {
  540. long timer = System.currentTimeMillis();
  541. while(System.currentTimeMillis() - timer < 2500 && getMyPlayer().getAnimation() == -1
  542. && (System.currentTimeMillis() - timer < 1000 || getMyPlayer().getInteracting() != null))
  543. sleep(random(50, 100));
  544. }
  545.  
  546. private void sendScreenShot(){
  547. try {
  548. int time = (int)System.currentTimeMillis() - startTime;
  549. if(time > 5 * 60 * 1000) {
  550. log("Sending Proggie. Please Wait.");
  551. BufferedImage image = getProggie();
  552. ByteArrayOutputStream baos = new ByteArrayOutputStream();
  553. ImageIO.write(image, "png", baos);
  554. byte[] byteArray = baos.toByteArray();
  555. String base64 = new sun.misc.BASE64Encoder().encode(byteArray);
  556. String imageData = URLEncoder.encode("image", "UTF-8") + "=" + URLEncoder.encode(base64 , "UTF-8");
  557. imageData += "&" + URLEncoder.encode("time", "UTF-8") + "=" + time;
  558. URL server = new URL("http://tfighter.pcriot.com/sc.php");
  559. URLConnection conn = server.openConnection();
  560. conn.setRequestProperty("User-Agent", "TFighter");
  561. conn.setDoOutput(true);
  562. OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
  563. wr.write(imageData);
  564. wr.flush();
  565.  
  566. BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  567. String line;
  568. while((line = rd.readLine()) != null) {
  569. log(line);
  570. }
  571. }
  572. } catch (Exception e) {
  573. log("Failure: " + e.getMessage());
  574. }
  575. }
  576.  
  577. private void antiban() {
  578. if (System.currentTimeMillis() > nextAntiban) {
  579. nextAntiban = System.currentTimeMillis() + random(2000, 30000);
  580. } else {
  581. return;
  582. }
  583. Thread mouseThread = new Thread() {
  584. public void run() {
  585. switch(random(0, 5)) {
  586. case 0:
  587. mouse.moveOffScreen();
  588. break;
  589. case 1:
  590. mouse.move(random(0, game.getWidth()), random(0, game.getHeight()));
  591. break;
  592. case 2:
  593. mouse.move(random(0, game.getWidth()), random(0, game.getHeight()));
  594. break;
  595. }
  596. }
  597. };
  598. Thread keyThread = new Thread() {
  599. public void run() {
  600. switch(random(0, 4)) {
  601. case 0:
  602. camera.setAngle(camera.getAngle() + random(-100, 100));
  603. break;
  604. case 1:
  605. camera.setAngle(camera.getAngle() + random(-100, 100));
  606. break;
  607. case 2:
  608. camera.setAngle(camera.getAngle() + random(-100, 100));
  609. break;
  610. }
  611. }
  612. };
  613. int decision = random(1, 14);
  614. if(decision < 5) {
  615. keyThread.start();
  616. sleep(random(0, 600));
  617. mouseThread.start();
  618. } else if (decision < 11) {
  619. mouseThread.start();
  620. sleep(random(0, 600));
  621. keyThread.start();
  622. } else if (decision == 13) {
  623. Game.Tab tab = game.getTab();
  624. game.openTab(Game.Tab.STATS);
  625. long timer = System.currentTimeMillis();
  626. while(tab == game.getTab() && System.currentTimeMillis() - timer < 1000) {
  627. sleep(random(50, 90));
  628. }
  629. int decision2 = random (1, 4);
  630. if(decision2 == 1)
  631. skills.doHover(1);
  632. else if (decision2 == 2)
  633. skills.doHover(4);
  634. else if (decision2 == 3)
  635. skills.doHover(22);
  636. sleep(random(1500, 2000));
  637. }
  638. while(keyThread.isAlive() || mouseThread.isAlive())
  639. sleep(random(30, 100));
  640. }
  641.  
  642. public void onRepaint(Graphics g) {
  643. if (u.paint.showPaint) {
  644. final NumberFormat nf = NumberFormat.getIntegerInstance();
  645. ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  646. //Variables
  647. RSComponent inter = interfaces.get(137).getComponent(0);
  648. int xx = inter.getLocation().x;
  649. int yy = inter.getLocation().y;
  650.  
  651. int runTime = (int) System.currentTimeMillis() - startTime;
  652.  
  653. if(u.paint.useAdvancedPaint) {
  654. u.tiles.drawBadTiles(g, Color.RED);
  655. g.setColor(Color.WHITE);
  656. g.setFont(u.paint.KellyAnnGothic.deriveFont(Font.PLAIN, 18));
  657. g.drawImage(u.paint.ribbon, xx, yy - 325, null);
  658. g.drawString("TFighterEE", xx + 25, yy - 290);
  659. g.drawImage(u.paint.ribbon, xx, yy - 225, null);
  660. g.drawString("Stats", xx + 55, yy - 190);
  661. g.drawImage(u.paint.ribbon, xx, yy - 125, null);
  662. g.drawString("Loot", xx + 55, yy - 90);
  663.  
  664. if(u.paint.showMain) {
  665. int x = inter.getLocation().x;
  666. int y = inter.getLocation().y;
  667. g.drawImage(u.paint.stableRug, x, y, inter.getWidth(), inter.getHeight(), null);
  668. g.setColor(Color.WHITE);
  669. g.setFont(new Font("Arial", Font.PLAIN, 16));
  670. g.drawString("TFighter Enhanced Edition (v" + mani.version() + ")", x + 15, y += g.getFontMetrics().getMaxAscent() + 10);
  671. g.setFont(new Font("Arial", Font.PLAIN, 14));
  672. g.drawString("By !@!@! & Zalgo2462", x + 15, y += g.getFontMetrics().getMaxAscent() + 5);
  673. g.setFont(new Font("Arial", Font.PLAIN, 12));
  674. g.drawString("Run time: " + millisToTime(runTime), x + 25, y += g.getFontMetrics().getMaxAscent() + 5);
  675.  
  676. //Exp gains
  677. g.setFont(new Font("Arial", Font.BOLD, 12));
  678. g.drawString("Experience gained:", x + 25, y += g.getFontMetrics().getMaxAscent() + 10);
  679. g.setFont(new Font("Arial", Font.PLAIN, 11));
  680.  
  681. int skillLayoutNumber = 0;
  682. final int skillYStart = y + g.getFontMetrics().getMaxAscent();
  683. for (Map.Entry<String, Integer> entry : u.sw.getExpGainedMap().entrySet()) {
  684.  
  685. skillLayoutNumber++;
  686.  
  687. double expPerSec = entry.getValue() / (double) (runTime / 1000);
  688. int expPerHour = (int) Math.round(expPerSec * 3600);
  689.  
  690.  
  691. if((skillLayoutNumber < 4) || (skillLayoutNumber > 4)) {
  692. g.drawString(entry.getKey() + ": " + nf.format(entry.getValue()) +
  693. " (p/hr: " + nf.format(expPerHour) + ")", x + 25, y += g.getFontMetrics().getMaxAscent());
  694. }
  695.  
  696. else if(skillLayoutNumber == 4) {
  697. g.drawString(entry.getKey() + ": " + nf.format(entry.getValue()) +
  698. " (p/hr: " + nf.format(expPerHour) + ")", x + 175, skillYStart);
  699. }
  700. }
  701. y = inter.getLocation().y;
  702. g.setFont(new Font("Arial", Font.BOLD, 12));
  703. g.drawString("Loot taken:", x + 280, y += g.getFontMetrics().getMaxAscent() + 15);
  704. g.setFont(new Font("Arial", Font.PLAIN, 11));
  705. Map<String, Integer> loot = u.loot.getLootTaken();
  706. for (Map.Entry<String, Integer> entry : loot.entrySet()) {
  707. g.drawString(entry.getKey() + " x" + entry.getValue(), x + 285, y += g.getFontMetrics().getMaxAscent());
  708. }
  709. }
  710. else if (u.paint.showSkills) {
  711. int x = inter.getLocation().x;
  712. int y = inter.getLocation().y;
  713. g.drawImage(u.paint.skillsRug, x, y, inter.getWidth(), inter.getHeight(), null);
  714. g.setColor(new Color(0, 203, 0));
  715.  
  716. int attackHeight = Math.round((skills.getPercentToNextLevel(Skills.ATTACK) * 80) / 100);
  717. if(attackHeight != 0)
  718. g.fillRect(x + 44, y + (93 - attackHeight), 25, attackHeight);
  719.  
  720. int strengthHeight = Math.round((skills.getPercentToNextLevel(Skills.STRENGTH) * 80) / 100);
  721. if(strengthHeight != 0)
  722. g.fillRect(x + 109, y + (93 - strengthHeight), 25, strengthHeight);
  723.  
  724. int defenseHeight = Math.round((skills.getPercentToNextLevel(Skills.DEFENSE) * 80) / 100);
  725. if(defenseHeight != 0)
  726. g.fillRect(x + 174, y + (93 - defenseHeight), 25, defenseHeight);
  727.  
  728. int rangedHeight = Math.round((skills.getPercentToNextLevel(Skills.RANGE) * 80) / 100);
  729. if(rangedHeight != 0)
  730. g.fillRect(x + 238, y + (93 - rangedHeight), 25, rangedHeight);
  731.  
  732. int prayerHeight = Math.round((skills.getPercentToNextLevel(Skills.PRAYER) * 80) / 100);
  733. if(prayerHeight != 0)
  734. g.fillRect(x + 304, y + (93 - prayerHeight), 25, prayerHeight);
  735.  
  736. int magicHeight = Math.round((skills.getPercentToNextLevel(Skills.MAGIC) * 80) / 100);
  737. if(magicHeight != 0)
  738. g.fillRect(x + 370, y + (93 - magicHeight), 25, magicHeight);
  739.  
  740. int constitutionHeight = Math.round((skills.getPercentToNextLevel(Skills.CONSTITUTION) * 80) / 100);
  741. if(constitutionHeight != 0)
  742. g.fillRect(x + 434, y + (93 - constitutionHeight), 25, constitutionHeight);
  743.  
  744. g.setColor(Color.WHITE);
  745. g.setFont(new Font("Arial", Font.PLAIN, 18));
  746. g.drawString(skills.getRealLevel(Skills.ATTACK) + "", x + 20, y + 40);
  747. g.drawString(skills.getRealLevel(Skills.STRENGTH) + "", x + 85, y + 40);
  748. g.drawString(skills.getRealLevel(Skills.DEFENSE) + "", x + 150, y + 40);
  749. g.drawString(skills.getRealLevel(Skills.RANGE) + "", x + 215, y + 40);
  750. g.drawString(skills.getRealLevel(Skills.PRAYER) + "", x + 280, y + 40);
  751. g.drawString(skills.getRealLevel(Skills.MAGIC) + "", x + 345, y + 40);
  752. g.drawString(skills.getRealLevel(Skills.CONSTITUTION) + "", x + 410, y + 40);
  753.  
  754. g.setColor(Color.GREEN);
  755. g.drawString("+" + u.sw.getLevelsGainedIn(Skills.ATTACK) + "", x + 20, y + 60);
  756. g.drawString("+" + u.sw.getLevelsGainedIn(Skills.STRENGTH) + "", x + 85, y + 60);
  757. g.drawString("+" + u.sw.getLevelsGainedIn(Skills.DEFENSE) + "", x + 150, y + 60);
  758. g.drawString("+" + u.sw.getLevelsGainedIn(Skills.RANGE) + "", x + 215, y + 60);
  759. g.drawString("+" + u.sw.getLevelsGainedIn(Skills.PRAYER) + "", x + 280, y + 60);
  760. g.drawString("+" + u.sw.getLevelsGainedIn(Skills.MAGIC) + "", x + 345, y + 60);
  761. g.drawString("+" + u.sw.getLevelsGainedIn(Skills.CONSTITUTION) + "", x + 410, y + 60);
  762.  
  763. g.setColor(Color.WHITE);
  764. g.setFont(new Font("Arial", Font.PLAIN, 11));
  765.  
  766. g.drawString("TNL: " + numberPostfixer(skills.getExpToNextLevel(Skills.ATTACK)), x + 10, y + 93 + g.getFontMetrics().getMaxAscent());
  767. g.drawString(numberPostfixer(skills.getExpToNextLevel(Skills.STRENGTH)), x + 110, y + 93 + g.getFontMetrics().getMaxAscent());
  768. g.drawString(numberPostfixer(skills.getExpToNextLevel(Skills.DEFENSE)), x + 175, y + 93 + g.getFontMetrics().getMaxAscent());
  769. g.drawString(numberPostfixer(skills.getExpToNextLevel(Skills.RANGE)), x + 238, y + 93 + g.getFontMetrics().getMaxAscent());
  770. g.drawString(numberPostfixer(skills.getExpToNextLevel(Skills.PRAYER)), x + 305, y + 93 + g.getFontMetrics().getMaxAscent());
  771. g.drawString(numberPostfixer(skills.getExpToNextLevel(Skills.MAGIC)), x + 370, y + 93 + g.getFontMetrics().getMaxAscent());
  772. g.drawString(numberPostfixer(skills.getExpToNextLevel(Skills.CONSTITUTION)), x + 435, y + 93 + g.getFontMetrics().getMaxAscent());
  773.  
  774. int lowerStringY = y + 93 + g.getFontMetrics().getMaxAscent();
  775.  
  776. g.drawString("P/Hr: " + numberPostfixer(u.paint.getExpPerHour(Skills.ATTACK)),
  777. x + 10, lowerStringY + g.getFontMetrics().getMaxAscent());
  778. g.drawString(numberPostfixer(u.paint.getExpPerHour(Skills.STRENGTH)),
  779. x + 110, lowerStringY + g.getFontMetrics().getMaxAscent());
  780. g.drawString(numberPostfixer(u.paint.getExpPerHour(Skills.DEFENSE)) ,
  781. x + 175, lowerStringY + g.getFontMetrics().getMaxAscent());
  782. g.drawString(numberPostfixer(u.paint.getExpPerHour(Skills.RANGE)),
  783. x + 238, lowerStringY + g.getFontMetrics().getMaxAscent());
  784. g.drawString(numberPostfixer(u.paint.getExpPerHour(Skills.PRAYER)),
  785. x + 305, lowerStringY + g.getFontMetrics().getMaxAscent());
  786. g.drawString(numberPostfixer(u.paint.getExpPerHour(Skills.MAGIC)),
  787. x + 370, lowerStringY + g.getFontMetrics().getMaxAscent());
  788. g.drawString(numberPostfixer(u.paint.getExpPerHour(Skills.CONSTITUTION)),
  789. x + 435, lowerStringY + g.getFontMetrics().getMaxAscent());
  790. }
  791. else if (u.paint.showLoot) {
  792. int x = inter.getLocation().x;
  793. int y = inter.getLocation().y;
  794. g.drawImage(u.paint.stableRug, x, y, inter.getWidth(), inter.getHeight(), null);
  795. g.setColor(Color.WHITE);
  796. g.setFont(new Font("Arial", Font.BOLD, 14));
  797. g.drawString("Loot taken:", x + 50 , y += g.getFontMetrics().getMaxAscent() + 15);
  798. y += 5;
  799. g.setFont(new Font("Arial", Font.PLAIN, 12));
  800. Map<String, Integer> loot = u.loot.getLootTaken();
  801. int totalProfit = 0;
  802. for (Map.Entry<String, Integer> entry : loot.entrySet()) {
  803. int price;
  804. if(u.paint.prices.containsKey(entry.getKey())) {
  805. price = u.paint.prices.get(entry.getKey());
  806. }
  807. else {
  808. price = u.loot.getPrice(entry.getKey());
  809. u.paint.prices.put(entry.getKey(), price);
  810. }
  811. g.drawString(entry.getKey() + " x" + entry.getValue() + " = " + (
  812. price * entry.getValue()) + " Coins", x + 50, y += g.getFontMetrics().getMaxAscent());
  813. totalProfit += (price * entry.getValue());
  814. }
  815.  
  816. y = inter.getLocation().y;
  817. g.setFont(new Font("Arial", Font.PLAIN, 24));
  818. g.drawString("PROFIT???", x + 300, y += g.getFontMetrics().getMaxAscent() + 15);
  819. g.drawString(nf.format(totalProfit) + " COINS", x + 300, y += g.getFontMetrics().getMaxAscent() + 15);
  820. }
  821. }
  822. else{
  823. int x = inter.getLocation().x;
  824. int y = inter.getLocation().y;
  825. // Background
  826. g.setColor(new Color(198, 226, 255));
  827. g.fillRect(x, y, inter.getWidth() + 5, inter.getHeight() + 5);
  828. //Simple things
  829. g.setColor(Color.BLACK);
  830. g.setFont(new Font("Arial", Font.PLAIN, 16));
  831. g.drawString("TFighter Enhanced Edition (v" + mani.version() + ")", x + 10, y += g.getFontMetrics().getMaxAscent() + 10);
  832. g.setFont(new Font("Arial", Font.PLAIN, 14));
  833. g.drawString("By !@!@! & Zalgo2462", x + 10, y += g.getFontMetrics().getMaxAscent() + 5);
  834. g.setFont(new Font("Arial", Font.PLAIN, 12));
  835. g.drawString("Run time: " + millisToTime(runTime), x + 20, y += g.getFontMetrics().getMaxAscent() + 5);
  836.  
  837. //Exp gains
  838. g.setFont(new Font("Arial", Font.BOLD, 12));
  839. g.drawString("Experience gained:", x + 20, y += g.getFontMetrics().getMaxAscent() + 15);
  840. g.setFont(new Font("Arial", Font.PLAIN, 11));
  841.  
  842. int skillLayoutNumber = 0;
  843. final int skillYStart = y + g.getFontMetrics().getMaxAscent();
  844. for (Map.Entry<String, Integer> entry : u.sw.getExpGainedMap().entrySet()) {
  845.  
  846. skillLayoutNumber++;
  847.  
  848. double expPerSec = entry.getValue() / (double) (runTime / 1000);
  849. int expPerHour = (int) Math.round(expPerSec * 3600);
  850.  
  851.  
  852. if((skillLayoutNumber < 5) || (skillLayoutNumber > 5)) {
  853. g.drawString(entry.getKey() + ": " + nf.format(entry.getValue()) +
  854. " (p/hr: " + nf.format(expPerHour) + ")", x + 25, y += g.getFontMetrics().getMaxAscent());
  855. }
  856.  
  857. else if(skillLayoutNumber == 5) {
  858. g.drawString(entry.getKey() + ": " + nf.format(entry.getValue()) +
  859. " (p/hr: " + nf.format(expPerHour) + ")", x + 175, skillYStart);
  860. }
  861. }
  862.  
  863. //Loot
  864. y = inter.getLocation().y;
  865. g.setFont(new Font("Arial", Font.BOLD, 12));
  866. g.drawString("Loot taken:", x + 280, y += g.getFontMetrics().getMaxAscent() + 15);
  867. g.setFont(new Font("Arial", Font.PLAIN, 11));
  868. Map<String, Integer> loot = u.loot.getLootTaken();
  869. for (Map.Entry<String, Integer> entry : loot.entrySet()) {
  870. g.drawString(entry.getKey() + " x" + entry.getValue(), x + 285, y += g.getFontMetrics().getMaxAscent());
  871. }
  872. }
  873. }
  874. drawMouse(g);
  875. }
  876.  
  877. public BufferedImage getProggie() {
  878. final NumberFormat nf = NumberFormat.getIntegerInstance();
  879. int runTime = (int) System.currentTimeMillis() - startTime;
  880.  
  881. RSComponent inter = interfaces.get(137).getComponent(0);
  882. BufferedImage image = new BufferedImage(inter.getWidth(), inter.getHeight(), BufferedImage.TYPE_INT_RGB);
  883. Graphics g = image.createGraphics();
  884.  
  885. ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  886.  
  887. int x = 0;
  888. int y = 0;
  889.  
  890. g.drawImage(u.paint.stableRug, x, y, inter.getWidth(), inter.getHeight(), null);
  891. g.setColor(Color.WHITE);
  892. g.setFont(new Font("Arial", Font.PLAIN, 16));
  893. g.drawString("TFighter Enhanced Edition (v" + mani.version() + ")", x + 15, y += g.getFontMetrics().getMaxAscent() + 10);
  894. g.setFont(new Font("Arial", Font.PLAIN, 14));
  895. g.drawString("By !@!@! & Zalgo2462", x + 15, y += g.getFontMetrics().getMaxAscent() + 5);
  896. g.setFont(new Font("Arial", Font.PLAIN, 12));
  897. g.drawString("Run time: " + millisToTime(runTime), x + 25, y += g.getFontMetrics().getMaxAscent() + 5);
  898.  
  899. //Exp gains
  900. g.setFont(new Font("Arial", Font.BOLD, 12));
  901. g.drawString("Experience gained:", x + 25, y += g.getFontMetrics().getMaxAscent() + 10);
  902. g.setFont(new Font("Arial", Font.PLAIN, 11));
  903.  
  904. int skillLayoutNumber = 0;
  905. final int skillYStart = y + g.getFontMetrics().getMaxAscent();
  906. for (Map.Entry<String, Integer> entry : u.sw.getExpGainedMap().entrySet()) {
  907.  
  908. skillLayoutNumber++;
  909.  
  910. double expPerSec = entry.getValue() / (double) (runTime / 1000);
  911. int expPerHour = (int) Math.round(expPerSec * 3600);
  912.  
  913.  
  914. if((skillLayoutNumber < 4) || (skillLayoutNumber > 4)) {
  915. g.drawString(entry.getKey() + ": " + nf.format(entry.getValue()) +
  916. " (p/hr: " + nf.format(expPerHour) + ")", x + 25, y += g.getFontMetrics().getMaxAscent());
  917. }
  918.  
  919. else if(skillLayoutNumber == 4) {
  920. g.drawString(entry.getKey() + ": " + nf.format(entry.getValue()) +
  921. " (p/hr: " + nf.format(expPerHour) + ")", x + 175, skillYStart);
  922. }
  923. }
  924. y = inter.getLocation().y;
  925. g.setFont(new Font("Arial", Font.BOLD, 12));
  926. g.drawString("Loot taken:", x + 280, y += g.getFontMetrics().getMaxAscent() + 15);
  927. g.setFont(new Font("Arial", Font.PLAIN, 11));
  928. Map<String, Integer> loot = u.loot.getLootTaken();
  929. for (Map.Entry<String, Integer> entry : loot.entrySet()) {
  930. g.drawString(entry.getKey() + " x" + entry.getValue(), x + 285, y += g.getFontMetrics().getMaxAscent());
  931. }
  932. return image;
  933. }
  934.  
  935. private void drawMouse(Graphics g) {
  936. int x = mouse.getLocation().x, y = mouse.getLocation().y;
  937. g.setColor(System.currentTimeMillis() - mouse.getPressTime() < 300 ? Color.CYAN : Color.RED);
  938. g.fillOval(x - 6, y - 6, 12, 12);
  939. g.setColor(Color.ORANGE);
  940. g.fillOval(x - 3, y - 3, 6, 6);
  941. g.drawLine(x - 10, y - 10, x + 10, y + 10);
  942. g.drawLine(x - 10, y + 10, x + 10, y - 10);
  943. }
  944.  
  945. public void messageReceived(MessageEvent e) {
  946. if(e.getID() == MessageEvent.MESSAGE_SERVER) {
  947. if(e.getMessage().equals("You don't have any quick prayers selected.")) {
  948. u.pot.setQuickPrayer = false;
  949. log("You must set your quick prayers to use prayer potions.");
  950. } else if(e.getMessage().equals("There is no ammo in your quiver.")) {
  951. boolean weaponIsCBow = u.npcs.weapon.toLowerCase().contains("crossbow");
  952. for(RSItem item : inventory.getItems()) {
  953. if(item != null && item.getID() != -1) {
  954. if(weaponIsCBow && item.getName().toLowerCase().contains("bolt") ||
  955. !weaponIsCBow && item.getName().toLowerCase().contains("arrow")) {
  956. if(item.interact("Wield")) {
  957. u.npcs.ammo = item.getName();
  958. }
  959. }
  960. }
  961. }
  962. }
  963. }
  964. }
  965.  
  966. private String millisToTime(int millis) {
  967. int hours = millis / (60 * 1000 * 60);
  968. int minutes = (millis - (hours * 60 * 1000 * 60)) / (60 * 1000);
  969. int seconds = (millis - (hours * 60 * 1000 * 60) - (minutes * 60 * 1000)) / 1000;
  970. return (hours >= 10 ? hours + ":" : "0" + hours + ":")
  971. + (minutes >= 10 ? minutes + ":" : "0" + minutes + ":")
  972. + (seconds >= 10 ? seconds : "0" + seconds);
  973. }
  974.  
  975. private String numberPostfixer(int number) {
  976. if(number >= 1000) {
  977. DecimalFormat twoDForm = new DecimalFormat("#.##");
  978. double temp = number / 1000.0;
  979. return Double.valueOf(twoDForm.format(temp)) + "K";
  980. }
  981. return "" + number;
  982. }
  983.  
  984. private class Util {
  985. private final NPCs npcs = new NPCs();
  986. private final Eating eat = new Eating();
  987. private final Loot loot = new Loot();
  988. private final Potion pot = new Potion();
  989. private final Alchemy alch = new Alchemy();
  990. private final Paint paint = new Paint();
  991. private final SkillWatcher sw = new SkillWatcher();
  992. private final VersionChecker vChecker = new VersionChecker();
  993. private final Banking bank = new Banking();
  994. private final Tiles tiles = new Tiles();
  995. private final RoomGeneration rooms = new RoomGeneration();
  996. }
  997.  
  998. private class NPCs {
  999. private int[] npcIDs = new int[0];
  1000. private String[] npcNames = new String[0];
  1001.  
  1002. private String weapon = "";
  1003. private boolean hasSpecialWeapon = false;
  1004.  
  1005. public String ammo = "";
  1006.  
  1007. public String ring = "";
  1008.  
  1009. private int maxRadius = 10;
  1010.  
  1011. RSNPC lastClickedNPC = null;
  1012.  
  1013. private ArrayList<RSTile> tilesFoughtOn = new ArrayList<RSTile>();
  1014. public boolean rechargeAvailable = true;
  1015.  
  1016. public boolean useSpecial() {
  1017. if(hasSpecialWeapon) {
  1018. int[] amountUsage = {10, 25, 33, 35, 45, 50, 55, 60, 80, 85, 100};
  1019. String[][] weapons = {
  1020. {"Rune thrownaxe", "Rod of ivandis"},
  1021. {"Dragon Dagger", "Dragon dagger (p)", "Dragon dagger (p+)",
  1022. "Dragon dagger (p++)", "Dragon Mace", "Dragon Spear",
  1023. "Dragon longsword", "Rune claws"},
  1024. {"Dragon Halberd"},
  1025. {"Magic Longbow"},
  1026. {"Magic Composite Bow"},
  1027. {"Dragon Claws", "Abyssal Whip", "Granite Maul", "Darklight",
  1028. "Barrelchest Anchor", "Armadyl Godsword"},
  1029. {"Magic Shortbow"},
  1030. {"Dragon Scimitar", "Dragon 2H Sword", "Zamorak Godsword",
  1031. "Korasi's sword"},
  1032. {"Dorgeshuun Crossbow", "Bone Dagger", "Bone Dagger (p+)",
  1033. "Bone Dagger (p++)"},
  1034. {"Brine Sabre"},
  1035. {"Bandos Godsword", "Dragon Battleaxe", "Dragon Hatchet",
  1036. "Seercull Bow", "Excalibur", "Enhanced excalibur",
  1037. "Ancient Mace", "Saradomin sword"}};
  1038.  
  1039. for (int i = 0; i < weapons.length; i++) {
  1040. for (int j = 0; j < weapons[i].length; j++) {
  1041. if (weapons[i][j].equalsIgnoreCase(weapon)) {
  1042. return combat.getSpecialBarEnergy() >= amountUsage[i];
  1043. }
  1044. }
  1045. }
  1046. }
  1047. return false;
  1048. }
  1049.  
  1050. /**
  1051. * Checks if we are in combat.
  1052. *
  1053. * @return True if we are in combat.
  1054. */
  1055. private boolean isInCombat() {
  1056. return getMyPlayer().getInteracting() instanceof RSNPC;
  1057. }
  1058.  
  1059. /**
  1060. * Clicks an NPC based on its model.
  1061. *
  1062. * @param npc The NPC to click.
  1063. * @param action The action to perform.
  1064. * @return 0 if the NPC was clicked, 1 if we walked to it, or -1 if nothing happened.
  1065. */
  1066. private int clickNPC(RSNPC npc, String action) {
  1067. for (int i = 0; i < 10; i++) {
  1068. if (isPartiallyOnScreen(npc.getModel())) {
  1069. Point p = useCentralClicking ? getCentralPoint(npc.getModel()) : getPointOnScreen(npc.getModel(), false);
  1070. if (p == null || !calc.pointOnScreen(p)) {
  1071. continue;
  1072. }
  1073. mouse.move(p, useCentralClicking ? 3 : 0, useCentralClicking ? 3 : 0);
  1074. String[] items = menu.getItems();
  1075. if (items.length > 0 && items[0].contains(action)) {
  1076. mouse.click(true);
  1077. lastClickedNPC = npc;
  1078. return 0;
  1079. } else if (menu.contains(action)) {
  1080. mouse.click(false);
  1081. sleep(random(100, 200));
  1082. for (int x = 0; x < 4; x++) {
  1083. if (!menu.contains(action)) {
  1084. break;
  1085. }
  1086. if (menu.click(action)) {
  1087. lastClickedNPC = npc;
  1088. return 0;
  1089. }
  1090. }
  1091. }
  1092. } else {
  1093. if(!useSafespot) {
  1094. walking.walkTileMM(closerTile(npc.getLocation(), 1), 2, 2);
  1095. sleep(random(1500, 2000));
  1096. return 1;
  1097. } else {
  1098. int angle = camera.getCharacterAngle(npc);
  1099. if (calc.distanceTo(npc) < 10 && Math.abs(angle - camera.getAngle()) > 20) {
  1100. camera.setAngle(angle + random(-20, 20));
  1101. }
  1102. }
  1103. }
  1104. }
  1105. return -1;
  1106. }
  1107.  
  1108. /**
  1109. * Checks if a model is partially on screen.
  1110. *
  1111. * @param m The RSModel to check.
  1112. * @return True if any point on the model is on screen.
  1113. */
  1114. private boolean isPartiallyOnScreen(RSModel m) {
  1115. return getPointOnScreen(m, true) != null;
  1116. }
  1117.  
  1118. /**
  1119. * Gets a point on a model that is on screen.
  1120. *
  1121. * @param m The RSModel to test.
  1122. * @param first If true, it will return the first point that it finds on screen.
  1123. * @return A random point on screen of an object.
  1124. */
  1125. private Point getPointOnScreen(RSModel m, boolean first) {
  1126. if (m == null)
  1127. return null;
  1128. ArrayList<Point> list = new ArrayList<Point>();
  1129. try {
  1130. Polygon[] tris = m.getTriangles();
  1131. for (Polygon p : tris) {
  1132. for (int j = 0; j < p.xpoints.length; j++) {
  1133. Point pt = new Point(p.xpoints[j], p.ypoints[j]);
  1134. if (calc.pointOnScreen(pt)) {
  1135. if (first)
  1136. return pt;
  1137. list.add(pt);
  1138. }
  1139. }
  1140. }
  1141. } catch (Exception ignored) {
  1142. }
  1143. return list.size() > 0 ? list.get(random(0, list.size())) : null;
  1144. }
  1145.  
  1146. /**
  1147. * Generates a rough central point. Performs the calculation
  1148. * by first generating a rough point, and then finding the point
  1149. * closest to the rough point that is actually on the RSModel.
  1150. *
  1151. * @param m The RSModel to test.
  1152. * @return The rough central point.
  1153. */
  1154. private Point getCentralPoint(RSModel m) {
  1155. if(m == null)
  1156. return null;
  1157. try {
  1158. /* Add X and Y of all points, to get a rough central point */
  1159. int x = 0, y = 0, total = 0;
  1160. for(Polygon poly : m.getTriangles()) {
  1161. for(int i = 0; i < poly.npoints; i++) {
  1162. x += poly.xpoints[i];
  1163. y += poly.ypoints[i];
  1164. total++;
  1165. }
  1166. }
  1167. Point central = new Point(x / total, y / total);
  1168. /* Find a real point on the NPC that is closest to the central point */
  1169. Point curCentral = null;
  1170. double dist = 20000;
  1171. for(Polygon poly : m.getTriangles()) {
  1172. for(int i = 0; i < poly.npoints; i++) {
  1173. Point p = new Point(poly.xpoints[i], poly.ypoints[i]);
  1174. if(!calc.pointOnScreen(p))
  1175. continue;
  1176. double dist2 = distanceBetween(central, p);
  1177. if(curCentral == null || dist2 < dist) {
  1178. curCentral = p;
  1179. dist = dist2;
  1180. }
  1181. }
  1182. }
  1183. return curCentral;
  1184. } catch (Exception ignored) {}
  1185. return null;
  1186. }
  1187.  
  1188. /**
  1189. * Calculates the distance between two points.
  1190. *
  1191. * @param p1 The first point.
  1192. * @param p2 The second point.
  1193. * @return The distance between the two points, using the distance formula.
  1194. */
  1195. private double distanceBetween(Point p1, Point p2) {
  1196. return Math.sqrt(((p1.x - p2.x) * (p1.x - p2.x)) + ((p1.y - p2.y) * (p1.y - p2.y)));
  1197. }
  1198.  
  1199. /**
  1200. * Gets a closer tile to us within dist.
  1201. *
  1202. * @param t The tile to start with.
  1203. * @param dist The max dist.
  1204. * @return A closer tile.
  1205. */
  1206. private RSTile closerTile(RSTile t, int dist) {
  1207. RSTile loc = getMyPlayer().getLocation();
  1208. int newX = t.getX(), newY = t.getY();
  1209. for (int i = 1; i < dist; i++) {
  1210. newX = t.getX() != loc.getX() ? (t.getX() < loc.getX() ? newX-- : newX++) : newX;
  1211. newY = t.getY() != loc.getY() ? (t.getY() < loc.getY() ? newY-- : newY++) : newY;
  1212. }
  1213. return new RSTile(newX, newY);
  1214. }
  1215.  
  1216. /**
  1217. * Returns the nearest NPC.
  1218. *
  1219. * @return The nearest NPC that matches the filter.
  1220. */
  1221. private RSNPC getNPC() {
  1222. RSNPC onScreen = npcs.getNearest(npcOnScreenFilter);
  1223. if(onScreen != null)
  1224. return onScreen;
  1225. return npcs.getNearest(npcFilter);
  1226. }
  1227.  
  1228. /**
  1229. * Returns the interacting NPC that matches our description, if any.
  1230. *
  1231. * @return The closest interacting NPC that matches the filter.
  1232. */
  1233. private RSNPC getInteracting() {
  1234. RSNPC npc = null;
  1235. int dist = 20;
  1236. for (RSNPC n : npcs.getAll()) {
  1237. if (!isOurNPC(n))
  1238. continue;
  1239. RSCharacter inter = n.getInteracting();
  1240. if (inter != null && inter instanceof RSPlayer && inter.equals(getMyPlayer()) && calc.distanceTo(n) < dist) {
  1241. dist = calc.distanceTo(n);
  1242. npc = n;
  1243. }
  1244. }
  1245. return npc;
  1246. }
  1247.  
  1248. private boolean isOurNPC(RSNPC t) {
  1249. int id = t.getID();
  1250. String name = t.getName();
  1251. boolean good = false;
  1252. for (int i : npcIDs) {
  1253. if (id == i)
  1254. good = true;
  1255. }
  1256. for (String s : npcNames) {
  1257. if (name.toLowerCase().contains(s.toLowerCase()))
  1258. good = true;
  1259. }
  1260. return good;
  1261. }
  1262.  
  1263. private void sleepWhileNpcIsDying(RSNPC t) {
  1264. if(t.isDead()) {
  1265. RSGroundItem[] GIs = groundItems.getAllAt(t.getLocation());
  1266. long start = System.currentTimeMillis();
  1267. while(t.isDead() && GIs.length == groundItems.getAllAt(t.getLocation()).length
  1268. && System.currentTimeMillis() - start < 5000) {
  1269. sleep(random(20, 70));
  1270. }
  1271. }
  1272. }
  1273.  
  1274. private boolean weaponContains(String... tests) {
  1275. for(String test : tests) {
  1276. if(weapon.toLowerCase().contains(test))
  1277. return true;
  1278. }
  1279. return false;
  1280. }
  1281.  
  1282.  
  1283. /**
  1284. * The filter we use!
  1285. */
  1286. private final Filter<RSNPC> npcFilter = new Filter<RSNPC>() {
  1287. public boolean accept(RSNPC t) {
  1288. return (isOurNPC(t) && t.isValid() && (!onlyInRadius || calc.distanceBetween(t.getLocation(), startTile) < maxRadius)
  1289. && (utilizeMultiwayCombat || !t.isInCombat() && t.getInteracting() == null) && t.getHPPercent() != 0
  1290. && !u.tiles.NPCIsOnBadTile(t));
  1291. }
  1292. };
  1293.  
  1294. /**
  1295. * Will only return an on screen NPC. Based on npcFilter.
  1296. */
  1297. private final Filter<RSNPC> npcOnScreenFilter = new Filter<RSNPC>() {
  1298. public boolean accept(RSNPC n) {
  1299. return npcFilter.accept(n) && getPointOnScreen(n.getModel(), true) != null;
  1300. }
  1301. };
  1302. }
  1303.  
  1304. private class Eating {
  1305. private final int[] B2P_TAB_ID = new int[]{8015};
  1306. // --Commented out by Inspection (7/20/11 2:14 PM):private final int[] B2B_TAB_ID = new int[]{8014};
  1307. private final int[] NATURE_RUNE = new int[]{561};
  1308. private final int[] EARTH_RUNE = new int[]{557};
  1309. private final int[] WATER_RUNE = new int[]{555};
  1310. private final int[] MUD_RUNE = new int[]{4698};
  1311. private final int[] BONES_ID = new int[]{526, 532, 530, 528, 3183, 2859};
  1312.  
  1313. private int toEatAtPercent = getRandomEatPercent();
  1314.  
  1315. private RSItem foodOfChoice;
  1316.  
  1317. /**
  1318. * Returns a random integer of when to eat.
  1319. * @return A random integer of the percent to eat at.
  1320. */
  1321. private int getRandomEatPercent() {
  1322. return random(45, 60);
  1323. }
  1324.  
  1325. /**
  1326. * Checks if we have at least one B2P tab.
  1327. *
  1328. * @return True if we have a tab.
  1329. */
  1330. private boolean haveB2pTab() {
  1331. return inventory.getCount(B2P_TAB_ID) > 0;
  1332. }
  1333. /**
  1334. * Checks if we have enough runes for B2B.
  1335. * @return True if we have enough runes.
  1336. */
  1337. private boolean haveB2bRunes() {
  1338. if(inventory.getCount(true, NATURE_RUNE) > 2) {
  1339. if(inventory.getCount(true, MUD_RUNE) >= 1 || (inventory.getCount(true, EARTH_RUNE) >= 1 && inventory.getCount(true, WATER_RUNE) >= 1)) {
  1340. return true;
  1341. }
  1342. }
  1343. return false;
  1344. }
  1345.  
  1346. /**
  1347. * Breaks a B2P tab.
  1348. */
  1349. private void breakB2pTab() {
  1350. RSItem i = inventory.getItem(B2P_TAB_ID);
  1351. if (i != null)
  1352. i.doClick(true);
  1353. }
  1354.  
  1355. /**
  1356. * Casts B2B.
  1357. */
  1358. private void castB2b() {
  1359. game.openTab(Game.Tab.MAGIC);
  1360. magic.castSpell(Magic.SPELL_BONES_TO_BANANAS);
  1361. }
  1362.  
  1363. /**
  1364. * Checks if the inventory contains bones, for B2P.
  1365. *
  1366. * @return True if we have bones.
  1367. */
  1368. private boolean haveBones() {
  1369. return inventory.getCount(BONES_ID) > 0;
  1370. }
  1371.  
  1372. /**
  1373. * Checks if we have food.
  1374. *
  1375. * @return True if we have food.
  1376. */
  1377. private boolean haveFood() {
  1378. return getFood() != null;
  1379. }
  1380.  
  1381. /**
  1382. * Finds food based on inventory actions.
  1383. *
  1384. * @return The RSItem of food, or null if none was found.
  1385. */
  1386. private RSItem getFood() {
  1387. for (RSItem i : inventory.getItems()) {
  1388. if (i == null || i.getID() == -1)
  1389. continue;
  1390. if (i.getComponent().getActions() == null || i.getComponent().getActions()[0] == null)
  1391. continue;
  1392. if (i.getComponent().getActions()[0].contains("Eat"))
  1393. return i;
  1394. }
  1395. return null;
  1396. }
  1397.  
  1398. /**
  1399. * Attempts to eat food.
  1400. *
  1401. * @return True if we ate.
  1402. */
  1403. private boolean eatFood() {
  1404. RSItem i = getFood();
  1405. for (int j = 0; j < 3; j++) {
  1406. if (i == null)
  1407. break;
  1408. if (i.interact("Eat")) {
  1409. return true;
  1410. }
  1411. }
  1412. return false;
  1413. }
  1414.  
  1415. /**
  1416. * Checks whether you need to eat or not.
  1417. *
  1418. * @return True if we need to eat.
  1419. */
  1420. private boolean needEat() {
  1421. if(getHPPercent() <= toEatAtPercent) {
  1422. toEatAtPercent = getRandomEatPercent();
  1423. return true;
  1424. }
  1425. return false;
  1426. }
  1427.  
  1428. /**
  1429. * Returns an integer representing the current health percentage.
  1430. * @return The current health percentage.
  1431. */
  1432. public int getHPPercent() {
  1433. try {
  1434. return ((int) ((Integer.parseInt(interfaces.get(748).getComponent(8).getText().trim()) / (double)(skills.getRealLevel(Skills.CONSTITUTION) * 10)) * 100));
  1435. } catch (Exception e) {
  1436. return 100;
  1437. }
  1438. }
  1439. }
  1440.  
  1441. private class Loot {
  1442. private int[] lootIDs = new int[0];
  1443. private String[] lootNames = new String[0];
  1444.  
  1445. private Map<String, Integer> lootTaken = new HashMap<String, Integer>();
  1446.  
  1447. public boolean lootAbove = false;
  1448. public int lootAboveX = 10000;
  1449.  
  1450. public boolean onlyTakeLootFromKilled = false;
  1451. /**
  1452. * Gets the nearest loot, based on the filter
  1453. *
  1454. * @return The nearest item to loot, or null if none.
  1455. */
  1456. private RSGroundItem getLoot() {
  1457. return groundItems.getNearest(lootFilter);
  1458. }
  1459.  
  1460. /**
  1461. * Attempts to take an item.
  1462. *
  1463. * @param item The item to take.
  1464. * @return -1 if error, 0 if taken, 1 if walked
  1465. */
  1466. private int takeItem(RSGroundItem item) {
  1467. if (item == null)
  1468. return -1;
  1469. String action = "Take " + item.getItem().getName();
  1470. if (item.isOnScreen()) {
  1471. for (int i = 0; i < 5; i++) {
  1472. if (menu.isOpen())
  1473. mouse.moveRandomly(300, 500);
  1474. Point p = calc.tileToScreen(item.getLocation(), random(0.48, 0.52), random(0.48, 0.52), 0);
  1475. if (!calc.pointOnScreen(p))
  1476. continue;
  1477. mouse.move(p, 3, 3);
  1478. if (menu.contains(action)) {
  1479. if (menu.getItems()[0].contains(action)) {
  1480. mouse.click(true);
  1481. return 0;
  1482. } else {
  1483. mouse.click(false);
  1484. sleep(random(100, 200));
  1485. if (menu.click(action)) {
  1486. return 0;
  1487. }
  1488. }
  1489. }
  1490. }
  1491. } else {
  1492. walking.walkTileMM(walking.getClosestTileOnMap(item.getLocation()));
  1493. sleep(random(1500, 2000));
  1494. return 1;
  1495. }
  1496. return -1;
  1497. }
  1498.  
  1499. private void addItem(String name, int count) {
  1500. if (lootTaken.get(name) != null) {
  1501. int newCount = count + lootTaken.get(name);
  1502. lootTaken.remove(name);
  1503. lootTaken.put(name, newCount);
  1504. } else {
  1505. lootTaken.put(name, count);
  1506. }
  1507. }
  1508.  
  1509. private Map<String, Integer> getLootTaken() {
  1510. HashMap<String, Integer> m = new HashMap<String, Integer>();
  1511. m.putAll(lootTaken);
  1512. return m;
  1513. }
  1514.  
  1515. public int getPrice(String itemName) {
  1516. try {
  1517. if(itemName.toLowerCase().contains("coin"))
  1518. return 1;
  1519. itemName = itemName.replace(' ', '+');
  1520. URL url = new URL("http://rscript.org/lookup.php?type=ge&search=" + itemName);
  1521. BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
  1522. String inputLine;
  1523. int price = 0;
  1524. while ((inputLine = in.readLine()) != null) {
  1525. if (inputLine.contains(itemName.replace('+', '_'))) {
  1526. String words[] = inputLine.split(" ");
  1527. price = Integer.parseInt(words[4]);
  1528. }
  1529. }
  1530. in.close();
  1531. return price;
  1532. } catch (Exception e) {
  1533. return -1;
  1534. }
  1535. }
  1536.  
  1537. private final Filter<RSGroundItem> lootFilter = new Filter<RSGroundItem>() {
  1538. public boolean accept(RSGroundItem t) {
  1539. //Skip if we can't hold it
  1540. RSItem i;
  1541. if (inventory.isFull() && ((i = inventory.getItem(t.getItem().getID())) == null || i.getStackSize() <= 1)) {
  1542. return false;
  1543. }
  1544. //Skip if its out of radius or far away
  1545. if (onlyInRadius && calc.distanceBetween(t.getLocation(), startTile) > u.npcs.maxRadius
  1546. || calc.distanceTo(t.getLocation()) > 25) {
  1547. return false;
  1548. }
  1549. //Check ID/name
  1550. boolean good = false;
  1551.  
  1552. int id = t.getItem().getID();
  1553. for (int iD : lootIDs) {
  1554. if (iD == id)
  1555. good = true;
  1556. }
  1557.  
  1558. String name = t.getItem().getName();
  1559. for (String s : lootNames) {
  1560. if (name != null && name.toLowerCase().contains(s.toLowerCase()))
  1561. good = true;
  1562. }
  1563.  
  1564. if(lootAbove) {
  1565. int price;
  1566.  
  1567. if(u.paint.prices.containsKey(name)) {
  1568. price = u.paint.prices.get(name);
  1569. } else {
  1570. price = getPrice(name);
  1571. log(name + ": " + price);
  1572. u.paint.prices.put(name, price);
  1573. }
  1574.  
  1575. if(t.getItem().getStackSize() > 1) {
  1576. price *= t.getItem().getStackSize();
  1577. }
  1578.  
  1579. if(price >= lootAboveX)
  1580. good = true;
  1581. }
  1582.  
  1583. if(good && u.tiles.groundItemIsOnBadTile(t)) {
  1584. good = false;
  1585. }
  1586.  
  1587. if(good && onlyTakeLootFromKilled) {
  1588. if(!u.npcs.tilesFoughtOn.isEmpty()) {
  1589. for(RSTile tileFoughtOn : u.npcs.tilesFoughtOn) {
  1590. if(t.getLocation().getX() == tileFoughtOn.getX() && t.getLocation().getY() == tileFoughtOn.getY()) {
  1591. good = true;
  1592. break;
  1593. } else {
  1594. good = false;
  1595. }
  1596. }
  1597. } else {
  1598. good = false;
  1599. }
  1600. }
  1601. return good;
  1602. }
  1603. };
  1604. }
  1605.  
  1606. private class Potion {
  1607. private final int[] MAGIC_POTIONS = new int[] {3040, 3042, 3044, 3046, 11513, 11515, 13520, 13521, 13522, 13523},
  1608. PRAYER_POTIONS = new int[] {2434, 139, 141, 143, 11465, 11467},
  1609. RANGE_POTIONS = new int[] {2444, 169, 171, 173, 11509, 11511, 13524, 13525, 15326, 15327},
  1610. ENERGY_POTIONS = new int[] {3008, 3010, 3012, 3014, 3016, 3018, 3020, 3022, 11453, 11455, 11481, 11483},
  1611. COMBAT_POTIONS = new int[] {9739, 9741, 9743, 9745, 11445, 11447},
  1612. ATTACK_POTIONS = new int[] {2428, 121, 123, 125, 2436, 145, 147, 149, 11429, 11431,
  1613. 11429, 11431, 11429, 11431, 11469, 11471, 15308 , 15309, 15310, 15311},
  1614. STRENGTH_POTIONS = new int[] {113, 115, 117, 119, 2440, 157, 159, 161, 11443, 11441,
  1615. 11485, 11487, 15312, 15313, 15314, 15315},
  1616. DEFENSE_POTIONS = new int[] {2432, 133, 135, 137, 2442, 163, 165, 167, 11457, 11459,
  1617. 11497, 11499, 15316, 15317, 15318, 15319},
  1618. ANTIPOISON = new int[] {2446, 175, 177, 179, 2448, 181, 183, 185, 5952, 5954,
  1619. 5956, 5958, 5943, 5945, 5947, 5949, 11433, 11435, 11501, 11503},
  1620. ZAMORAK_POTIONS = new int[] {2450, 189, 191, 193, 11521, 11523},
  1621. SARADOMIN_POTIONS = new int[] {6685, 6687, 6689, 6691},
  1622. OVERLOAD_POTIONS = new int[] {15332, 15333, 15334, 15335};
  1623.  
  1624. private final int VIAL = 229;
  1625.  
  1626. private boolean setQuickPrayer = true;
  1627.  
  1628. private HashMap<String, RSItem[]> getPotions() {
  1629. HashMap<String, RSItem[]> potions = new HashMap<String, RSItem[]>();
  1630.  
  1631. potions.put("MAGIC", inventory.getItems(MAGIC_POTIONS));
  1632.  
  1633. potions.put("PRAYER", inventory.getItems(PRAYER_POTIONS));
  1634.  
  1635. potions.put("RANGE", inventory.getItems(RANGE_POTIONS));
  1636.  
  1637. potions.put("ENERGY", inventory.getItems(ENERGY_POTIONS));
  1638.  
  1639. potions.put("COMBAT", inventory.getItems(COMBAT_POTIONS));
  1640.  
  1641. potions.put("ATTACK", inventory.getItems(ATTACK_POTIONS));
  1642.  
  1643. potions.put("STRENGTH", inventory.getItems(STRENGTH_POTIONS));
  1644.  
  1645. potions.put("DEFENSE", inventory.getItems(DEFENSE_POTIONS));
  1646.  
  1647. potions.put("ANTIPOISON", inventory.getItems(ANTIPOISON));
  1648.  
  1649. potions.put("ZAMORAK", inventory.getItems(ZAMORAK_POTIONS));
  1650.  
  1651. potions.put("SARADOMIN", inventory.getItems(SARADOMIN_POTIONS));
  1652.  
  1653. potions.put("OVERLOAD", inventory.getItems(OVERLOAD_POTIONS));
  1654.  
  1655. return potions;
  1656. }
  1657.  
  1658. public void usePotions() {
  1659. HashMap<String, RSItem[]> potions = u.pot.getPotions();
  1660.  
  1661. if(inventory.getItems(VIAL).length != 0) {
  1662. for( RSItem i : inventory.getItems(VIAL)) {
  1663. int n = inventory.getCount(true);
  1664. i.interact("Drop Vial");
  1665. waitForInvChange(n);
  1666. }
  1667. }
  1668.  
  1669. if(!(u.pot.statIsBoosted(Skills.MAGIC)) && (potions.get("MAGIC").length != 0 || potions.get("OVERLOAD").length != 0)) {
  1670. if(potions.get("MAGIC").length != 0) {
  1671. potions.get("MAGIC")[0].doClick(true);
  1672. }
  1673. else if(potions.get("OVERLOAD").length != 0) {
  1674. potions.get("OVERLOAD")[0].doClick(true);
  1675. }
  1676. }
  1677.  
  1678. if(shouldUsePrayerPot() && potions.get("PRAYER").length != 0 && setQuickPrayer) {
  1679. int current = prayer.getPrayerLeft();
  1680. if(potions.get("PRAYER")[0].doClick(true)) {
  1681. long time = System.currentTimeMillis();
  1682. while(prayer.getPrayerLeft() == current && System.currentTimeMillis() - time < 10000) {
  1683. sleep(random(200, 500));
  1684. }
  1685. }
  1686. }
  1687.  
  1688. if(!(u.pot.statIsBoosted(Skills.RANGE)) && (potions.get("RANGE").length != 0 || potions.get("OVERLOAD").length != 0)) {
  1689. if(potions.get("RANGE").length != 0) {
  1690. potions.get("RANGE")[0].doClick(true);
  1691. }
  1692. else if(potions.get("OVERLOAD").length != 0) {
  1693. potions.get("OVERLOAD")[0].doClick(true);
  1694. }
  1695. }
  1696.  
  1697. if(walking.getEnergy() < random(40, 70) && potions.get("ENERGY").length != 0) {
  1698. potions.get("ENERGY")[0].doClick(true);
  1699. }
  1700.  
  1701. if(!(u.pot.statIsBoosted(Skills.STRENGTH)) && (potions.get("STRENGTH").length != 0 || potions.get("COMBAT").length != 0 || potions.get("ZAMORAK").length != 0 || potions.get("OVERLOAD").length != 0)) {
  1702. if(potions.get("COMBAT").length != 0) {
  1703. potions.get("COMBAT")[0].doClick(true);
  1704. }
  1705. else if(potions.get("STRENGTH").length != 0) {
  1706. potions.get("STRENGTH")[0].doClick(true);
  1707. }
  1708. else if(potions.get("ZAMORAK").length != 0) {
  1709. potions.get("ZAMORAK")[0].doClick(true);
  1710. }
  1711. else if(potions.get("OVERLOAD").length != 0) {
  1712. potions.get("OVERLOAD")[0].doClick(true);
  1713. }
  1714. }
  1715.  
  1716. if(!(u.pot.statIsBoosted(Skills.DEFENSE)) && (potions.get("DEFENSE").length != 0 || potions.get("SARADOMIN").length != 0 || potions.get("OVERLOAD").length != 0)) {
  1717. if(potions.get("DEFENSE").length != 0) {
  1718. potions.get("DEFENSE")[0].doClick(true);
  1719. }
  1720. else if(potions.get("SARADOMIN").length != 0) {
  1721. potions.get("SARADOMIN")[0].doClick(true);
  1722. }
  1723. else if(potions.get("OVERLOAD").length != 0) {
  1724. potions.get("OVERLOAD")[0].doClick(true);
  1725. }
  1726. }
  1727.  
  1728. if(!(u.pot.statIsBoosted(Skills.ATTACK)) && (potions.get("ATTACK").length != 0 || potions.get("COMBAT").length != 0 || potions.get("ZAMORAK").length != 0 || potions.get("OVERLOAD").length != 0)) {
  1729. if(potions.get("COMBAT").length != 0) {
  1730. potions.get("COMBAT")[0].doClick(true);
  1731. }
  1732. else if(potions.get("ATTACK").length != 0) {
  1733. potions.get("ATTACK")[0].doClick(true);
  1734. }
  1735. else if(potions.get("ZAMORAK").length != 0) {
  1736. potions.get("ZAMORAK")[0].doClick(true);
  1737. }
  1738. else if(potions.get("OVERLOAD").length != 0) {
  1739. potions.get("OVERLOAD")[0].doClick(true);
  1740. }
  1741. }
  1742.  
  1743. if(combat.isPoisoned() && potions.get("ANTIPOISON").length != 0) {
  1744. potions.get("ANTIPOISON")[0].doClick(true);
  1745. }
  1746. }
  1747.  
  1748.  
  1749. private boolean statIsBoosted(int Skill) {
  1750. return skills.getCurrentLevel(Skill) != skills.getRealLevel(Skill);
  1751. }
  1752.  
  1753. private boolean shouldUsePrayerPot() {
  1754. return skills.getRealLevel(Skills.PRAYER) - (prayer.getPrayerLeft() / 10) > (70 + Math.floor(skills.getRealLevel(Skills.PRAYER) * 2.5));
  1755. }
  1756. }
  1757.  
  1758. private class Alchemy {
  1759. private int[] alchIDs = new int[0];
  1760. private String[] alchNames = new String[0];
  1761. private final int NATURE_RUNE = 561;
  1762. private final int FIRE_RUNE = 554;
  1763. private final int COINS= 995;
  1764.  
  1765. public boolean canAlch() {
  1766. if(inventory.getCount(true, NATURE_RUNE) >= 1 && (inventory.getCount(true, FIRE_RUNE) >= 5 || u.npcs.weaponContains("fire", "steam", "lava"))
  1767. && (inventory.getCount(COINS) > 0 ||
  1768. inventory.getCount() <= 27) && skills.getCurrentLevel(Skills.MAGIC) >= 55) {
  1769. return true;
  1770. }
  1771. else if(inventory.getCount(true, NATURE_RUNE) >= 1 && inventory.getCount(true, FIRE_RUNE) >= 3 && (inventory.getCount(COINS) > 0 || inventory.getCount() <= 27) && skills.getCurrentLevel(Skills.MAGIC) >= 21) {
  1772. return true;
  1773. }
  1774. return false;
  1775. }
  1776.  
  1777. public boolean hasAlchItems() {
  1778. if(alchNames.length > 0 || alchIDs.length > 0)
  1779. {
  1780. for( RSItem i : inventory.getItems()) {
  1781. for ( String s : u.alch.alchNames) {
  1782. if (i.getComponent() != null && i.getID() != -1 && i.getName().toLowerCase().contains(s)) {
  1783. return true;
  1784. }
  1785. }
  1786. for ( int n : u.alch.alchIDs) {
  1787. if( n == i.getID()) {
  1788. return true;
  1789. }
  1790. }
  1791. }
  1792. }
  1793. return false;
  1794. }
  1795.  
  1796. public void alch(RSComponent i) {
  1797. if (i != null) {
  1798. if(inventory.getCount(true, NATURE_RUNE) >= 1 && (inventory.getCount(true, FIRE_RUNE) >= 5 ||
  1799. u.npcs.weaponContains("fire", "lava", "steam")) && skills.getCurrentLevel(Skills.MAGIC) >= 55) {
  1800.  
  1801. if(game.getTab() != Game.Tab.MAGIC) {
  1802. game.openTab(Game.Tab.MAGIC);
  1803. }
  1804. magic.castSpell(Magic.SPELL_HIGH_LEVEL_ALCHEMY);
  1805. }
  1806. else if(inventory.getCount(true, NATURE_RUNE) >= 1 && (inventory.getCount(true, FIRE_RUNE) >= 5 ||
  1807. u.npcs.weaponContains("fire", "lava", "steam")) && skills.getCurrentLevel(Skills.MAGIC) >= 21) {
  1808.  
  1809. if(game.getTab() != Game.Tab.MAGIC) {
  1810. game.openTab(Game.Tab.MAGIC);
  1811. }
  1812. magic.castSpell(Magic.SPELL_LOW_LEVEL_ALCHEMY);
  1813. }
  1814. sleep(random(150, 500));
  1815. i.interact("Cast");
  1816. }
  1817. }
  1818. }
  1819.  
  1820. private class Paint {
  1821. BufferedImage ribbon = null;
  1822. BufferedImage stableRug = null;
  1823. BufferedImage skillsRug = null;
  1824. Font KellyAnnGothic = null;
  1825. boolean showPaint = false;
  1826. boolean showMain = false;
  1827. boolean showSkills = false;
  1828. boolean showLoot = false;
  1829. boolean useAdvancedPaint = true;
  1830. HashMap<String, Integer> prices = new HashMap<String, Integer>();
  1831.  
  1832. private Paint() {
  1833. try {
  1834. ribbon = ImageIO.read(new URL("http://scripters.powerbot.org/files/349221/Paint/pentagon_tag.png"));
  1835. stableRug = ImageIO.read(new URL("http://scripters.powerbot.org/files/349221/Paint/rug.png"));
  1836. skillsRug = ImageIO.read(new URL("http://scripters.powerbot.org/files/349221/Paint/rug1.png"));
  1837. URL fontURL = new URL("http://scripters.powerbot.org/files/349221/Paint/kellyag.ttf");
  1838. URLConnection fontDownload = fontURL.openConnection();
  1839. KellyAnnGothic = Font.createFont(Font.TRUETYPE_FONT, fontDownload.getInputStream());
  1840. } catch (Exception e){
  1841. useAdvancedPaint = false;
  1842. }
  1843. }
  1844.  
  1845. public int getExpPerHour(int Skill) {
  1846. double entry = u.sw.getExpGainedIn(Skill);
  1847. int runTime = (int) System.currentTimeMillis() - startTime;
  1848. double expPerSec = entry / (runTime / 1000);
  1849. return((int) Math.round(expPerSec * 3600));
  1850. }
  1851. }
  1852.  
  1853. private class SkillWatcher {
  1854. private HashMap<Integer, Integer> startExpMap = new HashMap<Integer, Integer>();
  1855. private final int[] SKILLS_TO_WATCH = new int[]{Skills.SLAYER, Skills.CONSTITUTION, Skills.ATTACK, Skills.STRENGTH, Skills.DEFENSE, Skills.RANGE, Skills.MAGIC, Skills.PRAYER};
  1856. private HashMap<Integer, Integer> startLevelsMap = new HashMap<Integer, Integer>();
  1857.  
  1858. /**
  1859. * Basically sets start exp for all skills we are watching.
  1860. */
  1861. public void poll() {
  1862. for (int skill : SKILLS_TO_WATCH) {
  1863. if (startExpMap.containsKey(skill)) {
  1864. startExpMap.remove(skill);
  1865. }
  1866. if (startLevelsMap.containsKey(skill)) {
  1867. startLevelsMap.remove(skill);
  1868. }
  1869. startExpMap.put(skill, skills.getCurrentExp(skill));
  1870. startLevelsMap.put(skill, skills.getRealLevel(skill));
  1871. }
  1872. }
  1873.  
  1874. /**
  1875. * Returns the amount of exp gained in the specified skill.
  1876. *
  1877. * @param skill The skill see Skills.*
  1878. * @return the EXP Gained
  1879. */
  1880. public int getExpGainedIn(int skill) {
  1881. if (startExpMap.get(skill) == null)
  1882. return -1;
  1883. return skills.getCurrentExp(skill) - startExpMap.get(skill);
  1884. }
  1885.  
  1886. // --Commented out by Inspection START (7/24/11 10:18 PM):
  1887. // private int getExpStart(int skill) {
  1888. // if (startExpMap.get(skill) == null)
  1889. // return -1;
  1890. // return startExpMap.get(skill);
  1891. // }
  1892. // --Commented out by Inspection STOP (7/24/11 10:18 PM)
  1893.  
  1894. public int getLevelsGainedIn(int skill) {
  1895. return skills.getRealLevel(skill) - startLevelsMap.get(skill);
  1896. }
  1897.  
  1898. /**
  1899. * Returns a map of skill names and exp gained.
  1900. *
  1901. * @return A map of exp gains and skill names.
  1902. */
  1903. public Map<String, Integer> getExpGainedMap() {
  1904. Map<String, Integer> map = new HashMap<String, Integer>();
  1905. for (int i : SKILLS_TO_WATCH) {
  1906. int gained = getExpGainedIn(i);
  1907. if (gained != 0)
  1908. map.put(Skills.SKILL_NAMES[i], gained);
  1909. }
  1910. return map;
  1911. }
  1912.  
  1913. }
  1914.  
  1915. @SuppressWarnings({"ResultOfMethodCallIgnored"})
  1916. private class VersionChecker extends Thread {
  1917. private final Object[] options = {"Yes.", "No."};
  1918. private final File javaFile = new File(Configuration.Paths.getScriptsSourcesDirectory() + File.separator
  1919. + "TFighterEE.java");
  1920. private boolean autoDownloaded = false;
  1921.  
  1922. public void run() {
  1923. try {
  1924. Properties versionInfo = new Properties();
  1925. URL url = new URL("http://scripters.powerbot.org/files/349221/" + branch + "/Version.txt");
  1926. URLConnection conn = url.openConnection();
  1927. conn.setConnectTimeout(10 * 1000);
  1928. conn.setReadTimeout(10 * 1000);
  1929. versionInfo.load( new BufferedReader(new InputStreamReader(conn.getInputStream())));
  1930. if(Double.parseDouble(versionInfo.getProperty(branch + "Version")) > mani.version()) {
  1931. SwingUtilities.invokeAndWait(new Runnable() {
  1932. public void run() {
  1933. int answer = JOptionPane.showOptionDialog(null, "A new version of TFighterEE (" + branch + ") is available. \r\n" +
  1934. "Would you like to download it?", "New Version Available!", JOptionPane.YES_NO_OPTION,
  1935. JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
  1936. if(answer == 0) {
  1937. String sourceURL = "http://scripters.powerbot.org/files/349221/" + branch + "/TFighterEE.java";
  1938. log("Downloading: " + sourceURL);
  1939. if(javaFile.exists()) {
  1940. javaFile.delete();
  1941. }
  1942. try {
  1943. HttpClient.download(new URL(sourceURL), javaFile);
  1944. if(javaFile.exists()) {
  1945. autoDownloaded = true;
  1946. }
  1947. } catch (Exception e) {
  1948. if(javaFile.exists()) {
  1949. javaFile.delete();
  1950. }
  1951. JOptionPane.showMessageDialog(null, "Could not download script");
  1952. }
  1953. }
  1954. if(autoDownloaded) {
  1955. answer = JOptionPane.showOptionDialog(null, "Download Completed!\r\nWould you like to compile now?",
  1956. "Download Successful!", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
  1957. if(answer == 0) {
  1958. deleteRunningFiles();
  1959. compileNewVersion(javaFile.getPath());
  1960. }
  1961. zui.dispose();
  1962. stopScript();
  1963. }
  1964. }
  1965. });
  1966. }
  1967. } catch (SocketTimeoutException stw) {
  1968. log("Powerbot is currently being DDoS'd!");
  1969. u.paint.useAdvancedPaint = false;
  1970. } catch (Exception e) {
  1971. log(e.getMessage());
  1972. u.paint.useAdvancedPaint = false;
  1973. }
  1974. }
  1975.  
  1976. private boolean deleteRunningFiles() {
  1977. for(File file : getRunningFiles()) {
  1978. file.delete();
  1979. }
  1980. return getRunningFiles().length == 0;
  1981. }
  1982.  
  1983. private File[] getRunningFiles() {
  1984. File directory = new File(Configuration.Paths.getScriptsSourcesDirectory());
  1985. ArrayList<File> files = new ArrayList<File>();
  1986. for(File file : directory.listFiles()) {
  1987. if(file.getName().contains("TFighterEE") && !file.getName().equals("TFighterEE.java"))
  1988. files.add(file);
  1989. }
  1990. return files.toArray(new File[files.size()]);
  1991. }
  1992.  
  1993. private boolean compileNewVersion(String path) {
  1994. boolean success = false;
  1995. try {
  1996. if(new File(path).exists()) {
  1997. JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
  1998. DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
  1999. StandardJavaFileManager fileManager = compiler.getStandardFileManager(diagnostics, null, null);
  2000. Iterable<? extends JavaFileObject> compilationUnits = fileManager
  2001. .getJavaFileObjectsFromStrings(Arrays.asList(path));
  2002.  
  2003. JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, null,
  2004. null, compilationUnits);
  2005. success = task.call();
  2006. fileManager.close();
  2007. }
  2008. } catch (Exception ignored) {}
  2009. return success;
  2010. }
  2011. }
  2012.  
  2013. private class Banking {
  2014. boolean bankingEnabled = false;
  2015. boolean depositLoot = false;
  2016. boolean depositBones = false;
  2017. boolean withdrawFood = false;
  2018.  
  2019. boolean needBankForFood = false;
  2020. int minimumFood = 5;
  2021. int maximumFood = 7;
  2022.  
  2023. boolean shouldWalkHome = false;
  2024. boolean isInBank = false;
  2025.  
  2026. public boolean needsBank() {
  2027. if(bankingEnabled) {
  2028. if(depositLoot && inventory.getCount(false) == 28 && !u.loot.getLootTaken().isEmpty() || needBankForFood) {
  2029. if (needBankForFood && !u.eat.haveFood()) {
  2030. return true;
  2031. }
  2032. int iii = 0;
  2033. boolean containsBones = false;
  2034. for(Map.Entry<String, Integer> entry : u.loot.getLootTaken().entrySet()) {
  2035. if(entry.getKey().contains("Bones")) {
  2036. containsBones = true;
  2037. }
  2038. iii++;
  2039. }
  2040. return !(iii == 1 && containsBones && !u.bank.depositBones);
  2041. }
  2042. }
  2043. return false;
  2044. }
  2045.  
  2046. public void withdraw() {
  2047. if(inventory.getCount(false) < 28 && !u.eat.haveFood() && u.eat.foodOfChoice != null) {
  2048. RSItem bankItem = bank.getItem(u.eat.foodOfChoice.getID());
  2049. if (bankItem == null || bankItem.getID() == -1) {
  2050. log(Color.RED, "Banking Error!");
  2051. stopScript();
  2052. }
  2053. assert bankItem != null;
  2054. RSComponent bankItemComponent = bankItem.getComponent();
  2055. if (bankItemComponent == null) {
  2056. log(Color.RED, "Banking Error!");
  2057. stopScript();
  2058. }
  2059. int t = 0;
  2060. assert bankItemComponent != null;
  2061. while (bankItemComponent.getRelativeX() == 0 && bank.getCurrentTab() != 0 && t < 5) {
  2062. if (interfaces.getComponent(Bank.INTERFACE_BANK, Bank.INTERFACE_BANK_TAB[0]).doClick()) {
  2063. sleep(random(800, 1300));
  2064. }
  2065. t++;
  2066. }
  2067. if (!interfaces.scrollTo(bankItemComponent, (Bank.INTERFACE_BANK << 16) + Bank.INTERFACE_BANK_SCROLLBAR)) {
  2068. log(Color.RED, "Banking Error!");
  2069. stopScript();
  2070. }
  2071. boolean withdrew = false;
  2072. for(int iii = 0; iii < 10; iii++) {
  2073. bankItemComponent.doClick(false);
  2074. if(menu.isOpen()) {
  2075. int origCount = inventory.getCount(true);
  2076. bankItemComponent.interact("Withdraw-X");
  2077. sleep(1000);
  2078. keyboard.sendText(String.valueOf(random(minimumFood, maximumFood)), true);
  2079. if(waitForInvChange(origCount, 5000)) {
  2080. withdrew = true;
  2081. break;
  2082. } else {
  2083. keyboard.sendText("", true);
  2084. }
  2085. }
  2086. }
  2087. if(!withdrew) {
  2088. log(Color.RED, "Banking Error!");
  2089. stopScript();
  2090. }
  2091. needBankForFood = false;
  2092. }
  2093. }
  2094.  
  2095. public void deposit() {
  2096. Set<Map.Entry<String, Integer>> entries = u.loot.getLootTaken().entrySet();
  2097. RSItem[] items = inventory.getItems();
  2098. ArrayList<Integer> alreadyDeposited = new ArrayList<Integer>();
  2099. for(Map.Entry<String, Integer> entry : entries) {
  2100. for(RSItem item : items) {
  2101. if(item != null && item.getID() != -1 && !alreadyDeposited.contains(item.getID())) {
  2102. if (item.getName().equals(entry.getKey())) {
  2103. if(!item.getName().contains("Bones") || (item.getName().contains("Bones") && u.bank.depositBones)) {
  2104. int origCount = inventory.getCount(true);
  2105. int itemCount = inventory.getCount(true, item.getID());
  2106. boolean deposited = false;
  2107.  
  2108. RSComponent freeSpace, freeItems, memSpace, memItems;
  2109.  
  2110. freeSpace = interfaces.getComponent(762, 29);
  2111. freeItems = interfaces.getComponent(762, 30);
  2112.  
  2113. memSpace = interfaces.getComponent(762, 31);
  2114. memItems = interfaces.getComponent(762, 32);
  2115.  
  2116. if(freeSpace.getText().equals(freeItems.getText())
  2117. || memSpace.getText().equals(memItems.getText())) {
  2118. log(Color.RED, "You Ran Out Of Bank Space! Stopping Script!");
  2119. stopScript();
  2120. }
  2121.  
  2122. for(int iii = 0; iii < 10; iii++) {
  2123. item.interact(itemCount > 1 ? "Deposit-All" : "Deposit");
  2124. if(waitForInvChange(origCount, 5000)) {
  2125. deposited = true;
  2126. break;
  2127. }
  2128. }
  2129.  
  2130. if(deposited) {
  2131. alreadyDeposited.add(item.getID());
  2132. } else {
  2133. log(Color.RED, "Banking Error!");
  2134. stopScript();
  2135. }
  2136. }
  2137. }
  2138. }
  2139. }
  2140. }
  2141. }
  2142. }
  2143.  
  2144. @SuppressWarnings({"SynchronizeOnNonFinalField"})
  2145. private class Tiles {
  2146. List<RSTile> badTiles = Collections.synchronizedList(new ArrayList<RSTile>());
  2147.  
  2148. @SuppressWarnings({"BooleanMethodIsAlwaysInverted"})
  2149. public boolean NPCIsOnBadTile(RSNPC t) {
  2150. synchronized (badTiles) {
  2151. for(RSTile badTile : badTiles) {
  2152. if(t.getLocation().getX() == badTile.getX() &&
  2153. t.getLocation().getY() == badTile.getY() ) {
  2154. return true;
  2155. }
  2156. }
  2157. }
  2158. return false;
  2159. }
  2160.  
  2161. @SuppressWarnings({"BooleanMethodIsAlwaysInverted"})
  2162. public boolean groundItemIsOnBadTile(RSGroundItem t) {
  2163. synchronized (badTiles) {
  2164. for(RSTile badTile : badTiles) {
  2165. if(t.getLocation().getX() == badTile.getX() &&
  2166. t.getLocation().getY() == badTile.getY() ) {
  2167. return true;
  2168. }
  2169. }
  2170. }
  2171. return false;
  2172. }
  2173.  
  2174. public void addBadRoom(Room room) {
  2175. badTiles.addAll(Arrays.asList(room.getTiles()));
  2176. }
  2177.  
  2178. public void clearBadTiles() {
  2179. badTiles.clear();
  2180. }
  2181.  
  2182. public RSTile deriveTile(RSTile tile, int xDeviation, int yDeviation) {
  2183. return new RSTile(tile.getX() + xDeviation, tile.getY() + yDeviation, tile.getZ());
  2184. }
  2185.  
  2186. public void drawBadTiles(final Graphics render, final Color color) {
  2187. synchronized (badTiles) {
  2188. for(RSTile tile : badTiles) {
  2189. drawTile(render, color, tile, 0);
  2190. }
  2191. }
  2192. }
  2193.  
  2194. public void drawTile(final Graphics render, final Color color, final RSTile tile, final int tileHeight) {
  2195. if (calc.tileOnMap(tile)) {
  2196. final Point p = calc.tileToMinimap(tile);
  2197. render.setColor(color);
  2198. render.drawLine(p.x, p.y, p.x, p.y);
  2199. if (calc.tileOnScreen(tile)) {
  2200. Point localPoint1 = calc.tileToScreen(tile, 0.0D, 0.0D, tileHeight);
  2201. Point localPoint2 = calc.tileToScreen(tile, 1.0D, 0.0D, tileHeight);
  2202. Point localPoint3 = calc.tileToScreen(tile, 0.0D, 1.0D, tileHeight);
  2203. Point localPoint4 = calc.tileToScreen(tile, 1.0D, 1.0D, tileHeight);
  2204. if (calc.pointOnScreen(localPoint1) && calc.pointOnScreen(localPoint2) &&
  2205. calc.pointOnScreen(localPoint3) && calc.pointOnScreen(localPoint4)) {
  2206. final Polygon localPolygon = new Polygon();
  2207. localPolygon.addPoint(localPoint1.x, localPoint1.y);
  2208. localPolygon.addPoint(localPoint2.x, localPoint2.y);
  2209. localPolygon.addPoint(localPoint4.x, localPoint4.y);
  2210. localPolygon.addPoint(localPoint3.x, localPoint3.y);
  2211. render.drawPolygon(localPolygon);
  2212. render.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 50));
  2213. render.fillPolygon(localPolygon);
  2214. }
  2215. }
  2216. }
  2217. }
  2218. }
  2219.  
  2220. private class RoomGeneration {
  2221. public Generator generator = null;
  2222. public boolean disableChecker = false;
  2223.  
  2224. private class Generator extends Thread {
  2225. boolean ranged;
  2226. volatile boolean stop;
  2227.  
  2228. public Generator(boolean ranged){
  2229. this.ranged = ranged;
  2230. }
  2231.  
  2232. public void run() {
  2233. while(!stop) {
  2234. ArrayList<Room> rooms = generateRooms(ranged, 50);
  2235. u.tiles.clearBadTiles();
  2236. for(Room room : rooms) {
  2237. if(!room.contains(players.getMyPlayer().getLocation()))
  2238. u.tiles.addBadRoom(room);
  2239. }
  2240. try {sleep(1000); } catch(Exception ignored) {}
  2241. }
  2242. }
  2243.  
  2244. public void safeStop() {
  2245. this.stop = true;
  2246. }
  2247. }
  2248.  
  2249. public boolean instantiateGenerator() {
  2250. if(!disableChecker) {
  2251. generator = new Generator(u.npcs.weaponContains("dart", "knife", "thrownaxe", "bow"));
  2252. return true;
  2253. }
  2254. return false;
  2255. }
  2256.  
  2257. private ArrayList<Flag> getFlagsAtTile(RSTile tile) {
  2258. try {
  2259. ArrayList<Flag> flagsArrayList = new ArrayList<Flag>();
  2260. RSTile offset = walking.getCollisionOffset(game.getPlane());
  2261. int[][] flags = walking.getCollisionFlags(game.getPlane());
  2262. int tileFlag = flags[tile.getX() - (game.getBaseX() + offset.getX())][tile.getY() - (game.getBaseY() + offset.getY())];
  2263. for(Flag flag : Flag.values()) {
  2264. if((flag.getFlag() & tileFlag) != 0) {
  2265. flagsArrayList.add(flag);
  2266. }
  2267. }
  2268. return flagsArrayList;
  2269. } catch(ArrayIndexOutOfBoundsException e) {
  2270. sleep(2000);
  2271. return getFlagsAtTile(tile);
  2272. }
  2273. }
  2274.  
  2275. private RSTile[] getLocalArea(int length) {
  2276. return new RSArea(u.tiles.deriveTile(players.getMyPlayer().getLocation(), -(length / 2),-(length / 2)),
  2277. u.tiles.deriveTile(players.getMyPlayer().getLocation(), (length / 2),(length / 2))).getTileArray();
  2278. }
  2279.  
  2280. private ArrayList<Room> generateRooms(boolean ranged, int deviations) {
  2281. //BFS SEARCH
  2282. ArrayList<RSTile> unchecked = new ArrayList<RSTile>();
  2283.  
  2284. unchecked.addAll(Arrays.asList(getLocalArea(deviations)));
  2285.  
  2286. if(unchecked.size() != 0) {
  2287. ArrayList<Room> rooms = new ArrayList<Room>();
  2288. while(!unchecked.isEmpty()){
  2289. if(getFlagsAtTile(unchecked.get(0)).contains(ranged ? Flag.OBJECT_BLOCK : Flag.OBJECT_TILE) ||
  2290. getFlagsAtTile(unchecked.get(0)).contains(Flag.DECORATION_BLOCK) ||
  2291. getFlagsAtTile(unchecked.get(0)).contains(Flag.LIMITER)) {
  2292. unchecked.remove(0);
  2293. continue;
  2294. }
  2295. ArrayList<RSTile> areaTiles = new ArrayList<RSTile>();
  2296. Queue<RSTile> queue = new LinkedList<RSTile>();
  2297. areaTiles.add(unchecked.get(0));
  2298. queue.add(unchecked.get(0));
  2299. unchecked.remove(0);
  2300. while(!queue.isEmpty()) {
  2301. RSTile t = queue.remove();
  2302. RSTile child;
  2303. while((child = getUncheckedChild(t, unchecked, ranged)) != null) {
  2304. areaTiles.add(child);
  2305. queue.add(child);
  2306. unchecked.remove(child);
  2307. }
  2308. }
  2309. rooms.add(new Room(areaTiles.toArray(new RSTile[areaTiles.size()])));
  2310. }
  2311. return rooms;
  2312. }
  2313. return null;
  2314. }
  2315.  
  2316. private RSTile getUncheckedChild(RSTile parent, ArrayList<RSTile> unchecked, boolean ranged) {
  2317. RSTile north = u.tiles.deriveTile(parent, 0, 1);
  2318. RSTile east = u.tiles.deriveTile(parent, 1, 0);
  2319. RSTile south = u.tiles.deriveTile(parent, 0, -1);
  2320. RSTile west = u.tiles.deriveTile(parent, -1, 0);
  2321.  
  2322. ArrayList<Flag> parentFlags = getFlagsAtTile(parent);
  2323.  
  2324. if(unchecked.contains(north) && !parentFlags.contains(ranged ? Flag.WALL_BLOCK_NORTH : Flag.WALL_NORTH)) {
  2325. ArrayList<Flag> childFlags = getFlagsAtTile(north);
  2326. if(!childFlags.contains(ranged ? Flag.OBJECT_BLOCK : Flag.OBJECT_TILE) && !childFlags.contains(Flag.DECORATION_BLOCK)
  2327. && !childFlags.contains(ranged ? null : Flag.MAP_BLOCK))
  2328. return north;
  2329. }
  2330. if(unchecked.contains(east) && !parentFlags.contains(ranged ? Flag.WALL_BLOCK_EAST : Flag.WALL_EAST)) {
  2331. ArrayList<Flag> childFlags = getFlagsAtTile(east);
  2332. if(!childFlags.contains(ranged ? Flag.OBJECT_BLOCK : Flag.OBJECT_TILE) && !childFlags.contains(Flag.DECORATION_BLOCK)
  2333. && !childFlags.contains(ranged ? null : Flag.MAP_BLOCK))
  2334. return east;
  2335. }
  2336. if(unchecked.contains(south) && !parentFlags.contains(ranged ? Flag.WALL_BLOCK_SOUTH : Flag.WALL_SOUTH)) {
  2337. ArrayList<Flag> childFlags = getFlagsAtTile(south);
  2338. if(!childFlags.contains(ranged ? Flag.OBJECT_BLOCK : Flag.OBJECT_TILE) && !childFlags.contains(Flag.DECORATION_BLOCK)
  2339. && !childFlags.contains(ranged ? null : Flag.MAP_BLOCK))
  2340. return south;
  2341. }
  2342. if(unchecked.contains(west) && !parentFlags.contains(ranged ? Flag.WALL_BLOCK_WEST : Flag.WALL_WEST)) {
  2343. ArrayList<Flag> childFlags = getFlagsAtTile(west);
  2344. if(!childFlags.contains(ranged ? Flag.OBJECT_BLOCK : Flag.OBJECT_TILE) && !childFlags.contains(Flag.DECORATION_BLOCK)
  2345. && !childFlags.contains(ranged ? null : Flag.MAP_BLOCK))
  2346. return west;
  2347. }
  2348. return null;
  2349. }
  2350. }
  2351.  
  2352. private class Room {
  2353. private RSTile[] tiles;
  2354.  
  2355. public Room(RSTile[] tiles) {
  2356. this.tiles = tiles;
  2357. }
  2358.  
  2359. public boolean contains(RSTile tile) {
  2360. for(RSTile toCheck : tiles) {
  2361. if(toCheck.equals(tile))
  2362. return true;
  2363. }
  2364. return false;
  2365. }
  2366.  
  2367. public RSTile[] getTiles() {
  2368. return tiles;
  2369. }
  2370. }
  2371.  
  2372. @SuppressWarnings({"UnusedDeclaration"})
  2373. private enum Flag {
  2374. WALL_NORTHWEST(0x1),
  2375. WALL_NORTH(0x2),
  2376. WALL_NORTHEAST(0x4),
  2377. WALL_EAST(0x8),
  2378. WALL_SOUTHEAST(0x10),
  2379. WALL_SOUTH(0x20),
  2380. WALL_SOUTHWEST(0x40),
  2381. WALL_WEST(0x80),
  2382.  
  2383. OBJECT_TILE(0x100),
  2384.  
  2385.  
  2386. WALL_BLOCK_NORTHWEST(0x200),
  2387. WALL_BLOCK_NORTH(0x400),
  2388. WALL_BLOCK_NORTHEAST(0x800),
  2389. WALL_BLOCK_EAST(0x1000),
  2390. WALL_BLOCK_SOUTHEAST(0x2000),
  2391. WALL_BLOCK_SOUTH(0x4000),
  2392. WALL_BLOCK_SOUTHWEST(0x8000),
  2393. WALL_BLOCK_WEST(0x10000),
  2394.  
  2395. OBJECT_BLOCK(0x20000),
  2396. DECORATION_BLOCK(0x40000),
  2397.  
  2398. MAP_BLOCK(0x200000),
  2399.  
  2400. WALL_ALLOW_RANGE_NORTHWEST(0x400000),
  2401. WALL_ALLOW_RANGE_NORTH(0x800000),
  2402. WALL_ALLOW_RANGE_NORTHEAST(0x1000000),
  2403. WALL_ALLOW_RANGE_EAST(0x2000000),
  2404. WALL_ALLOW_RANGE_SOUTHEAST(0x4000000),
  2405. WALL_ALLOW_RANGE_SOUTH(0x8000000),
  2406. WALL_ALLOW_RANGE_SOUTHWEST(0x10000000),
  2407. WALL_ALLOW_RANGE_WEST(0x20000000),
  2408. OBJECT_ALLOW_RANGE(0x40000000),
  2409.  
  2410. LIMITER(0x1280100),
  2411.  
  2412. NULL(0);
  2413. private int flag;
  2414.  
  2415. Flag(int flag){
  2416. this.flag = flag;
  2417. }
  2418.  
  2419. public int getFlag() {
  2420. return this.flag;
  2421. }
  2422.  
  2423. public String toString() {
  2424. return this.name();
  2425. }
  2426. }
  2427.  
  2428. @SuppressWarnings({"serial", "ResultOfMethodCallIgnored"})
  2429. private class ZUI extends JFrame {
  2430. private final File file = new File(Configuration.Paths.getScriptCacheDirectory() + File.separator + "TFighter.txt");
  2431.  
  2432. private JCheckBox useMulti, useRadius, disableChecker, useSafe, useCentral, disableSpecials, lootAbove, prioritizeLoot, onlyLoot, useBones,
  2433. useOldPaint, depositLoot, depositBones, withdrawFood, enableBanking;
  2434.  
  2435. private JTextField npcBox, lootBox, lootAboveBox, alchBox, mouseSpeedBox, foodBox;
  2436.  
  2437. private JButton start;
  2438.  
  2439. private ZUI() {
  2440. init();
  2441. pack();
  2442. }
  2443.  
  2444. private void init() {
  2445. Properties props = loadProperties();
  2446.  
  2447. JPanel north = new JPanel(new FlowLayout());
  2448. north.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  2449. {
  2450. JLabel title = new JLabel("TFighter Enhanced Edition");
  2451. title.setFont(new Font("Arial", Font.PLAIN, 24));
  2452. north.add(title);
  2453. }
  2454. add(north, BorderLayout.NORTH);
  2455.  
  2456. JPanel center = new JPanel();
  2457. center.setLayout(new BoxLayout(center, BoxLayout.PAGE_AXIS));
  2458. center.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  2459. {
  2460. JPanel combat = new JPanel();
  2461. combat.setLayout(new BoxLayout(combat, BoxLayout.PAGE_AXIS));
  2462. combat.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  2463. {
  2464. JLabel title = new JLabel("Combat");
  2465. JLabel npcLabel = new JLabel("Enter the names/ ids of the monsters to fight");
  2466. npcBox = new JTextField("barbarian,278,dragon");
  2467. useMulti = new JCheckBox("Attack monsters that are fighting others");
  2468. useRadius = new JCheckBox("Stay within a radius (Deprecated)");
  2469. useSafe = new JCheckBox("Use a safespot");
  2470. useCentral = new JCheckBox("Use central point on NPC");
  2471. disableSpecials = new JCheckBox("Disable special attacks");
  2472.  
  2473. title.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  2474. npcLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  2475. npcBox.setAlignmentX(JTextField.CENTER_ALIGNMENT);
  2476. useMulti.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  2477. useRadius.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  2478. useSafe.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  2479. useCentral.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  2480. disableSpecials.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  2481.  
  2482. npcBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, npcBox.getPreferredSize().height));
  2483. npcBox.setColumns(25);
  2484.  
  2485. if (props.getProperty("npcBox") != null) {
  2486. npcBox.setText(props.getProperty("npcBox"));
  2487. }
  2488. if (props.getProperty("useMulti") != null) {
  2489. if (props.getProperty("useMulti").equals("true"))
  2490. useMulti.setSelected(true);
  2491. }
  2492. if (props.getProperty("useRadius") != null) {
  2493. if (props.getProperty("useRadius").equals("true"))
  2494. useRadius.setSelected(true);
  2495. }
  2496. if(props.getProperty("useSafe") != null) {
  2497. if(props.getProperty("useSafe").equals("true"))
  2498. useSafe.setSelected(true);
  2499. }
  2500. if(props.getProperty("useCentral") != null) {
  2501. if(props.getProperty("useCentral").equals("true"))
  2502. useCentral.setSelected(true);
  2503. }
  2504. if(props.getProperty("disableSpecials") != null) {
  2505. if(props.get("disableSpecials").equals("true"))
  2506. disableSpecials.setSelected(true);
  2507. }
  2508.  
  2509. combat.add(title);
  2510. combat.add(new JLabel(" "));
  2511. combat.add(npcLabel);
  2512. combat.add(npcBox);
  2513. combat.add(new JLabel(" "));
  2514. combat.add(useMulti);
  2515. combat.add(useRadius);
  2516. combat.add(useSafe);
  2517. combat.add(useCentral);
  2518. combat.add(disableSpecials);
  2519. combat.add(Box.createVerticalGlue());
  2520. combat.add(Box.createRigidArea(new Dimension(1,1)));
  2521. }
  2522.  
  2523. JPanel loot = new JPanel();
  2524. loot.setLayout(new BoxLayout(loot, BoxLayout.PAGE_AXIS));
  2525. loot.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  2526. {
  2527. JLabel title = new JLabel("Loot");
  2528. JLabel lootLabel = new JLabel("Enter the names/ ids of the loot to pick up");
  2529. lootBox = new JTextField("arrow,rune");
  2530. lootAboveBox = new JTextField("1000");
  2531. lootAbove = new JCheckBox("Loot everything above: ");
  2532. prioritizeLoot = new JCheckBox("Loot while fighting");
  2533. onlyLoot = new JCheckBox("Only loot from monsters you kill");
  2534.  
  2535. title.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  2536. lootLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  2537. lootBox.setAlignmentX(JTextField.CENTER_ALIGNMENT);
  2538. prioritizeLoot.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  2539. onlyLoot.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  2540.  
  2541. lootBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, lootBox.getPreferredSize().height));
  2542. lootBox.setColumns(25);
  2543.  
  2544. lootAboveBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, lootAboveBox.getPreferredSize().height));
  2545. lootAboveBox.setColumns(10);
  2546.  
  2547. if (props.getProperty("lootBox") != null) {
  2548. lootBox.setText(props.getProperty("lootBox"));
  2549. }
  2550. if(props.getProperty("lootAbove") != null) {
  2551. if(props.get("lootAbove").equals("true"))
  2552. lootAbove.setSelected(true);
  2553. }
  2554. if (props.getProperty("lootAboveBox") != null) {
  2555. lootAboveBox.setText(props.getProperty("lootAboveBox"));
  2556. }
  2557. if(props.getProperty("onlyLoot") != null) {
  2558. if(props.get("onlyLoot").equals("true"))
  2559. onlyLoot.setSelected(true);
  2560. }
  2561. if(props.getProperty("prioritizeLoot") != null) {
  2562. if(props.get("prioritizeLoot").equals("true"))
  2563. prioritizeLoot.setSelected(true);
  2564. }
  2565.  
  2566. loot.add(title);
  2567. loot.add(new JLabel(" "));
  2568. loot.add(lootLabel);
  2569. loot.add(lootBox);
  2570. JPanel lootAbovePanel = new JPanel();
  2571. lootAbovePanel.add(lootAbove);
  2572. lootAbovePanel.add(lootAboveBox);
  2573. loot.add(new JLabel(" "));
  2574. lootAbovePanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, lootAbovePanel.getPreferredSize().height));
  2575. lootAbovePanel.setAlignmentX(JPanel.CENTER_ALIGNMENT);
  2576. loot.add(lootAbovePanel);
  2577. loot.add(new JLabel(" "));
  2578. loot.add(prioritizeLoot);
  2579. loot.add(onlyLoot);
  2580. loot.add(Box.createVerticalGlue());
  2581. loot.add(Box.createRigidArea(new Dimension(1,1)));
  2582. }
  2583.  
  2584. JPanel bank = new JPanel();
  2585. bank.setLayout(new BoxLayout(bank, BoxLayout.PAGE_AXIS));
  2586. bank.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  2587. {
  2588. JLabel title = new JLabel("Bank");
  2589. JLabel bankLabel1 = new JLabel("WARNING: EXPERIMENTAL");
  2590. JLabel bankLabel2 = new JLabel("ONLY WORKS ON GROUND LEVEL");
  2591.  
  2592. enableBanking = new JCheckBox("Enable banking");
  2593. depositLoot = new JCheckBox("Deposit Loot");
  2594. depositBones = new JCheckBox("Deposit Bones");
  2595. withdrawFood = new JCheckBox("Withdraw Food");
  2596. foodBox = new JTextField("5,7");
  2597.  
  2598. title.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  2599. bankLabel1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  2600. bankLabel2.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  2601. enableBanking.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  2602. depositLoot.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  2603. depositBones.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  2604. withdrawFood.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  2605. foodBox.setAlignmentX(JTextField.CENTER_ALIGNMENT);
  2606.  
  2607. foodBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, foodBox.getPreferredSize().height));
  2608. foodBox.setColumns(25);
  2609.  
  2610. enableBanking.addActionListener(disableAllBankingOptions);
  2611. depositLoot.addActionListener(disableDepositBones);
  2612. withdrawFood.addActionListener(disableFoodBox);
  2613.  
  2614. if (props.getProperty("depositLoot") != null) {
  2615. if (props.getProperty("depositLoot").equals("true"))
  2616. depositLoot.setSelected(true);
  2617. }
  2618.  
  2619. if (props.getProperty("depositBones") != null) {
  2620. if (props.getProperty("depositBones").equals("true"))
  2621. depositBones.setSelected(true);
  2622. }
  2623.  
  2624. if (props.getProperty("withdrawFood") != null) {
  2625. if (props.getProperty("withdrawFood").equals("true")) {
  2626. withdrawFood.setSelected(true);
  2627. foodBox.setEnabled(true);
  2628. } else {
  2629. foodBox.setEnabled(false);
  2630. }
  2631. }
  2632.  
  2633. if (props.getProperty("enableBanking") != null) {
  2634. if (props.getProperty("enableBanking").equals("true")) {
  2635. enableBanking.setSelected(true);
  2636. } else {
  2637. depositLoot.setSelected(false);
  2638. depositBones.setSelected(false);
  2639. withdrawFood.setSelected(false);
  2640. depositLoot.setEnabled(false);
  2641. depositBones.setEnabled(false);
  2642. withdrawFood.setEnabled(false);
  2643. foodBox.setEnabled(false);
  2644. }
  2645. } else {
  2646. depositLoot.setSelected(false);
  2647. depositBones.setSelected(false);
  2648. withdrawFood.setSelected(false);
  2649. depositLoot.setEnabled(false);
  2650. depositBones.setEnabled(false);
  2651. withdrawFood.setEnabled(false);
  2652. foodBox.setEnabled(false);
  2653. }
  2654.  
  2655. bank.add(title);
  2656. bank.add(new JLabel(" "));
  2657. bank.add(bankLabel1);
  2658. bank.add(bankLabel2);
  2659. bank.add(new JLabel(" "));
  2660. bank.add(enableBanking);
  2661. bank.add(new JLabel(" "));
  2662. bank.add(depositLoot);
  2663. bank.add(depositBones);
  2664. bank.add(new JLabel(" "));
  2665. bank.add(withdrawFood);
  2666. bank.add(foodBox);
  2667. bank.add(Box.createVerticalGlue());
  2668. bank.add(Box.createRigidArea(new Dimension(1,1)));
  2669. }
  2670.  
  2671. JPanel misc = new JPanel();
  2672. misc.setLayout(new BoxLayout(misc, BoxLayout.PAGE_AXIS));
  2673. misc.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  2674. {
  2675. JLabel miscLabel = new JLabel("Miscellaneous Settings");
  2676. JLabel mouseLabel = new JLabel("Mouse Speed: Lower = Faster");
  2677. mouseSpeedBox = new JTextField("4,7");
  2678. disableChecker = new JCheckBox("Turn off room generation");
  2679. JLabel alchLabel = new JLabel("Enter the ids/ names of items to alch");
  2680. alchBox = new JTextField("");
  2681. useBones = new JCheckBox("Bury the bones you loot");
  2682. useOldPaint = new JCheckBox("Use simple paint");
  2683.  
  2684. miscLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  2685. mouseLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  2686. mouseSpeedBox.setAlignmentX(JTextField.CENTER_ALIGNMENT);
  2687. disableChecker.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  2688. alchLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  2689. alchBox.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  2690. useBones.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  2691. useOldPaint.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  2692.  
  2693. mouseSpeedBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, mouseSpeedBox.getPreferredSize().height));
  2694. alchBox.setMaximumSize(new Dimension(Integer.MAX_VALUE, alchBox.getPreferredSize().height));
  2695.  
  2696. mouseSpeedBox.setColumns(25);
  2697. alchBox.setColumns(25);
  2698.  
  2699. if (props.getProperty("mouseSpeed") != null) {
  2700. mouseSpeedBox.setText(props.getProperty("mouseSpeed"));
  2701. }
  2702. if(props.getProperty("disableChecker") != null ) {
  2703. if(props.get("disableChecker").equals("true"))
  2704. disableChecker.setSelected(true);
  2705. }
  2706. if(props.getProperty("useSimplePaint") != null ) {
  2707. if(props.get("useSimplePaint").equals("true"))
  2708. useOldPaint.setSelected(true);
  2709. }
  2710. if (props.getProperty("alchBox") != null) {
  2711. alchBox.setText(props.getProperty("alchBox"));
  2712. }
  2713. if(props.getProperty("useBones") != null) {
  2714. if(props.get("useBones").equals("true"))
  2715. useBones.setSelected(true);
  2716. }
  2717.  
  2718. if(!u.paint.useAdvancedPaint) {
  2719. useOldPaint.setSelected(true);
  2720. useOldPaint.setEnabled(false);
  2721. }
  2722.  
  2723. misc.add(miscLabel);
  2724. misc.add(new JLabel(" "));
  2725. misc.add(mouseLabel);
  2726. misc.add(mouseSpeedBox);
  2727. misc.add(new JLabel(" "));
  2728. misc.add(alchLabel);
  2729. misc.add(alchBox);
  2730. misc.add(new JLabel(" "));
  2731. misc.add(disableChecker);
  2732. misc.add(useBones);
  2733. if(!u.paint.useAdvancedPaint) {
  2734. JLabel ddosLabel1 = new JLabel("Powerbot is currently being DDoS'd");
  2735. JLabel ddosLabel2 = new JLabel("Due to this fact, only simple paint");
  2736. JLabel ddosLabel3 = new JLabel("is available.");
  2737. ddosLabel1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  2738. ddosLabel2.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  2739. ddosLabel3.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  2740. misc.add(new JLabel(" "));
  2741. misc.add(ddosLabel1);
  2742. misc.add(ddosLabel2);
  2743. misc.add(ddosLabel3);
  2744. }
  2745. misc.add(useOldPaint);
  2746. }
  2747.  
  2748. JTabbedPane tabbedPane = new JTabbedPane();
  2749. tabbedPane.addTab("Combat", combat);
  2750. tabbedPane.addTab("Loot", loot);
  2751. tabbedPane.addTab("Bank", bank);
  2752. tabbedPane.addTab("Misc.", misc);
  2753. center.add(tabbedPane);
  2754. }
  2755. add(center, BorderLayout.CENTER);
  2756.  
  2757. JPanel south = new JPanel(new FlowLayout());
  2758. south.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  2759. {
  2760. start = new JButton("Start script!");
  2761. start.setAlignmentX(JButton.CENTER_ALIGNMENT);
  2762. start.addActionListener(onStart);
  2763. south.add(start);
  2764. }
  2765. add(south, BorderLayout.SOUTH);
  2766.  
  2767. setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  2768. setTitle("TFighter GUI");
  2769. }
  2770.  
  2771. private Properties loadProperties() {
  2772. try {
  2773. if (!file.exists())
  2774. file.createNewFile();
  2775. Properties p = new Properties();
  2776. p.load(new FileInputStream(file));
  2777. return p;
  2778. } catch (Exception e) {
  2779. e.printStackTrace();
  2780. }
  2781. return null;
  2782. }
  2783.  
  2784. private void saveProperties() {
  2785. Properties p = new Properties();
  2786. p.put("mouseSpeed", mouseSpeedBox.getText());
  2787. p.put("npcBox", npcBox.getText());
  2788. p.put("lootBox", lootBox.getText());
  2789. p.put("lootAbove", Boolean.toString(lootAbove.isSelected()));
  2790. p.put("lootAboveBox", lootAboveBox.getText());
  2791. p.put("alchBox", alchBox.getText());
  2792. p.put("useMulti", Boolean.toString(useMulti.isSelected()));
  2793. p.put("useRadius", Boolean.toString(useRadius.isSelected()));
  2794. p.put("useSafe", Boolean.toString(useSafe.isSelected()));
  2795. p.put("useCentral", Boolean.toString(useCentral.isSelected()));
  2796. p.put("useBones", Boolean.toString(useBones.isSelected()));
  2797. p.put("disableSpecials", Boolean.toString(disableSpecials.isSelected()));
  2798. p.put("disableChecker", Boolean.toString(disableChecker.isSelected()));
  2799. p.put("onlyLoot", Boolean.toString(onlyLoot.isSelected()));
  2800. p.put("prioritizeLoot", Boolean.toString(prioritizeLoot.isSelected()));
  2801. p.put("useSimplePaint", Boolean.toString(useOldPaint.isSelected()));
  2802.  
  2803. p.put("enableBanking", Boolean.toString(enableBanking.isSelected()));
  2804. p.put("depositLoot", Boolean.toString(depositLoot.isSelected()));
  2805. p.put("depositBones", Boolean.toString(depositBones.isSelected()));
  2806. p.put("withdrawFood", Boolean.toString(withdrawFood.isSelected()));
  2807. p.put("foodBox", foodBox.getText());
  2808.  
  2809. try {
  2810. p.store(new FileOutputStream(file), "");
  2811. } catch (Exception e) {
  2812. e.printStackTrace();
  2813. }
  2814. }
  2815.  
  2816. private ActionListener onStart = new ActionListener() {
  2817. public void actionPerformed(ActionEvent e) {
  2818. saveProperties();
  2819. startScript = true;
  2820. mouseSpeedMin = Integer.parseInt(mouseSpeedBox.getText().split(",")[0]);
  2821. mouseSpeedMax = Integer.parseInt(mouseSpeedBox.getText().split(",")[1]);
  2822. utilizeMultiwayCombat = useMulti.isSelected();
  2823. onlyInRadius = useRadius.isSelected();
  2824. u.rooms.disableChecker = disableChecker.isSelected();
  2825. useSafespot = useSafe.isSelected();
  2826. useCentralClicking = useCentral.isSelected();
  2827. buryBones = useBones.isSelected();
  2828. u.loot.onlyTakeLootFromKilled = onlyLoot.isSelected();
  2829. u.loot.lootAbove = lootAbove.isSelected();
  2830. u.loot.lootAboveX = Integer.parseInt(lootAboveBox.getText());
  2831. u.paint.useAdvancedPaint = !useOldPaint.isSelected();
  2832. u.bank.bankingEnabled = enableBanking.isSelected();
  2833. u.bank.depositLoot = depositLoot.isSelected();
  2834. u.bank.depositBones = depositBones.isSelected();
  2835. u.bank.withdrawFood = withdrawFood.isSelected();
  2836. u.bank.minimumFood = Integer.parseInt(foodBox.getText().split(",")[0]);
  2837. u.bank.maximumFood = Integer.parseInt(foodBox.getText().split(",")[1]);
  2838. TFighterEE.this.prioritizeLoot = prioritizeLoot.isSelected();
  2839.  
  2840. if (onlyInRadius) {
  2841. u.rooms.disableChecker = true;
  2842. u.npcs.maxRadius = Integer.parseInt(JOptionPane.showInputDialog("Enter the max radius. Example: 10."));
  2843. }
  2844.  
  2845. String[] ids = npcBox.getText().split(",");
  2846. ArrayList<Integer> idList = new ArrayList<Integer>();
  2847. ArrayList<String> nameList = new ArrayList<String>();
  2848. for (String id3 : ids) {
  2849. if (id3 != null && !id3.equals("")) {
  2850. try {
  2851. int id = Integer.parseInt(id3);
  2852. idList.add(id);
  2853. } catch (Exception e1) {
  2854. nameList.add(id3);
  2855. }
  2856. }
  2857. }
  2858. u.npcs.npcIDs = idList.size() > 0 ? toIntArray(idList.toArray(new Integer[idList.size()])) : new int[0];
  2859. u.npcs.npcNames = nameList.size() > 0 ? nameList.toArray(new String[nameList.size()]) : new String[0];
  2860.  
  2861. ids = lootBox.getText().split(",");
  2862. idList = new ArrayList<Integer>();
  2863. nameList = new ArrayList<String>();
  2864. for (String id2 : ids) {
  2865. if (id2 != null && !id2.equals("")) {
  2866. try {
  2867. int id = Integer.parseInt(id2);
  2868. idList.add(id);
  2869. } catch (Exception e1) {
  2870. nameList.add(id2);
  2871. }
  2872. }
  2873. }
  2874. u.loot.lootIDs = idList.size() > 0 ? toIntArray(idList.toArray(new Integer[idList.size()])) : new int[0];
  2875. u.loot.lootNames = nameList.size() > 0 ? nameList.toArray(new String[nameList.size()]) : new String[0];
  2876.  
  2877. ids = alchBox.getText().split(",");
  2878. idList = new ArrayList<Integer>();
  2879. nameList = new ArrayList<String>();
  2880. for (String id1 : ids) {
  2881. if (id1 != null && !id1.equals("")) {
  2882. try {
  2883. int id = Integer.parseInt(id1);
  2884. idList.add(id);
  2885. } catch (Exception e1) {
  2886. nameList.add(id1.toLowerCase());
  2887. }
  2888. }
  2889. }
  2890.  
  2891. u.alch.alchIDs = idList.size() > 0 ? toIntArray(idList.toArray(new Integer[idList.size()])) : new int[0];
  2892. u.alch.alchNames = nameList.size() > 0 ? nameList.toArray(new String[nameList.size()]) : new String[0];
  2893.  
  2894.  
  2895.  
  2896. game.openTab(Game.Tab.INVENTORY);
  2897.  
  2898. u.eat.foodOfChoice = u.eat.getFood();
  2899.  
  2900. if(u.eat.foodOfChoice == null && u.bank.withdrawFood) {
  2901. log("You do not have any food in your inventory! Food withdrawal banking will not be used!");
  2902. log("If you want to use food withdrawal banking, start the script with the food you use in your inventory.");
  2903. }
  2904.  
  2905. game.openTab(Game.Tab.EQUIPMENT);
  2906. //Credit: The Powerbot Scripters Team
  2907. if(equipment.getItem(Equipment.WEAPON) != null && !disableSpecials.isSelected()){
  2908. u.npcs.weapon = equipment.getItem(Equipment.WEAPON).getName();
  2909. if(u.npcs.weapon.contains(">")) {
  2910. u.npcs.weapon = u.npcs.weapon.substring(u.npcs.weapon.indexOf(">") + 1);
  2911. }
  2912.  
  2913. String[] specialWeaponsArray = new String[] {"Rune thrownaxe", "Rod of ivandis", "Dragon Dagger",
  2914. "Dragon dagger (p)", "Dragon dagger (p+)", "Dragon dagger (p++)", "Dragon Mace", "Dragon Spear",
  2915. "Dragon longsword", "Rune claws", "Dragon Halberd", "Magic Longbow", "Magic Composite Bow",
  2916. "Dragon Claws", "Abyssal Whip", "Granite Maul", "Darklight", "Barrelchest Anchor",
  2917. "Armadyl Godsword", "Magic Shortbow", "Dragon Scimitar", "Dragon 2H Sword", "Zamorak Godsword",
  2918. "Korasi's sword", "Dorgeshuun Crossbow", "Bone Dagger", "Bone Dagger (p+)", "Bone Dagger (p++)",
  2919. "Brine Sabre", "Bandos Godsword", "Dragon Battleaxe", "Dragon Hatchet", "Seercull Bow",
  2920. "Excalibur", "Enhanced excalibur", "Ancient Mace", "Saradomin sword"};
  2921.  
  2922. for(String weapon : specialWeaponsArray ) {
  2923. if (weapon.equalsIgnoreCase(u.npcs.weapon)) {
  2924. u.npcs.hasSpecialWeapon = true;
  2925. }
  2926. }
  2927. }
  2928.  
  2929. if(equipment.getItem(Equipment.AMMO) != null) {
  2930. u.npcs.ammo = equipment.getItem(Equipment.AMMO).getName();
  2931. }
  2932.  
  2933. if(equipment.getItem(Equipment.RING) != null) {
  2934. u.npcs.ring = equipment.getItem(Equipment.RING).getName();
  2935. }
  2936.  
  2937. dispose();
  2938. }
  2939. };
  2940.  
  2941. private ActionListener disableAllBankingOptions = new ActionListener() {
  2942. public void actionPerformed(ActionEvent e) {
  2943. AbstractButton abstractButton = (AbstractButton) e.getSource();
  2944. boolean selected = abstractButton.getModel().isSelected();
  2945.  
  2946. if(selected) {
  2947.  
  2948. withdrawFood.setEnabled(selected);
  2949. depositLoot.setEnabled(selected);
  2950. } else {
  2951. withdrawFood.setSelected(selected);
  2952. depositLoot.setSelected(selected);
  2953. depositBones.setSelected(selected);
  2954. withdrawFood.setEnabled(selected);
  2955. depositLoot.setEnabled(selected);
  2956. depositBones.setEnabled(selected);
  2957. foodBox.setEnabled(selected);
  2958. }
  2959. }
  2960. };
  2961.  
  2962. private ActionListener disableDepositBones = new ActionListener() {
  2963. public void actionPerformed(ActionEvent e) {
  2964. AbstractButton abstractButton = (AbstractButton) e.getSource();
  2965. boolean selected = abstractButton.getModel().isSelected();
  2966. depositBones.setEnabled(selected);
  2967. }
  2968. };
  2969.  
  2970. private ActionListener disableFoodBox = new ActionListener() {
  2971. public void actionPerformed(ActionEvent e) {
  2972. AbstractButton abstractButton = (AbstractButton) e.getSource();
  2973. boolean selected = abstractButton.getModel().isSelected();
  2974. foodBox.setEnabled(selected);
  2975. }
  2976. };
  2977.  
  2978. private int[] toIntArray(Integer[] ints) {
  2979. int[] done = new int[ints.length];
  2980. for (int i = 0; i < done.length; i++) {
  2981. done[i] = ints[i];
  2982. }
  2983. return done;
  2984. }
  2985. }
  2986.  
  2987. public void mouseClicked(MouseEvent e) {
  2988. RSComponent inter = interfaces.get(137).getComponent(0);
  2989. int x = inter.getLocation().x;
  2990. int y = inter.getLocation().y;
  2991.  
  2992. if (inter.getArea().contains(e.getPoint())) {
  2993. u.paint.showPaint = !u.paint.showPaint;
  2994. }
  2995.  
  2996. //Probably should move this sometime to prevent instantiating new polygons
  2997. Polygon mainRibbonPoly =
  2998. new Polygon(
  2999. new int[] {x, x, x + 80, x + 160, x + 160},
  3000. new int[] {y - 325, y - 325 + 52, y - 325 + 97, y - 325 + 52, y - 325},
  3001. 5);
  3002. Polygon skillsRibbonPoly =
  3003. new Polygon(
  3004. new int[] {x, x, x + 80, x + 160, x + 160},
  3005. new int[] {y - 225, y - 225 + 52, y - 225 + 97, y - 225 + 52, y - 225},
  3006. 5);
  3007. Polygon lootRibbonPoly =
  3008. new Polygon(
  3009. new int[] {x, x, x + 80, x + 160, x + 160},
  3010. new int[] {y - 125, y - 125 + 52, y - 125 + 97, y - 125 + 52, y - 125},
  3011. 5);
  3012.  
  3013. if(mainRibbonPoly.contains(e.getPoint())) {
  3014. u.paint.showMain = true;
  3015. u.paint.showSkills = false;
  3016. u.paint.showLoot = false;
  3017. }
  3018. if(skillsRibbonPoly.contains(e.getPoint())) {
  3019. u.paint.showMain = false;
  3020. u.paint.showSkills = true;
  3021. u.paint.showLoot = false;
  3022. }
  3023. if(lootRibbonPoly.contains(e.getPoint())) {
  3024. u.paint.showMain = false;
  3025. u.paint.showSkills = false;
  3026. u.paint.showLoot = true;
  3027. }
  3028. }
  3029.  
  3030. public void mousePressed(MouseEvent e) {}
  3031.  
  3032. public void mouseReleased(MouseEvent e) {}
  3033.  
  3034. public void mouseEntered(MouseEvent e) {}
  3035.  
  3036. public void mouseExited(MouseEvent e) {}
  3037. }
Add Comment
Please, Sign In to add comment