Advertisement
iant06

Untitled

Sep 17th, 2015
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. package scripts.moneymaking.iplankfarmer.banking;
  2.  
  3. import org.tribot.api.General;
  4. import org.tribot.api.Timing;
  5. import org.tribot.api2007.Banking;
  6. import org.tribot.api2007.Game;
  7. import org.tribot.api2007.Inventory;
  8. import org.tribot.api2007.Player;
  9. import org.tribot.api2007.types.RSItem;
  10.  
  11. import scripts.moneymaking.iplankfarmer.Script;
  12. import scripts.moneymaking.iplankfarmer.types.EnergyPotion;
  13. import scripts.moneymaking.iplankfarmer.utils.Constants;
  14.  
  15. public class Potions {
  16.  
  17. private Script script;
  18.  
  19. public Potions(Script script) {
  20. setScript(script);
  21. }
  22.  
  23. private int potionDrank = 0;
  24. private int potionAmt = 0;
  25.  
  26. public void handleEnergyPotions() {
  27. if(getScript().getEnergyPotion().equals(EnergyPotion.NONE) ||
  28. Game.getRunEnergy() >= 80) {
  29. return;
  30. }
  31. if(getScript().getBanking().openBankScreen()) {
  32. final EnergyPotion POTION = getScript().getEnergyPotion();
  33. boolean isRegular = POTION.equals(EnergyPotion.REGULAR);
  34. final int[] REGULAR = Constants.ENERGY_POTION;
  35. final int[] SUPER = Constants.SUPER_ENERGY_POTION;
  36. final int[] POTIONS = isRegular ? REGULAR : SUPER;
  37. int normalAmt = isRegular ? 2 : 1;
  38. potionAmt = normalAmt;
  39. for(int i = 1; i < POTIONS.length; i++) {
  40. int potionId = POTIONS[i];
  41. if(withdrawEnergyPotion(i, Banking.find(potionId))) {
  42. if(i == 0) {
  43. potionAmt++;
  44. continue;
  45. }
  46. if(potionAmt != normalAmt) {
  47. drinkEnergyPotion(0, Inventory.find(POTIONS[0]));
  48. };
  49. drinkEnergyPotion(i, Inventory.find(potionId));
  50. }
  51. }
  52. }
  53. }
  54.  
  55. public boolean withdrawEnergyPotion(int i, RSItem[] energyPotion) {
  56. if(energyPotion != null && energyPotion.length > 0) {
  57. Banking.withdraw((Game.getRunEnergy() > 50 && getScript().getEnergyPotion().equals(EnergyPotion.REGULAR)) ? 1 : 2, energyPotion[0].getID());
  58. if(getScript().getBanking().isItemWithdrawn(energyPotion[0].getID(), 1000)) {
  59. return true;
  60. }
  61. }
  62. return false;
  63. }
  64.  
  65. public int getDosage(int id) {
  66. switch(id) {
  67. case 3022:
  68. case 3014:
  69. return 1;
  70. case 3012:
  71. case 3020:
  72. return 2;
  73. case 3018:
  74. case 3010:
  75. return 3;
  76. case 3008:
  77. case 3016:
  78. return 4;
  79. }
  80. return 0;
  81. }
  82.  
  83. public void drinkEnergyPotion(int i, RSItem[] energyPotion) {
  84. getScript().getBanking().setDrankPotions(true);
  85. while(Banking.isBankScreenOpen()) {
  86. Banking.close();
  87. getScript().sleep(200, 400);
  88. }
  89. if(energyPotion == null || energyPotion.length <= 0) {
  90. switch(getScript().getEnergyPotion()) {
  91. case REGULAR:
  92. energyPotion = Inventory.find(Constants.ENERGY_POTION[0], Constants.ENERGY_POTION[1], Constants.ENERGY_POTION[2], Constants.ENERGY_POTION[3]);
  93. break;
  94. case SUPER:
  95. energyPotion = Inventory.find(Constants.SUPER_ENERGY_POTION[0], Constants.SUPER_ENERGY_POTION[1], Constants.SUPER_ENERGY_POTION[2], Constants.SUPER_ENERGY_POTION[3]);
  96. break;
  97. }
  98. }
  99. int potionCount = 0;
  100. for(int x = 0; x < energyPotion.length; x++) {
  101. potionCount += Inventory.getCount(energyPotion[x].getID());
  102. }
  103. for(int l = 0; l < potionCount - 1; l++) {
  104. for(int j = 0; j < getDosage(energyPotion[0].getID()); j++) {
  105. if(getPotionDrank() < potionAmt && Game.getRunEnergy() < 80) {
  106. while(Banking.isBankScreenOpen()) {
  107. Banking.close();
  108. getScript().sleep(200, 400);
  109. }
  110. if(energyPotion[l].click("Drink")) {
  111. if(isDrinkingPotion(1000)) {
  112. if(isPotionDrank(2000)) {
  113. double moneySpent = getScript().getData().getMoneySpent();
  114. getScript().getData().setMoneySpent(moneySpent + calculateMoneySpent());
  115. if(j == getDosage(energyPotion[l].getID()) - 1) {
  116. if(l == potionCount -1) {
  117. if(getScript().getBanking().openBankScreen()) {
  118. Banking.depositAllExcept(new int[] { 995 });
  119. setPotionDrank(getPotionDrank() + 1);
  120. break;
  121. }
  122. }
  123. }
  124. }
  125. }
  126. }
  127. }
  128. }
  129. }
  130. }
  131.  
  132. private boolean isDrinkingPotion(int i) {
  133. long t = System.currentTimeMillis();
  134. while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
  135. if (Player.getAnimation() == 829) {
  136. return true;
  137. }
  138. getScript().sleep(50, 150);
  139. }
  140. return false;
  141. }
  142.  
  143. private boolean isPotionDrank(int i) {
  144. long t = System.currentTimeMillis();
  145. while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
  146. if (Player.getAnimation() == -1) {
  147. return true;
  148. }
  149. getScript().sleep(50, 150);
  150. }
  151. return false;
  152. }
  153.  
  154. public double calculateMoneySpent() {
  155. double price = getScript().getEnergyPotionPrice();
  156. return ((double) price / 4);
  157. }
  158.  
  159. public void setScript(Script script) {
  160. this.script = script;
  161. }
  162.  
  163. public Script getScript() {
  164. return script;
  165. }
  166.  
  167. public void setPotionDrank(int potionDrank) {
  168. this.potionDrank = potionDrank;
  169. }
  170.  
  171. public int getPotionDrank() {
  172. return potionDrank;
  173. }
  174.  
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement