Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.osbot.rs07.api.map.Area;
- import org.osbot.rs07.script.Script;
- import org.osbot.rs07.script.ScriptManifest;
- import org.osbot.rs07.utility.ConditionalSleep;
- import java.awt.*;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.net.URL;
- import java.net.URLConnection;
- import javax.imageio.ImageIO;
- import java.io.IOException;
- @ScriptManifest(author = "iManCity", name = "SuperKebaber", info = "Turns Kebabs into Super Kebabs!", version = 0.1, logo = "")
- public class SuperKebaber extends Script {
- // This is an enum of all the possible states of the script
- private enum State {
- WALKING_TO_ALI, WALKING_TO_SHANTAY, LOGOUT
- }
- private final Area shantayBank = new Area(3310, 3123, 3305, 3118);
- private final Area ali = new Area(3355, 2976, 3353, 2973);
- private final Area shantayPassN = new Area(3303, 3117, 3304, 3117);
- private final Area shantayPassS = new Area(3302, 3113, 3306, 3115);
- private final Area rugMerchantN = new Area(3306, 3107, 3309, 3111);
- private final Area rugMerchantS = new Area(3349, 2999, 3353, 3002);
- private Image img1;
- private final int superKebabID = 4608;
- private int superKebabPrice = -1;
- private long prevSuperCount; // Stores the amount of super kebabs in the inventory
- private long superCounter; // Stores the amount of super kebabs collected
- private long startTime;
- @Override
- public void onStart() {
- img1 = getImage("NEED PNG");
- // When the script starts, set the prevSuperCount to the amount of super kebabs in the inventory
- prevSuperCount = getInventory().getAmount(4608);
- startTime = System.currentTimeMillis();
- superKebabPrice = getPrice(superKebabID); // get the price of super kebabs
- }
- private Image getImage(String url) {
- try {
- return ImageIO.read(new URL(url));
- } catch (IOException e) {
- }
- return null;
- }
- // This method returns what State the script is in at the current point in time.
- private State getState() throws InterruptedException {
- if (getInventory().contains("Coins") && (getInventory().contains("Kebab")) && (getInventory().contains("Shantay pass")) && (!ali.contains(myPlayer()))) {
- return State.WALKING_TO_ALI;
- }
- if ((!getInventory().contains("Kebab"))) {
- return State.WALKING_TO_SHANTAY;
- }
- return State.LOGOUT;
- }
- @Override
- public int onLoop() throws InterruptedException {
- /*
- A switch statement, is just like having multiple if else statements,
- where we are only checking the value on one variable
- */
- switch (getState()) { // get the result of the getState() method
- case WALKING_TO_ALI:
- log("Walking to Ali");
- walkAli(); // when the value is walkAli, call the walkAli() method (walk to ali)
- talkAli(); // when the value is talkAli, call the talkAli() method (make super kebabs)
- break;
- case WALKING_TO_SHANTAY:
- log("Walking to Bank");
- walkShantay(); // when the value is walkShantay, call the walkShantay() method (walk to shantay)
- bank(); // when the value is bank, call the bank() method (bank the super kebabs)
- break;
- case LOGOUT:
- log("Waiting");
- return random(300, 600);
- }
- return random(200, 300);
- }
- // This method goes to Ali;
- private void walkAli() throws InterruptedException {
- //getWalking().webWalk(ali); using my longer method for now
- getWalking().webWalk(shantayPassN);
- objects.closest("Shantay pass").interact("Go-through");
- getWalking().webWalk(rugMerchantN);
- npcs.closest("Rug Merchant").interact("Travel");
- if (dialogues.isPendingOption()) {
- dialogues.selectOption("Pollnivneach");}
- getWalking().webWalk(ali);
- }
- // This method talks to Ali and makes the Super kebabs
- private void talkAli() throws InterruptedException {
- while (getInventory().contains("Kebab")) {
- if (npcs.closest(3536) != null) {
- npcs.closest(3536).interact("Talk-to");
- }
- new ConditionalSleep(5000) {
- @Override
- public boolean condition() throws InterruptedException {
- return getDialogues().inDialogue();
- }
- }.sleep();
- if (getDialogues().inDialogue()) {
- dialogues.completeDialogue("Would");
- }
- if ((ali.contains(myPosition())) && getInventory().contains("Red hot sauce")) {
- if (getInventory().interact("Use", "Red hot sauce")) {
- getInventory().interact("Use", "Kebab");
- }
- }
- }
- updateSuperCount(); // Update the super kebab counter
- }
- // This method goes to the Shantay pass;
- private void walkShantay() throws InterruptedException {
- getWalking().webWalk(shantayBank);
- }
- // This method banks;
- private void bank() throws InterruptedException {
- if (!getBank().isOpen()) {
- getBank().open();
- } else {
- getBank().depositAll(4608);
- getBank().withdraw("Kebab", 25);
- }
- }
- // This method updates the super counter;
- private void updateSuperCount() {
- long superInvcount = getInventory().getAmount(4608);
- superCounter += (superInvcount - prevSuperCount);
- prevSuperCount = superInvcount;
- }
- @Override
- public void onPaint(final Graphics2D g) {
- Font font1 = new Font("Sans-Serif", Font.BOLD, 13);
- g.setFont(font1);
- g.setColor(Color.WHITE);
- g.drawImage(img1, 8, 345, null);
- g.drawString("Runtime: " + formatTime(System.currentTimeMillis() - startTime), 8, 285);
- g.drawString("Super Kebabs made: " + superCounter, 8, 300);
- if (superKebabPrice > -1) {
- g.drawString("Super Kebab price: " + superKebabPrice, 8, 315);
- g.drawString("Profit: " + formatValue(superKebabPrice * superCounter), 8, 330);
- }
- }
- // Converts ms to a timestamp
- private String formatTime(long ms) {
- long s = ms / 1000, m = s / 60, h = m / 60, d = h / 24;
- s %= 60;
- m %= 60;
- h %= 24;
- return d > 0 ? String.format("%02d:%02d:%02d:%02d", d, h, m, s) :
- h > 0 ? String.format("%02d:%02d:%02d", h, m, s) :
- String.format("%02d:%02d", m, s);
- }
- // Converts a value to m or k
- private String formatValue(long v) {
- return (v > 1_000_000) ? String.format("%.2fm", (double) (v / 1_000_000)) :
- (v > 1000) ? String.format("%.1fk", (double) (v / 1000)) :
- v + "";
- }
- // Gets the price of an item from the rsbuddy api
- private int getPrice(int id) {
- try {
- URL url = new URL("http://api.rsbuddy.com/grandExchange?a=guidePrice&i=" + id);
- URLConnection con = url.openConnection();
- con.setUseCaches(true);
- BufferedReader br = new BufferedReader(new InputStreamReader(con.getInputStream()));
- String[] data = br.readLine().replace("{", "").replace("}", "").split(",");
- return Integer.parseInt(data[0].split(":")[1]);
- } catch (Exception e) {
- log(e);
- }
- return -1;
- }
- @Override
- public void onExit() {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement