Exemplo n.º 1
0
 /**
  * @param id ID of the item you want to withdraw.
  * @param amount Amount of the item you want to withdraw.
  * @param type Withdraw type: WITHDRAW_
  */
 private void withdraw(int id, int amount, int type) {
   boolean doAction = false;
   Item item = getItem(id);
   if (isOpen() && contains(id) && item != null) {
     doAction = scrollToItem(item);
   }
   if (doAction) {
     String action = "Withdraw-" + amount;
     if (type == WITHDRAW_ALL) {
       action = "Withdraw-All";
     } else if (type == WITHDRAW_ALL_BUT_ONE) {
       action = "Withdraw-All but one";
     }
     if (item.hasAction(action)) {
       item.doAction(action);
     } else { // withdraw X
       if (item.doAction("Withdraw-X")) {
         for (int i = 0; i < random(2000, 3000); i += 50) {
           IComponent c = botEnv.interfaces.getComponent(752, 5);
           if (c != null && c.isValid() && c.isVisible()) {
             sleep(500, 1000);
             botEnv.keyboard.writeText(Integer.toString(amount), true);
             break;
           }
           sleep(50);
         }
       }
     }
   }
 }
Exemplo n.º 2
0
 /**
  * Checks how many of the specified item the bank contains.
  *
  * @param itemName Case-insensitive item name to count.
  * @return itemAmount Stack size of item in bank.
  */
 public int getCount(String itemName) {
   if (!isOpen()) return 0;
   for (Item item : getItems()) {
     if (item == null) continue;
     else if (item.getName().equalsIgnoreCase(itemName)) return item.getStackSize();
   }
   return 0;
 }
Exemplo n.º 3
0
 /**
  * Checks how many of the specified item the bank contains.
  *
  * @param itemID ID of the item to count.
  * @return itemAmount Stack size of item in bank.
  */
 public int getCount(int itemID) {
   if (!isOpen()) return 0;
   for (Item item : getItems()) {
     if (item == null) continue;
     if (item.getID() == itemID) return item.getStackSize();
   }
   return 0;
 }
Exemplo n.º 4
0
 /**
  * Gets the Item for a specified item ID.
  *
  * @param itemID Item ID to look for.
  * @return Object of type Item with the specified ID.
  */
 public Item getItem(int itemID) {
   if (!isOpen()) return null;
   for (Item item : getItems()) {
     if (item == null) {
       continue;
     }
     if (item.getID() == itemID) {
       return item;
     }
   }
   return null;
 }
Exemplo n.º 5
0
 /**
  * Gets the Item for a specified item name.
  *
  * @param itemName Case-insensitive item name to look for.
  * @return Object of type Item with the specified name.
  */
 public Item getItem(String itemName) {
   if (!isOpen()) return null;
   for (Item item : getItems()) {
     if (item == null) {
       continue;
     }
     if (item.getName().equalsIgnoreCase(itemName)) {
       return item;
     }
   }
   return null;
 }
Exemplo n.º 6
0
 /**
  * Checks if the bank contains any of the given items identified by their IDs.
  *
  * @param IDs The item IDs to check for.
  * @return True if any of the specified items are found.
  */
 public boolean contains(int... IDs) {
   Item[] items = getItems();
   for (Item item : items) {
     if (item != null) {
       for (int ID : IDs) {
         if (item.getID() == ID) {
           return true;
         }
       }
     }
   }
   return false;
 }
Exemplo n.º 7
0
 /**
  * Checks if the bank contains any of the given items.
  *
  * @param names Item names. Must be exact (case ignored).
  * @return Whether or not the bank contains the specified item(s).
  */
 public boolean contains(String... names) {
   Item[] items = getItems();
   for (Item item : items) {
     if (item == null) {
       continue;
     }
     for (String name : names) {
       if (item.getName().equalsIgnoreCase(name)) {
         return true;
       }
     }
   }
   return false;
 }
Exemplo n.º 8
0
 /**
  * Deposits all of the specified item in the inventory.
  *
  * @param itemID Name of item to be deposited.
  * @return Whether or not the items were deposited.
  */
 public boolean depositAll(int itemID) {
   if (!isOpen() || botEnv.inventory.getItems().length == 0) {
     return false;
   }
   int count = 0;
   for (Item it : botEnv.inventory.getItems()) {
     if (it.getID() == itemID) {
       count++;
       it.doAction("Deposit-all");
       sleep(100, 200);
     }
     if (botEnv.inventory.getCount(false, itemID) == 0) {
       break;
     }
   }
   return count != 0;
 }
Exemplo n.º 9
0
 /**
  * Deposits all of the specified item in the inventory.
  *
  * @param itemName Name of item to be deposited.
  * @return Whether or not the items were deposited.
  */
 public boolean depositAll(String itemName) {
   if (!isOpen()) {
     return false;
   }
   int count = 0;
   for (Item it : botEnv.inventory.getItems()) {
     if (it.getName().contains(itemName)) {
       count++;
       it.doAction("Deposit-all");
       sleep(100, 200);
     }
     if (botEnv.inventory.getCount(false, itemName) == 0) {
       break;
     }
   }
   return count != 0;
 }
Exemplo n.º 10
0
  /**
   * Deposits all the items excluding the specified IDs.
   *
   * @param ids Item IDs not to deposit.
   * @return Whether or not the deposit was successful.
   * @author Ampzz
   */
  public boolean depositAllExcept(int... ids) {

    if (!isOpen()) return false;

    Item[] allItems = botEnv.inventory.getItems();
    if (allItems.length == 0) return false;

    ArrayList<Item> possItems = new ArrayList<Item>();

    for (Item iItem : allItems) {
      boolean add = true;

      for (int id : ids) {
        if (iItem.getID() == id) add = false;
      }

      if (possItems.size() > 0 && add) {
        for (Item kItem : possItems) {
          if (kItem.getID() == iItem.getID()) add = false;
        }
      }

      if (add) possItems.add(iItem);
    }

    if (possItems.size() == 0) return true;

    for (Item jItem : possItems) {
      jItem.doAction("Deposit-all");
      sleep(300, 700);
    }

    return true;
  }
Exemplo n.º 11
0
 public boolean scrollToItem(Item i) {
   Interface bankInterface = botEnv.interfaces.getInterface(Bank.BANK_INTERFACE_ID);
   IComponent itemContainer = bankInterface.getComponent(Bank.BANK_ITEM_PANE_ID);
   if (!i.container.isElementVisible()) {
     bankInterface.getComponent(62).doClick();
     sleep(500, 1000);
   }
   /*if (bankInterface.getComponent(61).getTextureID() != 1419 && (itemContainer.getBounds().getLocation().equals(i.getBounds().getLocation()) ||
           i.container.getRelativeX() == 0 && i.container.getRelativeY() == 0)) {
       bankInterface.getComponent(62).doClick();
       sleep(500, 1000);
   }   */
   if (itemContainer.getBounds().contains(i.getCenter())) {
     return true;
   }
   IComponent arrow;
   if (i.getCenter().getY() < itemContainer.getAbsoluteY()) {
     arrow = bankInterface.getComponent(114).getChildren()[4];
   } else {
     arrow = bankInterface.getComponent(114).getChildren()[5];
   }
   Point p = botEnv.mouse.getMousePos();
   if (!arrow.getBounds().contains(p)) {
     botEnv.mouse.moveMouse(arrow.getBounds());
   }
   EventFactory eventFactory = new EventFactory(botEnv);
   p = botEnv.mouse.getMousePos();
   MouseEvent mouseEvent = eventFactory.createMousePress(p.x, p.y, true);
   botEnv.dispatchEvent(mouseEvent);
   KTimer timeout = new KTimer(random(5000, 6000));
   while (!itemContainer.getBounds().contains(i.getCenter()) && !timeout.isDone()) {
     sleep(200, 500);
   }
   mouseEvent = eventFactory.createMouseRelease(p.x, p.y, true);
   botEnv.dispatchEvent(mouseEvent);
   mouseEvent = eventFactory.createMouseClicked(p.x, p.y, true);
   botEnv.dispatchEvent(mouseEvent);
   return itemContainer.getBounds().contains(i.getCenter());
 }
Exemplo n.º 12
0
 /**
  * Gets an item array of all the bank items.
  *
  * @return Array of bank items.
  */
 public Item[] getItems() {
   Interfaces interfaces = botEnv.interfaces;
   Interface inventoryInterface = interfaces.getInterface(BANK_INTERFACE_ID);
   if (inventoryInterface == null) {
     return new Item[0];
   }
   IComponent inventoryPane = inventoryInterface.getComponent(BANK_ITEM_PANE_ID);
   IComponent[] children = inventoryPane.getChildren();
   if (children == null || children.length == 0) {
     return new Item[0];
   }
   List<Item> items = new ArrayList<Item>();
   for (IComponent aChildren : children) {
     if (aChildren == null) {
       continue;
     }
     Item item = new Item(botEnv, aChildren);
     if (item.getID() == -1) {
       continue;
     }
     items.add(item);
   }
   return items.toArray(new Item[items.size()]);
 }