Guest User

Untitled

a guest
Jun 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.02 KB | None | 0 0
  1. import java.awt.Color;
  2.  
  3. import java.awt.Graphics;
  4.  
  5. import java.awt.Graphics2D;
  6.  
  7. import java.awt.Point;
  8.  
  9. import java.awt.RenderingHints;
  10.  
  11. import java.util.HashSet;
  12.  
  13. import java.util.Set;
  14.  
  15.  
  16. import com.rarebot.event.listeners.PaintListener;
  17.  
  18. import com.rarebot.script.Script;
  19.  
  20. import com.rarebot.script.ScriptManifest;
  21.  
  22. import com.rarebot.script.methods.Skills;
  23.  
  24. import com.rarebot.script.util.Timer;
  25.  
  26. import com.rarebot.script.wrappers.RSArea;
  27.  
  28. import com.rarebot.script.wrappers.RSComponent;
  29.  
  30. import com.rarebot.script.wrappers.RSItem;
  31.  
  32. import com.rarebot.script.wrappers.RSNPC;
  33.  
  34. import com.rarebot.script.wrappers.RSObject;
  35.  
  36. import com.rarebot.script.wrappers.RSTile;
  37.  
  38.  
  39. @ScriptManifest(name = "Guild Ranger", authors = { "Vastico" }, description = "Trains range at the ranging guild on the targets.", version = 1.2)
  40.  
  41. public class RangedGuildBotRS extends Script implements PaintListener {
  42.  
  43.  
  44. private interface GameConstants {
  45.  
  46.  
  47.  
  48. RSArea SHOOTING_AREA = new RSArea(2669, 3417, 2673, 3420);
  49.  
  50.  
  51.  
  52. RSArea SAFE_AREA = new RSArea(2646, 3440, 2643, 3444);
  53.  
  54.  
  55.  
  56. RSTile GUILD_DOOR_TILE = new RSTile(2659, 3437);
  57.  
  58.  
  59.  
  60. RSTile SAFE_DOOR_TILE = new RSTile(2656, 3440);
  61.  
  62.  
  63.  
  64. int TARGET = 1308;
  65.  
  66.  
  67.  
  68. int BRONZE_ARROW = 882;
  69.  
  70.  
  71.  
  72. int COMPETITION_JUDGE = 693;
  73.  
  74.  
  75.  
  76. int GUILD_DOOR = 2514;
  77.  
  78.  
  79.  
  80. int PAYMENT_INTERFACE = 1188;
  81.  
  82.  
  83.  
  84. int TARGET_INTERFACE = 325;
  85.  
  86.  
  87.  
  88. Color BACKGROUND_COLOR = new Color(0, 0, 0, 100);
  89.  
  90.  
  91.  
  92. Color TEXT_COLOR = new Color(255, 255, 255, 255);
  93.  
  94.  
  95.  
  96. RenderingHints ANTI_ALIASING = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  97.  
  98.  
  99.  
  100. }
  101.  
  102.  
  103. private abstract class Action {
  104.  
  105.  
  106.  
  107. public abstract void execute();
  108.  
  109.  
  110.  
  111. public abstract void complete();
  112.  
  113.  
  114.  
  115. public abstract boolean isValid();
  116.  
  117.  
  118.  
  119. public abstract String getDescription();
  120.  
  121.  
  122.  
  123. public void paint(Graphics render) {
  124.  
  125. }
  126.  
  127.  
  128.  
  129. }
  130.  
  131.  
  132.  
  133. private abstract class ObjectAction extends Action {
  134.  
  135.  
  136.  
  137. private final int id;
  138.  
  139. private final String action;
  140.  
  141. private Point location;
  142.  
  143. private int attempts = 0;
  144.  
  145.  
  146.  
  147. public ObjectAction(int id, String action) {
  148.  
  149. this.id = id;
  150.  
  151. this.action = action;
  152.  
  153. }
  154.  
  155.  
  156.  
  157. public void execute() {
  158.  
  159. if (location != null) {
  160.  
  161. mouse.move(location, 1, 1);
  162.  
  163. if (isTargetInterfaceOpen()) {
  164.  
  165. mouse.click(location, 1, 1, true);
  166.  
  167. }
  168.  
  169. if(menu.doAction(action)) {
  170.  
  171. sleep(20);
  172.  
  173. attempts = 0;
  174.  
  175. } else if (attempts > 8) {
  176.  
  177. failsafe = true;
  178.  
  179. } else {
  180.  
  181. attempts ++;
  182.  
  183. }
  184.  
  185. } else {
  186.  
  187. RSObject obj = objects.getNearest(id);
  188.  
  189. if (obj != null) {
  190.  
  191. if (obj.isOnScreen()) {
  192.  
  193. location = obj.getModel().getPoint();
  194.  
  195. } else {
  196.  
  197. camera.turnTo(obj, 10);
  198.  
  199. }
  200.  
  201. }
  202.  
  203. }
  204.  
  205. }
  206.  
  207.  
  208.  
  209. public void complete() {
  210.  
  211. attempts = 0;
  212.  
  213. location = null;
  214.  
  215. }
  216.  
  217.  
  218.  
  219. public String getDescription() {
  220.  
  221. return "Object Action [" + action + "]";
  222.  
  223. }
  224.  
  225.  
  226.  
  227. }
  228.  
  229.  
  230.  
  231. private abstract class NPCAction extends Action {
  232.  
  233.  
  234. private int id;
  235.  
  236. private String action;
  237.  
  238.  
  239. public NPCAction(int id, String action) {
  240.  
  241. this.id = id;
  242.  
  243. this.action = action;
  244.  
  245. }
  246.  
  247.  
  248. public void execute() {
  249.  
  250. if (judge == null) {
  251.  
  252. judge = npcs.getNearest(id);
  253.  
  254. }
  255.  
  256. if (judge != null) {
  257.  
  258. if (!judge.isOnScreen()) {
  259.  
  260. camera.turnTo(judge, 10);
  261.  
  262. } else if (judge.doAction(action)) {
  263.  
  264. if (!getMyPlayer().isIdle()) {
  265.  
  266. sleep(2000);
  267.  
  268. }
  269.  
  270. sleep(1000);
  271.  
  272. }
  273.  
  274. }
  275.  
  276. }
  277.  
  278.  
  279.  
  280. public void complete() {
  281.  
  282.  
  283.  
  284. }
  285.  
  286.  
  287.  
  288. public String getDescription() {
  289.  
  290. return "NPC Action [" + action + "]";
  291.  
  292. }
  293.  
  294.  
  295.  
  296. }
  297.  
  298.  
  299.  
  300. private abstract class UniversalAction extends Action {
  301.  
  302.  
  303.  
  304. public void execute() {
  305.  
  306. }
  307.  
  308.  
  309. public void complete() {
  310.  
  311. }
  312.  
  313.  
  314. public boolean isValid() {
  315.  
  316. return false;
  317.  
  318. }
  319.  
  320.  
  321. public String getDescription() {
  322.  
  323. return "";
  324.  
  325. }
  326.  
  327.  
  328.  
  329. }
  330.  
  331.  
  332.  
  333. private abstract class WalkToArea extends Action {
  334.  
  335.  
  336.  
  337. private final RSArea destination;
  338.  
  339. private final String description;
  340.  
  341. private RSTile location;
  342.  
  343.  
  344.  
  345. public WalkToArea(RSArea destination, String description) {
  346.  
  347. this.destination = destination;
  348.  
  349. this.description = description;
  350.  
  351. }
  352.  
  353.  
  354.  
  355. public abstract boolean isTargetValid();
  356.  
  357.  
  358.  
  359. public void execute() {
  360.  
  361. if (!walking.isRunEnabled() && walking.getEnergy() > random(20, 50)) {
  362.  
  363. walking.setRun(true);
  364.  
  365. sleep(500);
  366.  
  367. }
  368.  
  369. RSTile tile = destination.getCentralTile();
  370.  
  371. if (location == null || getMyPlayer().isIdle() || (calc.distanceTo(location) < 10 && !destination.contains(location))) {
  372.  
  373. if (calc.tileOnScreen(tile) && random(0, 10) > 7) {
  374.  
  375. walking.walkTileOnScreen(calc.getTileOnScreen(tile));
  376.  
  377. } else {
  378.  
  379. walking.walkTo(tile);
  380.  
  381. }
  382.  
  383. location = walking.getDestination();
  384.  
  385. sleep(random(1000, 1800));
  386.  
  387. } else {
  388.  
  389. idle();
  390.  
  391. }
  392.  
  393. }
  394.  
  395.  
  396.  
  397. public void complete() {
  398.  
  399. location = null;
  400.  
  401. }
  402.  
  403.  
  404.  
  405. public boolean isValid() {
  406.  
  407. return isTargetValid() && !destination.contains(getMyPlayer().getLocation());
  408.  
  409. }
  410.  
  411.  
  412.  
  413. public String getDescription() {
  414.  
  415. return "Walk To Area [" + description + "]";
  416.  
  417. }
  418.  
  419.  
  420.  
  421. }
  422.  
  423.  
  424. private Set<Action> actions;
  425.  
  426. private long startTime = 0L;
  427.  
  428. private int startXp = 0;
  429.  
  430. private int startLvl = 0;
  431.  
  432. private RSNPC judge;
  433.  
  434. private Action action;
  435.  
  436. private boolean failsafe = false;
  437.  
  438.  
  439.  
  440. private boolean spamClicking = true;
  441.  
  442.  
  443.  
  444. public boolean onStart() {
  445.  
  446. actions = new HashSet<Action>();
  447.  
  448.  
  449.  
  450. actions.add(new UniversalAction() {
  451.  
  452.  
  453. public void execute() {
  454.  
  455. RSComponent closeInterface = interfaces.getComponent(GameConstants.TARGET_INTERFACE, 40);
  456.  
  457. if (closeInterface != null && closeInterface.isValid()) {
  458.  
  459. closeInterface.doClick();
  460.  
  461. sleep(500);
  462.  
  463. }
  464.  
  465. failsafe = false;
  466.  
  467. }
  468.  
  469.  
  470.  
  471. public boolean isValid() {
  472.  
  473. return failsafe && isTargetInterfaceOpen();
  474.  
  475. }
  476.  
  477.  
  478.  
  479. public String getDescription() {
  480.  
  481. return "Closing Failsafe Interface";
  482.  
  483. }
  484.  
  485.  
  486.  
  487. });
  488.  
  489.  
  490.  
  491. actions.add(new UniversalAction() {
  492.  
  493.  
  494. public void execute() {
  495.  
  496. RSComponent paymentInterface = interfaces.getComponent(GameConstants.PAYMENT_INTERFACE, 1);
  497.  
  498. if (paymentInterface != null && paymentInterface.isValid()) {
  499.  
  500. paymentInterface.doClick();
  501.  
  502. sleep(500);
  503.  
  504. }
  505.  
  506. }
  507.  
  508.  
  509.  
  510. public boolean isValid() {
  511.  
  512. return isPaymentInterfaceOpen();
  513.  
  514. }
  515.  
  516.  
  517.  
  518. public String getDescription() {
  519.  
  520. return "Paying Competition Judge";
  521.  
  522. }
  523.  
  524.  
  525.  
  526. });
  527.  
  528.  
  529.  
  530. actions.add(new UniversalAction() {
  531.  
  532.  
  533. public void execute() {
  534.  
  535. RSItem bronzeArrow = inventory.getItem(GameConstants.BRONZE_ARROW);
  536.  
  537. if (bronzeArrow != null) {
  538.  
  539. bronzeArrow.doAction("Wield");
  540.  
  541. sleep(800);
  542.  
  543. }
  544.  
  545. }
  546.  
  547.  
  548. public boolean isValid() {
  549.  
  550. return hasArrowsInInventory();
  551.  
  552. }
  553.  
  554.  
  555. public String getDescription() {
  556.  
  557. return "Wielding Arrows";
  558.  
  559. }
  560.  
  561.  
  562.  
  563. });
  564.  
  565.  
  566.  
  567. actions.add(new WalkToArea(GameConstants.SAFE_AREA, "safe area") {
  568.  
  569. public void execute() {
  570.  
  571. RSObject obj = objects.getNearest(GameConstants.GUILD_DOOR);
  572.  
  573. if (obj != null && calc.distanceBetween(obj.getLocation(), GameConstants.GUILD_DOOR_TILE) < 2) {
  574.  
  575. if (obj.isOnScreen()) {
  576.  
  577. if (obj.doAction("Open")) {
  578.  
  579. sleep(random(1000, 2000));
  580.  
  581. }
  582.  
  583. } else if (!GameConstants.GUILD_DOOR_TILE.equals(walking.getDestination())) {
  584.  
  585. walking.walkTo(GameConstants.GUILD_DOOR_TILE);
  586.  
  587. }
  588.  
  589. } else {
  590.  
  591. super.execute();
  592.  
  593. }
  594.  
  595. }
  596.  
  597.  
  598.  
  599. public boolean isTargetValid() {
  600.  
  601. return isAttackingRanger();
  602.  
  603. }
  604.  
  605. });
  606.  
  607.  
  608.  
  609. actions.add(new WalkToArea(GameConstants.SHOOTING_AREA, "shooting area") {
  610.  
  611. public void execute() {
  612.  
  613. RSObject obj = objects.getNearest(GameConstants.GUILD_DOOR);
  614.  
  615. if (obj != null && calc.distanceBetween(obj.getLocation(), GameConstants.SAFE_DOOR_TILE) < 2) {
  616.  
  617. if (obj.isOnScreen()) {
  618.  
  619. if (obj.doAction("Open")) {
  620.  
  621. sleep(random(1000, 2000));
  622.  
  623. }
  624.  
  625. } else if (!GameConstants.SAFE_DOOR_TILE.equals(walking.getDestination())) {
  626.  
  627. walking.walkTo(GameConstants.SAFE_DOOR_TILE);
  628.  
  629. }
  630.  
  631. } else {
  632.  
  633. super.execute();
  634.  
  635. }
  636.  
  637. }
  638.  
  639.  
  640.  
  641. public boolean isTargetValid() {
  642.  
  643. return !inShootingArea() && !isAttackingRanger();
  644.  
  645. }
  646.  
  647. });
  648.  
  649.  
  650.  
  651. actions.add(new ObjectAction(GameConstants.TARGET, "Fire-at") {
  652.  
  653. public void execute() {
  654.  
  655. super.execute();
  656.  
  657. }
  658.  
  659. public boolean isValid() {
  660.  
  661. return !canCompete() && inShootingArea() && !hasArrowsInInventory() && !failsafe;
  662.  
  663. }
  664.  
  665. });
  666.  
  667.  
  668.  
  669. actions.add(new NPCAction(GameConstants.COMPETITION_JUDGE, "Compete") {
  670.  
  671. public boolean isValid() {
  672.  
  673. return canCompete() && !isPaymentInterfaceOpen() && !hasArrowsInInventory() && !isTargetInterfaceOpen();
  674.  
  675. }
  676.  
  677. });
  678.  
  679.  
  680.  
  681. return true;
  682.  
  683. }
  684.  
  685.  
  686.  
  687. public int loop() {
  688.  
  689. mouse.setSpeed(random(6, 8));
  690.  
  691. if (camera.getPitch() > 1) {
  692.  
  693. camera.setPitch(false);
  694.  
  695. }
  696.  
  697. if (action != null) {
  698.  
  699. if (action.isValid()) {
  700.  
  701. action.execute();
  702.  
  703. } else {
  704.  
  705. action.complete();
  706.  
  707. action = null;
  708.  
  709. }
  710.  
  711. } else {
  712.  
  713. for (Action a : actions) {
  714.  
  715. if (a.isValid()) {
  716.  
  717. action = a;
  718.  
  719. break;
  720.  
  721. }
  722.  
  723. }
  724.  
  725. }
  726.  
  727. return random(50, 100);
  728.  
  729. }
  730.  
  731.  
  732.  
  733. public void onFinish() {
  734.  
  735. }
  736.  
  737.  
  738.  
  739. private boolean inShootingArea() {
  740.  
  741. return GameConstants.SHOOTING_AREA.contains(getMyPlayer().getLocation());
  742.  
  743. }
  744.  
  745.  
  746.  
  747. private boolean isAttackingRanger() {
  748.  
  749. return getMyPlayer().getInteracting() != null && getMyPlayer().getInteracting().getName().equals("Guard");
  750.  
  751. }
  752.  
  753.  
  754.  
  755. private boolean canSpamClick() {
  756.  
  757. return spamClicking;
  758.  
  759. }
  760.  
  761.  
  762.  
  763. private boolean canCompete() {
  764.  
  765. if (judge == null) {
  766.  
  767. judge = npcs.getNearest(GameConstants.COMPETITION_JUDGE);
  768.  
  769. }
  770.  
  771. if (judge != null) {
  772.  
  773. String[] actions = judge.getActions();
  774.  
  775. if (actions != null && actions.length > 0) {
  776.  
  777. for (String action : actions) {
  778.  
  779. if (action == null) {
  780.  
  781. continue;
  782.  
  783. }
  784.  
  785. if (action.equals("Compete")) {
  786.  
  787. return true;
  788.  
  789. }
  790.  
  791. }
  792.  
  793. }
  794.  
  795. }
  796.  
  797. return settings.getSetting(156) == 0;
  798.  
  799. }
  800.  
  801.  
  802.  
  803. private boolean hasArrowsInInventory() {
  804.  
  805. return inventory.getCount(GameConstants.BRONZE_ARROW) > 0;
  806.  
  807. }
  808.  
  809.  
  810.  
  811. private boolean isTargetInterfaceOpen() {
  812.  
  813. return interfaces.get(GameConstants.TARGET_INTERFACE).isValid();
  814.  
  815. }
  816.  
  817.  
  818.  
  819. private boolean isPaymentInterfaceOpen() {
  820.  
  821. return interfaces.get(GameConstants.PAYMENT_INTERFACE).isValid();
  822.  
  823. }
  824.  
  825.  
  826.  
  827. private void idle() {
  828.  
  829. if(canSpamClick()) {
  830.  
  831. return;
  832.  
  833. }
  834.  
  835. if (random(0, 50) == 0) {
  836.  
  837. int rand2 = random(1, 3);
  838.  
  839. for (int i = 0; i < rand2; i++) {
  840.  
  841. mouse.move(random(100, 700), random(100, 500));
  842.  
  843. sleep(random(200, 700));
  844.  
  845. }
  846.  
  847. mouse.move(random(0, 800), 647, 50, 100);
  848.  
  849. sleep(random(100, 1500));
  850.  
  851. mouse.move(random(75, 400), random(75, 400), 30);
  852.  
  853. }
  854.  
  855. if (random(0, 50) == 0) {
  856.  
  857. Point curPos = mouse.getLocation();
  858.  
  859. mouse.move(random(0, 750), random(0, 500), 20);
  860.  
  861. sleep(random(100, 300));
  862.  
  863. mouse.move(curPos, 20, 20);
  864.  
  865. }
  866.  
  867. if (random(0, 50) == 0) {
  868.  
  869. int angle = camera.getAngle() + random(-40, 40);
  870.  
  871. if (angle < 0) {
  872.  
  873. angle += 359;
  874.  
  875. }
  876.  
  877. if (angle > 359) {
  878.  
  879. angle -= 359;
  880.  
  881. }
  882.  
  883. camera.setAngle(angle);
  884.  
  885. }
  886.  
  887. }
  888.  
  889.  
  890. public void onRepaint(Graphics render) {
  891.  
  892. if (game.isLoggedIn() && skills.getRealLevel(Skills.RANGE) >= 40) {
  893.  
  894. Graphics2D g = (Graphics2D)render;
  895.  
  896. g.setRenderingHints(GameConstants.ANTI_ALIASING);
  897.  
  898. if (startTime == 0) {
  899.  
  900. startTime = System.currentTimeMillis();
  901.  
  902. }
  903.  
  904. if (startXp == 0) {
  905.  
  906. startXp = skills.getCurrentExp(Skills.RANGE);
  907.  
  908. }
  909.  
  910. if (startLvl == 0) {
  911.  
  912. startLvl = skills.getRealLevel(Skills.RANGE);
  913.  
  914. }
  915.  
  916. if (action != null) {
  917.  
  918. action.paint(g);
  919.  
  920. }
  921.  
  922. g.setColor(GameConstants.BACKGROUND_COLOR);
  923.  
  924. g.fillRect(10, 35, 205, 195);
  925.  
  926. g.setColor(GameConstants.TEXT_COLOR);
  927.  
  928. g.drawRect(10, 35, 205, 195);
  929.  
  930. g.drawString("GuildRanger by Vastico", 20, 55);
  931.  
  932. g.drawString(Timer.format(System.currentTimeMillis() - startTime), 20, 75);
  933.  
  934. g.drawString(action != null ? action.getDescription() : "Calculating...", 20, 95);
  935.  
  936. g.drawString("XP Gained: " + (skills.getCurrentExp(Skills.RANGE) - startXp), 20, 115);
  937.  
  938. g.drawString("XP Per Hour: " + calculateXpPerHour(), 20, 135);
  939.  
  940. g.drawString("Current Level: " + skills.getRealLevel(Skills.RANGE), 20, 155);
  941.  
  942. g.drawString("Levels Gained: " + (skills.getRealLevel(Skills.RANGE) - startLvl), 20, 175);
  943.  
  944. g.drawString("Current Score: " + settings.getSetting(157), 20, 195);
  945.  
  946. int hit = settings.getSetting(156);
  947.  
  948. hit = hit >= 1 ? hit - 1 : 0;
  949.  
  950. g.drawString("Arrows Fired(10): " + hit, 20, 215);
  951.  
  952. }
  953.  
  954. }
  955.  
  956.  
  957.  
  958. private int calculateXpPerHour() {
  959.  
  960. int gainedXp = (skills.getCurrentExp(Skills.RANGE) - startXp);
  961.  
  962. return(int) ((3600000.0 / (double) (System.currentTimeMillis() - startTime)) * gainedXp);
  963.  
  964. }
  965.  
  966.  
  967. }
Add Comment
Please, Sign In to add comment