All pastes #2080611 Raw Edit

Unnamed

public text v1 · immutable
#2080611 ·published 2011-09-10 01:55 UTC
rendered paste body
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.awt.*;
import java.net.MalformedURLException;
import java.net.URL;
import javax.imageio.ImageIO;
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.methods.Skills;
import org.rsbot.script.util.Timer;
import org.rsbot.script.wrappers.RSItem;
 
@ScriptManifest(authors = "Albi, xPure2", name = "AIO Herbie.", version = 1.3, description = "Let's make some pots!")
public class AlbisAIOHerblore extends Script implements PaintListener, MouseListener {
 
	ScriptManifest SM = getClass().getAnnotation(ScriptManifest.class);

    private State currentState;
    private boolean showPaint = true;
    private Timer antiBanTimer;
    private long startTime;
    BufferedImage normal = null, clicked = null;
    Rectangle button = new Rectangle(211, 296, 86, 22);
    int tab = 1;
    Point p;
    private String whichPot = "", debugMsg = "";
    private int startXP = 0, failsafe = 0, fstIngred, sndIngred, product, XPgained, XPToNextLvl, levelsGained, startLevel, currLevel;
    private long runTime = 0, seconds = 0;
 
    private enum State {
        DEPOSITING, WITHDRAWING, MAKE, WITHDREW_TOO_MUCH, UNK
    }
 
    private State getState() {
        if (!bank.isOpen() && inventory.containsOneOf(fstIngred, sndIngred)) {
            return State.MAKE;
        } else if (bank.isOpen() && inventory.isFull() && (inventory.contains(fstIngred) && !inventory.contains(sndIngred))
                || (!inventory.contains(fstIngred) && inventory.contains(sndIngred))) {
            return State.WITHDREW_TOO_MUCH;
        } else if (bank.isOpen() && inventory.getCount() > 0) {
            return State.DEPOSITING;
        } else if (bank.isOpen() && inventory.getCount() == 0) {
            return State.WITHDRAWING;
        } else {
            return State.UNK;
        }
    }
 
    public boolean inventoryCheck(int fst, int snd) {
        return (inventory.getCount(fst) == 0 || inventory.getCount(snd) == 0);
    }
 
    public void mixIngredients(int fst, int snd) {
        try {
            if (!interfaces.get(905).getComponent(14).isValid()) {
                inventory.useItem(inventory.getItem(fst), inventory.getItem(snd));
                sleep(2000, 3000);
            }
            if (interfaces.get(905).getComponent(14).doClick()) {
                mouse.moveOffScreen();
                while (!inventoryCheck(fst, snd) && failsafe < 4) {
                    sleep(2000, 5000);
                    failsafe++;
                    mouse.moveSlightly();
                }
                if (failsafe < 4) {
                    if (!interfaces.get(905).getComponent(14).isValid()) {
                        inventory.useItem(inventory.getItem(fst), inventory.getItem(snd));
                        sleep(2000, 3000);
                    }
                    failsafe = 0;
                }
                whichPot = inventory.getItem(product).getName();
            }
        } catch (NullPointerException e) {
            debugMsg = "Line: " + Thread.currentThread().getStackTrace()[2].getLineNumber() + ", NPE in mixIngredients()";
            log.warning(debugMsg);
        }
    }
 
    public void withdrawIngreds() {
        if (bank.getItem(fstIngred) == null || bank.getItem(sndIngred) == null) {
            log("No ingreds to carry on..");
            game.logout(false);
            stopScript(true);
        } else {
            while (!inventory.contains(fstIngred) && !inventory.contains(sndIngred)) {
                bank.withdraw(fstIngred, 14);
                sleep(800, 1200);
                bank.withdraw(sndIngred, 14);
            }
            bank.close();
        }
    }
 
    @Override
    public boolean onStart() {
    	try {
			final URL cursorURL = new URL("http://i48.tinypic.com/313623n.png");
			final URL cursor80URL = new URL("http://i46.tinypic.com/9prjnt.png");
			normal = ImageIO.read(cursorURL);
			clicked = ImageIO.read(cursor80URL);
		} catch (MalformedURLException e) {
			log("Unable to buffer cursor.");
		} catch (IOException e) {
			log("Unable to open cursor image.");
		}
        mouse.setSpeed(random(6, 8));
            if (inventory.getCount() == 0) {
                log("No primary mixes in inventory, quitting..");
                stopScript(true);
                return false;
            } else {
                fstIngred = inventory.getItemAt(0).getID();
                sndIngred = inventory.getItemAt(1).getID();
                sleep(800, 1200);
                mixIngredients(fstIngred, sndIngred);
                for (RSItem item : inventory.getItems()) {
                    if (item != null) {
                        if (item.getID() != fstIngred && item.getID() != sndIngred) {
                            product = item.getID();
                            break;
                        }
                    }
                }
                antiBanTimer = new Timer(random(150000, 300000));
                startTime = System.currentTimeMillis();
                startLevel = skills.getCurrentLevel(Skills.HERBLORE);
                startXP = skills.getCurrentExp(Skills.HERBLORE);
                XPgained = skills.getCurrentExp(Skills.HERBLORE) - startXP;
                XPToNextLvl = skills.getExpToNextLevel(Skills.HERBLORE);
                currLevel = skills.getCurrentLevel(Skills.HERBLORE);
                return true;
            }
    }
 
