Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.95 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.Color;
  3. import java.awt.FlowLayout;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.awt.Graphics2D;
  7. import java.awt.Point;
  8. import java.awt.Polygon;
  9. import java.awt.RenderingHints;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12. import java.awt.event.MouseEvent;
  13. import java.awt.event.MouseListener;
  14. import java.io.File;
  15. import java.io.FileInputStream;
  16. import java.io.FileOutputStream;
  17. import java.text.NumberFormat;
  18. import java.util.ArrayList;
  19. import java.util.HashMap;
  20. import java.util.LinkedList;
  21. import java.util.List;
  22. import java.util.Map;
  23. import java.util.Properties;
  24.  
  25. import javax.swing.BorderFactory;
  26. import javax.swing.BoxLayout;
  27. import javax.swing.JButton;
  28. import javax.swing.JCheckBox;
  29. import javax.swing.JComboBox;
  30. import javax.swing.JFrame;
  31. import javax.swing.JLabel;
  32. import javax.swing.JOptionPane;
  33. import javax.swing.JPanel;
  34. import javax.swing.JTextField;
  35.  
  36. import org.rsbot.event.listeners.PaintListener;
  37. import org.rsbot.script.Script;
  38. import org.rsbot.script.ScriptManifest;
  39. import org.rsbot.script.methods.Game;
  40. import org.rsbot.script.methods.Skills;
  41. import org.rsbot.script.util.Filter;
  42. import org.rsbot.script.wrappers.RSCharacter;
  43. import org.rsbot.script.wrappers.RSComponent;
  44. import org.rsbot.script.wrappers.RSGroundItem;
  45. import org.rsbot.script.wrappers.RSInterface;
  46. import org.rsbot.script.wrappers.RSItem;
  47. import org.rsbot.script.wrappers.RSModel;
  48. import org.rsbot.script.wrappers.RSNPC;
  49. import org.rsbot.script.wrappers.RSPlayer;
  50. import org.rsbot.script.wrappers.RSTile;
  51. import org.rsbot.util.GlobalConfiguration;
  52.  
  53. /**
  54. * Change log:
  55. * v1.02: Includes click here to continue hotfix.
  56. * v1.01: Prioritize looting over combat. Safespotting + looting is now possible. Implemented new LoopAction structure internally.
  57. * v1.00: Milestone release.
  58. * Added:
  59. * -Safespot ability
  60. * -Central clicking
  61. * -Clicking continue
  62. * -Antiban - performs camera + mouse at same time! (sometimes)
  63. * -Declared stable
  64. * v0.96: Hopefully finally fixed food
  65. * v0.95: Small error, caused null pointer
  66. * v0.94: Fixed eating.
  67. * v0.93: Hide paint by clicking it.
  68. * v0.92: Loot support, mainly. Many small changes.
  69. * v0.91: Oops, forgot to add mouse speed settings!
  70. * v0.9: Initial release
  71. */
  72. @ScriptManifest(name = "proFighter", authors = "promean", keywords = {"profighter", "profighter"}, version = 1.02)
  73. public class profighter extends Script implements PaintListener, MouseListener {
  74.  
  75. private final static ScriptManifest mani = profighter.class.getAnnotation(ScriptManifest.class);
  76.  
  77. private final Util u = new Util();
  78.  
  79.  
  80. private RSTile startTile;
  81.  
  82. private long nextAntiban = 0;
  83.  
  84. private int badFoodCount = 0;
  85. private int startTime = 0;
  86. private int mouseSpeedMin = 4, mouseSpeedMax = 7;
  87.  
  88. private boolean startScript, showPaint;
  89. private boolean onlyInRadius = false;
  90. private boolean utilizeMultiwayCombat = false;
  91. private boolean useSafespot = false;
  92. private boolean useCentralClicking = true;
  93. private boolean prioritizeLoot = false;
  94.  
  95. private List<LoopAction> loopActions = new LinkedList<LoopAction>();
  96.  
  97.  
  98. public boolean onStart() {
  99. if (!game.isLoggedIn()) {
  100. log("Start logged in.");
  101. return false;
  102. }
  103. showPaint = true;
  104. startScript = false;
  105. FighterGUI gui = new FighterGUI();
  106. while (!startScript) {
  107. if (!gui.isVisible())
  108. return false;
  109. sleep(100);
  110. }
  111.  
  112. startTile = getMyPlayer().getLocation();
  113. u.sw.poll();
  114. startTime = (int) System.currentTimeMillis();
  115.  
  116. LoopAction[] actions;
  117. if(prioritizeLoot)
  118. actions = new LoopAction[] { new LootLoop(), (useSafespot ? new SafespotLoop() : null), new InCombatLoop(), new AttackLoop() };
  119. else
  120. actions = new LoopAction[] { (useSafespot ? new SafespotLoop() : null), new InCombatLoop(), new LootLoop(), new AttackLoop() };
  121.  
  122. for(LoopAction a : actions)
  123. loopActions.add(a);
  124.  
  125. return true;
  126. }
  127.  
  128. @Override
  129. public int loop() {
  130. if (random(0, 3) == 0 || mouse.getSpeed() < mouseSpeedMin || mouse.getSpeed() > mouseSpeedMax) {
  131. mouse.setSpeed(random(mouseSpeedMin, mouseSpeedMax));
  132. }
  133. if (camera.getPitch() < 90) {
  134. camera.setPitch(true);
  135. return random(50, 100);
  136. }
  137. if (!walking.isRunEnabled() && walking.getEnergy() > random(60, 90)) {
  138. walking.setRun(true);
  139. return random(1200, 1600);
  140. }
  141. if(canContinue()) {
  142. clickContinue();
  143. return random(1200, 1600);
  144. }
  145. if (game.getCurrentTab() != Game.TAB_INVENTORY) {
  146. game.openTab(Game.TAB_INVENTORY);
  147. return random(700, 1500);
  148. }
  149. if (u.eat.needEat()) {
  150. if (u.eat.haveFood()) {
  151. badFoodCount = 0;
  152. u.eat.eatFood();
  153. } else if (u.eat.haveB2pTab() && u.eat.haveBones()) {
  154. u.eat.breakB2pTab();
  155. return random(2600, 3000);
  156. } else {
  157. badFoodCount++;
  158. if (badFoodCount > 5) {
  159. log("out of food,logging out! Stopping.");
  160. stopScript();
  161. }
  162. }
  163. return random(1200, 1600);
  164. }
  165. for(LoopAction a : loopActions)
  166. if(a != null && a.activate())
  167. return a.loop();
  168. return random(50, 200);
  169. }
  170.  
  171. private interface LoopAction {
  172. public int loop();
  173. public boolean activate();
  174. }
  175.  
  176. private class InCombatLoop implements LoopAction {
  177.  
  178. public int loop() {
  179. antiban();
  180. return random(50, 200);
  181. }
  182.  
  183. public boolean activate() {
  184. return u.npcs.isInCombat();
  185. }
  186.  
  187. }
  188.  
  189. private class AttackLoop implements LoopAction {
  190.  
  191. public int loop() {
  192. RSNPC inter = u.npcs.getInteracting();
  193. RSNPC n = inter != null ? inter : u.npcs.getNPC();
  194. if (n != null) {
  195. int result = u.npcs.clickNPC(n, "Attack " + n.getName());
  196. if (result == 0) {
  197. if(!useSafespot) {
  198. waitWhileMoving();
  199. } else {
  200. waitForAnim();
  201. }
  202. return random(300, 500);
  203. } else if (result == 1) {
  204. waitWhileMoving();
  205. return random(0, 200);
  206. }
  207. } else {
  208. if (calc.distanceTo(startTile) > 5) {
  209. walking.walkTileMM(walking.getClosestTileOnMap(startTile));
  210. waitWhileMoving();
  211. } else {
  212. antiban();
  213. }
  214. }
  215. return random(50, 200);
  216. }
  217.  
  218. public boolean activate() {
  219. return !u.npcs.isInCombat();
  220. }
  221.  
  222. }
  223.  
  224. private class SafespotLoop implements LoopAction {
  225.  
  226. public int loop() {
  227. if (!calc.tileOnScreen(startTile)) {
  228. walking.walkTileMM(startTile);
  229. } else {
  230. tiles.doAction(startTile, "Walk");
  231. }
  232. waitWhileMoving();
  233. return random(200, 500);
  234. }
  235.  
  236. public boolean activate() {
  237. return useSafespot && calc.distanceTo(startTile) > 0;
  238. }
  239.  
  240. }
  241.  
  242. private class LootLoop implements LoopAction {
  243.  
  244. private RSGroundItem loot = null;
  245.  
  246. @Override
  247. public int loop() {
  248. int origCount = inventory.getCount(true);
  249. String name = loot.getItem().getName();
  250. int count = loot.getItem().getStackSize();
  251. int result = u.loot.takeItem(loot);
  252. if (result == 0) {
  253. waitWhileMoving();
  254. if (waitForInvChange(origCount)) {
  255. u.loot.addItem(name, count);
  256. }
  257. } else if (result == 1) {
  258. waitWhileMoving();
  259. }
  260. return random(50, 200);
  261. }
  262.  
  263. public boolean activate() {
  264. return (loot = u.loot.getLoot()) != null;
  265. }
  266.  
  267. }
  268.  
  269. /**
  270. * Waits until we are no longer moving.
  271. */
  272. private void waitWhileMoving() {
  273. long start = System.currentTimeMillis();
  274. while (System.currentTimeMillis() - start < 1500 && !getMyPlayer().isMoving()) {
  275. sleep(random(50, 200));
  276. }
  277. while (getMyPlayer().isMoving()) {
  278. sleep(random(20, 50));
  279. }
  280. }
  281.  
  282. /**
  283. * True if click continue interface is valid.
  284. * @return True if you can click continue.
  285. */
  286. private boolean canContinue() {
  287. return getContinueInterface() != null;
  288. }
  289.  
  290. /**
  291. * True if we successfully clicked continue.
  292. * @return True if we clicked continue.
  293. */
  294. private boolean clickContinue() {
  295. RSComponent c = getContinueInterface();
  296. if(c != null)
  297. return c.doClick();
  298. return false;
  299. }
  300.  
  301. /**
  302. * Gets the "Click here to continue" button on any interface.
  303. * @return The "Click here to continue" button.
  304. */
  305. private RSComponent getContinueInterface() {
  306. for(RSInterface iface : interfaces.getAll()) {
  307. //skip chat
  308. if(iface.getIndex() == 137)
  309. continue;
  310. for(RSComponent c : iface.getComponents()) {
  311. if(c != null && c.isValid() && c.containsText("Click here to continue")
  312. && c.getAbsoluteX() > 100 && c.getAbsoluteY() > 300)
  313. return c;
  314. }
  315. }
  316. return null;
  317. }
  318.  
  319. /**
  320. * Waits until the inventory count changes
  321. */
  322. private boolean waitForInvChange(int origCount) {
  323. long start = System.currentTimeMillis();
  324. while (inventory.getCount(true) == origCount && System.currentTimeMillis() - start < 2000) {
  325. sleep(random(20, 70));
  326. }
  327. return inventory.getCount(true) != origCount;
  328. }
  329.  
  330. /**
  331. * Used in safe spotting. Waits for an animation.
  332. */
  333. private void waitForAnim() {
  334. long timer = System.currentTimeMillis();
  335. while(System.currentTimeMillis() - timer < 2500 && getMyPlayer().getAnimation() == -1
  336. && (System.currentTimeMillis() - timer < 1000 || getMyPlayer().getInteracting() != null))
  337. sleep(random(50, 100));
  338. }
  339.  
  340. /**
  341. * Performs a random action, always.
  342. * Actions: move mouse, move mouse off screen, move camera.
  343. */
  344. private void antiban() {
  345. if (System.currentTimeMillis() > nextAntiban) {
  346. nextAntiban = System.currentTimeMillis() + random(2000, 30000);
  347. } else {
  348. return;
  349. }
  350. Thread mouseThread = new Thread() {
  351. public void run() {
  352. switch(random(0, 5)) {
  353. case 0:
  354. mouse.moveOffScreen();
  355. break;
  356. case 1:
  357. mouse.move(random(0, game.getWidth()), random(0, game.getHeight()));
  358. break;
  359. case 2:
  360. mouse.move(random(0, game.getWidth()), random(0, game.getHeight()));
  361. break;
  362. }
  363. }
  364. };
  365. Thread keyThread = new Thread() {
  366. public void run() {
  367. switch(random(0, 4)) {
  368. case 0:
  369. camera.setAngle(camera.getAngle() + random(-100, 100));
  370. break;
  371. case 1:
  372. camera.setAngle(camera.getAngle() + random(-100, 100));
  373. break;
  374. case 2:
  375. camera.setAngle(camera.getAngle() + random(-100, 100));
  376. break;
  377. }
  378. }
  379. };
  380. if(random(0, 2) == 0) {
  381. keyThread.start();
  382. sleep(random(0, 600));
  383. mouseThread.start();
  384. } else {
  385. mouseThread.start();
  386. sleep(random(0, 600));
  387. keyThread.start();
  388. }
  389. while(keyThread.isAlive() || mouseThread.isAlive())
  390. sleep(random(30, 100));
  391. }
  392.  
  393. @Override
  394. public void onRepaint(Graphics g) {
  395. if (showPaint) {
  396. final NumberFormat nf = NumberFormat.getIntegerInstance();
  397. ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  398. //Variables
  399. RSComponent inter = interfaces.get(137).getComponent(0);
  400. int x = inter.getLocation().x;
  401. int y = inter.getLocation().y;
  402.  
  403. //Counters
  404. int runTime = (int) System.currentTimeMillis() - startTime;
  405.  
  406. //Background
  407. g.setColor(new Color(198, 226, 255));
  408. g.fillRect(x, y, inter.getWidth() + 5, inter.getHeight() + 5);
  409.  
  410. //Simple things
  411. g.setColor(Color.BLACK);
  412. g.setFont(new Font("Arial", Font.PLAIN, 18));
  413. g.drawString("TFighter by !@!@! (v" + mani.version() + ")", x + 10, y += g.getFontMetrics().getMaxAscent() + 10);
  414. g.setFont(new Font("Arial", Font.PLAIN, 12));
  415. g.drawString("Run time: " + millisToTime(runTime), x + 20, y += g.getFontMetrics().getMaxAscent() + 5);
  416.  
  417. //Exp gains
  418. g.setFont(new Font("Arial", Font.BOLD, 12));
  419. g.drawString("Experience gained:", x + 20, y += g.getFontMetrics().getMaxAscent() + 15);
  420. g.setFont(new Font("Arial", Font.PLAIN, 11));
  421. for (Map.Entry<String, Integer> entry : u.sw.getExpGainedMap().entrySet()) {
  422. double expPerSec = entry.getValue() / (double) (runTime / 1000);
  423. int expPerHour = (int) Math.round(expPerSec * 3600);
  424. g.drawString(entry.getKey() + ": " + nf.format(entry.getValue()) +
  425. " (p/hr: " + nf.format(expPerHour) + ")", x + 25, y += g.getFontMetrics().getMaxAscent());
  426. }
  427.  
  428. //Loot
  429. y = inter.getLocation().y;
  430. g.setFont(new Font("Arial", Font.BOLD, 12));
  431. g.drawString("Loot taken:", x + 280, y += g.getFontMetrics().getMaxAscent() + 15);
  432. g.setFont(new Font("Arial", Font.PLAIN, 11));
  433. Map<String, Integer> loot = u.loot.getLootTaken();
  434. for (Map.Entry<String, Integer> entry : loot.entrySet()) {
  435. g.drawString(entry.getKey() + " x" + entry.getValue(), x + 285, y += g.getFontMetrics().getMaxAscent());
  436. }
  437. }
  438. drawMouse(g);
  439. }
  440.  
  441. private void drawMouse(Graphics g) {
  442. int x = mouse.getLocation().x, y = mouse.getLocation().y;
  443. g.setColor(System.currentTimeMillis() - mouse.getPressTime() < 300 ? Color.CYAN : Color.RED);
  444. g.fillOval(x - 6, y - 6, 12, 12);
  445. g.setColor(Color.ORANGE);
  446. g.fillOval(x - 3, y - 3, 6, 6);
  447. g.drawLine(x - 10, y - 10, x + 10, y + 10);
  448. g.drawLine(x - 10, y + 10, x + 10, y - 10);
  449. }
  450.  
  451. /**
  452. * Formats the given value into a clock format
  453. * that follows the form of 00:00:00
  454. *
  455. * @param millis The total millis to be evaluated
  456. * @return A String representation of millis, formatted as a clock
  457. */
  458. private String millisToTime(int millis) {
  459. int hours = millis / (60 * 1000 * 60);
  460. int minutes = (millis - (hours * 60 * 1000 * 60)) / (60 * 1000);
  461. int seconds = (millis - (hours * 60 * 1000 * 60) - (minutes * 60 * 1000)) / 1000;
  462. return (hours >= 10 ? hours + ":" : "0" + hours + ":")
  463. + (minutes >= 10 ? minutes + ":" : "0" + minutes + ":")
  464. + (seconds >= 10 ? seconds : "0" + seconds);
  465. }
  466.  
  467. private class Util {
  468. private final NPCs npcs = new NPCs();
  469. private final Eating eat = new Eating();
  470. private final Loot loot = new Loot();
  471. private final SkillWatcher sw = new SkillWatcher();
  472. }
  473.  
  474. private class NPCs {
  475.  
  476. private int[] npcIDs = new int[0];
  477. private String[] npcNames = new String[0];
  478.  
  479. private int maxRadius = 10;
  480.  
  481. /**
  482. * Checks if we are in combat.
  483. *
  484. * @return True if we are in combat.
  485. */
  486. private boolean isInCombat() {
  487. return getMyPlayer().getInteracting() instanceof RSNPC;
  488. }
  489.  
  490. /**
  491. * Clicks an NPC based on its model.
  492. *
  493. * @param npc The NPC to click.
  494. * @param action The action to perform.
  495. * @return 0 if the NPC was clicked, 1 if we walked to it, or -1 if nothing happened.
  496. */
  497. private int clickNPC(RSNPC npc, String action) {
  498. for (int i = 0; i < 10; i++) {
  499. if (isPartiallyOnScreen(npc.getModel())) {
  500. Point p = useCentralClicking ? getCentralPoint(npc.getModel()) : getPointOnScreen(npc.getModel(), false);
  501. if (p == null || !calc.pointOnScreen(p)) {
  502. continue;
  503. }
  504. mouse.move(p, useCentralClicking ? 3 : 0, useCentralClicking ? 3 : 0);
  505. String[] items = menu.getItems();
  506. if (items.length > 0 && items[0].contains(action)) {
  507. mouse.click(true);
  508. return 0;
  509. } else if (menu.contains(action)) {
  510. mouse.click(false);
  511. sleep(random(100, 200));
  512. for (int x = 0; x < 4; x++) {
  513. if (!menu.contains(action)) {
  514. break;
  515. }
  516. if (menu.doAction(action)) {
  517. return 0;
  518. }
  519. }
  520. }
  521. } else {
  522. if(!useSafespot) {
  523. walking.walkTileMM(closerTile(npc.getLocation(), 1), 2, 2);
  524. return 1;
  525. } else {
  526. int angle = camera.getCharacterAngle(npc);
  527. if (calc.distanceTo(npc) < 10 && Math.abs(angle - camera.getAngle()) > 20) {
  528. camera.setAngle(angle + random(-20, 20));
  529. }
  530. }
  531. }
  532. }
  533. return -1;
  534. }
  535.  
  536. /**
  537. * Checks if a model is partially on screen.
  538. *
  539. * @param m The RSModel to check.
  540. * @return True if any point on the model is on screen.
  541. */
  542. private boolean isPartiallyOnScreen(RSModel m) {
  543. return getPointOnScreen(m, true) != null;
  544. }
  545.  
  546. /**
  547. * Gets a point on a model that is on screen.
  548. *
  549. * @param m The RSModel to test.
  550. * @param first If true, it will return the first point that it finds on screen.
  551. * @return A random point on screen of an object.
  552. */
  553. private Point getPointOnScreen(RSModel m, boolean first) {
  554. if (m == null)
  555. return null;
  556. ArrayList<Point> list = new ArrayList<Point>();
  557. try {
  558. Polygon[] tris = m.getTriangles();
  559. for (int i = 0; i < tris.length; i++) {
  560. Polygon p = tris[i];
  561. for (int j = 0; j < p.xpoints.length; j++) {
  562. Point pt = new Point(p.xpoints[j], p.ypoints[j]);
  563. if (calc.pointOnScreen(pt)) {
  564. if (first)
  565. return pt;
  566. list.add(pt);
  567. }
  568. }
  569. }
  570. } catch (Exception e) {
  571. }
  572. return list.size() > 0 ? list.get(random(0, list.size())) : null;
  573. }
  574.  
  575. /**
  576. * Generates a rough central point. Performs the calculation
  577. * by first generating a rough point, and then finding the point
  578. * closest to the rough point that is actually on the RSModel.
  579. *
  580. * @param m The RSModel to test.
  581. * @return The rough central point.
  582. */
  583. private Point getCentralPoint(RSModel m) {
  584. if(m == null)
  585. return null;
  586. try {
  587. /* Add X and Y of all points, to get a rough central point */
  588. int x = 0, y = 0, total = 0;
  589. for(Polygon poly : m.getTriangles()) {
  590. for(int i = 0; i < poly.npoints; i++) {
  591. x += poly.xpoints[i];
  592. y += poly.ypoints[i];
  593. total++;
  594. }
  595. }
  596. Point central = new Point(x / total, y / total);
  597. /* Find a real point on the NPC that is closest to the central point */
  598. Point curCentral = null;
  599. double dist = 20000;
  600. for(Polygon poly : m.getTriangles()) {
  601. for(int i = 0; i < poly.npoints; i++) {
  602. Point p = new Point(poly.xpoints[i], poly.ypoints[i]);
  603. if(!calc.pointOnScreen(p))
  604. continue;
  605. double dist2 = distanceBetween(central, p);
  606. if(curCentral == null || dist2 < dist) {
  607. curCentral = p;
  608. dist = dist2;
  609. }
  610. }
  611. }
  612. return curCentral;
  613. } catch (Exception e) {}
  614. return null;
  615. }
  616.  
  617. /**
  618. * Calculates the distance between two points.
  619. *
  620. * @param p1 The first point.
  621. * @param p2 The second point.
  622. * @return The distance between the two points, using the distance formula.
  623. */
  624. private double distanceBetween(Point p1, Point p2) {
  625. return Math.sqrt(((p1.x - p2.x) * (p1.x - p2.x)) + ((p1.y - p2.y) * (p1.y - p2.y)));
  626. }
  627.  
  628. /**
  629. * Gets a closer tile to us within dist.
  630. *
  631. * @param t The tile to start with.
  632. * @param dist The max dist.
  633. * @return A closer tile.
  634. */
  635. private RSTile closerTile(RSTile t, int dist) {
  636. RSTile loc = getMyPlayer().getLocation();
  637. int newX = t.getX(), newY = t.getY();
  638. for (int i = 1; i < dist; i++) {
  639. newX = t.getX() != loc.getX() ? (t.getX() < loc.getX() ? newX-- : newX++) : newX;
  640. newY = t.getY() != loc.getY() ? (t.getY() < loc.getY() ? newY-- : newY++) : newY;
  641. }
  642. return new RSTile(newX, newY);
  643. }
  644.  
  645. /**
  646. * Returns the nearest NPC.
  647. *
  648. * @return The nearest NPC that matches the filter.
  649. */
  650. private RSNPC getNPC() {
  651. RSNPC onScreen = npcs.getNearest(npcOnScreenFilter);
  652. if(onScreen != null)
  653. return onScreen;
  654. return npcs.getNearest(npcFilter);
  655. }
  656.  
  657. /**
  658. * Returns the interacting NPC that matches our description, if any.
  659. *
  660. * @return The closest interacting NPC that matches the filter.
  661. */
  662. private RSNPC getInteracting() {
  663. RSNPC npc = null;
  664. int dist = 20;
  665. for (RSNPC n : npcs.getAll()) {
  666. if (!isOurNPC(n))
  667. continue;
  668. RSCharacter inter = n.getInteracting();
  669. if (inter != null && inter instanceof RSPlayer && inter.equals(getMyPlayer()) && calc.distanceTo(n) < dist) {
  670. dist = calc.distanceTo(n);
  671. npc = n;
  672. }
  673. }
  674. return npc;
  675. }
  676.  
  677. private boolean isOurNPC(RSNPC t) {
  678. int id = t.getID();
  679. String name = t.getName();
  680. boolean good = false;
  681. for (int i : npcIDs) {
  682. if (id == i)
  683. good = true;
  684. }
  685. for (String s : npcNames) {
  686. if (name.toLowerCase().contains(s.toLowerCase()))
  687. good = true;
  688. }
  689. return good;
  690. }
  691.  
  692. /**
  693. * The filter we use!
  694. */
  695. private final Filter<RSNPC> npcFilter = new Filter<RSNPC>() {
  696. public boolean accept(RSNPC t) {
  697. return (isOurNPC(t) && t.isValid() && (!onlyInRadius || calc.distanceBetween(t.getLocation(), startTile) < maxRadius)
  698. && (utilizeMultiwayCombat || !t.isInCombat() && t.getInteracting() == null) && t.getHPPercent() != 0);
  699. }
  700. };
  701.  
  702. /**
  703. * Will only return an on screen NPC. Based on npcFilter.
  704. */
  705. private final Filter<RSNPC> npcOnScreenFilter = new Filter<RSNPC>() {
  706. public boolean accept(RSNPC n) {
  707. return npcFilter.accept(n) && getPointOnScreen(n.getModel(), true) != null;
  708. }
  709. };
  710. }
  711.  
  712. private class Eating {
  713.  
  714. private final int[] B2P_TAB_ID = new int[]{8015};
  715. private final int[] BONES_ID = new int[]{526, 532, 530, 528, 3183, 2859};
  716.  
  717. private int toEatAtPercent = getRandomEatPercent();
  718.  
  719. /**
  720. * Returns a random integer of when to eat.
  721. * @return A random integer of the percent to eat at.
  722. */
  723. private int getRandomEatPercent() {
  724. return random(45, 60);
  725. }
  726.  
  727. /**
  728. * Checks if we have at least one B2P tab.
  729. *
  730. * @return True if we have a tab.
  731. */
  732. private boolean haveB2pTab() {
  733. return inventory.getCount(B2P_TAB_ID) > 0;
  734. }
  735.  
  736. /**
  737. * Breaks a B2P tab.
  738. */
  739. private void breakB2pTab() {
  740. RSItem i = inventory.getItem(B2P_TAB_ID);
  741. if (i != null)
  742. i.doClick(true);
  743. }
  744.  
  745. /**
  746. * Checks if the inventory contains bones, for B2P.
  747. *
  748. * @return True if we have bones.
  749. */
  750. private boolean haveBones() {
  751. return inventory.getCount(BONES_ID) > 0;
  752. }
  753.  
  754. /**
  755. * Checks if we have food.
  756. *
  757. * @return True if we have food.
  758. */
  759. private boolean haveFood() {
  760. return getFood() != null;
  761. }
  762.  
  763. /**
  764. * Finds food based on inventory actions.
  765. *
  766. * @return The RSItem of food, or null if none was found.
  767. */
  768. private RSItem getFood() {
  769. for (RSItem i : inventory.getItems()) {
  770. if (i == null || i.getID() == -1)
  771. continue;
  772. if (i.getComponent().getActions() == null || i.getComponent().getActions()[0] == null)
  773. continue;
  774. if (i.getComponent().getActions()[0].contains("Eat"))
  775. return i;
  776. }
  777. return null;
  778. }
  779.  
  780. /**
  781. * Attempts to eat food.
  782. *
  783. * @return True if we ate.
  784. */
  785. private boolean eatFood() {
  786. RSItem i = getFood();
  787. for (int j = 0; j < 3; j++) {
  788. if (i == null)
  789. break;
  790. if (i.doAction("Eat")) {
  791. return true;
  792. }
  793. }
  794. return false;
  795. }
  796.  
  797. /**
  798. * Checks whether you need to eat or not.
  799. *
  800. * @return True if we need to eat.
  801. */
  802. private boolean needEat() {
  803. if(getHPPercent() <= toEatAtPercent) {
  804. toEatAtPercent = getRandomEatPercent();
  805. return true;
  806. }
  807. return false;
  808. }
  809.  
  810. /**
  811. * Returns an integer representing the current health percentage.
  812. * @return The current health percentage.
  813. */
  814. public int getHPPercent() {
  815. try {
  816. return ((int) ((Integer.parseInt(interfaces.get(748).getComponent(8).getText().trim()) / (double)(skills.getRealLevel(Skills.CONSTITUTION) * 10)) * 100));
  817. } catch (Exception e) {
  818. return 100;
  819. }
  820. }
  821. }
  822.  
  823. private class Loot {
  824.  
  825. private int[] lootIDs = new int[0];
  826. private String[] lootNames = new String[0];
  827.  
  828. private Map<String, Integer> lootTaken = new HashMap<String, Integer>();
  829.  
  830. /**
  831. * Gets the nearest loot, based on the filter
  832. *
  833. * @return The nearest item to loot, or null if none.
  834. */
  835. private RSGroundItem getLoot() {
  836. return groundItems.getNearest(lootFilter);
  837. }
  838.  
  839. /**
  840. * Attempts to take an item.
  841. *
  842. * @param item The item to take.
  843. * @return -1 if error, 0 if taken, 1 if walked
  844. */
  845. private int takeItem(RSGroundItem item) {
  846. if (item == null)
  847. return -1;
  848. String action = "Take " + item.getItem().getName();
  849. if (item.isOnScreen()) {
  850. for (int i = 0; i < 5; i++) {
  851. if (menu.isOpen())
  852. mouse.moveRandomly(300, 500);
  853. Point p = calc.tileToScreen(item.getLocation(), random(0.48, 0.52), random(0.48, 0.52), 0);
  854. if (!calc.pointOnScreen(p))
  855. continue;
  856. mouse.move(p, 3, 3);
  857. if (menu.contains(action)) {
  858. if (menu.getItems()[0].contains(action)) {
  859. mouse.click(true);
  860. return 0;
  861. } else {
  862. mouse.click(false);
  863. sleep(random(100, 200));
  864. if (menu.doAction(action))
  865. return 0;
  866. }
  867. }
  868. }
  869. } else {
  870. walking.walkTileMM(walking.getClosestTileOnMap(item.getLocation()));
  871. return 1;
  872. }
  873. return -1;
  874. }
  875.  
  876. private void addItem(String name, int count) {
  877. if (lootTaken.get(name) != null) {
  878. int newCount = count + lootTaken.get(name);
  879. lootTaken.remove(name);
  880. lootTaken.put(name, newCount);
  881. } else {
  882. lootTaken.put(name, count);
  883. }
  884. }
  885.  
  886. private Map<String, Integer> getLootTaken() {
  887. HashMap<String, Integer> m = new HashMap<String, Integer>();
  888. m.putAll(lootTaken);
  889. return m;
  890. }
  891.  
  892. private final Filter<RSGroundItem> lootFilter = new Filter<RSGroundItem>() {
  893. public boolean accept(RSGroundItem t) {
  894. //Skip if we can't hold it
  895. RSItem i;
  896. if (inventory.isFull() && ((i = inventory.getItem(t.getItem().getID())) == null || i.getStackSize() <= 1)) {
  897. return false;
  898. }
  899. //Skip if its out of radius or far away
  900. if (onlyInRadius && calc.distanceBetween(t.getLocation(), startTile) > u.npcs.maxRadius
  901. || calc.distanceTo(t.getLocation()) > 25) {
  902. return false;
  903. }
  904. //Check ID/name
  905. boolean good = false;
  906. int id = t.getItem().getID();
  907. for (int iD : lootIDs) {
  908. if (iD == id)
  909. good = true;
  910. }
  911. String name = t.getItem().getName();
  912. for (String s : lootNames) {
  913. if (name != null && name.toLowerCase().contains(s.toLowerCase()))
  914. good = true;
  915. }
  916. return good;
  917. }
  918. };
  919.  
  920. }
  921.  
  922. private class SkillWatcher {
  923.  
  924. private Map<Integer, Integer> startExpMap = new HashMap<Integer, Integer>();
  925. private final int[] SKILLS_TO_WATCH = new int[]{Skills.SLAYER, Skills.CONSTITUTION, Skills.ATTACK, Skills.STRENGTH, Skills.DEFENSE, Skills.RANGE, Skills.MAGIC};
  926.  
  927. /**
  928. * Basically sets start exp for all skills we are watching.
  929. */
  930. private void poll() {
  931. for (int skill : SKILLS_TO_WATCH) {
  932. if (startExpMap.containsKey(skill))
  933. startExpMap.remove(skill);
  934. startExpMap.put(skill, skills.getCurrentExp(skill));
  935. }
  936. }
  937.  
  938. /**
  939. * Returns the amount of exp gained in the specified skill.
  940. *
  941. * @param skill The skill see Skills.*
  942. * @return
  943. */
  944. private int getExpGainedIn(int skill) {
  945. if (startExpMap.get(skill) == null)
  946. return -1;
  947. return skills.getCurrentExp(skill) - startExpMap.get(skill);
  948. }
  949.  
  950. /**
  951. * Returns a map of skill names and exp gained.
  952. *
  953. * @return A map of exp gains and skill names.
  954. */
  955. private Map<String, Integer> getExpGainedMap() {
  956. Map<String, Integer> map = new HashMap<String, Integer>();
  957. for (int i : SKILLS_TO_WATCH) {
  958. int gained = getExpGainedIn(i);
  959. if (gained != 0)
  960. map.put(Skills.SKILL_NAMES[i], gained);
  961. }
  962. return map;
  963. }
  964.  
  965. }
  966.  
  967. @SuppressWarnings("serial")
  968. private class FighterGUI extends JFrame {
  969.  
  970. private final File file = new File(GlobalConfiguration.Paths.getSettingsDirectory() + System.getProperty("file.separator") + "TFighterProps.txt");
  971.  
  972. private JCheckBox useMulti, useRadius, useSafe, useCentral, prioritizeLoot;
  973. private JTextField npcBox, lootBox, mouseSpeedBox;
  974.  
  975. private FighterGUI() {
  976. init();
  977. pack();
  978. setVisible(true);
  979. }
  980.  
  981. private void init() {
  982. Properties props = loadProperties();
  983. JPanel north = new JPanel(new FlowLayout());
  984. north.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  985. {
  986. JLabel title = new JLabel("TFighter by !@!@!");
  987. title.setFont(new Font("Arial", Font.PLAIN, 28));
  988. north.add(title);
  989. }
  990. add(north, BorderLayout.NORTH);
  991.  
  992. JPanel center = new JPanel();
  993. center.setLayout(new BoxLayout(center, BoxLayout.PAGE_AXIS));
  994. center.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  995. {
  996. mouseSpeedBox = new JTextField("4,7");
  997. useMulti = new JCheckBox("Utilize multiway combat");
  998. useRadius = new JCheckBox("Only attack within a radius");
  999. useSafe = new JCheckBox("Use safespot?");
  1000. useCentral = new JCheckBox("Use central point on NPC? (instead of random)");
  1001. npcBox = new JTextField("2,5,1,Chicke");
  1002. lootBox = new JTextField("arrow,feather");
  1003. prioritizeLoot = new JCheckBox("Prioritize loot over combat?");
  1004.  
  1005. mouseSpeedBo*****tAlignmentX(JTextField.CENTER_ALIGNMENT);
  1006. useMulti.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  1007. useRadius.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  1008. npcBo*****tAlignmentX(JTextField.CENTER_ALIGNMENT);
  1009. lootBo*****tAlignmentX(JTextField.CENTER_ALIGNMENT);
  1010. useSafe.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  1011. useCentral.setAlignmentX(JCheckBox.CENTER_ALIGNMENT);
  1012.  
  1013. if (props.getProperty("mouseSpeed") != null) {
  1014. mouseSpeedBo*****tText(props.getProperty("mouseSpeed"));
  1015. }
  1016. if (props.getProperty("useMulti") != null) {
  1017. if (props.getProperty("useMulti").equals("true"))
  1018. useMulti.setSelected(true);
  1019. }
  1020. if (props.getProperty("useRadius") != null) {
  1021. if (props.getProperty("useRadius").equals("true"))
  1022. useRadius.setSelected(true);
  1023. }
  1024. if (props.getProperty("npcBox") != null) {
  1025. npcBo*****tText(props.getProperty("npcBox"));
  1026. }
  1027. if (props.getProperty("lootBox") != null) {
  1028. lootBo*****tText(props.getProperty("lootBox"));
  1029. }
  1030. if(props.getProperty("useSafe") != null) {
  1031. if(props.getProperty("useSafe").equals("true"))
  1032. useSafe.setSelected(true);
  1033. }
  1034. if(props.getProperty("useCentral") != null) {
  1035. if(props.getProperty("useCentral").equals("true"))
  1036. useCentral.setSelected(true);
  1037. }
  1038. if(props.getProperty("prioritizeLoot") != null) {
  1039. if(props.get("prioritizeLoot").equals("true"))
  1040. prioritizeLoot.setSelected(true);
  1041. }
  1042.  
  1043. JLabel lbl1 = new JLabel("Enter your desired mouse speed (max,min)");
  1044. lbl1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  1045. center.add(lbl1);
  1046. center.add(mouseSpeedBox);
  1047. center.add(useMulti);
  1048. center.add(useRadius);
  1049. center.add(useSafe);
  1050. center.add(useCentral);
  1051. center.add(new JLabel(" "));
  1052. JLabel lbl2 = new JLabel("Enter the IDs and/or names of the NPCs to fight.");
  1053. lbl2.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  1054. center.add(lbl2);
  1055. JLabel lbl3 = new JLabel("You can mix and match these, all in the same box!");
  1056. lbl3.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  1057. center.add(lbl3);
  1058. center.add(npcBox);
  1059. JLabel lbl4 = new JLabel("Enter the IDs and/or names of items to loot.");
  1060. lbl4.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  1061. center.add(lbl4);
  1062. center.add(lootBox);
  1063. center.add(prioritizeLoot);
  1064. prioritizeLoot.setAlignmentX(JComboBox.CENTER_ALIGNMENT);
  1065. JLabel lbl5 = new JLabel("If selected, you will loot while in combat.");
  1066. lbl5.setAlignmentX(JLabel.CENTER_ALIGNMENT);
  1067. center.add(lbl5);
  1068. }
  1069. add(center, BorderLayout.CENTER);
  1070.  
  1071. JPanel south = new JPanel(new FlowLayout());
  1072. south.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  1073. {
  1074. JButton start = new JButton("Start script!");
  1075. start.setAlignmentX(JButton.CENTER_ALIGNMENT);
  1076. start.addActionListener(onStart);
  1077. south.add(start);
  1078. }
  1079. add(south, BorderLayout.SOUTH);
  1080.  
  1081. setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  1082. setTitle("TFighter GUI");
  1083. }
  1084.  
  1085. private Properties loadProperties() {
  1086. try {
  1087. if (!file.exists())
  1088. file.createNewFile();
  1089. Properties p = new Properties();
  1090. p.load(new FileInputStream(file));
  1091. return p;
  1092. } catch (Exception e) {
  1093. e.printStackTrace();
  1094. }
  1095. return null;
  1096. }
  1097.  
  1098. private void saveProperties() {
  1099. Properties p = new Properties();
  1100. p.put("mouseSpeed", mouseSpeedBox.getText());
  1101. p.put("useMulti", Boolean.toString(useMulti.isSelected()));
  1102. p.put("useRadius", Boolean.toString(useRadius.isSelected()));
  1103. p.put("useSafe", Boolean.toString(useSafe.isSelected()));
  1104. p.put("useCentral", Boolean.toString(useCentral.isSelected()));
  1105. p.put("npcBox", npcBox.getText());
  1106. p.put("lootBox", lootBox.getText());
  1107. p.put("prioritizeLoot", Boolean.toString(prioritizeLoot.isSelected()));
  1108. try {
  1109. p.store(new FileOutputStream(file), "");
  1110. } catch (Exception e) {
  1111. e.printStackTrace();
  1112. }
  1113. }
  1114.  
  1115. private ActionListener onStart = new ActionListener() {
  1116. @Override
  1117. public void actionPerformed(ActionEvent e) {
  1118. saveProperties();
  1119. startScript = true;
  1120. mouseSpeedMin = Integer.parseInt(mouseSpeedBox.getText().split(",")[0]);
  1121. mouseSpeedMax = Integer.parseInt(mouseSpeedBox.getText().split(",")[0]);
  1122. utilizeMultiwayCombat = useMulti.isSelected();
  1123. onlyInRadius = useRadius.isSelected();
  1124. useSafespot = useSafe.isSelected();
  1125. useCentralClicking = useCentral.isSelected();
  1126. TFighter.this.prioritizeLoot = prioritizeLoot.isSelected();
  1127. if (onlyInRadius) {
  1128. u.npcs.maxRadius = Integer.parseInt(JOptionPane.showInputDialog("Enter the max radius. Example: 10"));
  1129. }
  1130. String[] ids = npcBox.getText().split(",");
  1131. ArrayList<Integer> idList = new ArrayList<Integer>();
  1132. ArrayList<String> nameList = new ArrayList<String>();
  1133. for (int i = 0; i < ids.length; i++) {
  1134. if (ids[i] != null && !ids[i].equals("")) {
  1135. try {
  1136. int id = Integer.parseInt(ids[i]);
  1137. idList.add(id);
  1138. } catch (Exception e1) {
  1139. nameList.add(ids[i]);
  1140. }
  1141. }
  1142. }
  1143. u.npcs.npcIDs = idList.size() > 0 ? toIntArray(idList.toArray(new Integer[0])) : new int[0];
  1144. u.npcs.npcNames = nameList.size() > 0 ? nameList.toArray(new String[0]) : new String[0];
  1145.  
  1146. ids = lootBox.getText().split(",");
  1147. idList = new ArrayList<Integer>();
  1148. nameList = new ArrayList<String>();
  1149. for (int i = 0; i < ids.length; i++) {
  1150. if (ids[i] != null && !ids[i].equals("")) {
  1151. try {
  1152. int id = Integer.parseInt(ids[i]);
  1153. idList.add(id);
  1154. } catch (Exception e1) {
  1155. nameList.add(ids[i]);
  1156. }
  1157. }
  1158. }
  1159. u.loot.lootIDs = idList.size() > 0 ? toIntArray(idList.toArray(new Integer[0])) : new int[0];
  1160. u.loot.lootNames = nameList.size() > 0 ? nameList.toArray(new String[0]) : new String[0];
  1161. dispose();
  1162. }
  1163. };
  1164.  
  1165. private int[] toIntArray(Integer[] ints) {
  1166. int[] done = new int[ints.length];
  1167. for (int i = 0; i < done.length; i++) {
  1168. done[i] = ints[i].intValue();
  1169. }
  1170. return done;
  1171. }
  1172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement