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.api2007.Banking;
- import org.tribot.api2007.Game;
- import org.tribot.api2007.Inventory;
- import org.tribot.api2007.Player;
- import org.tribot.api2007.types.RSItem;
- import scripts.moneymaking.iplankfarmer.Script;
- import scripts.moneymaking.iplankfarmer.types.EnergyPotion;
- import scripts.moneymaking.iplankfarmer.utils.Constants;
- public class Potions {
- private Script script;
- public Potions(Script script) {
- setScript(script);
- }
- private int potionDrank = 0;
- private int potionAmt = 0;
- public void handleEnergyPotions() {
- if(getScript().getEnergyPotion().equals(EnergyPotion.NONE) ||
- Game.getRunEnergy() >= 80) {
- return;
- }
- if(getScript().getBanking().openBankScreen()) {
- final EnergyPotion POTION = getScript().getEnergyPotion();
- boolean isRegular = POTION.equals(EnergyPotion.REGULAR);
- final int[] REGULAR = Constants.ENERGY_POTION;
- final int[] SUPER = Constants.SUPER_ENERGY_POTION;
- final int[] POTIONS = isRegular ? REGULAR : SUPER;
- int normalAmt = isRegular ? 2 : 1;
- potionAmt = normalAmt;
- for(int i = 1; i < POTIONS.length; i++) {
- int potionId = POTIONS[i];
- if(withdrawEnergyPotion(i, Banking.find(potionId))) {
- if(i == 0) {
- potionAmt++;
- continue;
- }
- if(potionAmt != normalAmt) {
- drinkEnergyPotion(0, Inventory.find(POTIONS[0]));
- };
- drinkEnergyPotion(i, Inventory.find(potionId));
- }
- }
- }
- }
- public boolean withdrawEnergyPotion(int i, RSItem[] energyPotion) {
- if(energyPotion != null && energyPotion.length > 0) {
- Banking.withdraw((Game.getRunEnergy() > 50 && getScript().getEnergyPotion().equals(EnergyPotion.REGULAR)) ? 1 : 2, energyPotion[0].getID());
- if(getScript().getBanking().isItemWithdrawn(energyPotion[0].getID(), 1000)) {
- return true;
- }
- }
- return false;
- }
- public int getDosage(int id) {
- switch(id) {
- case 3022:
- case 3014:
- return 1;
- case 3012:
- case 3020:
- return 2;
- case 3018:
- case 3010:
- return 3;
- case 3008:
- case 3016:
- return 4;
- }
- return 0;
- }
- public void drinkEnergyPotion(int i, RSItem[] energyPotion) {
- getScript().getBanking().setDrankPotions(true);
- while(Banking.isBankScreenOpen()) {
- Banking.close();
- getScript().sleep(200, 400);
- }
- if(energyPotion == null || energyPotion.length <= 0) {
- switch(getScript().getEnergyPotion()) {
- case REGULAR:
- energyPotion = Inventory.find(Constants.ENERGY_POTION[0], Constants.ENERGY_POTION[1], Constants.ENERGY_POTION[2], Constants.ENERGY_POTION[3]);
- break;
- case SUPER:
- energyPotion = Inventory.find(Constants.SUPER_ENERGY_POTION[0], Constants.SUPER_ENERGY_POTION[1], Constants.SUPER_ENERGY_POTION[2], Constants.SUPER_ENERGY_POTION[3]);
- break;
- }
- }
- int potionCount = 0;
- for(int x = 0; x < energyPotion.length; x++) {
- potionCount += Inventory.getCount(energyPotion[x].getID());
- }
- for(int l = 0; l < potionCount - 1; l++) {
- for(int j = 0; j < getDosage(energyPotion[0].getID()); j++) {
- if(getPotionDrank() < potionAmt && Game.getRunEnergy() < 80) {
- while(Banking.isBankScreenOpen()) {
- Banking.close();
- getScript().sleep(200, 400);
- }
- if(energyPotion[l].click("Drink")) {
- if(isDrinkingPotion(1000)) {
- if(isPotionDrank(2000)) {
- double moneySpent = getScript().getData().getMoneySpent();
- getScript().getData().setMoneySpent(moneySpent + calculateMoneySpent());
- if(j == getDosage(energyPotion[l].getID()) - 1) {
- if(l == potionCount -1) {
- if(getScript().getBanking().openBankScreen()) {
- Banking.depositAllExcept(new int[] { 995 });
- setPotionDrank(getPotionDrank() + 1);
- break;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
- private boolean isDrinkingPotion(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
- if (Player.getAnimation() == 829) {
- return true;
- }
- getScript().sleep(50, 150);
- }
- return false;
- }
- private boolean isPotionDrank(int i) {
- long t = System.currentTimeMillis();
- while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
- if (Player.getAnimation() == -1) {
- return true;
- }
- getScript().sleep(50, 150);
- }
- return false;
- }
- public double calculateMoneySpent() {
- double price = getScript().getEnergyPotionPrice();
- return ((double) price / 4);
- }
- public void setScript(Script script) {
- this.script = script;
- }
- public Script getScript() {
- return script;
- }
- public void setPotionDrank(int potionDrank) {
- this.potionDrank = potionDrank;
- }
- public int getPotionDrank() {
- return potionDrank;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement