Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts.clues;
- import org.tribot.api.General;
- import org.tribot.api.Timing;
- import org.tribot.api.types.generic.Condition;
- import org.tribot.api.util.ABCUtil;
- import org.tribot.api2007.Banking;
- import org.tribot.api2007.Equipment;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.Player;
- import org.tribot.api2007.WebWalking;
- import org.tribot.api2007.types.RSArea;
- import org.tribot.api2007.types.RSItem;
- import org.tribot.api2007.types.RSTile;
- import scripts.clues.types.EmoteClue;
- import scripts.clues.types.TeleportLocation;
- import scripts.clues.types.TeleportMethod;
- import scripts.methods.Item;
- import scripts.methods.Methods;
- public class Bank {
- private Main main;
- private boolean bankTeleport = false;
- private int tries = 0;
- private long last_busy_time = System.currentTimeMillis();
- private final ABCUtil abc = new ABCUtil();
- public Bank(Main main) {
- setMain(main);
- }
- public boolean openBank() {
- getMain().getEquipped().checkEquipment();
- if(Banking.isBankScreenOpen()) {
- return true;
- }
- getMain().setStatus("Opening Bank");
- abc.waitNewOrSwitchDelay(last_busy_time, false);
- Banking.openBank();
- last_busy_time = System.currentTimeMillis();
- return Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return Banking.isBankScreenOpen();
- }
- }, General.random(4000, 6000));
- }
- public boolean withdrawBankItem(int id, int amount) {
- Item i = Methods.getData(id);
- int inventoryAmount = Inventory.getCount(id);
- if(inventoryAmount < amount && Banking.isBankScreenOpen()) {
- abc.waitNewOrSwitchDelay(last_busy_time, false);
- RSItem[] item = Banking.find(id);
- if(item.length <= 0) {
- getMain().println("Cannot find " + i.getName() + ".");
- getMain().setEndScript(true);
- return false;
- }
- getMain().setStatus("Withdrawing " + i.getName());
- General.sleep(abc.DELAY_TRACKER.ITEM_INTERACTION.next());
- abc.DELAY_TRACKER.ITEM_INTERACTION.reset();
- Banking.withdraw(amount, id);
- if(Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return Inventory.getCount(id) > inventoryAmount;
- }
- }, General.random(2000, 4000))) {
- return true;
- }
- }
- return Inventory.getCount(id) >= amount;
- }
- public boolean withdrawBankItem(String id, int amount) {
- int inventoryAmount = Inventory.getCount(id);
- if(inventoryAmount < amount && Banking.isBankScreenOpen()) {
- abc.waitNewOrSwitchDelay(last_busy_time, false);
- RSItem[] item = Banking.find(id);
- if(item.length <= 0) {
- getMain().println("Cannot find " + id + ".");
- getMain().setEndScript(true);
- return false;
- }
- getMain().setStatus("Withdrawing " + id);
- General.sleep(abc.DELAY_TRACKER.ITEM_INTERACTION.next());
- abc.DELAY_TRACKER.ITEM_INTERACTION.reset();
- Banking.withdraw(amount, id);
- if(Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return Inventory.getCount(id) > inventoryAmount;
- }
- }, General.random(2000, 4000))) {
- return true;
- }
- }
- return Inventory.getCount(id) >= amount;
- }
- public boolean withdrawRequiredEquipment(String[] reqItems) {
- getMain().setStatus("Depositing Items");
- Banking.depositAllExcept(getRequiredInventoryItems());
- boolean[] hasItems = new boolean[reqItems.length];
- for(int i = 0; i < reqItems.length; i++) {
- hasItems[i] = Inventory.getCount(reqItems[i]) > 0
- || Equipment.isEquipped(reqItems[i]);
- }
- for(int i = 0; i < hasItems.length; i++) {
- hasItems[i] = withdrawBankItem(reqItems[i], 1);
- }
- for(boolean b : hasItems) {
- if(!b)
- return false;
- }
- return true;
- }
- public boolean withdrawTabs() {
- boolean hasVar = withdrawBankItem(Constants.VARROCK_TAB_ID, 20);
- boolean hasLum = withdrawBankItem(Constants.LUMBRIDGE_TAB_ID, 20);
- boolean hasFal = withdrawBankItem(Constants.FALADOR_TAB_ID, 20);
- boolean hasCam = withdrawBankItem(Constants.CAMELOT_TAB_ID, 20);
- return hasVar && hasLum && hasFal && hasCam;
- }
- public boolean withdrawRunes() {
- boolean hasLaw = withdrawBankItem(Constants.LAW_RUNE_ID, 100);
- boolean hasAir = withdrawBankItem(Constants.AIR_RUNE_ID, 300);
- boolean hasWater = withdrawBankItem(Constants.WATER_RUNE_ID, 100);
- boolean hasEarth = withdrawBankItem(Constants.EARTH_RUNE_ID, 100);
- boolean hasFire = withdrawBankItem(Constants.FIRE_RUNE_ID, 100);
- return hasLaw && hasAir && hasWater && hasEarth && hasFire;
- }
- public boolean canPerform() {
- boolean hasRing = Inventory.getCount(Constants.DUEL_RING_ID) > 0
- || Equipment.isEquipped(Constants.DUEL_RING_ID);
- boolean hasNecklace = Inventory.getCount(Constants.GAMES_NECKLACE_ID) > 0
- || Equipment.isEquipped(Constants.GAMES_NECKLACE_ID);
- boolean hasRunes = Inventory.getCount(Constants.LAW_RUNE_ID) > 3
- && Inventory.getCount(Constants.AIR_RUNE_ID) > 10
- && Inventory.getCount(Constants.WATER_RUNE_ID) > 10
- && Inventory.getCount(Constants.EARTH_RUNE_ID) > 10
- && Inventory.getCount(Constants.FIRE_RUNE_ID) > 10;
- boolean hasTabs = Inventory.getCount(Constants.VARROCK_TAB_ID) >= 3
- && Inventory.getCount(Constants.LUMBRIDGE_TAB_ID) >= 3
- && Inventory.getCount(Constants.CAMELOT_TAB_ID) >= 3
- && Inventory.getCount(Constants.FALADOR_TAB_ID) >= 3;
- boolean teleports = getMain().getTeleportMethod().equals(TeleportMethod.TABS)
- ? hasTabs : hasRunes;
- boolean hasFood = getMain().getFoodAmount() > 0
- ? Inventory.getCount(getMain().getFoodName()) >= 2 : true;
- boolean hasSpade = Inventory.getCount(Constants.SPADE) >= 0;
- return hasRing && hasNecklace && teleports && hasFood && hasSpade;
- }
- public boolean performBankTask() {
- getMain().setStatus("Depositing Items");
- Banking.depositAllExcept(getRequiredInventoryItems());
- if(getMain().getFoodName().equals("Trout"))
- depositNotedTrout(); //Deposit noted trout if we are using trout as food
- boolean teleports = getMain().getTeleportMethod().equals(TeleportMethod.TABS)
- ? withdrawTabs() : withdrawRunes();
- boolean ring = Inventory.getCount(Constants.DUEL_RING_ID) > 0
- || Equipment.isEquipped(Constants.DUEL_RING_ID);
- boolean necklace = Inventory.getCount(Constants.DUEL_RING_ID) > 0
- || Equipment.isEquipped(Constants.DUEL_RING_ID);
- boolean spade = Inventory.getCount(Constants.SPADE) > 0;
- boolean food = true;
- if(!ring)
- ring = withdrawBankItem(Constants.DUEL_RING_ID[0], 1);
- if(!necklace)
- necklace = withdrawBankItem(Constants.GAMES_NECKLACE_ID[0], 1);
- if(!spade)
- spade = withdrawBankItem(Constants.SPADE, 1);
- if(getMain().getFoodAmount() > 0) {
- if(Inventory.getCount(getMain().getFoodName()) <= 3) {
- food = withdrawBankItem(getMain().getFoodName(), getMain().getFoodAmount());
- }
- }
- checkForClue();
- return teleports && ring && necklace && spade && food;
- }
- public boolean bankForEquipment(ClueTask task, String[] requiredItems) {
- if(!getMain().getClueScroll().isEmoteTeleport()) {
- TeleportLocation loc = task.getTeleLocation();
- RSTile walk = task.getEmoteClue().getWalkLocation();
- RSArea teleArea = !getMain().getBank().isBankAtLocation(loc) ? TeleportLocation.FALADOR.getArea() : task.getTeleLocationArea();
- int dist = teleArea.getRandomTile().distanceTo(Player.getPosition());
- int walkDist = walk.distanceTo(Player.getPosition());
- if(dist > walkDist && Player.getPosition().getPlane() == 0 && !Locations.inHamDungeon() && walkDist < 100) {
- getMain().println("Teleport Distance("+dist+") is greater than the Walking Distance("+walkDist+").");
- getMain().getClueScroll().setEmoteTeleport(true);
- return false;
- }
- if(dist > 50) {
- if(!getMain().getBank().isBankAtLocation(loc))
- getMain().getTeleporting().teleportTo(TeleportLocation.FALADOR);
- else {
- getMain().getTeleporting().teleportTo(loc);
- getMain().getClueScroll().setTeleported(true);
- }
- getMain().getClueScroll().setEmoteTeleport(true);
- }
- }
- checkPlane();
- if(!requiredItems[0].equals("")) {
- if(Banking.openBank()) {
- if((!getMain().getClueScroll().hasAllItems(task) && Banking.isBankScreenOpen())) {
- getMain().setStatus("Withdrawing Required Equipment");
- getMain().getBank().withdrawRequiredEquipment(requiredItems);
- }
- } else if(!Banking.isInBank()) {
- getMain().setStatus("Walking to Bank");
- WebWalking.walkToBank();
- }
- if(Banking.isBankScreenOpen()) {
- Banking.close();
- }
- }
- return Inventory.getCount(requiredItems) >= requiredItems.length;
- }
- public boolean checkPlane() {
- if(Player.getPosition().getPlane() > 0
- && !Locations.LUMBRIDGE_CASLTE_SECOND_FLOOR.contains(Player.getPosition())) {
- if(getMain().getClueScroll().tooManyTries(tries)) {
- tries = 0;
- getMain().getTeleporting().teleportTo(TeleportLocation.FALADOR);
- return true;
- }
- tries++;
- abc.waitNewOrSwitchDelay(last_busy_time, false);
- getMain().getClueScroll().climb(false);
- last_busy_time = System.currentTimeMillis();
- return true;
- }
- return false;
- }
- public String[] getRequiredInventoryItems() {
- String[] invItems = Constants.INVENTORY_ITEMS;
- String[] teleports = getMain().getTeleportMethod().equals(TeleportMethod.TABS)
- ? Constants.TABS : Constants.RUNES;
- String[] reqItems = new String[4];
- String[] equipment = new String[getMain().getEquipped().getPlayerEquipment().size()];
- String[] items = new String[invItems.length + reqItems.length + equipment.length + Constants.RUNES.length + Constants.EMOTE_EQUIPMENT.length + 10];
- int index = 0;
- int eIndex = 0;
- int tIndex = 0;
- //set equipment array
- for(int i = 0; i < equipment.length; i++) {
- equipment[i] = getMain().getEquipped().getPlayerEquipment().get(i);
- }
- //add inventory items to array
- for(int i = 0; i < invItems.length; i++) {
- items[i] = invItems[i];
- index = i;
- }
- index++;
- // add food to array
- items[index] = getMain().getFoodName();
- index++;
- // add teleports to array
- int start = index;
- for(int i = start; i < start + teleports.length; i++) {
- items[i] = teleports[tIndex++];
- index = i;
- }
- index++;
- //add start equipment to array
- start = index;
- for(int i = start; i < start + equipment.length; i++) {
- if(!Equipment.isEquipped(equipment[eIndex])) {
- items[i] = equipment[eIndex];
- }
- eIndex++;
- index = i;
- }
- index++;
- //add emote equipment to array
- if(getMain().getClueTask() != null) {
- EmoteClue e = getMain().getClueTask().getEmoteClue();
- if(e != null) {
- int length = e.getItems().length;
- int reqIndex = 0;
- start = index;
- for(int i = start; i < start + length; i++) {
- items[i] = e.getItems()[reqIndex++];
- index = i;
- }
- }
- return items;
- }
- return items;
- }
- public boolean checkForClue() {
- if(!getMain().getClueScroll().hasClue()) {
- if(withdrawBankItem("Clue scroll (easy)", 1)) {
- return true;
- }
- }
- if(!getMain().getClueScroll().hasCasket()) {
- if(withdrawBankItem("Casket (easy)", 1)) {
- return true;
- }
- }
- return false;
- }
- public boolean depositNotedTrout() {
- if(Banking.isBankScreenOpen()) {
- RSItem[] trout = Inventory.find(334);
- if(trout.length > 0) {
- if(trout[0].click("Deposit-All")) {
- return true;
- }
- }
- }
- return false;
- }
- public boolean isBankAtLocation(TeleportLocation loc) {
- switch(loc) {
- case BURTHORPE:
- case LUMBRIDGE:
- return false;
- case DUELARENA:
- case ARDOUGNE:
- case CAMELOT:
- case CASTLEWARS:
- case FALADOR:
- case VARROCK:
- return true;
- }
- return false;
- }
- public boolean isInBank() {
- for (BankLocation bank : BankLocation.values())
- if (bank.contains(Player.getPosition()))
- return true;
- return false;
- }
- public int getClosestBankDistance() {
- int distance = 500;
- for (BankLocation bank : BankLocation.values()) {
- if(bank.distanceTo(Player.getPosition()) < distance)
- distance = bank.distanceTo(Player.getPosition());
- }
- return distance;
- }
- public enum BankLocation {
- CASTLE_WARS(new RSArea(new RSTile(2443, 3082, 0), new RSTile(2441, 3085, 0))),
- LUMBRIDGE(new RSArea(new RSTile(3210, 3216, 2), new RSTile(3207, 3220, 2))),
- DRAYNOR(new RSArea(new RSTile(3092, 3246, 0), new RSTile(3095, 3240, 0))),
- VARROCK_EAST(new RSArea(new RSTile(3257, 3419, 0), new RSTile(3250, 3423, 0))),
- VARROCK_WEST(new RSArea(new RSTile(3185, 3433, 0), new RSTile(3180, 3447, 0))),
- GRAND_EXCHANGE(new RSArea(new RSTile[] {
- new RSTile(3170, 3495, 0),
- new RSTile(3159, 3495, 0),
- new RSTile(3159, 3485, 0),
- new RSTile(3170, 3485, 0)
- })),
- PORT_SARIM(new RSArea(new RSTile(3047, 3233, 0), new RSTile(3042, 3238, 0))),
- FALADOR_EAST(new RSArea(new RSTile(3018, 3355, 0), new RSTile(3009, 3358, 0))),
- FALADOR_WEST(new RSArea(new RSTile[]{new RSTile(2949, 3368, 0),
- new RSTile(2949, 3369, 0),
- new RSTile(2948, 3369, 0),
- new RSTile(2947, 3373, 0),
- new RSTile(2943, 3373, 0),
- new RSTile(2943, 3368, 0)
- })),
- AL_KHARID(new RSArea(new RSTile(3272, 3162, 0), new RSTile(3269, 3171, 0))),
- EDGEVILLE(new RSArea(new RSTile[]{
- new RSTile(3094, 3488, 0),
- new RSTile(3091, 3488, 0),
- new RSTile(3091, 3494, 0),
- new RSTile(3094, 3498, 0),
- new RSTile(3098, 3498, 0),
- new RSTile(3099, 3494, 0),
- new RSTile(3095, 3494, 0)
- })),
- CATHERBY(new RSArea(new RSTile(2812, 3441, 0), new RSTile(2806, 3438, 0))),
- SEERS_VILLAGE(new RSArea(new RSTile(2730, 3493, 0), new RSTile(2721, 3490, 0)));
- private RSArea area;
- BankLocation(RSArea area) {
- this.area = area;
- }
- public RSArea getArea() {
- return area;
- }
- public boolean contains(RSTile tile) {
- return getArea().contains(tile);
- }
- public int distanceTo(RSTile tile) {
- return getArea().getRandomTile().distanceTo(tile);
- }
- }
- public Main getMain() {
- return main;
- }
- public void setMain(Main main) {
- this.main = main;
- }
- public boolean isBankTeleport() {
- return bankTeleport;
- }
- public void setBankTeleport(boolean bankTeleport) {
- this.bankTeleport = bankTeleport;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement