Update Bank.java

This commit is contained in:
Danial
2021-10-07 12:50:18 +13:00
parent 419f7212db
commit c8f2521e64
+97 -29
View File
@@ -2,11 +2,9 @@ package ParaScript.strategies;
import ParaScript.data.Variables; import ParaScript.data.Variables;
import org.parabot.environment.api.utils.Time; import org.parabot.environment.api.utils.Time;
import org.parabot.environment.input.Keyboard;
import org.parabot.environment.scripts.framework.Strategy; import org.parabot.environment.scripts.framework.Strategy;
import org.rev317.min.api.methods.*;
import org.rev317.min.api.wrappers.Npc; import org.rev317.min.api.wrappers.Npc;
import org.rev317.min.api.wrappers.TilePath; import org.rev317.min.api.methods.*;
import org.rev317.min.api.wrappers.Item; import org.rev317.min.api.wrappers.Item;
public class Bank implements Strategy { public class Bank implements Strategy {
@@ -17,40 +15,110 @@ public class Bank implements Strategy {
&& Game.isLoggedIn() && Game.isLoggedIn()
&& Variables.shouldBankItems() && Variables.shouldBankItems()
&& (Variables.getStatus() == "none" || Variables.getStatus() == "banking items") && (Variables.getStatus() == "none" || Variables.getStatus() == "banking items")
&& Inventory.isFull(); && Inventory.isFull()
&& openBank();
} }
@Override @Override
public void execute() { public void execute() {
Variables.pathToWalk = new TilePath(Variables.VARROCK_EAST_MINE_PATH_TO_BANK); bankAll();
Variables.setStatus("banking items");
while (Variables.pathToWalk != null && !Variables.pathToWalk.hasReached()) {
if (!Game.isLoggedIn()) new HandleLogin().execute();
Variables.pathToWalk.traverse();
Time.sleep(2500);
}
depositItems();
} }
public void depositItems() { public static boolean isBankOpen() {
Npc banker = Npcs.getClosest(494); return Game.getOpenInterfaceId() == 5292;
if (banker != null) }
{
banker.interact(Npcs.Option.BANK); public static boolean openBank() {
} else { if (isBankOpen()) {
Keyboard.getInstance().sendKeys("I can't find the banker!"); return true;
} }
Time.sleep(3000); Npc banker = Npcs.getClosest(494);
if (Game.getOpenInterfaceId() == 5292) { if (banker != null) {
if (Variables.skill_to_train == Skill.MINING) banker.interact(Npcs.Option.BANK);
org.rev317.min.api.methods.Bank.depositAllExcept(1266, 1268, 1270, 1272, 1274, 1276); Time.sleep(() -> isBankOpen(), 10000);
else if (Variables.skill_to_train == Skill.WOODCUTTING) return true;
org.rev317.min.api.methods.Bank.depositAllExcept(1350, 1352, 1354, 1356, 1358, 1360, 6740); } else {
else { System.out.println("Unable to find a banker");
org.rev317.min.api.methods.Bank.depositAllExcept(1); return false;
Variables.addItemGained(28); }
}
public static int getInventorySlot(int item_id){
Item item = Inventory.getItem(item_id + 1);
if (item == null) return -1;
return item.getSlot();
}
public static int getBankSlot(int item_id){
item_id++;
int slot = 0;
for (int bank_item_id : Variables.bank_items){
if (bank_item_id == item_id) return slot;
slot++;
}
return -1;
}
public static void bankAll(){
if (!openBank()) return;
Variables.setStatus("Banking items");
try {
for (int item_id : Variables.getItemIDs()) {
int inventory_slot = getInventorySlot(item_id);
if (inventory_slot >= 0) {
Menu.sendAction(431, item_id, inventory_slot, 5064, 3);
Time.sleep(50);
}
Time.sleep(200);
} }
Variables.setStatus("none"); } catch (Exception err){
System.out.println("Banking error: ¯\\_(ツ)_/¯");
}
}
public static void withdrawItem(int item_id, int amount){
if (!openBank()) return;
int slot = getBankSlot(item_id);
if (slot < 0) return;
switch(amount){
case 1:
Menu.sendAction(632, item_id, slot, 5382, 6);
return;
case 5:
Menu.sendAction(78, item_id, slot, 5382, 5);
return;
case 10:
Menu.sendAction(867, item_id, slot, 5382, 4);
return;
case -1: // all
Menu.sendAction(431, item_id, slot, 5382, 3);
return;
default: // x
Menu.sendAction(53, item_id, slot, 5382, 2);
return;
}
}
public static void depositItem(int item_id, int amount){
if (!openBank()) return;
int slot = Bank.getInventorySlot(item_id);
if (slot < 0) return;
switch(amount){
case 1:
Menu.sendAction(632, item_id, slot, 5064, 6);
return;
case 5:
Menu.sendAction(78, item_id, slot, 5064, 5);
return;
case 10:
Menu.sendAction(867, item_id, slot, 5064, 4);
return;
case -1: // all
Menu.sendAction(431, item_id, slot, 5064, 3);
return;
default: // x
Menu.sendAction(53, item_id, slot, 5064, 2);
return;
} }
} }
} }