Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts.moneymaking.iplankfarmer.banking;
- import org.tribot.api.General;
- import org.tribot.api.Timing;
- import org.tribot.api.input.Mouse;
- import org.tribot.api2007.Banking;
- import org.tribot.api2007.Camera;
- import org.tribot.api2007.Equipment;
- import org.tribot.api2007.Game;
- import org.tribot.api2007.Equipment.SLOTS;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.Player;
- import org.tribot.api2007.WebWalking;
- import org.tribot.api2007.types.RSItem;
- import org.tribot.api2007.types.RSObject;
- import scripts.methods.Methods;
- import scripts.moneymaking.iplankfarmer.Script;
- import scripts.moneymaking.iplankfarmer.types.EnergyPotion;
- import scripts.moneymaking.iplankfarmer.types.Plank;
- import scripts.moneymaking.iplankfarmer.types.ScriptTask;
- import scripts.moneymaking.iplankfarmer.types.State;
- import scripts.moneymaking.iplankfarmer.utils.Constants;
- import scripts.moneymaking.iplankfarmer.utils.Locations;
- public class Bank {
- private Script script;
- public Bank(Script script) {
- setScript(script);
- }
- public void setScript(Script script) {
- this.script = script;
- }
- public Script getScript() {
- return script;
- }
- private int logAmount = 0;
- private boolean drankPotions = false;
- public boolean drankPotions() {
- return drankPotions;
- }
- public void setDrankPotions(boolean drankPotions) {
- this.drankPotions = drankPotions;
- }
- public boolean performBankTask() {
- getScript().setState(State.BANKING);
- getScript().getData().getTripInformation();
- getScript().getData().setTimeout(System.currentTimeMillis());
- getScript().getPotions().setPotionDrank(0);
- while((Locations.isInsideBank() || Locations.isInsideCastleWars()) && !getScript().getData().isTimedOut(10000, 15000)) {
- if(getScript().isEndScript()) {
- return false;
- }
- getScript().println("Performing Bank Task");
- if(Locations.isInsideCastleWars()) {
- if(Methods.distanceTo(getScript(), Locations.CASTLE_WARS_TILE) > 4) {
- WebWalking.walkToBank();
- Methods.performAntiBan(getScript());
- getScript().getData().checkPlayerRun();
- }
- }
- if(openBankScreen()) {
- depositItems();
- final Plank PLANK = getScript().getPlank();
- final ScriptTask TASK = getScript().getTask();
- if(TASK.equals(ScriptTask.CHOP_LOGS)) {
- RSItem[] ring = Equipment.find(SLOTS.RING);
- if(ring == null || ring.length <= 0) {
- if(getScript().getDuelRing().withdraw()) {
- Banking.close();
- getScript().getDuelRing().equip();
- }
- }
- }
- if(TASK.equals(ScriptTask.CHOP_AND_PLANK) && PLANK.equals(Plank.TEAK)) {
- if(!Locations.isInsideCastleWars()) {
- int logAmount = getLogAmount();
- while(logAmount < 20 && !Locations.isInsideCastleWars()) {
- if(getScript().getDuelRing().isWearing()) {
- Banking.close();
- getScript().getDuelRing().rub();
- } else if(getScript().getDuelRing().withdraw()) {
- Banking.close();
- getScript().getDuelRing().equip();
- getScript().getDuelRing().rub();
- }
- }
- } else {
- getScript().println("TEAK CHOP AND PLANK: VARROC BANK DUEL RING");
- RSItem[] ring = Equipment.find(SLOTS.RING);
- if(ring == null || ring.length <= 0) {
- getScript().getVarrockTab().withdraw();
- }
- }
- }
- if(!getScript().getEnergyPotion().equals(EnergyPotion.NONE)) {
- if(!drankPotions) {
- getScript().getPotions().handleEnergyPotions();
- }
- }
- withdrawRequiredItems();
- if(!isFinished()) {
- int logAmount = Inventory.getCount(getScript().getPlank().getLogId());
- if(Inventory.getCount(995) < (logAmount * getScript().getPlank().getPricePerPlank())) {
- withdrawMoney();
- isMoneyWithdrawn(1000);
- }
- }
- }
- if(isFinished()) {
- drankPotions = false;
- getScript().setState(State.WALKING_TO_TREE);
- return true;
- }
- }
- return false;
- }
- private int getLogAmount() {
- final Plank PLANK = getScript().getPlank();
- final int LOG_ID = PLANK.getLogId();
- RSItem[] logs = Banking.find(LOG_ID);
- if(logs != null && logs.length > 0) {
- return logs[0].getStack();
- }
- return 0;
- }
- private void withdrawRequiredItems() {
- switch(getScript().getTask()) {
- case CHOP_LOGS:
- if(!getScript().getAxe().setAxe()) {
- getScript().println("Out of axes.");
- getScript().setEndScript(true);
- }
- break;
- case CHOP_AND_PLANK:
- if(getScript().getPlank().equals(Plank.TEAK) && Locations.isInsideBank()) {
- int amount = getLogAmount();
- if(amount > 20) {
- amount = amount > 27 ? 27 : amount;
- if(Inventory.getCount(getScript().getPlank().getLogId()) < amount) {
- withdrawLogs();
- }
- }
- break;
- }
- if(!getScript().getAxe().setAxe()) {
- getScript().println("Out of axes.");
- getScript().setEndScript(true);
- }
- break;
- case MAKE_PLANKS:
- int amount = getLogAmount();
- amount = amount > 27 ? 27 : amount;
- if(Inventory.getCount(getScript().getPlank().getLogId()) < amount) {
- withdrawLogs();
- }
- break;
- }
- }
- public boolean isItemWithdrawn(int id, int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
- RSItem[] item = Inventory.find(id);
- if (item != null && item.length > 0) {
- return true;
- }
- getScript().sleep(50, 150);
- }
- return false;
- }
- private boolean isMoneyWithdrawn(int i) {
- long t = System.currentTimeMillis();
- int count = getScript().getPlank().getPricePerPlank() * (getScript().getAxe().wearing() ? 27 : 26);
- while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
- if (Inventory.getCount(Constants.GOLD) >= count) {
- return true;
- }
- getScript().sleep(50, 150);
- }
- return false;
- }
- private boolean withdrawLogs() {
- final Plank PLANK = getScript().getPlank();
- int logId = PLANK.getLogId();
- if(openBankScreen()) {
- RSItem[] logs = Banking.find(logId);
- if(logs != null && logs.length > 0) {
- int amt = logs[0].getStack();
- amt = amt > 27 ? 27 : amt;
- logAmount = amt;
- Banking.withdraw(logAmount, logId);
- return isLogWithdrawn(1000);
- } else {
- getScript().println("Out of logs.");
- getScript().setEndScript(true);
- return false;
- }
- }
- return false;
- }
- public int leastAmountNeeded = getPricePerPlank() * 27;
- private int getPricePerPlank() {
- try {
- switch(getScript().getPlank()) {
- case REGULAR:
- return Constants.GOLD_PER_REG_PLANK;
- case OAK:
- return Constants.GOLD_PER_OAK_PLANK;
- case TEAK:
- return Constants.GOLD_PER_TEAK_PLANK;
- case MAHOGANY:
- return Constants.GOLD_PER_MAHOGANY_PLANK;
- }
- return 0;
- } catch(NullPointerException e) {
- }
- return 0;
- }
- private int goldWithdrawAmount = 0;
- private int bankGoldAmount() {
- RSItem[] gold = Banking.find(995);
- if(gold != null && gold.length > 0) {
- return gold[0].getStack();
- }
- return 0;
- }
- private void withdrawMoney() {
- int plankAmount = getPlankAmount();
- int[] goldcount = { 200000, 100000, 50000, 25000 };
- if(goldWithdrawAmount == 0 || bankGoldAmount() < goldWithdrawAmount) {
- for(int i = 0; i < goldcount.length; i++) {
- if(bankGoldAmount() > goldcount[i]) {
- goldWithdrawAmount = goldcount[i];
- break;
- }
- }
- }
- int goldCount = Inventory.getCount(Constants.GOLD);
- if(goldCount < goldWithdrawAmount) {
- if(openBankScreen()) {
- RSItem[] gold = Banking.find(Constants.GOLD);
- if(gold != null && gold.length > 0) {
- if(gold[0].getStack() >= goldWithdrawAmount) {
- Banking.withdraw(goldWithdrawAmount, Constants.GOLD);
- } else {
- getScript().println("Not enough gold.");
- getScript().setEndScript(true);
- return;
- }
- }
- }
- }
- }
- public int getPlankAmount() {
- int plankAmount = 0;
- switch(getScript().getTask()) {
- case CHOP_AND_PLANK:
- boolean wearingAxe = getScript().getAxe().wearing();
- if(getScript().getPlank().equals(Plank.TEAK)) {
- plankAmount = 27;
- } else {
- plankAmount = wearingAxe ? 27 : 26;
- }
- break;
- case MAKE_PLANKS:
- plankAmount = Inventory.getCount(getScript().getPlank().getLogId());
- break;
- }
- return plankAmount;
- }
- public int getFreeInventorySpace() {
- int taken = 0;
- for(RSItem i : Inventory.getAll()) {
- if(i != null) {
- taken++;
- continue;
- }
- }
- return 28 - taken;
- }
- public boolean isFinished() {
- int goldAmount;
- int spaces;
- int logAmount = Inventory.getCount(getScript().getPlank().getLogId());
- switch(getScript().getTask()) {
- case CHOP_LOGS:
- spaces = 28 - (getScript().getAxe().wearing() ? 0 : 1);
- if(getScript().getAxe().hasAxe()) {
- if(getFreeInventorySpace() == spaces) {
- return true;
- }
- }
- return false;
- case CHOP_AND_PLANK:
- spaces = 27 - (getScript().getAxe().wearing() ? 0 : 1);
- if(getScript().getPlank().equals(Plank.TEAK)) {
- if(Locations.isInsideCastleWars()) {
- RSItem[] ring = Equipment.find(SLOTS.RING);
- if(ring != null && ring.length > 0) {
- spaces++;
- }
- if(getScript().getAxe().hasAxe()) {
- if(getFreeInventorySpace() == spaces) {
- return true;
- }
- }
- }
- if(Locations.isInsideBank()) {
- final Plank PLANK = getScript().getPlank();
- final int logId = PLANK.getLogId();
- goldAmount = logAmount * PLANK.getPricePerPlank();
- return Inventory.getCount(logId) >= logAmount && Inventory.getCount(Constants.GOLD) >= goldAmount;
- }
- }
- goldAmount = spaces * getScript().getPlank().getPricePerPlank();
- if(getScript().getAxe().hasAxe()) {
- if(Inventory.getCount(Constants.GOLD) >= goldAmount) {
- if(getFreeInventorySpace() == spaces) {
- return true;
- }
- }
- }
- break;
- case MAKE_PLANKS:
- final Plank PLANK = getScript().getPlank();
- final int logId = PLANK.getLogId();
- goldAmount = 27 * PLANK.getPricePerPlank();
- if(Inventory.getCount(logId) > 0
- && Inventory.getCount(Constants.GOLD) >= goldAmount) {
- return true;
- }
- return false;
- }
- return false;
- }
- public boolean walkToBooth() {
- Mouse.setSpeed(110 + General.random(10, 20));
- WebWalking.setUseAStar(true);
- WebWalking.walkTo(Locations.BANK_TILE);
- Methods.performAntiBan(getScript());
- getScript().getData().checkPlayerRun();
- if(isInBank(3000)) {
- getScript().setState(State.BANKING);
- return true;
- }
- return false;
- }
- private boolean isInBank(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
- if (Locations.isInsideBank()) {
- Camera.setCameraAngle(General.random(60, 80));
- return true;
- }
- if (Locations.isInsideCastleWars()) {
- Camera.setCameraAngle(General.random(60, 80));
- return true;
- }
- if (!Player.isMoving()) {
- return false;
- }
- getScript().sleep(50, 150);
- }
- return false;
- }
- public boolean openBankScreen() {
- getScript().getData().setTimeout(System.currentTimeMillis());
- while(!Banking.isBankScreenOpen() && !getScript().getData().isTimedOut(7000, 8000)) {
- RSObject bank = Methods.findObjectByModelPoints(new int[]{Constants.BANK_BOOTH, Constants.BANK_CHEST});
- if(bank != null) {
- Banking.openBank();
- if(isPinScreenOpen(1000)) {
- if(Banking.isPinScreenOpen()) {
- if(!Banking.inPin()) {
- return false;
- }
- }
- }
- }
- }
- return Banking.isBankScreenOpen();
- }
- private boolean depositItems() {
- final Plank SET_PLANK = getScript().getPlank();
- switch(getScript().getTask()) {
- case CHOP_LOGS:
- Banking.depositAllExcept(new int[]{getScript().getData().getAxeId()});
- break;
- case CHOP_AND_PLANK:
- if(SET_PLANK.equals(Plank.TEAK) && Locations.isInsideBank()) {
- Banking.depositAll();
- } else {
- Banking.depositAllExcept(new int[]{getScript().getData().getAxeId()});
- }
- break;
- case MAKE_PLANKS:
- Banking.depositAllExcept(new int[]{ 995, getScript().getPlank().getLogId() });
- break;
- }
- return isAllItemsDeposited(1000);
- }
- private boolean isPinScreenOpen(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
- if (Banking.isBankScreenOpen()) {
- return false;
- }
- if (Banking.isPinScreenOpen()) {
- return true;
- }
- getScript().sleep(50, 150);
- }
- return false;
- }
- private boolean isAllItemsDeposited(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
- int space = getScript().getAxe().wearing() ? 28 : 27;
- if(getFreeInventorySpace() == space) {
- return true;
- }
- getScript().sleep(50, 150);
- }
- return false;
- }
- private boolean isLogWithdrawn(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
- if(Inventory.getCount(getScript().getPlank().getLogId()) == logAmount) {
- return true;
- }
- getScript().sleep(50, 150);
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement