Guest User

Untitled

a guest
Jul 9th, 2017
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.22 KB | None | 0 0
  1. import org.osbot.rs07.api.ui.Skill;
  2. import org.osbot.rs07.api.util.Utilities;
  3. import org.osbot.rs07.script.Script;
  4.  
  5. import org.osbot.rs07.script.ScriptManifest;
  6. import org.osbot.rs07.utility.ConditionalSleep;
  7.  
  8. import java.awt.*;
  9.  
  10. @ScriptManifest(name = "Rod Fishing", author = "Sonysi", version = 1.0, info = "", logo = "")
  11.  
  12. public class rodFishing extends Script {
  13.  
  14.     public enum State {
  15.         Idle, Fishing, Dropping
  16.     }
  17.  
  18.     String state = "initializing";
  19.     private long startTime;
  20.     int startLevel, curLevel;
  21.  
  22.     int[] fishingSpots = {1542};
  23.  
  24.     public void onStart() {
  25.         startTime = System.currentTimeMillis();
  26.         experienceTracker.start(Skill.FISHING);
  27.         startLevel = skills.getStatic(Skill.FISHING);
  28.     }
  29.  
  30.     private State getState() throws InterruptedException {
  31.  
  32.         if (map.isWithinRange(npcs.closest(fishingSpots[0]), 10)) {
  33.             if (!inventory.isFull() && !isAnimating()) {
  34.                 state = "Fishing";
  35.                 return State.Fishing;
  36.             }
  37.         }
  38.        
  39.         if (!inventory.contains("Feather")) {
  40.             stop();
  41.         }
  42.  
  43.         if (inventory.isFull()) {
  44.             return State.Dropping;
  45.         }
  46.  
  47.         if (isAnimating() && getMap().isWithinRange(npcs.closest(fishingSpots[0]), 3)) {
  48.             return State.Idle;
  49.         }
  50.  
  51.         return State.Idle;
  52.  
  53.     }
  54.  
  55.     public int onLoop() throws InterruptedException {
  56.        
  57.         if (dialogues.isPendingContinuation()) {
  58.             Utilities.takeScreenshot();
  59.             dialogues.clickContinue();
  60.             new ConditionalSleep(2000) {
  61.                 @Override
  62.                 public boolean condition() throws InterruptedException {
  63.                     return !dialogues.isPendingContinuation();
  64.                 }
  65.             }.sleep();
  66.         }
  67.  
  68.         switch (getState()) {
  69.         case Dropping:
  70.             state = "Dropping";
  71.             inventory.dropAllExcept("Feather", "Barbarian rod");
  72.             break;
  73.  
  74.         case Fishing:
  75.             if (map.isWithinRange(npcs.closest(fishingSpots[0]), 10)) {
  76.                 if (!inventory.isFull() && !isAnimating()) {
  77.                     state = "Fishing";
  78.                     npcs.closest(fishingSpots[0]).interact("Use-rod");
  79.                     sleep(random(1500, 2500));
  80.                 }
  81.             }
  82.             break;
  83.  
  84.         case Idle:
  85.             new ConditionalSleep(5000) {
  86.                 @Override
  87.                 public boolean condition() throws InterruptedException {
  88.                     return !isAnimating() || inventory.isFull();
  89.                 }
  90.             }.sleep();
  91.             break;
  92.         }
  93.         return 100;
  94.  
  95.     }
  96.  
  97.     public boolean isAnimating() throws InterruptedException {
  98.         int i = 0;
  99.         while (i < 20) {
  100.             if (myPlayer().isAnimating() || players.myPlayer().isMoving()) {
  101.                 return true;
  102.             }
  103.             i++;
  104.         }
  105.         return false;
  106.     }
  107.  
  108.     public final String formatTime(final long ms){
  109.         long s = ms / 1000, m = s / 60, h = m / 60;
  110.         s %= 60; m %= 60; h %= 24;
  111.         return String.format("%02d:%02d:%02d", h, m, s);
  112.     }
  113.  
  114.     private final RenderingHints antialiasing = new RenderingHints(
  115.             RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  116.     private final Color color1 = new Color(60, 60, 60, 150);
  117.     private final Color color2 = new Color(0, 0, 0);
  118.     private final Color color3 = new Color(255, 255, 255);
  119.     private final Color color4 = new Color(50, 50, 50);
  120.     private final BasicStroke stroke1 = new BasicStroke(1);
  121.     private final Font font1 = new Font("Estrangelo Edessa", 0, 13);
  122.  
  123.     public void onPaint(Graphics2D g) {
  124.         final long runTime = System.currentTimeMillis() - startTime;
  125.         g.setRenderingHints(antialiasing);
  126.  
  127.         g.setColor(color1);
  128.         g.fillRect(385, 45, 128, 80);
  129.         g.setColor(color4);
  130.         g.setStroke(stroke1);
  131.         g.drawRect(385, 45, 128, 80);
  132.         g.setFont(font1);
  133.  
  134.         g.setColor(color2);
  135.         g.drawString("Runtime: " + formatTime(runTime), 393, 60);
  136.         g.drawString("State: " + state, 393, 75);
  137.         g.drawString("Exp gained: " + experienceTracker.getGainedXP(Skill.FISHING), 393, 90);
  138.         g.drawString("Exp / hour: " + experienceTracker.getGainedXPPerHour(Skill.FISHING), 393, 105);
  139.         g.drawString("Levels gained: " + (getSkills().getStatic(Skill.FISHING) - startLevel), 393, 120);
  140.  
  141.         g.setColor(color3);
  142.         g.drawString("Runtime: " + formatTime(runTime), 392, 59);
  143.         g.drawString("State: " + state, 392, 74);
  144.         g.drawString("Exp gained: " + experienceTracker.getGainedXP(Skill.FISHING), 392, 89);
  145.         g.drawString("Exp / hour: " + experienceTracker.getGainedXPPerHour(Skill.FISHING), 392, 104);
  146.         g.drawString("Levels gained: " + (getSkills().getStatic(Skill.FISHING) - startLevel), 392, 119);
  147.     }
  148.  
  149.     public void onExit() {
  150.         Utilities.takeScreenshot();
  151.     }
  152.  
  153. }
Advertisement
Add Comment
Please, Sign In to add comment