All pastes #571338 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-06-17 03:03 UTC
rendered paste body
// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   BankInterface.java

package impsoft.nexus.bots.color.scriptable.components.gamescreen;

import impsoft.nexus.bots.color.scriptable.ColorSkeltonScriptable;
import impsoft.nexus.bots.color.scriptable.components.ClientScreen;
import impsoft.nexus.bots.color.scriptable.components.MenuFinder;
import impsoft.nexus.bots.color.scriptable.components.minimap.Compass;
import impsoft.nexus.bots.color.scriptable.components.tab.InventoryTab;
import impsoft.nexus.bots.color.scriptable.components.tab.TabContainer;
import impsoft.nexus.bots.color.scriptable.objects.EdgeRGBCluster;
import impsoft.nexus.bots.color.scriptable.objects.Menu;
import impsoft.nexus.bots.color.structures.*;
import impsoft.nexus.bots.color.util.*;
import impsoft.nexus.bots.reflection.objects.AryanPath;
import impsoft.nexus.bots.reflection.structures.AryanTile;
import java.awt.Color;
import java.awt.Rectangle;

// Referenced classes of package impsoft.nexus.bots.color.scriptable.components.gamescreen:
//            TopText

public class BankInterface
{

    protected static final Rectangle getShopSlotRectangle(int slot)
    {
        int x = slot % 8;
        int y = slot / 8;
        int xOff = 79;
        int yOff = 62;
        int xSeperation = 47;
        int ySeperation = 38;
        return new Rectangle(xOff + x * xSeperation, yOff + y * ySeperation, 31, 31);
    }

    protected static final Rectangle getShopSlotTextRectangle(int slot)
    {
        int x = slot % 8;
        int y = slot / 8;
        int xOff = 79;
        int yOff = 62;
        int xSeperation = 47;
        int ySeperation = 38;
        return new Rectangle(xOff + x * xSeperation, yOff + y * ySeperation, 31, 9);
    }

    public BankInterface(ColorSkeltonScriptable c)
    {
        theColorScriptable = c;
    }

    public final int doDepositAll()
        throws InterruptedException
    {
        return doDepositAllBut(new String[0]);
    }

    public final int doDepositAllBut(String thingsToKeep[])
        throws InterruptedException
    {
        if(open())
        {
            int count = theColorScriptable.theTabs.Inventory.doAction(thingsToKeep, "All", 28, true);
            exit();
            return count;
        } else
        {
            return -1;
        }
    }

    public int doDepositAll(String itemName, String action, int maxItemsToDo)
        throws InterruptedException
    {
        if(open())
        {
            int count = theColorScriptable.theTabs.Inventory.doAction(itemName, "1", maxItemsToDo, true);
            exit();
            return count;
        } else
        {
            return -1;
        }
    }

    public final int doDepositAllButAxe()
        throws InterruptedException
    {
        return doDepositAllBut(new String[] {
            "ax"
        });
    }

    public final int doDepositAllButPickAxe()
        throws InterruptedException
    {
        return doDepositAllBut(new String[] {
            "pickaxe"
        });
    }

    public final boolean open()
        throws InterruptedException
    {
        if(isInterfaceIsUp())
            return true;
        Bank theBank = null;
        AryanTile player = theColorScriptable.getLocation();
        for(int i = 0; i < theBanks.length; i++)
        {
            if(theBanks[i].location.distanceTo(player) >= 20)
                continue;
            theBank = theBanks[i];
            break;
        }

        if(theBank != null)
        {
            EdgeRGBCluster cluster = new EdgeRGBCluster(theBank.rgbs, theColorScriptable);
            Timer t = new Timer(20000L);
            for(int counter = 0; !t.isUp() && !isInterfaceIsUp(); counter++)
            {
                if(counter == 1)
                {
                    theColorScriptable.info("[BANK] setting compass");
                    theColorScriptable.theCompass.setTo(theBank.compass);
                }
                if(counter == 2)
                {
                    theColorScriptable.info("[BANK] Attempting to walkTo");
                    (new AryanPath(theBank.location, theColorScriptable)).walkToEnd();
                    theColorScriptable.theCompass.setTo(theBank.compass);
                }
                if(cluster.doTopTextAndMenu("Bank", "quickly") != null)
                    waitTillInterfaceIsUp();
                if(counter > 2)
                    counter = 0;
            }

        } else
        {
            theColorScriptable.warn("Bank not known using defaults");
            EdgeRGBCluster cluster = new EdgeRGBCluster(BANK_DEFAULT_RGBS, theColorScriptable);
            for(Timer t = new Timer(20000L); !t.isUp() && !isInterfaceIsUp();)
                if(cluster.doTopTextAndMenu("Bank", "quickly") != null)
                    waitTillInterfaceIsUp();

        }
        return isInterfaceIsUp();
    }

    public final void paint()
        throws InterruptedException
    {
        for(int i = 0; i < 48; i++)
            theColorScriptable.paintRectangle(SLOT_RECTANGLE[i], Color.red, 4000);

        for(int i = 0; i < 48; i++)
            theColorScriptable.paintRectangle(SLOT_RECTANGLE_OCR[i], Color.green, 4000);

        for(int i = 0; i < 48; i++)
        {
            int r = getStackSize(i + 1);
            if(r > 0)
                theColorScriptable.log((new StringBuilder(String.valueOf(i))).append("   ").append(r).toString());
        }

    }

    public final boolean openBankDepositAllItem(String item)
        throws InterruptedException
    {
        if(open())
        {
            theColorScriptable.theTabs.Inventory.doAction(item, "All", 28, true);
            exit();
            return true;
        } else
        {
            return false;
        }
    }

    public void exit()
        throws InterruptedException
    {
        if(!isInterfaceIsUp())
            return;
        Timer t;
        for(t = new Timer(10000L); !t.isUp() && isInterfaceIsUp(); Thread.sleep(500L))
        {
            theColorScriptable.mouseMove(BUTTON_CLOSE);
            Thread.sleep(1000L);
            theColorScriptable.mouseClickLeft(BUTTON_CLOSE);
        }

        if(t.isUp())
            theColorScriptable.warn("Failed to Close Interface");
    }

    public String getItemTopText(int slot)
        throws InterruptedException
    {
        for(int loop = 0; loop < 10 && isItemInSlot(slot); loop++)
        {
            theColorScriptable.mouseMove(SLOT_RECTANGLE[slot - 1]);
            Thread.sleep(1000L);
            theColorScriptable.waitTillNextFrame();
            String topText = theColorScriptable.theTopText.getTopText();
            if(topText.contains(" ") && topText.contains("/") || topText.contains("-"))
                return TextFormat.format(topText);
        }

        return null;
    }

    public boolean doBankSlot(String itemName, String action, boolean waitForItemCountChange)
        throws InterruptedException
    {
        if(open())
        {
            itemName = TextFormat.format(itemName);
            for(int i = 1; i <= 48 && isInterfaceIsUp(); i++)
            {
                String topText = getItemTopText(i);
                if(topText != null)
                {
                    theColorScriptable.debug((new StringBuilder("doBankSlot() TopText \"")).append(topText).append("\" in Bank Slot ").append(i).toString());
                    if(topText.contains(itemName))
                    {
                        XY mouse = theColorScriptable.getCurrentMouseXY();
                        if(SLOT_RECTANGLE[i - 1].contains(mouse.x, mouse.y))
                        {
                            if(isInterfaceIsUp())
                            {
                                theColorScriptable.mouseClickRight(mouse.x, mouse.y);
                                Menu menu = theColorScriptable.theMenuFinder.getMenu();
                                if(menu != null)
                                {
                                    int precount = -1;
                                    if(waitForItemCountChange)
                                        precount = getStackSize(i);
                                    if(menu.clickContains(action))
                                    {
                                        theColorScriptable.debug((new StringBuilder("doBankSlot() ")).append(action).append(" Selected").toString());
                                        for(Timer t1 = new Timer(2000L); theColorScriptable.theMenuFinder.isAMenuIn() && !t1.isUp(); theColorScriptable.waitTillNextFrame());
                                        if(waitForItemCountChange)
                                        {
                                            for(Timer t2 = new Timer(2000L); precount == getStackSize(i) && !t2.isUp(); theColorScriptable.waitTillNextFrame());
                                        }
                                        return true;
                                    }
                                    menu.exit();
                                }
                            } else
                            {
                                i--;
                                theColorScriptable.warn("doBankSlot() Interface Changed");
                            }
                        } else
                        {
                            i--;
                            theColorScriptable.warn("doBankSlot() Mouse Moved off Bank spot");
                        }
                    }
                }
            }

            exit();
            return false;
        } else
        {
            return false;
        }
    }

    public boolean doWithDraw10(String itemName)
        throws InterruptedException
    {
        return doBankSlot(itemName, "withdraw 10 ", false);
    }

    public boolean doWithDraw5(String itemName)
        throws InterruptedException
    {
        return doBankSlot(itemName, "withdraw 5 ", false);
    }

    public boolean doWithDraw1(String itemName)
        throws InterruptedException
    {
        return doBankSlot(itemName, "withdraw 1 ", false);
    }

    public boolean doWithDrawAll(String itemName)
        throws InterruptedException
    {
        return doBankSlot(itemName, "withdraw all ", false);
    }

    public final int getStackSize(int slot)
        throws InterruptedException
    {
        String ocr;
        if(!isItemInSlot(slot))
            break MISSING_BLOCK_LABEL_111;
        ocr = OCR.getTextInBounds(theColorScriptable.getColorMap(), SLOT_RECTANGLE_OCR[slot - 1], new RGB(255, 255, 0), "CharsTrade", 1, 1, 1);
        int size;
        if(ocr == null || ocr.length() <= 0)
            break MISSING_BLOCK_LABEL_109;
        ocr.replaceAll(" ", "");
        size = Integer.parseInt(ocr.replace("k", "000").replace("m", "000000"));
        if(size > 0)
            return size;
        break MISSING_BLOCK_LABEL_109;
        Exception e;
        e;
        theColorScriptable.exception(e);
        return 1;
        return 0;
    }

    public boolean isInterfaceIsUp()
        throws InterruptedException
    {
        return Pixel.compare(theColorScriptable.theClientScreen.getPixel(POINT_ON_INTERFACE_BORDER), INTERFACE_BORDER_COLOR, 5) && Pixel.compare(theColorScriptable.theClientScreen.getPixel(POINT2_ON_INTERFACE_BORDER), INTERFACE_BORDER_COLOR, 5);
    }

    public final boolean isItemInSlot(int slot)
        throws InterruptedException
    {
        return isItemInSlot(slot, theColorScriptable.getColorMap());
    }

    private final boolean isItemInSlot(int slot, short colormap[][][])
        throws InterruptedException
    {
        Rectangle bounds = SLOT_RECTANGLE[slot - 1];
        int num = ColorMapAnaylsis.countRGB(colormap, ITEM_BORDER, SLOT_RECTANGLE[slot - 1]);
        return num > 0 && num < bounds.height * bounds.width - 10;
    }

    public final boolean waitTillInterfaceIsUp()
        throws InterruptedException
    {
        if(isInterfaceIsUp())
            return true;
        for(Timer t = new Timer(5000L); !t.isUp() && !isInterfaceIsUp(); theColorScriptable.waitTillNextFrame());
        return isInterfaceIsUp();
    }

    private static final Rectangle BUTTON_CLOSE = new Rectangle(479, 39, 24, 14);
    private static final short INTERFACE_BORDER_COLOR[] = (new RGB(13, 13, 11)).toPixel();
    protected final ColorSkeltonScriptable theColorScriptable;
    private static final RGB ITEM_BORDER = new RGB(0, 0, 1);
    private static final XY POINT_ON_INTERFACE_BORDER = new XY(18, 56);
    private static final XY POINT2_ON_INTERFACE_BORDER = new XY(16, 108);
    private static final Rectangle SLOT_RECTANGLE[];
    private static final Rectangle SLOT_RECTANGLE_REDUCED[];
    private static final Rectangle SLOT_RECTANGLE_OCR[];
    private static final int VISABLE_HORIZONTAL_SLOTS = 8;
    private static final int VISABLE_VERTICAL_SLOTS = 6;
    private static final int VISABLE_TOTAL_SLOTS = 48;
    private static final int ITEM_SIZE = 31;
    private static final RGB BANK_DEFAULT_RGBS[] = {
        new RGB(107, 82, 49), new RGB(123, 95, 58), new RGB(102, 82, 58)
    };
    public static final Bank theBanks[] = {
        new Bank(new AryanTile(3184, 3437), new RGB[] {
            new RGB(80, 67, 26), new RGB(87, 74, 31)
        }, -90, "Varrock East"), new Bank(new AryanTile(3254, 3421), new RGB[] {
            new RGB(80, 67, 26), new RGB(87, 74, 31)
        }, 0, "Varrock West"), new Bank(new AryanTile(3270, 3167), new RGB[] {
            new RGB(82, 63, 9)
        }, 90, "Al Kharid"), new Bank(new AryanTile(3254, 3421), new RGB[] {
            new RGB(92, 69, 9), new RGB(102, 76, 9), new RGB(87, 66, 9)
        }, -90, "Draynor"), new Bank(new AryanTile(3013, 3355), new RGB[] {
            new RGB(107, 82, 49), new RGB(123, 95, 58), new RGB(102, 82, 58)
        }, -90, "Falador East"), new Bank(new AryanTile(2728, 3493), new RGB[] {
            new RGB(74, 55, 8), new RGB(84, 62, 8)
        }, 0, "Seers"), new Bank(new AryanTile(2809, 2440), new RGB[] {
            new RGB(111, 81, 27), new RGB(127, 115, 93), new RGB(159, 156, 155)
        }, -90, "Canterby"), new Bank(new AryanTile(3092, 3491), new RGB[] {
            new RGB(82, 63, 9), new RGB(87, 66, 9)
        }, -90, "Edgeville")
    };

    static 
    {
        SLOT_RECTANGLE = new Rectangle[48];
        SLOT_RECTANGLE_OCR = new Rectangle[48];
        SLOT_RECTANGLE_REDUCED = new Rectangle[48];
        for(int i = 0; i < 48; i++)
        {
            SLOT_RECTANGLE[i] = getShopSlotRectangle(i);
            SLOT_RECTANGLE_REDUCED[i] = new Rectangle(SLOT_RECTANGLE[i].x + SLOT_RECTANGLE[i].width / 2, SLOT_RECTANGLE[i].y + SLOT_RECTANGLE[i].height / 2, SLOT_RECTANGLE[i].width / 2, SLOT_RECTANGLE[i].height / 2);
            SLOT_RECTANGLE_OCR[i] = getShopSlotTextRectangle(i);
        }

    }
}