All pastes #261257 Raw Edit

Unnamed

public java v1 · immutable
#261257 ·published 2006-11-29 01:51 UTC
rendered paste body
import impsoft.ibot.Areas;import impsoft.ibot.Info;import impsoft.ibot.methods.Menu;import impsoft.ibot.methods.RGB;import impsoft.ibot.methods.RGBXY;import impsoft.ibot.methods.Script;import impsoft.ibot.methods.XY;import java.awt.Rectangle;import java.awt.event.KeyEvent;import java.util.ArrayList;/* * Used Rictoo's Dropping method. * Used MissSilabSoft's FindRed() method for MiniMap items */public class UltimateChopper extends Script {    public static double version = 1.0;    public static String[] commands = new String[] { "Min Sleep, Max Sleep" };    public static String arugs[];    public static String author = "Evil_, Rictoo";    public static String description = "Power cutter, that checks level!";    public String treename = "Tree";    public String treename2;    public String treename3;    public int minsleep;    public int maxsleep;    public RGB treecolor;    private RGB barColor = new RGB(0, 255, 0);    private Rectangle barRectangle = new Rectangle(230, 109, 288, 152);    @Override    public boolean doStart(String cmd, String[] args) {        if (args.length > 2) {            return false;        }        arugs = args;        minsleep = Integer.parseInt(arugs[0]);        maxsleep = Integer.parseInt(arugs[1]);        treecolor = new RGB(96, 112, 0);        return true;    }    @Override    public void script() throws InterruptedException {        while (!theBot.loggedIn) {            sleep(defaultmaxAgeInMillisecs);        }        if (getTab() != Info.TAB_OPTIONS && getTab() != -1) {            setTab(Info.TAB_OPTIONS);            sleep(defaultmaxAgeInMillisecs * 2);        }        setRun(true);        int tick = 0;        while (true) {            if (tick == 0) {                checkStats();                tick = 30;            } else {                tick--;            }            XY tree = getTree(treecolor, 5, 5, 5);            if (tree != null) {                log("Trying to chop");                mouseClickLeft(tree);                checkAxe();                sleep(400 + random(10, 300));                checkAxe();                checkBattle();                sleep(random(minsleep, maxsleep));                checkBattle();                checkInventory();            } else {                log("Failed to find Tree");                SendKey(KeyEvent.VK_LEFT, random(1000, 2000));            }            sleep(500 + random(minsleep, maxsleep));        }    }    public XY getTree(RGB color, int redTolerance, int greenTolerance,            int blueTolerance) throws InterruptedException {        log("Searching for " + color);        ArrayList<Rectangle> recs = new ArrayList<Rectangle>(4);        for (int attempts = 0; attempts < 100; attempts++) {            Rectangle ignore[] = new Rectangle[recs.size()];            for (int i = 0; i < ignore.length; i++) {                ignore[i] = recs.get(i);            }            XY match = findXYspiral(getColorArray2d(), Areas.GAME, ignore,                    currentMouseX(), currentMouseY(), color, redTolerance,                    greenTolerance, blueTolerance);            if (match == null)                break;            mouseMove(match.x, match.y);            sleep(defaultmaxAgeInMillisecs);            String topText = getTopText();            if ((treename != null && topText.indexOf(treename) != -1)                    || (treename2 != null && topText.indexOf(treename2) != -1)                    || (treename3 != null && topText.indexOf(treename3) != -1)) {                return new XY(currentMouseX(), currentMouseY());            } else {                recs.add(new Rectangle(currentMouseX() - 50,                        currentMouseY() - 50, 100, 100));            }        }        return null;    }    public void checkBattle() throws InterruptedException {        RGBXY barXY = findRGBXY(getColorArray2d(), barRectangle, barColor);        if (barXY != null) {            mouseClickLeft(62 + random(3, 5), 17 + random(3, 5));            sleep(random(2000, 4000));            checkBattle();        }    }    public void checkStats() throws InterruptedException {        if (getTab() != Info.TAB_STATS && getTab() != -1) {            setTab(Info.TAB_STATS);            sleep(defaultmaxAgeInMillisecs * 2);        }        int woodCuttingLevel = getStatBottom(Info.STAT_WOODCUTTING);        if (woodCuttingLevel >= 20)            treename2 = "Oak";        else            treename2 = null;        if (woodCuttingLevel >= 40)            treename3 = "Willow";        else            treename3 = null;    }    public void checkInventory() throws InterruptedException {        if (getTab() != Info.TAB_INVENTORY && getTab() != -1) {            setTab(Info.TAB_INVENTORY);            sleep(defaultmaxAgeInMillisecs * 2);        }        if (inventoryCount() >= 28) {            doAllInventory(new String[] { "axe" }, "drop");        }    }    /**     * @author ruler     */    public void checkAxe() throws InterruptedException {        if (getChat(4).indexOf("You need an axe to chop down this tree.") != -1) {            if (FindRed()) {                do {                    sleep(defaultmaxAgeInMillisecs);                } while (isMoving());                // TODO find the axe on ground?            } else {                log("Could Not Find Red in Mini Map");            }        }    }    /**     * @author MissSilabSoft, ruler     */    public boolean FindRed() throws InterruptedException {        XY red = findXYspiral(getColorArray2d(), Areas.MINI_MAP, null,                Areas.MINI_MAP_CENTER.x, Areas.MINI_MAP_CENTER.y, new RGB(252,                        6, 6), 10, 10, 10);        if (red != null) {            mouseClickLeft(red);            return true;        }        return false;    }    /**     *      * @param ignoreItemNames     *            The item names you dont want to do this action to     * @param Action     *            The name of the thing that comes up in the menu, dont have     *            spaces plz!     * @author ruler, aikon     * @throws InterruptedException     */    public void doAllInventory(String ignoreItemNames[], String Action)            throws InterruptedException {        int maxAttempts = 10;        if (getTab() != Info.TAB_INVENTORY && getTab() != -1) {            setTab(Info.TAB_INVENTORY);            sleep(defaultmaxAgeInMillisecs * 2);        }        for (int slot = 1; slot < 29; slot++) {            for (int attempt = 0; itemExist(slot) && attempt < maxAttempts; attempt++) {                mouseMove(Info.getInventoryRectangle(slot));                sleep(defaultmaxAgeInMillisecs + 1);                String topText = getTopText().trim();                if (topText.indexOf(" ") != -1 && topText.indexOf("/") != -1) {                    // This determines the items name from the topText                    String item = topText.substring(topText.indexOf(" "),                            topText.indexOf("/")).trim();                    if (item.length() > 1) {                        // We dont want to drop our pickaxe                        boolean ignore = false;                        if (ignoreItemNames != null)                            for (int ignoreIndex = 0; ignoreIndex < ignoreItemNames.length; ignoreIndex++) {                                if (topText                                        .indexOf(ignoreItemNames[ignoreIndex]) != -1) {                                    ignore = true;                                    break;                                }                            }                        if (ignore) {                            break;                        } else {                            log("Found a " + item + " in Inventory Slot "                                    + slot + " '" + Action + "ing'");                            doInventory(slot, Action);                            sleep(defaultmaxAgeInMillisecs + 250);                            if (itemExist(slot)) {                                slot--;                            } else {                                break;                            }                        }                    }                }                attempt++;            }        }    }    /**     *      * @param invIndex     *            The index you want to bring the menu up on     * @param Action     *            The name of the thing that comes up in the menu, dont have     *            spaces plz!     * @author ruler, aikon     * @throws InterruptedException     */    public void doInventory(int invIndex, String Action)            throws InterruptedException {        Rectangle inventorySpot = Info.getInventoryRectangle(invIndex);        int currentMouseX = currentMouseX();        int currentMouseY = currentMouseY();        if (inventorySpot.contains(currentMouseX, currentMouseY)) {            mouseClickRight(currentMouseX, currentMouseY, 250);        } else {            mouseClickRight(inventorySpot);        }        Menu invSlot = getMenu(Areas.INVENTORY, 2000);        if (invSlot != null) {            if (!invSlot.selectContains(Action)) {                invSlot.exit();            }        }    }}