Jump to content

TinderBoxes


Shaft

Recommended Posts

TinderBoxes

I've decided to port this script to osbot and publish it, since the method has crashed because of a video made by thirdagefilms.

Keep in mind the price checker isn't always right because it uses the osrs's api not osbuddy's api.

The numbers in the upper left corner are debug numbers.

What does it do:

    -Searches the bookshelf in Wise old man's house for tinderboxes

    -Banks

How to use:

    -talk to the wise old man before running.

Screen shot:

xnCLJRb.png

Source:

Spoiler

Main:



import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

import TinderBoxes.Calculations;

@ScriptManifest(author = "Shaft", info = "searches the shelf in wise old man's house", logo = "", name = "TinderBoxes", version = 1.0)
public class TinderBoxes extends Script {

	private final Area house = new Area(3087, 3251, 3092, 3255);
	private final Area bank = new Area(3092, 3242, 3094, 3245);
	private RS2Object shelf, booth;
	
	private Image chat = getImage("http://i.imgur.com/Y5iHofA.png");

	private int count, count2;
	private int price;
	private long startTime;

	
	public void onStart(){
		price = Calculations.getPrice(590);
		startTime = System.currentTimeMillis();
	}
	
	public int onLoop() throws InterruptedException {
		if (!getInventory().isFull()) {
			if (house.contains(myPlayer())) {
				if (count < 28) {
					if (getInventory().contains(i -> i != null && i.getName().equalsIgnoreCase("tinderbox"))) {
						count += getInventory().getAmount(i -> i != null && i.getId() == 590);
						getInventory().dropAll(i -> i != null && i.getId() == 590);
						new ConditionalSleep(1500, Calculations.Random(100, 200)) {
							public boolean condition() throws InterruptedException {
								return !getInventory().contains(i -> i != null && i.getName().equalsIgnoreCase("tinderbox"));
							}
						}.sleep();
					} else {
						shelf = getObjects().closest(g -> g != null && g.getId() == 7079);
						if(getCamera().getYawAngle() < 330 && getCamera().getYawAngle() > 30){
							int yaw = Calculations.Random(-331, 29);
							if(yaw < 0) yaw = yaw + (-1);
							getCamera().moveYaw(yaw);
							sleep(Calculations.Random(12, 16));
						}
						shelf.interact("Search");
						new ConditionalSleep(4500, Calculations.Random(100, 200)) {
							public boolean condition() throws InterruptedException {
								return getInventory().contains(i -> i != null && i.getName().equalsIgnoreCase("tinderbox"));
							}

						}.sleep();
						if(getInventory().contains(i -> i != null && i.getId() == 590 && i.getName().equalsIgnoreCase("tinderbox"))){
							count2++;
						};
					}
				} else {
					GroundItem tinderbox = getGroundItems().closest(i -> i != null && i.getId() == 590);
					tinderbox.interact("Take");
				}

			} else {
				getWalking().webWalk(house);
			}
		} else {
			bank();
		}

		return Calculations.Random(34, 49);
	}

	private void bank() {
		if (bank.contains(myPlayer())) {
			if (getBank().isOpen()) {
				getBank().depositAll();
				getBank().close();
				count = 0;
			} else {
				booth = getObjects().closest(g -> g != null && g.getName().equalsIgnoreCase("Bank booth") && g.hasAction("Bank"));
				booth.interact("Bank");
				new ConditionalSleep(4500, Calculations.Random(100, 200)) {
					public boolean condition() throws InterruptedException {
						return getBank().isOpen();
					}
				}.sleep();
			}
		} else {
			getWalking().webWalk(bank);
		}
	}
	
	public void onPaint(Graphics2D g){
		g.drawString("" + count, 50, 50);
		g.drawString("" + count2, 50, 65);
        g.drawImage(chat, 1, 254, null);
        long Runtime = System.currentTimeMillis() - startTime;
        
        long runtime = (int)(Runtime / 1000);
        long collectph = 3600 / runtime * count2;
        long profitph = collectph * price;
        long profit = count2 * price;
 
        g.setColor(new Color(31, 221, 223));
        g.drawString("" + count2, 30, 390);
        g.drawString("" + collectph, 30, 433);
        g.drawString("" + profit, 330, 390);
        g.drawString("" + profitph, 330, 433);
		
	}
	
	private Image getImage(String url) {
        try {
            return ImageIO.read(new URL(url));
        } catch (IOException e) {
            return null;
        }
    }

}

Calculations:



import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Random;

public class Calculations {
	
    private final static String BASE_URL = "http://services.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=";
    private final static int MILLION = 1000000;
    private final static int THOUSAND = 1000;
	
	public static int Random(int min, int max){
		Random r = new Random();
		return r.nextInt((max - min) + 1) +min;
	}
	
    public static int getPrice(final int id) {
        try (final BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(BASE_URL + id).openStream()))) {
            final String raw = reader.readLine().replace(",", "").replace("\"", "").split("price:")[1].split("}")[0];
            return raw.endsWith("m") || raw.endsWith("k") ? (int) (Double.parseDouble(raw.substring(0, raw.length() - 1))
                    * (raw.endsWith("m") ? MILLION : THOUSAND)) : Integer.parseInt(raw);
        } catch (final Exception e) {
            e.printStackTrace();
        }
        return -1;
    }


}

 

Download:

https://mega.nz/#!Bph1kTwD!qzJrtVYj45TDHUwri84YxGCuRwgPMQHB7P8khrb60LM

Edited by Shaft
  • Like 5
Link to comment
Share on other sites

  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...