Advertisement
Guest User

Super Kebabs

a guest
May 25th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.64 KB | None | 0 0
  1. import org.osbot.rs07.api.map.Area;
  2. import org.osbot.rs07.script.Script;
  3. import org.osbot.rs07.script.ScriptManifest;
  4. import org.osbot.rs07.utility.ConditionalSleep;
  5. import java.awt.*;
  6. import java.io.BufferedReader;
  7. import java.io.InputStreamReader;
  8. import java.net.URL;
  9. import java.net.URLConnection;
  10. import javax.imageio.ImageIO;
  11. import java.io.IOException;
  12.  
  13. @ScriptManifest(author = "iManCity", name = "SuperKebaber", info = "Turns Kebabs into Super Kebabs!", version = 0.1, logo = "")
  14. public class SuperKebaber extends Script {
  15.  
  16.     // This is an enum of all the possible states of the script
  17.     private enum State {
  18.         WALKING_TO_ALI, WALKING_TO_SHANTAY, LOGOUT
  19.     }
  20.  
  21.     private final Area shantayBank = new Area(3310, 3123, 3305, 3118);
  22.     private final Area ali = new Area(3355, 2976, 3353, 2973);
  23.     private final Area shantayPassN = new Area(3303, 3117, 3304, 3117);
  24.     private final Area shantayPassS = new Area(3302, 3113, 3306, 3115);
  25.     private final Area rugMerchantN = new Area(3306, 3107, 3309, 3111);
  26.     private final Area rugMerchantS = new Area(3349, 2999, 3353, 3002);
  27.  
  28.     private Image img1;
  29.  
  30.     private final int superKebabID = 4608;
  31.     private int superKebabPrice = -1;
  32.  
  33.     private long prevSuperCount; // Stores the amount of super kebabs in the inventory
  34.     private long superCounter; // Stores the amount of super kebabs collected
  35.     private long startTime;
  36.  
  37.     @Override
  38.     public void onStart() {
  39.  
  40.         img1 = getImage("NEED PNG");
  41.  
  42.         // When the script starts, set the prevSuperCount to the amount of super kebabs in the inventory
  43.         prevSuperCount = getInventory().getAmount(4608);
  44.  
  45.         startTime = System.currentTimeMillis();
  46.  
  47.         superKebabPrice = getPrice(superKebabID); // get the price of super kebabs
  48.     }
  49.  
  50.     private Image getImage(String url) {
  51.         try {
  52.             return ImageIO.read(new URL(url));
  53.         } catch (IOException e) {
  54.         }
  55.         return null;
  56.     }
  57.  
  58.     // This method returns what State the script is in at the current point in time.
  59.     private State getState() throws InterruptedException {
  60.  
  61.         if (getInventory().contains("Coins") && (getInventory().contains("Kebab")) && (getInventory().contains("Shantay pass")) && (!ali.contains(myPlayer()))) {
  62.             return State.WALKING_TO_ALI;
  63.         }
  64.  
  65.         if ((!getInventory().contains("Kebab"))) {
  66.             return State.WALKING_TO_SHANTAY;
  67.         }
  68.         return State.LOGOUT;
  69.     }
  70.  
  71.     @Override
  72.     public int onLoop() throws InterruptedException {
  73.  
  74.         /*
  75.         A switch statement, is just like having multiple if else statements,
  76.         where we are only checking the value on one variable
  77.         */
  78.         switch (getState()) { // get the result of the getState() method
  79.  
  80.             case WALKING_TO_ALI:
  81.                 log("Walking to Ali");
  82.                 walkAli(); // when the value is walkAli, call the walkAli() method (walk to ali)
  83.                 talkAli(); // when the value is talkAli, call the talkAli() method (make super kebabs)
  84.                 break;
  85.  
  86.             case WALKING_TO_SHANTAY:
  87.                 log("Walking to Bank");
  88.                 walkShantay(); // when the value is walkShantay, call the walkShantay() method (walk to shantay)
  89.                 bank(); // when the value is bank, call the bank() method (bank the super kebabs)
  90.                 break;
  91.  
  92.             case LOGOUT:
  93.                 log("Waiting");
  94.                 return random(300, 600);
  95.         }
  96.         return random(200, 300);
  97.     }
  98.  
  99.     // This method goes to Ali;
  100.     private void walkAli() throws InterruptedException {
  101.         //getWalking().webWalk(ali); using my longer method for now
  102.         getWalking().webWalk(shantayPassN);
  103.         objects.closest("Shantay pass").interact("Go-through");
  104.         getWalking().webWalk(rugMerchantN);
  105.         npcs.closest("Rug Merchant").interact("Travel");
  106.         if (dialogues.isPendingOption()) {
  107.             dialogues.selectOption("Pollnivneach");}
  108.         getWalking().webWalk(ali);
  109.     }
  110.  
  111.     // This method talks to Ali and makes the Super kebabs
  112.     private void talkAli() throws InterruptedException {
  113.         while (getInventory().contains("Kebab")) {
  114.             if (npcs.closest(3536) != null) {
  115.                 npcs.closest(3536).interact("Talk-to");
  116.             }
  117.  
  118.             new ConditionalSleep(5000) {
  119.                 @Override
  120.                 public boolean condition() throws InterruptedException {
  121.                     return getDialogues().inDialogue();
  122.                 }
  123.             }.sleep();
  124.  
  125.             if (getDialogues().inDialogue()) {
  126.                 dialogues.completeDialogue("Would");
  127.             }
  128.             if ((ali.contains(myPosition())) && getInventory().contains("Red hot sauce")) {
  129.                 if (getInventory().interact("Use", "Red hot sauce")) {
  130.                     getInventory().interact("Use", "Kebab");
  131.                 }
  132.             }
  133.         }
  134.         updateSuperCount(); // Update the super kebab counter
  135.     }
  136.  
  137.     // This method goes to the Shantay pass;
  138.     private void walkShantay() throws InterruptedException {
  139.         getWalking().webWalk(shantayBank);
  140.     }
  141.  
  142.     // This method banks;
  143.     private void bank() throws InterruptedException {
  144.         if (!getBank().isOpen()) {
  145.             getBank().open();
  146.         } else {
  147.             getBank().depositAll(4608);
  148.             getBank().withdraw("Kebab", 25);
  149.         }
  150.     }
  151.  
  152.     // This method updates the super counter;
  153.     private void updateSuperCount() {
  154.         long superInvcount = getInventory().getAmount(4608);
  155.         superCounter += (superInvcount - prevSuperCount);
  156.         prevSuperCount = superInvcount;
  157.     }
  158.  
  159.     @Override
  160.     public void onPaint(final Graphics2D g) {
  161.         Font font1 = new Font("Sans-Serif", Font.BOLD, 13);
  162.         g.setFont(font1);
  163.         g.setColor(Color.WHITE);
  164.         g.drawImage(img1, 8, 345, null);
  165.         g.drawString("Runtime: " + formatTime(System.currentTimeMillis() - startTime), 8, 285);
  166.         g.drawString("Super Kebabs made: " + superCounter, 8, 300);
  167.         if (superKebabPrice > -1) {
  168.             g.drawString("Super Kebab price: " + superKebabPrice, 8, 315);
  169.             g.drawString("Profit: " + formatValue(superKebabPrice * superCounter), 8, 330);
  170.         }
  171.     }
  172.  
  173.     // Converts ms to a timestamp
  174.     private String formatTime(long ms) {
  175.  
  176.         long s = ms / 1000, m = s / 60, h = m / 60, d = h / 24;
  177.         s %= 60;
  178.         m %= 60;
  179.         h %= 24;
  180.  
  181.         return d > 0 ? String.format("%02d:%02d:%02d:%02d", d, h, m, s) :
  182.                 h > 0 ? String.format("%02d:%02d:%02d", h, m, s) :
  183.                         String.format("%02d:%02d", m, s);
  184.     }
  185.  
  186.     // Converts a value to m or k
  187.     private String formatValue(long v) {
  188.         return (v > 1_000_000) ? String.format("%.2fm", (double) (v / 1_000_000)) :
  189.                 (v > 1000) ? String.format("%.1fk", (double) (v / 1000)) :
  190.                         v + "";
  191.     }
  192.  
  193.     // Gets the price of an item from the rsbuddy api
  194.     private int getPrice(int id) {
  195.         try {
  196.             URL url = new URL("http://api.rsbuddy.com/grandExchange?a=guidePrice&i=" + id);
  197.             URLConnection con = url.openConnection();
  198.             con.setUseCaches(true);
  199.             BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
  200.             String[] data = br.readLine().replace("{", "").replace("}", "").split(",");
  201.             return Integer.parseInt(data[0].split(":")[1]);
  202.         } catch (Exception e) {
  203.             log(e);
  204.         }
  205.         return -1;
  206.     }
  207.  
  208.     @Override
  209.     public void onExit() {
  210.     }
  211.  
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement