Advertisement
Guest User

Apple(5) Baskets

a guest
May 1st, 2016
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.Malii;
  2.  
  3. import org.osbot.rs07.script.Script;
  4. import org.osbot.rs07.script.ScriptManifest;
  5. import org.osbot.rs07.utility.ConditionalSleep;
  6.  
  7. import java.awt.*;
  8.  
  9. /**
  10.  * Created by Damian on 4/26/2016.
  11.  */
  12.  
  13. @ScriptManifest(
  14.         name = "Apple Baskets",
  15.         author = "Malii",
  16.         version = 1.0,
  17.         info = "Makes Apple(5) baskets",
  18.         logo = ""
  19. )
  20.  
  21. public class AppleBaskets extends Script {
  22.  
  23.     private String applesName;
  24.     private String basketsName;
  25.     private String invent;
  26.     private String empty;
  27.     private long startTime;
  28.  
  29.     public enum State {
  30.         DEPOSIT, WITHDRAW, BASKET, IDLE, LOGOUT,
  31.     }
  32.  
  33.     @Override
  34.     public void onStart() throws InterruptedException {
  35.  
  36.         if (this.getBank().isOpen())
  37.             this.getBank().close();
  38.  
  39.  
  40.         this.applesName = "Cooking apple";
  41.         this.basketsName = "Basket";
  42.         this.invent = "Apples(5)";
  43.         this.log("Apple Basket " + this.getVersion() + " Started");
  44.         {
  45.  
  46.  
  47.         }
  48.     }
  49.  
  50.     @Override
  51.     public int onLoop() throws InterruptedException {
  52.         State current = this.getState();
  53.         this.log(current.toString());
  54.         switch (current) {
  55.             case DEPOSIT: // Self explanatory
  56.                 this.deposit();
  57.  
  58.                 break;
  59.             case WITHDRAW: // Self explanatory
  60.                 this.withdraw();
  61.  
  62.                 break;
  63.             case BASKET: // Creates Apple(5)
  64.                 this.basket();
  65.  
  66.  
  67.                 break;
  68.  
  69.             case IDLE:
  70.  
  71.  
  72.                 break;
  73.  
  74.             case LOGOUT:
  75.                 this.logoutTab.logOut();
  76.  
  77.                 break;
  78.         }
  79.  
  80.         return gRandom(350, 450);
  81.     }
  82.  
  83.  
  84.     @Override
  85.     public void onExit() {
  86.         this.log("Thank you for using Apple Baskets " + this.getVersion());
  87.         this.log("Script Ended");
  88.  
  89.     }
  90.  
  91.  
  92.     public boolean basket() throws InterruptedException { // Fills baskets with apples
  93.         if (getInventory().interact("Fill", basketsName)) ;
  94.         {
  95.  
  96.             sleep(350);
  97.         }
  98.  
  99.         return false;
  100.     }
  101.  
  102.  
  103.     public void deposit() throws InterruptedException {
  104.         if (this.openBank()) {
  105.             this.getBank().depositAll();
  106.             sleep(200);
  107.         }
  108.     }
  109.  
  110.     public void withdraw() throws InterruptedException {
  111.         if (this.openBank()) {
  112.             while (!this.getInventory().contains(applesName) || !this.getInventory().contains(basketsName)) {
  113.                 this.getBank().withdraw(basketsName, 4);
  114.                 this.getBank().withdrawAll(applesName);
  115.  
  116.                 sleep(350);
  117.             }
  118.             this.closeBank();
  119.         }
  120.  
  121.     }
  122.  
  123.     public boolean openBank() throws InterruptedException {
  124.         if (!getBank().isOpen()) { //if bank is not open
  125.             getBank().open(); //opens the nearest bank
  126.             new ConditionalSleep(2400) { //2400ms
  127.                 @Override
  128.                 public boolean condition() throws InterruptedException {
  129.                     return getBank().isOpen(); //sleeps 2400ms or until the bank is open!
  130.                 }
  131.             }.sleep();
  132.         } else {
  133.             return true;
  134.         }
  135.  
  136.         return false;
  137.     }
  138.  
  139.  
  140.     public void closeBank() throws InterruptedException {
  141.         if (this.getBank().isOpen()) {
  142.             this.getBank().close();
  143.  
  144.             new ConditionalSleep(2030) {
  145.                 @Override
  146.                 public boolean condition() throws InterruptedException {
  147.                     return !getBank().isOpen(); //sleep 2030 ms (2 seconds)or until bank is closed!
  148.                 }
  149.             }.sleep();
  150.         }
  151.     }
  152.  
  153.     public State logout() throws InterruptedException {
  154.         if (!bank.contains(5377) || !bank.contains(1956)) {
  155.             this.getLogoutTab().logOut();
  156.  
  157.         }
  158.         return State.LOGOUT;
  159.     }
  160.  
  161.  
  162.     public State getState() {
  163.         if (this.getInventory().contains(this.invent) && !this.getInventory().contains(this.basketsName)) {
  164.             return State.DEPOSIT;
  165.         } else if (!this.getInventory().contains(this.applesName) || !this.getInventory().contains(this.basketsName)) {
  166.             return State.WITHDRAW;
  167.         } else if (this.getInventory().contains(this.applesName) && this.getInventory().contains(this.basketsName)) {
  168.             return State.BASKET;
  169.         } else if (!bank.contains(5377) || !bank.contains(1956)) {
  170.             return State.LOGOUT;
  171.         }
  172.  
  173.  
  174.         return State.IDLE;
  175.     }
  176.  
  177.  
  178.     @Override
  179.     public void onPaint(Graphics2D g) {
  180.  
  181.  
  182.     }
  183.  
  184. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement