Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2014
892
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.91 KB | None | 0 0
  1. import org.osbot.rs07.api.map.Position;
  2. import org.osbot.rs07.api.model.RS2Object;
  3. import org.osbot.rs07.input.mouse.MiniMapTileDestination;
  4. import org.osbot.rs07.script.Script;
  5. import org.osbot.rs07.script.ScriptManifest;
  6. import org.osbot.rs07.utility.Area;
  7.  
  8. import java.awt.*;
  9.  
  10. @ScriptManifest(author = "You!", info = "I made this script!", name = "Basic Miner", version = 1.0, logo = "")
  11. public class BasicMiner extends Script {
  12.  
  13.     private static final int[] TIN_ID = { 7140, 7141, 7142 };
  14.  
  15.     private Position[] path = {
  16.             new Position(3283, 3363, 0),
  17.             new Position(3290, 3374, 0),
  18.             new Position(3292, 3386, 0),
  19.             new Position(3292, 3392, 0),
  20.             new Position(3291, 3401, 0),
  21.             new Position(3287, 3413, 0),
  22.             new Position(3282, 3427, 0),
  23.             new Position(3270, 3429, 0),
  24.             new Position(3256, 3429, 0),
  25.             new Position(3254, 3421, 0)
  26.     };
  27.  
  28.     private static final Area MINE_AREA = new Area(3277, 3358, 3293, 3371);
  29.     private static final Area BANK_AREA = new Area(3250, 3419, 3257, 3423);
  30.  
  31.     private enum State {
  32.         MINE, WALK_TO_BANK, BANK, WALK_TO_MINE
  33.     };
  34.  
  35.     private State getState() {
  36.         if (inventory.isFull() && MINE_AREA.contains(myPlayer()))
  37.             return State.WALK_TO_BANK;
  38.         if (!inventory.isFull() && BANK_AREA.contains(myPlayer()))
  39.             return State.WALK_TO_MINE;
  40.         if (inventory.isFull() && BANK_AREA.contains(myPlayer()))
  41.             return State.BANK;
  42.         return State.MINE;
  43.     }
  44.  
  45.     private void traversePath(Position[] path, boolean reversed) throws InterruptedException {
  46.         if (!reversed) {
  47.             for (int i = 1; i < path.length; i++)
  48.                 if (!walkTile(path[i]))
  49.                     i--;
  50.         } else {
  51.             for (int i = path.length-2; i > 0; i--)
  52.                 if (!walkTile(path[i]))
  53.                     i--;
  54.         }
  55.     }
  56.  
  57.     private boolean walkTile(Position p) throws InterruptedException {
  58.         mouse.move(new MiniMapTileDestination(bot, p), false);
  59.         sleep(random(150, 250));
  60.         mouse.click(false);
  61.         int failsafe = 0;
  62.         while (failsafe < 10 && myPlayer().getPosition().distance(p) > 2) {
  63.             sleep(200);
  64.             failsafe++;
  65.             if (myPlayer().isMoving())
  66.                 failsafe = 0;
  67.         }
  68.         if (failsafe == 10)
  69.             return false;
  70.         return true;
  71.     }
  72.  
  73.     @Override
  74.     public void onStart() {
  75.         log("I can't believe script writing is this easy! I love learning!");
  76.     }
  77.  
  78.     @Override
  79.     public int onLoop() throws InterruptedException {
  80.         switch (getState()) {
  81.             case MINE:
  82.                 if (!myPlayer().isAnimating()) {
  83.                     RS2Object vein = objects.closest(TIN_ID);
  84.                     if (vein != null) {
  85.                         if (vein.interact("Mine"))
  86.                             sleep(random(1000, 1500));
  87.                     }
  88.                 }
  89.                 break;
  90.             case WALK_TO_BANK:
  91.                 traversePath(path, false);
  92.                 sleep(random(1500, 2500));
  93.                 break;
  94.             case WALK_TO_MINE:
  95.                 traversePath(path, true);
  96.                 sleep(random(1500, 2500));
  97.                 break;
  98.             case BANK:
  99.                 RS2Object bankBooth = objects.closest("Bank booth");
  100.                 if (bankBooth != null) {
  101.                     if (bankBooth.interact("Bank")) {
  102.                         while (!bank.isOpen())
  103.                             sleep(250);
  104.                         bank.depositAll();
  105.                     }
  106.                 }
  107.                 break;
  108.         }
  109.         return random(200, 300);
  110.     }
  111.  
  112.     @Override
  113.     public void onExit() {
  114.         log("Thanks for using this wonderful script!");
  115.     }
  116.  
  117.     @Override
  118.     public void onPaint(Graphics2D g) {
  119.  
  120.     }
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement