Jump to content

[Rough] Banking API [Replaces and expands the original!]


NotoriousPP

Recommended Posts

Well I thought today I would release some of my private collection of different snippets to hopefully help new writers learn a little bit, and to maybe see a rise in quality of scripts throughout this forum.
 
For my fourth release, I'm going to share something I spent hours on, I put way more work into this one class than I probably should of, though it was a great learning experience, and am glad I chose to do this. I cannot say this will work flawless, but rather give you a solid base for someone interested in creating their own banking methods. This class gives you full functionality of banking, allowing the writer to changes anything they don't like about banking. I have done my best to recreate every method in the OSBot Banking.class, while also expanding adding other methods I thought would be useful.
 
In my personal tests, I was able to bank 41.6% faster than using the orignal built in functions (Rounded Amounts: OSBot best time: 12s, My best time: 7s), so even though being very rough at the moment, it's still a major improvement from what we have at the moment.
 
I must thank/credit:
@TheScrub for his orignal banking API, as I used some of his methods.
@Archon for his snippet on bank scrolling.
@Nezz for his awesomeness helping me handle bank tab configs correctly, and helping review the class.
 
You guys are awesome! smile.png
 
Disclaimer: Please note that this API maybe partially functional, it by no means anywhere near perfect, I posted this in hopes of you guys going out and making your edits/revisions to the class to help diversify our scripts functionality! Please don't come to me asking why this doesn't work perfect, that up to you, I simply gave you a solid base to work from.
 
How does is work?
 
Well pretty much instead of using "client.getBank()", at the top of our banking class we will create a new Banking object like:

private Banking banking = new Banking(bot, client);

And after instantiating the Banking object, we can use it like:

 banking.withdraw("Lobster", 12);

So pretty much exactly like the old API, yet we just call the methods through own Banking class instead of OSBots.
 
Finally, where the magic happens:

(Added JDoc information tables to public methods to help you guys understand what is going on a little easier)

import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import org.osbot.engine.Bot;
import org.osbot.script.MethodProvider;
import org.osbot.script.mouse.MouseDestination;
import org.osbot.script.mouse.RectangleDestination;
import org.osbot.script.rs2.Client;
import org.osbot.script.rs2.model.Item;
import org.osbot.script.rs2.model.RS2Object;
import org.osbot.script.rs2.ui.RS2Interface;
import org.osbot.script.rs2.ui.RS2InterfaceChild;
import org.osbot.script.rs2.utility.ConditionalSleep;
import tools.api.methods.widgets.Menu;


/**
 * User: NotoriousPP
 * Date: 5/21/14
 * Time: 10:08 AM
 */
public class Banking {

    //Thanks Laz for all the constant values!
    //Most are unneeded, just there just in case.
    private Bot bot;
    private Client client;
    final int WITHDRAW_1 = 1,
            DEPOSIT_ALL_INV = 25,
            WITHDRAW_MODE_ITEM = 19,
            WITHDRAW_MODE_NOTE = 21,
            REARRANGE_MODE_SWAP = 14,
            REARRANGE_MODE_INSERT = 16,
            DEPOSIT_ALL_EQUIP = 27,
            BANK_INTERFACE = 12,
            ITEM_CONTAINER_START_X = 72,
            ITEM_CONTAINER_START_Y = 83,
            ITEM_CONTAINER_WIDTH = 371,
            ITEM_CONTAINER_HEIGHT = 210,
            ITEM_CONTAINER = 10,
            SLOT_SIZE_WIDTH = 35,
            SCROLL_CONTAINER = 10,
            MAX_TABS = 10,
            MAIN_TAB = 0,
            TAB_START_X = 62,
            TAB_START_Y = 45,
            TAB_HEIGHT = 32,
            CURRENT_TAB_CONFIG = 115,
            CURRENT_TAB_CONFIG_ONE = 867,
            CURRENT_TAB_CONFIG_TWO = 1052,
            CURRENT_TAB_CONFIG_THREE = 1053,
            TAB_WIDTH = 35,
            PARENT_ID = 12,
            CHAT_PARENT_ID = 548,
            CHILD_ONE_ID = 10,
            CHAT_CHILD_ID = 123;
    final double TAB_OFFSET = 40.33D,
            SLOT_OFFSET_X = 12.70D,
            SLOT_SIZE_HEIGHT = 35.98D,
            SLOT_OFFSET_Y = 5.99D;
    final Rectangle UP_ARROW = new Rectangle(481, 84, 15, 15),
            DOWN_ARROW = new Rectangle(481, 279, 15, 15);


    public Banking(Bot bot, Client client) {
        this.client = client;
        this.bot = bot;
    }

   //START: Public methods
   //------------------------------------------------------------------------

    /**
    * Searches for the best bank, based on type and distance
    * from player.
    * @return <tt>true</tt> if is open; otherwise <tt>false</tt>.
    */
    public boolean isOpen() {
        final RS2Interface rs2Interface = client.getInterface(BANK_INTERFACE);
        return rs2Interface != null &&
                (rs2Interface.isVisible()) &&
                rs2Interface.getChild(0) != null &&
                rs2Interface.getChild(0).isVisible();
    }

    /**
    * Searches for the best bank, based on type and distance
    * from player.
    * @return <tt>true</tt> if bank was already open, or opened successfully;
    * otherwise <tt>false</tt>.
    */
    public boolean open() throws InterruptedException {
        if (isOpen()) return true;
        final RS2Object BANK = getClosestBankObject();
        if (BANK != null) {
            if (BANK.interact(BANK.getName().equals("Bank booth") ? "Bank" : "Use")) {
                new ConditionalSleep(2000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return isOpen();
                    }
                }.sleep();
            }
            return isOpen();
        }
        return false;
    }

    /**
    * Scroll to the slot specified by item ID.
    * @param id the of the item you wish to scroll to.
    * @return <tt>true</tt> if scrolled successfully  and item is visible;
    * otherwise <tt>false</tt>.
    */
    public boolean scrollToItem(int id) throws InterruptedException {
        return scrollToItem(null, id);
    }

    /**
    * Scroll to the slot specified by item name.
    * @param name the of the item you wish to scroll to.
    * @return <tt>true</tt> if scrolled successfully
    * and item is visible;
    * otherwise <tt>false</tt>.
    */
    public boolean scrollToItem(String name) throws InterruptedException {
        return scrollToItem(name, -1);
    }

    /**
    * Checks to see if the specified interface is open.
    * @param parent the id of the parent interface.
    * @param child the id of the child interface.
    * @return <tt>true</tt> if interface and child is visible;
    * otherwise <tt>false</tt>.
    */
    public boolean isInterfaceOpen(int parent, int child) {
        final RS2Interface rs2Interface = client.getInterface(parent);
        if(rs2Interface != null && rs2Interface.isVisible()){
            final RS2InterfaceChild rs2InterfaceChild = rs2Interface.getChild(child);
            return rs2InterfaceChild != null && rs2InterfaceChild.isVisible();
        }
        return false;
    }

    /**
    * Right clicks the items with the specified id.
    * @param id the ID of the item you wish to click.
    * @return <tt>true</tt> if interface and child is visible;
    * otherwise <tt>false</tt>.
    */
    public boolean rightClickBankItem(int id) throws InterruptedException {
        return rightClickBankItem(null, id);
    }

    /**
    * Right clicks the items with the specified name.
    * @param name the name of the item you wish to click.
    * @return <tt>true</tt> if interface and child is visible;
    * otherwise <tt>false</tt>.
    */
    public boolean rightClickBankItem(String name) throws InterruptedException {
        return rightClickBankItem(name, -1);
    }

    /**
    * Right clicks the items with the specified name.
    * @return <tt>true</tt> if interface and child is visible;
    * otherwise <tt>false</tt>.
    */
    public int getScrollHeight() {
        final RS2InterfaceChild CHILD = getChild(PARENT_ID, SCROLL_CONTAINER);
        if (CHILD == null || !isOpen()) {
            return -1;
        }
        return CHILD.getScrollPosition();

    }

    /**
     *
     * @param slot The slot of the item you wish to get the horizontal row for!
     * @return int of the row of the item
     */
    public int getRow(int slot) {
        return slot / 8;
    }
    /**
     *
     * @param slot The slot of the item you wish to get the vertical column for!
     * @return int of the column of the item
     */
    public int getColumn(int slot) {
        return slot % 8;
    }

    /**
     * You can view the first 6 columns at the height of 0
     * @param slot The slot of the item you wish to get the scroll height for!
     * @return int of the scroll max height needed!
     */
    public int getMinScrollHeightNeeded(int slot) {
        return getRow(slot) > 5 ? (getRow(slot) - 5) * 37 : 0;
    }
    /**
     *
     * @param slot The slot of the item you wish to get the scroll height for!
     * @return int of the scroll min height needed!
     */
    public int getMaxScrollHeightNeeded(int slot) {
        return getMinScrollHeightNeeded(slot) + (37 * 5);
    }
    /**
     *
     * @param slot The slot of the item you wish to check visibility.
     * @return boolean if the slot is visible!
     */
    public boolean isSlotVisible(int slot) {
        return (getScrollHeight() >= getMinScrollHeightNeeded(slot) && getScrollHeight() <= getMaxScrollHeightNeeded(slot));
    }
    /**
     *
     * @param slot The slot of the item you wish to scroll to.
     * @return boolean if the slot needs to scroll up!
     */
    public boolean needToScrollUp(int slot) {
        return !isSlotVisible(slot) && getScrollHeight() > getMaxScrollHeightNeeded(slot);
    }
    /**
     *
     * @param slot The slot of the item you wish to scroll to.
     * @return boolean if the slot needs to scroll down!
     */
    public boolean needToScrollDown(int slot) {
        return !isSlotVisible(slot) && getScrollHeight() < getMinScrollHeightNeeded(slot);
    }
    /**
     *
     * @param slot The slot of the item you wish to scroll to.
     * @return boolean if the slot needs to scroll!
     */
    public boolean needToScroll(int slot) {
        return needToScrollDown(slot) || needToScrollUp(slot);
    }
    /**
     *
     * @param name Name of the item you wish to check bank for.
     * @return boolean if bank contains item.
     */
    public boolean contains(String name) {
        return contains(-1, name);
    }
    /**
     *
     * @param id Id of the item you wish to check bank for.
     * @return boolean if bank contains item.
     */
    public boolean contains(int id) {
        return contains(id, null);
    }

    /**
     *
     * @param id Id of item you wish to get the tab for.
     * @return  int of tab which contains id.
     */
    public int getTabForItem(int id){
        return getTabForItem(id, null);
    }
    /**
     *
     * @param name Name of item you wish to get the tab for.
     * @return  int of tab which contains name.
     */
    public int getTabForItem(String name){
        return getTabForItem(-1, name);
    }

    /**
     *
     * @return int of total item count in the main tab.
     */
    public int getMainTabItemCount() {
        final Item[] ITEMS = client.getInterface(BANK_INTERFACE).getItems(ITEM_CONTAINER);
        int index = 0;
        if(ITEMS != null){
            for(int i = getAllTabItemCount(); i < ITEMS.length; i++){
                if(ITEMS[i] != null){
                    index++;
                }
            }
        }
        return index;
    }
    /**
     * @param  tab the tab you wish to get item count for!
     * @return int of total item count in the desired tab.
     */
    public int getItemCountForTab(int tab) {
        if(tab <= 0){
            return getAllBankItems().length;
        } else if(tab <= 3){
            return getFormulatedCount(CURRENT_TAB_CONFIG_ONE, tab);
        } else if(tab <= 6){
            return getFormulatedCount(CURRENT_TAB_CONFIG_TWO, tab);
        } else {
            return getFormulatedCount(CURRENT_TAB_CONFIG_THREE, tab);
        }
    }

    /**
     *
     * @return true if successfully deposited everything, false if empty or failed.
     * @throws InterruptedException
     */
    public boolean depositAll() throws InterruptedException {
        final RS2InterfaceChild CHILD = getChild(BANK_INTERFACE, DEPOSIT_ALL_INV);
        if(CHILD != null && CHILD .isVisible()){
            return client.moveMouseTo(new RectangleDestination(CHILD.getRectangle()), false, true, false);
        }
        return false;
    }
    /**
     * @param id Id of item you wish to deposit all of!
     * @return true if successfully deposited all of item, false if doesn't contain item or failed.
     * @throws InterruptedException
     */
    public boolean depositAll(int id) throws InterruptedException {
        return (!client.getInventory().contains(id)) || client.getInventory().interactWithId(id, "Deposit-All");
    }
    /**
     * @param name Name of item you wish to deposit all of!
     * @return true if successfully deposited all of item, false if doesn't contain item or failed.
     * @throws InterruptedException
     */
    public boolean depositAll(String name) throws InterruptedException {
        return (!client.getInventory().contains(name)) || client.getInventory().interactWithName(name, "Deposit-All");
    }

    /**
     *
     * @param itemNames Names of the items you wish to keep.
     * @return  true if deposits all everything but itmes, false if empty or doesn't contain anything but items
     * @throws InterruptedException
     */
    public boolean depositAllExcept(String... itemNames) throws InterruptedException {
        return depositAllExcept(namesToIds(itemNames));
    }
    /**
     *
     * @param ids Ids of the items you wish to keep.
     * @return  true if deposits all everything but itmes, false if empty or doesn't contain anything but items
     * @throws InterruptedException
     */
    public boolean depositAllExcept(int... ids) throws InterruptedException {
        if (client.getInventory().isEmpty() || ids == null)
            return false;
        List<Integer> itemIds = new ArrayList<>();
        for (Item item : client.getInventory().getItems()){
            if (item != null) {
                if (!itemIds.contains(item.getId())){
                    boolean contains = false;
                    for(int i : ids){
                        if(item.getId() == i){
                            contains = true;
                        }
                    }
                    if(!contains){
                        itemIds.add(item.getId());
                    }
                }
            }
        }
        for (int i : itemIds){
            client.getInventory().interactWithId(i, "Deposit-All");
        }
        bot.getAPI().sleep(MethodProvider.random(300, 500));
        return client.getInventory().isEmptyExcept(ids);
    }

    /**
     *
     * @param slot Slot of the item you wish to get rect for!
     * @return Rectangle of slot in bank.
     */
    public Rectangle getSlotRectangle(int slot){
        double xCord = ITEM_CONTAINER_START_X, yCord = ITEM_CONTAINER_START_Y - getScrollHeight();
        xCord += getColumn(slot) * (getColumn(slot) == 0 ? SLOT_SIZE_WIDTH : SLOT_SIZE_WIDTH + SLOT_OFFSET_X);
        yCord += getRow(slot) * SLOT_SIZE_HEIGHT;
        return new Rectangle((int)xCord, (int)yCord, SLOT_SIZE_WIDTH, (int)SLOT_SIZE_HEIGHT);
    }

    /**
     *
     * @param tab Tab to get items from.
     * @return Item[] of all the items in desired tab.
     */
    public Item[] getItemsInTab(int tab){
        if(tab > 0){
            final Item[] ITEMS = client.getInterface(BANK_INTERFACE).getItems(ITEM_CONTAINER);
            if(ITEMS != null){
                List<Item> tabItems = new ArrayList<>();
                int startIndex = 0,
                        endIndex = getItemCountForTab(tab);
                for(int i = 1; i < tab; i++){
                    startIndex += getItemCountForTab(i);
                }
                endIndex += (startIndex - 1);
                for(int i = 0; i < ITEMS.length; i++){
                    if(i >= startIndex && i <= endIndex){
                        if(ITEMS[i] != null)
                            tabItems.add(ITEMS[i]);
                    }
                }
                if(!tabItems.isEmpty()){
                    return tabItems.toArray(new Item[tabItems.size()]);
                }
            }
        } else {
            final Item[] ITEMS = getAllBankItems();
            List<Item> tabItems = new ArrayList<>();
            if(ITEMS != null){
                for(int i = getAllTabItemCount(); i < ITEMS.length; i++){
                    if(ITEMS[i] != null){
                        tabItems.add(ITEMS[i]);
                    }
                }
            }
            if(!tabItems.isEmpty()){
                return tabItems.toArray(new Item[tabItems.size()]);
            }
        }
        return null;
    }

    /**
     *
     * @param tab Bank tab you wish to open
     * @return true if successfully opened tab, false if already opened or failed
     * @throws InterruptedException
     */
    public boolean openBankTab(int tab) throws InterruptedException{
        if(isOpen()){
            if(getCurrentTab() != tab){
                bot.getMouse().moveMouseTo(generateTabDestination(tab), false, true, false);
                bot.getAPI().sleep(MethodProvider.gRandom(400, 200));
                return true;
            }
        }
        return false;
    }

    /**
     *
     * @return int of bank tab currently open.
     */
    public int getCurrentTab(){
        return client.getConfig(CURRENT_TAB_CONFIG) / 4;
    }

    /**
     *
     * @return Get item count of all tabs  EXPECT the main tab.
     */
    public int getAllTabItemCount() {
        if(getOpenBankTabs() > 0){
            int offset = 0;
            for(int i = 1; i < getOpenBankTabs(); i++){
                if(getItemCountForTab(i) > 0){
                    offset += getItemCountForTab(i);
                }
            }
            return offset;
        } else {
            return getAllBankItems().length;
        }
    }
    /**
     *
     * @return int of all open bank tabs
     */
    public int getOpenBankTabs() {
        int available = 0;
        for(int i = 0; i < MAX_TABS; i++){
            if(i != 0 && getItemCountForTab(i) > 0){
                available++;
            }
        }
        return available;
    }
    /**
     *
     * @return int of all empty/available bank tabs
     */
    public int getEmptyBankTabs() {
        int available = 0;
        for(int i = 0; i < MAX_TABS; i++){
            if(i != 0 && getItemCountForTab(i) > 0){
                available++;
            }
        }
        return MAX_TABS - available;
    }
    /**
     *
     * @return Item[] of all items in that has been sorted.
     */
    public Item[] getAllBankItems(){
        final RS2InterfaceChild CHILD = getChild(PARENT_ID, CHILD_ONE_ID);
        if(CHILD != null){
            final Item[] ITEM_ARRAY = client.getInterface(PARENT_ID).getItems(CHILD_ONE_ID);
            if(ITEM_ARRAY != null && ITEM_ARRAY.length > 0){
                List<Item> sortedList = new ArrayList<>();
                //Add last part first
                for(int i = 0; i < ITEM_ARRAY.length; i++){
                    if(i > getAllTabItemCount()){
                        sortedList.add(ITEM_ARRAY[i]);
                    }
                }
                //Then the rest
                for(int i = 0; i < ITEM_ARRAY.length; i++){
                    if(i <= getAllTabItemCount()){
                        sortedList.add(ITEM_ARRAY[i]);
                    }
                }
                return sortedList.toArray(new Item[sortedList.size()]);
            }
        }
        return null;
    }

    /**
     *
     * @param name Name of item you wish to get.
     * @return Item in the bank that corresponds to the name given.
     */
    public Item getBankItem(String name){
        return getBankItem(name, -1);
    }
    /**
     *
     * @param id Id of item you wish to get.
     * @return Item in the bank that corresponds to the Id given.
     */
    public Item getBankItem(int id){
        return getBankItem(null, id);
    }

    /**
     *
     * @param name name of the item you wish to withdraw.
     * @param amount the amount of the item you want to withdraw.
     * @return  true if withdrew successfully, false if doesn't contain or failed
     * @throws InterruptedException
     */
    public boolean withdraw(String name, int amount) throws InterruptedException  {
        return withdraw(-1, name, amount);
    }
    /**
     *
     * @param id Id of the item you wish to withdraw.
     * @param amount the amount of the item you want to withdraw.
     * @return  true if withdrew successfully, false if doesn't contain or failed
     * @throws InterruptedException
     */
    public boolean withdraw(int id, int amount) throws InterruptedException  {
        return withdraw(id, null, amount);
    }

    /**
     *
     * @param name Name of item you wish to get slot for.
     * @return int of slot that corresponds to item.
     */
    public int getSlotForItem(String name) {
        return getSlotForItem(-1, name);
    }

    /**
     *
     * @param id Id of item you wish to get slot for.
     * @return int of slot that corresponds to item.
     */
    public int getSlotForItem(int id) {
        return getSlotForItem(id, null);
    }

    /**
     *
     * @param slot Slot you wish to get destination for.
     * @return MouseDestination of desired slot.
     */
    public MouseDestination getSlotDestination(int slot){
        return new RectangleDestination(getSlotRectangle(slot));
    }

    /**
     *
     * @param slot The slot you wish to scroll too
     * @throws InterruptedException
     */
    public void scrollToSlot(int slot) throws InterruptedException{
        int row = slot > 6 ? slot / 6 : 0;
        final int x = 482,
                y = 82 + (int) (row * 3.5D),
                width = 15,
                height = 10;
        bot.getMouse().moveMouseTo(new RectangleDestination(x, y, width, height), false, true, false);
        bot.getAPI().sleep(MethodProvider.gRandom(400, 100));
    }

    //END: Public methods
    //------------------------------------------------------------------------
    //START: Private methods

    private boolean rightClickBankItem(String name, int id) throws InterruptedException {
        final MouseDestination DESTINATION;
        DESTINATION = name == null ? getSlotDestination(getSlotForItem(id)) : getSlotDestination(getSlotForItem(name));
        if(DESTINATION != null){
            if(client.moveMouseTo(DESTINATION, false, true, true)){
                bot.getAPI().sleep(MethodProvider.gRandom(350, 100));
            }
        }
        return client.isMenuOpen();
    }

    private boolean contains(int id, String name) {
        Item[] items = getAllBankItems();
        if (items != null && items.length > 0) {
            for (Item i : items) {
                if (i != null && i.getId() > 0 && (id > 0 && i.getId() == id ||
                        (name != null && i.getName().equalsIgnoreCase(name)))){
                    return true;
                }
            }
        }
        return false;
    }

    private int[] namesToIds(String... itemNames){
        List<Integer> intList = new ArrayList<>();
        int[] intArray = null;
        for(String name : itemNames){
            if(client.getInventory().contains(name)){
                intList.add(client.getInventory().getItemForName(name).getId());
            }
        }
        if(!intList.isEmpty()){
            intArray = new int[intList.size()];
            for(int i = 0; i < intList.size(); i++){
                intArray[i] = intList.get(i);
            }
        }
        return intArray;
    }
    // Needs work!
    private boolean withdraw(final int id, final String name, final int amount) throws InterruptedException {
        if(contains(id)){
            final int TAB = name == null ? getTabForItem(id) : getTabForItem(name);
            if(TAB > 0 && getCurrentTab() != TAB){
                return openBankTab(TAB);
            }  else {
                final int SLOT = name == null ? getSlotForItem(id) : getSlotForItem(name);
                if(!needToScroll(SLOT)){
                    if(amount > 0 && amount < 5){
                        final MouseDestination DESTINATION = getSlotDestination(SLOT);
                        if(DESTINATION != null){
                            for(int i = 0; i < amount; i++){
                                client.moveMouseTo(DESTINATION, false, true, false);
                                bot.getAPI().sleep(MethodProvider.gRandom(400, 100));
                            }
                        }
                    } else if (rightClickBankItem(id)) {
                        if(client.isMenuOpen()) {
                            final Menu MENU = Menu.getActiveMenu(client);
                            if(MENU != null){
                                if(MENU.hasOption("Withdraw-" + amount)){
                                    if(MENU.moveMouseToOption("Withdraw-" + amount, true)){
                                        return new ConditionalSleep(2000) {
                                            @Override
                                            public boolean condition() throws InterruptedException {
                                                return client.getInventory().getAmount(id) >= amount;
                                            }
                                        }.sleep();
                                    }
                                } else if(MENU.moveMouseToOption("Withdraw-X", true)){
                                    new ConditionalSleep(2000) {
                                        @Override
                                        public boolean condition() throws InterruptedException {
                                            return isInterfaceOpen(CHAT_PARENT_ID, CHAT_CHILD_ID);
                                        }
                                    }.sleep();
                                    if(isInterfaceOpen(CHAT_PARENT_ID, CHAT_CHILD_ID)){
                                        client.typeString(amount + "");
                                        bot.getAPI().sleep(MethodProvider.gRandom(400, 200));
                                    }
                                } else if(MENU.hasOption("Cancel")){
                                    if(MENU.moveMouseToOption("Cancel", true)){
                                        new ConditionalSleep(2000) {
                                            @Override
                                            public boolean condition() throws InterruptedException {
                                                return !client.isMenuOpen();
                                            }
                                        }.sleep();
                                    }
                                }
                            }
                        }
                    }
                } else {
                    scrollToSlot(SLOT);
                    return true;
                }
            }
        }
        return false;
    }

    private RS2InterfaceChild getChild(int parent, int child) {
        if (client.getInterface(parent) != null) {
            RS2InterfaceChild c = client.getInterface(parent).getChild(child);
            if (c != null && c.isVisible()) {
                return c;
            }
        }
        return null;
    }

    private boolean scrollToItem(String name, int id) throws InterruptedException {
        if(isOpen()){
            final Item item = name != null ? getBankItem(name) : getBankItem(id);
            if(item != null){
                final int slot = name != null ? getSlotForItem(name) : getSlotForItem(id);
                if(slot >= 0){
                    scrollToSlot(slot);
                }
            }
        }
        return false;
    }

    private int getFormulatedCount(int config, int factor){
        final int tab1 = (client.getConfig(config)%(1024*1024))%1024;
        final int tab2 = ((client.getConfig(config)%(1024*1024)) - tab1)/1024;
        final int tab3 = (client.getConfig(config) - tab2 - tab1)/(1024*1024);
        if(factor == 1){
            return tab1;
        }  if(factor == 2){
            return tab2;
        } else {
            return tab3;
        }
    }

    private RectangleDestination generateTabDestination(int tab){
        final Rectangle rectangle = new Rectangle(TAB_START_X + (tab * TAB_WIDTH), TAB_START_Y, TAB_WIDTH, TAB_HEIGHT);
        return new RectangleDestination(rectangle);
    }


    private Item getBankItem(String name, int id){
        final Item[] ITEMS = getAllBankItems();
        if(ITEMS != null){
            for(Item item : ITEMS){
                if(item != null && ((id > 0 && item.getId() == id) || (name != null && item.getName().equalsIgnoreCase(name)))){
                    return item;
                }
            }
        }
        return null;
    }


    private int getTabForItem(int id, String name){
        if(getOpenBankTabs() > 0){
            for(int i = getOpenBankTabs(); i >= 0; i--){
                final Item[] ITEMS = getItemsInTab(i);
                if(ITEMS != null){
                    for(Item item : ITEMS){
                        if(item != null && (id > 0 && item.getId() == id ||
                                (name != null && item.getName().equalsIgnoreCase(name)))){
                            return i;

                        }
                    }
                }
            }
        } else {
            return 0;
        }
        return -1;
    }


    private int getSlotForItem(int id, String name) {
        if (isOpen()) {
            final Item[] ARRAY = (getCurrentTab() > 0 && getOpenBankTabs() > 0) ? getItemsInTab(getCurrentTab()) : getAllBankItems();
            if(ARRAY != null){
                for (int i = 0; i < ARRAY.length; i++) {
                    if (ARRAY[i] != null) {
                        if (ARRAY[i].getName() != null) {
                            if ((id > -1 && ARRAY[i].getId() == id) ||
                                    (name != null && ARRAY[i].getName().equalsIgnoreCase(name))) {
                                return i;
                            }
                        }
                    }
                }
            }
        }
        return -1;
    }

    private RS2Object getClosestBankObject(){
        final List<RS2Object> objectList = bot.getAPI().closestObjectListForName("Bank booth", "Bank chest"),
                finalList = new ArrayList<>();
        if(objectList != null && !objectList.isEmpty()){
            for(RS2Object r : objectList){
                if(r != null && r.exists() && r.getDefinition() != null){
                    for(String s : r.getDefinition().getActions()){
                        if(s != null && (s.equalsIgnoreCase("Bank") || s.equalsIgnoreCase("Use"))){
                            finalList.add(r);
                        }
                    }
                }
            }
            if(!finalList.isEmpty()){
                if(finalList.size() > 1){
                    Collections.sort(finalList, new Comparator<RS2Object>() {  //Sort list based on distance
                        @Override
                        public int compare(RS2Object i1, RS2Object i2) {
                            return bot.getAPI().realDistance(i1) - bot.getAPI().realDistance(i2);
                        }
                    });
                    for(RS2Object r : finalList){
                        if(r != null && r.exists()){
                            return r;
                        }
                    }
                } else {
                    return finalList.get(0);
                }
            }
        }
        return null;
    }
    //END: Private methods
    //------------------------------------------------------------------------
}


 
Questions/Comments?:
If you see anything I messed up on, or should be improved, please let me know, but be respectful about it, we have too make keyboard warriors thinking their hot shit, yet do nothing but bash others and never give any useful resources. But please remember this class file is almost 1k lines long, most of which I typed, so there may be mistakes, so if you find one/more, let me know and I'll fix it!
Even if you have a question, free to ask me, just please refrain from asking me blatant obvious questions, or ones you did little to no research on before asking, I'm not here to spoon feed you, though I am willing to help someone is trying.
 
I really hope you guys enjoy this, and let me know what you think! smile.png

Edited by NotoriousPP
  • Like 4
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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