    @Override
    public void onFinish() {
        env.saveScreenshot(true);
        log("Thankyou for using " + SM.name() + " v" + SM.version());
    }
 
    @Override
    public int loop() {
        currentState = getState();
        debugMsg = currentState.name();
        if (!antiBanTimer.isRunning()) {
            camera.moveRandomly(random(1, 360));
            antiBanTimer = null;
            antiBanTimer = new Timer(random(1500000, 3500000));
            antiBanTimer.reset();
        }
        switch (currentState) {
            case WITHDREW_TOO_MUCH:
            	bank.depositAll();
            	failsafe = 0;
            	return random(750, 1250);
            case DEPOSITING:
                bank.depositAll();
                failsafe = 0;
                return random(1000, 1500);
            case WITHDRAWING:
                withdrawIngreds();
                failsafe = 0;
                return random(1000, 1500);
            case MAKE:
                mixIngredients(fstIngred, sndIngred);
                bank.open();
                return random(1000, 1500);
            case UNK:
                if (!bank.isOpen()) {
                    bank.open();
                    bank.depositAll();
                }
                failsafe = 0;
                return random(1000, 1500);
        }
        return random(1000, 1500);
    }
 
    public void mouseClicked(MouseEvent e){
    	p = e.getPoint();
    	if (button.contains(p) && tab == 2) {
    		tab = 1;
    	}
    	if (button.contains(p) && tab == 1) {
    		tab = 2;
    	}
    }
 
    public void mousePressed(MouseEvent e) {
    }
 
    public void mouseReleased(MouseEvent e) {
    }
 
    public void mouseEntered(MouseEvent e) {
    }
 
    public void mouseExited(MouseEvent e) {
    }
 
    private Image getImage(String url) {
        try {
            return ImageIO.read(new URL(url));
        } catch(IOException e) {
            return null;
        }
    }

    private final Color color1 = new Color(0, 255, 0);
    private final Color color2 = new Color(0, 0, 0);
    private final Color color3 = new Color(0, 204, 0);
    private final Color color4 = new Color(51, 51, 51);

    private final BasicStroke stroke1 = new BasicStroke(1);

    private final Font font1 = new Font("Arial", 1, 14);
    private final Font font2 = new Font("Arial", 1, 12);
    private final Font font3 = new Font("Arial", 0, 12);

    private final Image img1 = getImage("http://images1.wikia.nocookie.net/__cb20110305043047/runescape/images/f/f1/Herblore-icon.png");
    private final Image img2 = getImage("http://images.wikia.com/runescape/images/b/ba/Herblore-hood-inv.png");
    private final Image img3 = getImage("http://images2.wikia.nocookie.net/__cb20091112192213/runescape/images/9/96/Herblore-cape-%28t%29-inv.png");

    public void onRepaint(Graphics g1) {
    	Graphics2D g = (Graphics2D)g1;
    	if (showPaint) {
    		runTime = System.currentTimeMillis() - startTime;
    		XPgained = skills.getCurrentExp(Skills.HERBLORE) - startXP;
    		XPToNextLvl = skills.getExpToNextLevel(Skills.HERBLORE);
    		currLevel = skills.getCurrentLevel(Skills.HERBLORE);
    		levelsGained = startLevel -= currLevel;
    		int XPHour = (int) ((XPgained) * 3600000.0 / runTime);
        	seconds = runTime / 1000;
        	String displayRunTime = String.format("%02d:%02d:%02d", seconds / 3600, (seconds % 3600) / 60, (seconds % 60));
        	g.setColor(color1);
        	g.fillRect(10, 350, 480, 120);
        	g.setColor(color2);
        	g.setStroke(stroke1);
        	g.drawRect(10, 350, 480, 120);
        	g.setFont(font1);
        	g.drawString("AlbisAIOHerblore", 20, 370);
        	g.setFont(font2);
        	g.drawString("v" + SM.version(), 180, 370);
        	g.setFont(font3);
        	g.drawString("Herblore Level: " + skills.getCurrentLevel(skills.HERBLORE) + "(" + levelsGained + ")", 200, 390);
        	g.drawString("Runtime (h:m:s): "  + displayRunTime, 20, 390);
        	g.drawString("Making: " + whichPot, 20, 410);
        	g.drawString("XP/Hr: " + XPHour, 200, 430);
        	g.drawString("XP untill Level up: " + XPToNextLvl, 200, 450);
        	g.drawImage(img1, 440, 360, null);
        	g.drawImage(img2, 440, 390, null);
        	g.drawImage(img3, 444, 431, null);
        	g.drawString("Debug: " + debugMsg, 20, 430);
        	g.setColor(color3);
        	g.fillRect(439, 319, 75, 17);
        	g.setColor(color4);
        	g.drawString("Hide Paint", 444, 332);
    	} else {
        	g.setColor(color3);
        	g.fillRect(439, 319, 75, 17);
        	g.setColor(color4);
        	g.drawString("Hide Paint", 444, 332);
    	}
        final Point p = mouse.getLocation();
		final Point c = mouse.getPressLocation();
		final long mpt = System.currentTimeMillis()- mouse.getPressTime();
		if (mouse.getPressTime() == -1 || mpt >= 1000) {
			g.drawImage(normal, p.x - 8, p.y - 8, null); // this

		}

		if (mpt < 1000) {
			g.drawImage(clicked, c.x - 8, c.y - 8, null);		

		}
    }
}