Advertisement
Guest User

Untitled

a guest
Oct 24th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.61 KB | None | 0 0
  1. package scripts.rangeguild;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.awt.Graphics2D;
  7. import java.awt.Image;
  8. import java.io.IOException;
  9. import java.net.URL;
  10.  
  11. import javax.imageio.ImageIO;
  12.  
  13. import org.tribot.api.General;
  14. import org.tribot.api.Timing;
  15. import org.tribot.api.input.Mouse;
  16. import org.tribot.api.util.abc.ABCUtil;
  17. import org.tribot.api2007.Camera;
  18. import org.tribot.api2007.ChooseOption;
  19. import org.tribot.api2007.Equipment;
  20. import org.tribot.api2007.Game;
  21. import org.tribot.api2007.Interfaces;
  22. import org.tribot.api2007.Inventory;
  23. import org.tribot.api2007.NPCChat;
  24. import org.tribot.api2007.NPCs;
  25. import org.tribot.api2007.Objects;
  26. import org.tribot.api2007.Player;
  27. import org.tribot.api2007.Skills;
  28. import org.tribot.api2007.Skills.SKILLS;
  29. import org.tribot.api2007.Walking;
  30. import org.tribot.api2007.types.RSInterface;
  31. import org.tribot.api2007.types.RSItem;
  32. import org.tribot.api2007.types.RSNPC;
  33. import org.tribot.api2007.types.RSObject;
  34. import org.tribot.api2007.types.RSTile;
  35. import org.tribot.script.Script;
  36. import org.tribot.script.ScriptManifest;
  37. import org.tribot.script.interfaces.Painting;
  38.  
  39. @ScriptManifest(authors = { "Genka" }, category = "Ranged", name = "GRangeGuild")
  40. public class Main extends Script implements Painting{
  41.     private int startXp = Skills.getXP(SKILLS.RANGED);
  42.     private ABCUtil abc = new ABCUtil();
  43.     private long time = System.currentTimeMillis();
  44.     private RSTile tile = new RSTile(2672, 3418);
  45.     private boolean running = true;
  46.  
  47.     @Override
  48.     public void run() {
  49.         while(running) {
  50.             if(hasCoins()) {
  51.                 if(Player.getPosition().distanceTo(tile) < 3) {
  52.                     if(!competitionStarted()) {
  53.                         startCompetition();
  54.                     } else if(setCamera()){
  55.                         train();
  56.                     }
  57.                 } else if(!Player.isMoving()) {
  58.                     Walking.walkTo(new RSTile(tile.getX() + General.random(-1, 1), tile.getY() + General.random(-1, 1)));
  59.                 }
  60.             } else {
  61.                 System.out.println("Out of coins. Stopping");
  62.                 running = false;
  63.             }
  64.             sleep(10, 50);
  65.         }
  66.        
  67.     }
  68.    
  69.     private boolean hasCoins() {
  70.         RSItem[] coins = Inventory.find("Coins");
  71.         if(coins.length > 0) {
  72.             if(coins[0].getStack() > 199) {
  73.                 return true;
  74.             }
  75.         }
  76.         return false;
  77.     }
  78.    
  79.     private boolean setCamera() {
  80.         if(Camera.getCameraAngle() > 48) {
  81.             Camera.setCameraAngle(General.random(30, 48));
  82.             long t = System.currentTimeMillis();
  83.             while(Timing.timeFromMark(t) < 1500 && Camera.getCameraAngle() > 48) {
  84.                 sleep(10, 250);
  85.             }
  86.         }
  87.         if(Camera.getCameraRotation() < 260 || Camera.getCameraRotation() > 340) {
  88.             Camera.setCameraRotation(General.random(270, 340));
  89.             long t = System.currentTimeMillis();
  90.             while(Timing.timeFromMark(t) < 1500 && Camera.getCameraAngle() < 260) {
  91.                 sleep(10, 250);
  92.             }
  93.         }
  94.         return Camera.getCameraAngle() < 49 && (Camera.getCameraRotation() > 259 && Camera.getCameraRotation() < 341);
  95.     }
  96.    
  97.    
  98.     private void train() {
  99.         if(!isInterfaceOpen()) {
  100.             doTimedActions();
  101.         }
  102.         if(!isInterfaceOpen() && !ChooseOption.isOpen()) {
  103.             if(Equipment.isEquipped("Bronze arrow")) {
  104.                 clickTarget();
  105.             } else {
  106.                 equipArrows();
  107.             }
  108.         } else if((isInterfaceOpen() || Timing.timeFromMark(time) > 3000) && ChooseOption.isOpen()) {
  109.             fireAt();
  110.         } else if(isInterfaceOpen()) {
  111.             closeInterface();
  112.         }
  113.     }
  114.    
  115.     private void closeInterface() {
  116.         RSInterface face = Interfaces.get(325, 89);
  117.         if(face != null) {
  118.             face.click("Close");
  119.             sleep(10, 400);
  120.         }
  121.     }
  122.    
  123.     private void fireAt() {
  124.         if(ChooseOption.select("Fire-at")) {
  125.             long t = System.currentTimeMillis();
  126.             while(Timing.timeFromMark(t) < 1500 && isInterfaceOpen()) {
  127.                 sleep(10, 250);
  128.             }
  129.             clickTarget();
  130.             time = System.currentTimeMillis();
  131.         }
  132.     }
  133.    
  134.     private void equipArrows() {
  135.         RSItem arrows[] = Inventory.find("Bronze arrow");
  136.         if(arrows.length > 0) {
  137.             arrows[0].click("Wield");
  138.             long t = System.currentTimeMillis();
  139.             while(Timing.timeFromMark(t) < 1500 && !Equipment.isEquipped("Bronze arrow")) {
  140.                 sleep(10, 250);
  141.             }
  142.         }
  143.     }
  144.    
  145.     private boolean competitionStarted() {
  146.         return Game.getSetting(156) != 0;
  147.     }
  148.    
  149.     private void clickTarget() {
  150.         RSObject[] target = Objects.getAt(new RSTile(2679, 3426, 0));
  151.         if(target.length > 0) {
  152.             if(target[0].hover()) {
  153.                 sleep(10, 100);
  154.                 Mouse.click(3);
  155.             }
  156.         }
  157.     }
  158.    
  159.     private boolean isInterfaceOpen() {
  160.         return Interfaces.get(325) != null;
  161.     }
  162.    
  163.     private void startCompetition() {
  164.             if(NPCChat.getName() == null && NPCChat.getOptions() == null) {
  165.                 talkToGuard();
  166.             } else if (NPCChat.getName() != null) {
  167.                 NPCChat.clickContinue(true);
  168.             } else if (NPCChat.getOptions() != null) {
  169.                 NPCChat.selectOption("Sure, I'll give it a go." , true);
  170.             }
  171.     }
  172.    
  173.     private void talkToGuard() {
  174.         RSNPC[] judge = NPCs.find("Competition Judge");
  175.         if(judge.length > 0) {
  176.             if(judge[0].click("Talk-to")) {
  177.                 long t = System.currentTimeMillis();
  178.                 while(Timing.timeFromMark(t) < 1500 && NPCChat.getName() == null) {
  179.                     sleep(10, 500);
  180.                 }
  181.             }
  182.         }
  183.     }
  184.    
  185.     private void doTimedActions() {
  186.         if (abc.shouldCheckTabs()) {
  187.             abc.checkTabs();
  188.         }
  189.         if (abc.shouldCheckXP()) { 
  190.             abc.checkXP();
  191.         }
  192.         if (abc.shouldExamineEntity()) {
  193.             abc.examineEntity();
  194.         }
  195.         if (abc.shouldMoveMouse()) {
  196.             abc.moveMouse();
  197.         }
  198.         if (abc.shouldPickupMouse()) {
  199.             abc.pickupMouse();
  200.         }
  201.         if (abc.shouldRightClick()) {
  202.             abc.rightClick();
  203.         }
  204.         if (abc.shouldRotateCamera()) {
  205.             abc.rotateCamera();
  206.         }
  207.         if (abc.shouldLeaveGame()) {
  208.             abc.leaveGame();
  209.         }
  210.     }
  211.    
  212.    
  213.    
  214.  
  215.      //START: Code generated using Enfilade's Easel
  216.     private Image getImage(String url) {
  217.         try {
  218.             return ImageIO.read(new URL(url));
  219.         } catch(IOException e) {
  220.             return null;
  221.         }
  222.     }
  223.  
  224.     private final Color color1 = new Color(255, 255, 255);
  225.     private final Font font1 = new Font("Arial", 0, 10);
  226.     private final Image img1 = getImage("https://i.imgur.com/bRetzk3.png");
  227.  
  228.     public void onPaint(Graphics g1) {
  229.         double multiplier = getRunningTime() / 3600000.0D;
  230.             int xpPerHour = (int) ((Skills.getXP(SKILLS.RANGED) - startXp) / multiplier);        
  231.                 Graphics2D g = (Graphics2D)g1;
  232.         g.drawImage(img1, 277, 345, null);
  233.         g.setFont(font1);
  234.         g.setColor(color1);
  235.         g.drawString("Runtime: " + Timing.msToString(getRunningTime()), 366, 409);
  236.         g.drawString("Range level: " + Skills.getActualLevel(SKILLS.RANGED), 366, 421);
  237.         g.drawString("XP: "  + (Skills.getXP(SKILLS.RANGED) - startXp) + " (" + xpPerHour + ")", 366, 433);
  238.     }
  239.     //END: Code generated using Enfilade's Easel
  240.  
  241. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement