Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts.runecrafting.abysscrafter;
- import org.tribot.api.General;
- import org.tribot.api.Timing;
- import org.tribot.api.util.ABCUtil;
- import org.tribot.api2007.Banking;
- import org.tribot.api2007.Combat;
- import org.tribot.api2007.Game;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.Options;
- import org.tribot.api2007.types.RSItem;
- import scripts.methods.Methods;
- public class Bank {
- private Main main;
- public boolean filledPouches = false;
- public Bank(Main main) {
- setMain(main);
- }
- public void setMain(Main main) {
- this.main = main;
- }
- public Main getMain() {
- return main;
- }
- public boolean performedBankTasks() {
- getMain().println("Checking health level...");
- if(Constants.isFoodRequired()) {
- getMain().println("Food is required.");
- return false;
- }
- getMain().println("Checking for house tab...");
- if(Inventory.getCount(Constants.HOUSE_TAB) <= 0) {
- getMain().println("House tab is required.");
- return false;
- }
- if(!Inventory.isFull()) {
- return false;
- }
- getMain().println("Checked inventory amount...");
- if(!filledPouches) {
- return false;
- }
- getMain().println("Checked for pouches...");
- //Methods.performAntiBan();
- if(Game.getRunEnergy() > abc.INT_TRACKER.NEXT_RUN_AT.next()) {
- Options.setRunOn(true);
- abc.INT_TRACKER.NEXT_RUN_AT.reset();
- }
- getMain().setState(State.TELEPORTING_TO_ABYSS);
- getMain().tabBroke = false;
- return true;
- }
- public boolean attemptBankTasks() {
- if(performedBankTasks()) {
- return true;
- }
- if(openBank()) {
- int[] itemsToKeep = {
- Constants.HOUSE_TAB, Constants.ESSENCE,
- Constants.POUCHES[0], Constants.POUCHES[1], Constants.POUCHES[2], Constants.POUCHES[3],
- Constants.DAMAGED_POUCHES[0], Constants.DAMAGED_POUCHES[1], Constants.DAMAGED_POUCHES[2]
- };
- Banking.depositAllExcept(itemsToKeep);
- depositItems(Inventory.getAll().length, 1000);
- if(Constants.isFoodRequired()) {
- eatFood();
- return false;
- }
- if(Inventory.getCount(Constants.HOUSE_TAB) <= 2) {
- if(General.random(0, 1) == 1
- || Inventory.getCount(Constants.HOUSE_TAB) == 0) {
- withdrawItem(Constants.HOUSE_TAB, 20);
- }
- }
- if(!filledPouches) {
- if(!Inventory.isFull())
- withdrawItem(Constants.ESSENCE, getFreeSpace());
- if(closeBank()) {
- fillPouches();
- if(performedBankTasks()) {
- return true;
- }
- }
- }
- if(openBank()) {
- if(Inventory.isFull()) {
- Banking.depositAllExcept(itemsToKeep);
- }
- withdrawItem(Constants.ESSENCE, getFreeSpace());
- }
- return true;
- }
- return false;
- }
- public boolean openBank() {
- if(Banking.isBankScreenOpen()) {
- return true;
- }
- /*if(!Player.getPosition().equals(Locations.BANK_WALK_TILE) && !Player.isMoving())
- WebWalking.walkTo(Locations.BANK_WALK_TILE);*/
- Banking.openBank();
- General.sleep(abc.DELAY_TRACKER.ITEM_INTERACTION.next());
- abc.DELAY_TRACKER.ITEM_INTERACTION.reset();
- return isBankScreenOpen(1000);
- }
- public boolean withdrawItem(int itemId, int withdrawAmount) {
- if(openBank()) {
- getMain().sleep(250, 500);
- RSItem[] item = Banking.find(itemId);
- if(item != null && item.length > 0) {
- Banking.withdraw(withdrawAmount, itemId);
- General.sleep(abc.DELAY_TRACKER.ITEM_INTERACTION.next());
- abc.DELAY_TRACKER.ITEM_INTERACTION.reset();
- if(isWithdrawingItem(2000, itemId, Inventory.getCount(itemId))) {
- return true;
- }
- } else {
- getMain().println("Can't find: " + itemId);
- }
- }
- return false;
- }
- private boolean isEatingFood(int amt, int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i) {
- if (Inventory.getCount(getMain().getFoodId()) < amt) {
- return true;
- }
- getMain().sleep(50, 150);
- }
- return false;
- }
- private boolean depositItems(int amt, int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i) {
- if (Inventory.getAll().length < amt) {
- return true;
- }
- getMain().sleep(50, 150);
- }
- return false;
- }
- private boolean isWithdrawingItem(int i, int id, int amt) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i) {
- if (Inventory.getCount(id) > amt) {
- return true;
- }
- getMain().sleep(50, 150);
- }
- return false;
- }
- private boolean filledPouch(int amt, int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i) {
- if (Inventory.getCount(Constants.ESSENCE) < amt) {
- return true;
- }
- getMain().sleep(50, 150);
- }
- return false;
- }
- public boolean isBankScreenOpen(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i) {
- if (Banking.isBankScreenOpen()) {
- return true;
- }
- getMain().sleep(50, 150);
- }
- return false;
- }
- private int getFoodAmount() {
- return (int) Math.ceil(((Combat.getMaxHP() - Combat.getHP()) / getMain().getHealAmount()));
- }
- private boolean eatFood() {
- int foodAmt = getFoodAmount();
- if(foodAmt == 0) {
- foodAmt = 1;
- }
- getMain().println("Food Amount Needed: " + foodAmt);
- if(openBank()) {
- int[] itemsToKeep = {
- Constants.HOUSE_TAB,
- Constants.POUCHES[0], Constants.POUCHES[1], Constants.POUCHES[2], Constants.POUCHES[3],
- Constants.DAMAGED_POUCHES[0], Constants.DAMAGED_POUCHES[1], Constants.DAMAGED_POUCHES[2]
- };
- Banking.depositAllExcept(itemsToKeep);
- depositItems(Inventory.getAll().length, 1000);
- if(!withdrawItem(getMain().getFoodId(), foodAmt)) {
- RSItem[] lob = Banking.find(getMain().getFoodId());
- if(lob == null || lob.length <= 0) {
- //getMain().setEndScript(true);
- getMain().println("Out of food.");
- return false;
- }
- }
- }
- if(closeBank()) {
- int count = Inventory.getCount(getMain().getFoodId());
- while(Inventory.getCount(getMain().getFoodId()) > 0 && Constants.isFoodRequired()) {
- RSItem[] lobster = Inventory.find(getMain().getFoodId());
- if(lobster != null && lobster.length > 0) {
- lobster[0].click("Eat");
- General.sleep(abc.DELAY_TRACKER.ITEM_INTERACTION.next());
- abc.DELAY_TRACKER.ITEM_INTERACTION.reset();
- isEatingFood(Inventory.getCount(getMain().getFoodId()), 2000);
- }
- getMain().sleep(50, 150);
- }
- int eaten = count - Inventory.getCount(getMain().getFoodId());
- int previousEaten = getMain().getLobstersEaten();
- getMain().setLobstersEaten(previousEaten + eaten);
- }
- return true;
- }
- private ABCUtil abc = new ABCUtil();
- private int getFreeSpace() {
- int space = 0;
- for(int i = 0; i < Inventory.getAll().length; i++) {
- if(Inventory.getAll()[i] == null) {
- space++;
- }
- }
- return space;
- }
- private boolean closeBank() {
- while(Banking.isBankScreenOpen()) {
- Banking.close();
- getMain().sleep(50, 150);
- }
- return !Banking.isBankScreenOpen();
- }
- private void fillPouches() {
- if(Inventory.getCount(Constants.ESSENCE) > 0) {
- int essCount = Inventory.getCount(Constants.ESSENCE);
- filledPouches = true;
- RSItem[] giantPouch = Inventory.find(Constants.POUCHES[3]);
- RSItem[] largePouch = Inventory.find(Constants.POUCHES[2]);
- RSItem[] medPouch = Inventory.find(Constants.POUCHES[1]);
- RSItem[] smallPouch = Inventory.find(Constants.POUCHES[0]);
- RSItem[] damagedGiant = Inventory.find(Constants.DAMAGED_POUCHES[2]);
- RSItem[] damagedLarge = Inventory.find(Constants.DAMAGED_POUCHES[1]);
- RSItem[] damagedMed = Inventory.find(Constants.DAMAGED_POUCHES[0]);
- boolean hasGiantPouch = false;
- if(giantPouch != null && giantPouch.length > 0) {
- hasGiantPouch = true;
- fillPouch(giantPouch);
- }
- if(damagedGiant != null && damagedGiant.length > 0) {
- hasGiantPouch = true;
- fillPouch(damagedGiant);
- }
- if(largePouch != null && largePouch.length > 0) {
- fillPouch(largePouch);
- }
- if(damagedLarge != null && damagedLarge.length > 0) {
- fillPouch(damagedLarge);
- }
- if(hasGiantPouch) {
- while(!Inventory.isFull()) {
- if(openBank()) {
- withdrawItem(Constants.ESSENCE, getFreeSpace());
- closeBank();
- }
- getMain().sleep(50, 150);
- }
- }
- if(medPouch != null && medPouch.length > 0) {
- fillPouch(medPouch);
- }
- if(damagedMed != null && damagedMed.length > 0) {
- fillPouch(damagedMed);
- }
- if(smallPouch != null && smallPouch.length > 0) {
- fillPouch(smallPouch);
- }
- if(essCount == Inventory.getCount(Constants.ESSENCE)) {
- if(performedBankTasks())
- getMain().setState(State.TELEPORTING_TO_ABYSS);
- }
- }
- }
- private boolean fillPouch(RSItem[] pouch) {
- int essCount = Inventory.getCount(Constants.ESSENCE);
- if(pouch != null && pouch.length > 0) {
- pouch[0].click("Fill");
- filledPouch(essCount, 1000);
- General.sleep(abc.DELAY_TRACKER.ITEM_INTERACTION.next());
- abc.DELAY_TRACKER.ITEM_INTERACTION.reset();
- }
- return Inventory.getCount(Constants.ESSENCE) < essCount;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement