Advertisement
Guest User

Untitled

a guest
Aug 13th, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class AlphaRunner extends Script implements Painting {
  2.     private static final Font FONT = new Font("Arial", Font.PLAIN, 14);
  3.     private static final int MINIMUM_HP_RATIO = 10;
  4.  
  5.     private final AtomicReference<String> status = new AtomicReference<>("");
  6.     private final AgilityCourse course = AgilityCourse.AL_KHARID_ROOF;
  7.     private final ABCUtil abcUtil = new ABCUtil();
  8.  
  9.     @Override
  10.     public void run() {
  11.         ThreadSettings.get().setClickingAPIUseDynamic(true);
  12.  
  13.         while (true) {
  14.             //pick up marks
  15.             if (course.isRoof()) {
  16.                 RSGroundItem[] marks = GroundItems.find(Filters.GroundItems.nameEquals("Mark of grace").combine(new Filter<RSGroundItem>() {
  17.                     @Override
  18.                     public boolean accept(RSGroundItem rsGroundItem) {
  19.                         return MyWalking.canReach(rsGroundItem.getPosition());
  20.                     }
  21.                 }, false));
  22.  
  23.                 if (marks.length > 0) {
  24.                     if (!marks[0].isOnScreen()) {
  25.                         MyWalking.walk(marks[0]);
  26.                         continue;
  27.                     }
  28.                     final int count = Inventory.getCount("Mark of grace");
  29.                     if (!marks[0].click("Take") || !Timing.waitCondition(new Condition() {
  30.                         @Override
  31.                         public boolean active() {
  32.                             return Game.getCrosshairState() == 2;
  33.                         }
  34.                     }, 500) || !Timing.waitCondition(new Condition() {
  35.                         @Override
  36.                         public boolean active() {
  37.                             return Inventory.getCount("Mark of grace") > count;
  38.                         }
  39.                     }, 4000)) continue;
  40.                 }
  41.             }
  42.  
  43.             //eat food
  44.             if (course != AgilityCourse.GNOME_COURSE) {
  45.                 final RSItem[] food = Inventory.find(Filters.Items.actionsContains("Eat"));
  46.                 final int hpRatio = Combat.getHPRatio();
  47.                 if (food.length > 0 && hpRatio <= abcUtil.INT_TRACKER.NEXT_EAT_AT.next()) {
  48.                     if (!food[0].click("Eat") || !Timing.waitCondition(new Condition() {
  49.                         @Override
  50.                         public boolean active() {
  51.                             return Combat.getHPRatio() > hpRatio;
  52.                         }
  53.                     }, 3000)) continue;
  54.  
  55.                     abcUtil.INT_TRACKER.NEXT_EAT_AT.reset();
  56.                 } else if (hpRatio < MINIMUM_HP_RATIO) {
  57.                     System.out.println("Logging out: Out of food");
  58.                     Login.logout();
  59.                     return;
  60.                 }
  61.             }
  62.  
  63.             //enable run
  64.             if (Game.getRunEnergy() <= abcUtil.INT_TRACKER.NEXT_RUN_AT.next() && Options.setRunOn(true)) {
  65.                 abcUtil.INT_TRACKER.NEXT_RUN_AT.reset();
  66.             }
  67.  
  68.             stepCourse(course);
  69.             sleep(100);
  70.         }
  71.     }
  72.  
  73.     /**
  74.      * Step over the next obstacle in the course.
  75.      * @param course The course that you want to traverse
  76.      */
  77.     public void stepCourse(final AgilityCourse course) {
  78.         final Obstacle obstacle = course.getNextObstacle();
  79.         if (obstacle == null) {
  80.             final Obstacle nearest = course.getNearestObstacle();
  81.             MyWalking.walk(Utility.getCenterTile(nearest.area));
  82.             return;
  83.         }
  84.  
  85.         final Rectangle bounds = obstacle.area.polygon.getBounds();
  86.         final RSObject[] object = Objects.findNearest(Math.max(bounds.width, bounds.height) + 1, obstacle.name);
  87.         if (object.length > 0) {
  88.             if (object[0].getPosition().distanceTo(Player.getPosition()) > 4) {
  89.                 status.set("Walking to " + obstacle.name + "...");
  90.                 MyWalking.walk(object[0].getPosition());
  91.                 return;
  92.             }
  93.             if (!object[0].isOnScreen()) {
  94.                 status.set("Turning camera to " + object[0].getPosition());
  95.                 Camera.turnToTile(object[0]);
  96.             }
  97.  
  98.             RSObjectDefinition def = object[0].getDefinition();
  99.             if (def == null) return;
  100.  
  101.             final String action = def.getActions()[0];
  102.             status.set("Clicking " + obstacle.name + "...");
  103.             if (object[0].click(action) && Timing.waitCondition(new Condition() {
  104.                 @Override
  105.                 public boolean active() {
  106.                     return Game.getCrosshairState() == 2;
  107.                 }
  108.             }, 500)) {
  109.                 status.set("Performing action " + action + "...");
  110.                 if (Timing.waitCondition(new Condition() {
  111.                     @Override
  112.                     public boolean active() {
  113.                         Obstacle next = course.getNextObstacle();
  114.                         return next != null && next != obstacle;
  115.                     }
  116.                 }, 10000)) {
  117.                     status.set("Successfully " + action + " " + obstacle.name);
  118.                 }
  119.             } else status.set("Failed to click " + obstacle.name);
  120.         }
  121.     }
  122.  
  123.     @Override
  124.     public void onPaint(Graphics g) {
  125.         g.setFont(FONT);
  126.         g.setColor(Color.LIGHT_GRAY);
  127.         g.drawString(status.get(), 10, 30);
  128.     }
  129. }
  130.  
  131. /**
  132. * Obstacle wrapper
  133. */
  134. class Obstacle {
  135.     public final String name;
  136.     public final RSArea area;
  137.  
  138.     Obstacle(String name, RSArea area) {
  139.         this.name = name;
  140.         this.area = area;
  141.     }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement