Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package scripts.smither;
- 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.Equipment;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.types.RSItem;
- public class Bank {
- private Main main;
- private ABCUtil abc = new ABCUtil();
- private BarType barType;
- private SmithLocation location;
- private Smithing item;
- private Forging forging;
- private ScriptTask task;
- public Bank(Main main) {
- setMain(main);
- setBarType(main.getBarType());
- setLocation(main.getSmithLocation());
- setItem(main.getItem());
- setForging(main.getForging());
- setTask(main.getTask());
- }
- public boolean canPerform() {
- int[] ores = getBarType().getOres();
- int[] amounts = getBarType().getAmounts();
- boolean hasFirstOre = Inventory.getCount(ores[0]) >= amounts[0];
- boolean hasSecondOre = Inventory.getCount(ores[1]) >= amounts[1];
- boolean mould = Inventory.getCount(Constants.CANNONBALL_MOULD) > 0;
- boolean steel = Inventory.getCount(Constants.STEEL_BAR) > 0;
- boolean hammer = Inventory.getCount(Constants.HAMMER) > 0;
- boolean bars = Inventory.getCount(getBarType().getItemId()) >= getItem().getBarsRequired();
- switch(getTask()) {
- case SMITHING:
- if(!getItem().equals(Smithing.CANNONBALLS)) {
- return hammer && bars;
- } else {
- return mould && steel;
- }
- case CANNONBALLS:
- if(mould) {
- if(hasFirstOre && hasSecondOre)
- return true;
- else {
- if(steel)
- return true;
- }
- }
- return false;
- case SMELTING:
- if(!getItem().equals(Smithing.CANNONBALLS)) {
- return hammer && bars;
- } else {
- return hasFirstOre && hasSecondOre;
- }
- }
- return false;
- }
- public boolean performedBankTask() {
- int[] ores = getBarType().getOres();
- int[] amounts = getOreWithdrawAmount();
- boolean hammer = Inventory.getCount(Constants.HAMMER) > 0;
- boolean bars = Inventory.getCount(getBarType().getItemId()) >= getItem().getBarsRequired();
- boolean ammomould = Inventory.getCount(Constants.CANNONBALL_MOULD) > 0;
- boolean forging = getForging().equals(Forging.YES);
- boolean mould = Inventory.getCount(Constants.CANNONBALL_MOULD) > 0;
- int ran = General.random(0, 1);
- boolean hasFirstOre;
- boolean hasSecondOre;
- switch(getTask()) {
- case SMITHING:
- if(Banking.isBankScreenOpen()) {
- int count = Inventory.getAll().length;
- Banking.depositAllExcept(Constants.HAMMER, getBarType().getItemId(), Constants.CANNONBALL_MOULD);
- if(isItemDeposited(count, 1000)) {
- getMain().sleep();
- }
- }
- if(!hammer && !getItem().equals(Smithing.CANNONBALLS)) {
- if(openBank()) {
- if(Inventory.getCount(Constants.HAMMER) <= 0) {
- if(withdrawItem(Constants.HAMMER, 1)) {
- hammer = Inventory.getCount(Constants.HAMMER) > 0;
- }
- }
- }
- }
- if(getItem().equals(Smithing.CANNONBALLS)) {
- if(!ammomould) {
- if(openBank()) {
- if(withdrawItem(Constants.CANNONBALL_MOULD, 1)) {
- ammomould = Inventory.getCount(Constants.CANNONBALL_MOULD) > 0;
- }
- }
- }
- }
- if(!bars) {
- if(openBank()) {
- if(withdrawItem(getBarType().getItemId(), (28 - Inventory.getAll().length))) {
- bars = Inventory.getCount(getBarType().getItemId()) >= getItem().getBarsRequired();
- }
- }
- }
- if(getItem().equals(Smithing.CANNONBALLS)) {
- if(ammomould && bars) {
- return true;
- }
- } else {
- if(hammer && bars) {
- return true;
- }
- }
- return false;
- case SMELTING:
- if(ran == 0) {
- hasFirstOre = Inventory.getCount(ores[0]) >= amounts[0];
- hasSecondOre = Inventory.getCount(ores[1]) >= amounts[1];
- } else {
- hasFirstOre = Inventory.getCount(ores[1]) >= amounts[1];
- hasSecondOre = Inventory.getCount(ores[0]) >= amounts[0];
- }
- if(Banking.isBankScreenOpen()) {
- Banking.depositAllExcept(getBarType().getOres());
- }
- if(forging) {
- if(!Equipment.isEquipped(Constants.RING_OF_FORGING)) {
- equipForgingRing();
- }
- }
- if(ran == 0) {
- if(!hasFirstOre) {
- if(openBank()) {
- if(withdrawItem(ores[0], amounts[0])) {
- hasFirstOre = Inventory.getCount(ores[0]) >= amounts[0];
- }
- }
- }
- if(amounts[1] > 0) {
- if(!hasSecondOre) {
- if(openBank()) {
- if(withdrawItem(ores[1], amounts[1])) {
- hasSecondOre = Inventory.getCount(ores[1]) >= amounts[1];
- }
- }
- }
- }
- } else {
- if(amounts[1] > 0) {
- if(!hasSecondOre) {
- if(openBank()) {
- if(withdrawItem(ores[1], amounts[1])) {
- hasSecondOre = Inventory.getCount(ores[1]) >= amounts[1];
- }
- }
- }
- }
- if(!hasFirstOre) {
- if(openBank()) {
- if(withdrawItem(ores[0], amounts[0])) {
- hasFirstOre = Inventory.getCount(ores[0]) >= amounts[0];
- }
- }
- }
- }
- return hasFirstOre && hasSecondOre;
- case CANNONBALLS:
- if(ran == 0) {
- hasFirstOre = Inventory.getCount(ores[0]) >= amounts[0];
- hasSecondOre = Inventory.getCount(ores[1]) >= amounts[1];
- } else {
- hasFirstOre = Inventory.getCount(ores[1]) >= amounts[1];
- hasSecondOre = Inventory.getCount(ores[0]) >= amounts[0];
- }
- if(Banking.isBankScreenOpen())
- Banking.depositAllExcept(Constants.CANNONBALL_MOULD, ores[0], ores[1]);
- if(!mould) {
- if(openBank()) {
- if(Inventory.getCount(Constants.CANNONBALL_MOULD) <= 0) {
- if(withdrawItem(Constants.CANNONBALL_MOULD, 1)) {
- mould = Inventory.getCount(Constants.CANNONBALL_MOULD) > 0;
- }
- }
- }
- }
- if(ran == 0) {
- if(!hasFirstOre) {
- if(openBank()) {
- if(withdrawItem(ores[0], amounts[0])) {
- hasFirstOre = Inventory.getCount(ores[0]) >= amounts[0];
- }
- }
- }
- if(amounts[1] > 0) {
- if(!hasSecondOre) {
- if(openBank()) {
- if(withdrawItem(ores[1], amounts[1])) {
- hasSecondOre = Inventory.getCount(ores[1]) >= amounts[1];
- }
- }
- }
- }
- } else {
- if(amounts[1] > 0) {
- if(!hasSecondOre) {
- if(openBank()) {
- if(withdrawItem(ores[1], amounts[1])) {
- hasSecondOre = Inventory.getCount(ores[1]) >= amounts[1];
- }
- }
- }
- }
- if(!hasFirstOre) {
- if(openBank()) {
- if(withdrawItem(ores[0], amounts[0])) {
- hasFirstOre = Inventory.getCount(ores[0]) >= amounts[0];
- }
- }
- }
- }
- if(mould && hasFirstOre && hasSecondOre) {
- return true;
- }
- return false;
- }
- return false;
- }
- public boolean equipForgingRing() {
- boolean hasRing = Inventory.getCount(Constants.RING_OF_FORGING) > 0;
- if(!hasRing) {
- if(openBank()) {
- if(withdrawItem(Constants.RING_OF_FORGING, 1)) {
- hasRing = Inventory.getCount(Constants.RING_OF_FORGING) > 0;
- }
- }
- }
- if(hasRing) {
- if(Banking.close()) {
- getMain().sleep();
- RSItem[] ring = Inventory.find(Constants.RING_OF_FORGING);
- if(ring != null && ring.length > 0) {
- if(ring[0].click("Wear")) {
- getMain().sleep();
- if(wearingRing(2000)) {
- int ringsUsed = getMain().getRingsUsed();
- getMain().setRingsUsed(ringsUsed++);
- return true;
- }
- }
- }
- }
- }
- return false;
- }
- public int[] getOreWithdrawAmount() {
- switch(getBarType()) {
- case ADAMANT:
- return new int[] { 4, 24 };
- case BRONZE:
- return new int[] { 14, 14 };
- case GOLD:
- return new int[] { 28, 0 };
- case IRON:
- return new int[] { 28, 0 };
- case MITHRIL:
- return new int[] { 5, 20};
- case RUNE:
- return new int[] { 3, 24 };
- case SILVER:
- return new int[] { 28, 0 };
- case STEEL:
- return new int[] { 9, 18 };
- }
- return new int[] { 0, 0 };
- }
- public boolean openBank() {
- if(isBankScreenOpen(100)) {
- return true;
- }
- Banking.openBank();
- General.sleep(abc.DELAY_TRACKER.ITEM_INTERACTION.next());
- abc.DELAY_TRACKER.ITEM_INTERACTION.reset();
- return isBankScreenOpen(2000);
- }
- 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(isItemWithdrawn(2000, itemId, Inventory.getCount(itemId))) {
- return true;
- }
- } else {
- if(!withdrawItem(itemId, withdrawAmount)) {
- getMain().println("Can't find: " + itemId);
- getMain().setEndScript(true);
- return false;
- }
- }
- }
- return false;
- }
- public boolean wearingRing(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i) {
- if(Equipment.isEquipped(Constants.RING_OF_FORGING)) {
- 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 boolean isItemWithdrawn(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 isItemDeposited(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;
- }
- public Main getMain() {
- return main;
- }
- public void setMain(Main main) {
- this.main = main;
- }
- public BarType getBarType() {
- return barType;
- }
- public void setBarType(BarType barType) {
- this.barType = barType;
- }
- public SmithLocation getLocation() {
- return location;
- }
- public void setLocation(SmithLocation location) {
- this.location = location;
- }
- public Smithing getItem() {
- return item;
- }
- public void setItem(Smithing item) {
- this.item = item;
- }
- public Forging getForging() {
- return forging;
- }
- public void setForging(Forging forging) {
- this.forging = forging;
- }
- public ScriptTask getTask() {
- return task;
- }
- public void setTask(ScriptTask task) {
- this.task = task;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement