Stefano_Groenland

sMiner v0.04

Aug 15th, 2014
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.66 KB | None | 0 0
  1. package stefano;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5.  
  6. import java.awt.Graphics2D;
  7.  
  8. import org.osbot.rs07.api.map.Position;
  9. import org.osbot.rs07.api.model.RS2Object;
  10. import org.osbot.rs07.input.mouse.MiniMapTileDestination;
  11. import org.osbot.rs07.script.Script;
  12. import org.osbot.rs07.script.ScriptManifest;
  13. import org.osbot.rs07.utility.Area;
  14.  
  15. @ScriptManifest(author = "Stefano", info = "Mines Copper!", name = "sMiner", version = 0.04, logo = "")
  16. public class SMiner extends Script {
  17.  
  18.     // variables for paint
  19.     int lastAmount;
  20.     int rocksMined = 0;
  21.     int timesBanked = 0;
  22.  
  23.     // rock id's
  24.     private static final int[] COPPER_ID = { 6821, 6822, 6823 };
  25.  
  26.     // path to bank
  27.     private Position[] path = { new Position(3283, 3363, 0),
  28.             new Position(3290, 3374, 0), new Position(3292, 3386, 0),
  29.             new Position(3292, 3392, 0), new Position(3291, 3401, 0),
  30.             new Position(3287, 3413, 0), new Position(3282, 3427, 0),
  31.             new Position(3270, 3429, 0), new Position(3256, 3429, 0),
  32.             new Position(3254, 3421, 0) };
  33.     // path to mine
  34.     private Position[] pathMine = { new Position(3254, 3421, 0),
  35.             new Position(3260, 3428, 0), new Position(3272, 3428, 0),
  36.             new Position(3287, 3419, 0), new Position(3289, 3411, 0),
  37.             new Position(3291, 3399, 0), new Position(3291, 3386, 0),
  38.             new Position(3285, 3372, 0), new Position(3286, 3365, 0)
  39.  
  40.     };
  41.  
  42.     // player area's where to do things
  43.     private static final Area MINE_AREA = new Area(3277, 3358, 3293, 3371);
  44.     private static final Area BANK_AREA = new Area(3250, 3419, 3257, 3423);
  45.  
  46.     // player states which will be used
  47.     private enum State {
  48.         MINE, WALK_TO_BANK, BANK, WALK_TO_MINE
  49.     };
  50.  
  51.     // getters for different states and the conditions
  52.     private State getState() {
  53.         if (inventory.isFull() && MINE_AREA.contains(myPlayer()))
  54.             return State.WALK_TO_BANK;
  55.         if (!inventory.isFull() && BANK_AREA.contains(myPlayer()))
  56.             return State.WALK_TO_MINE;
  57.         if (inventory.isFull() && BANK_AREA.contains(myPlayer()))
  58.             return State.BANK;
  59.         return State.MINE;
  60.     }
  61.  
  62.     // path to banking with for loop for each position in array
  63.     private void PathtoBank(Position[] path) throws InterruptedException {
  64.  
  65.         for (int i = 1; i < path.length; i++)
  66.             if (!walkTile(path[i]))
  67.                 i--;
  68.     }
  69.  
  70.     // path to mining with for loop for each position in array
  71.     private void PathtoMine(Position[] path) throws InterruptedException {
  72.  
  73.         for (int i = 1; i < pathMine.length; i++)
  74.             if (!walkTile(pathMine[i]))
  75.                 i--;
  76.     }
  77.  
  78.     // minimap walking with failsafe
  79.     private boolean walkTile(Position p) throws InterruptedException {
  80.         mouse.move(new MiniMapTileDestination(bot, p), false);
  81.         sleep(random(150, 250));
  82.         mouse.click(false);
  83.         int failsafe = 0;
  84.         while (failsafe < 10 && myPlayer().getPosition().distance(p) > 2) {
  85.             sleep(200);
  86.             failsafe++;
  87.             if (myPlayer().isMoving())
  88.                 failsafe = 0;
  89.         }
  90.         if (failsafe == 10)
  91.             return false;
  92.         return true;
  93.     }
  94.  
  95.     // what happens when script starts.
  96.     @Override
  97.     public void onStart() {
  98.         log("Stefano : Enjoy Mining !");
  99.     }
  100.  
  101.     public boolean invChange(String itemName){
  102.            return lastAmount != inventory.getAmount(itemName);
  103.         }
  104.     // while script run this is where the magic happens!
  105.     @Override
  106.     public int onLoop() throws InterruptedException {
  107.        
  108.         if(invChange("Copper ore")){
  109.                rocksMined++;
  110.            
  111.             }
  112.             lastAmount = (int) inventory.getAmount("Copper ore");
  113.        
  114.         switch (getState()) {
  115.         case MINE:
  116.             if (!myPlayer().isAnimating()) {
  117.                 RS2Object vein = objects.closest(COPPER_ID);
  118.                 if (vein != null) {
  119.                     if (vein.interact("Mine"))
  120.                         sleep(random(1000, 1500));
  121.                 }
  122.             }
  123.             break;
  124.         case WALK_TO_BANK:
  125.             PathtoBank(path);
  126.             sleep(random(1500, 2500));
  127.             break;
  128.         case WALK_TO_MINE:
  129.             PathtoMine(pathMine);
  130.             sleep(random(1500, 2500));
  131.             break;
  132.         case BANK:
  133.             RS2Object bankBooth = objects.closest("Bank booth");
  134.             if (bankBooth != null) {
  135.                 if (bankBooth.interact("Bank")) {
  136.                     while (!bank.isOpen())
  137.                         sleep(250);
  138.                     bank.depositAll();
  139.                     timesBanked++;
  140.                     rocksMined--;
  141.                     log("banking complete walking back to miningsite");
  142.                 }
  143.             }
  144.             break;
  145.         }
  146.         return random(200, 300);
  147.     }
  148.  
  149.     // what happens if the player leaves us :(
  150.     @Override
  151.     public void onExit() {
  152.         log("Thanks for using sMiner");
  153.     }
  154.  
  155.    
  156.     // our nice looking paint =D
  157.     @Override
  158.     public void onPaint(Graphics2D g) {
  159.  
  160.         Graphics2D gr = (Graphics2D) g;
  161.  
  162.         gr.setColor(Color.white);
  163.         gr.setFont(new Font("Arial", Font.PLAIN, 15));
  164.         gr.drawString("sMiner by Stefano", 25, 60);
  165.  
  166.         gr.setFont(new Font("Arial", Font.PLAIN, 10));
  167.         gr.drawString("Mined : " + rocksMined, 25, 75);
  168.         gr.drawString("Times Banked : " + timesBanked, 25, 85);
  169.     }
  170.  
  171. }
Advertisement
Add Comment
Please, Sign In to add comment