Advertisement
Guest User

Untitled

a guest
Sep 17th, 2015
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.94 KB | None | 0 0
  1. package scripts.runecrafting.abysscrafter;
  2.  
  3. import org.tribot.api.General;
  4. import org.tribot.api.Timing;
  5. import org.tribot.api.util.ABCUtil;
  6. import org.tribot.api2007.Banking;
  7. import org.tribot.api2007.Combat;
  8. import org.tribot.api2007.Game;
  9. import org.tribot.api2007.Inventory;
  10. import org.tribot.api2007.Options;
  11. import org.tribot.api2007.types.RSItem;
  12.  
  13. import scripts.methods.Methods;
  14.  
  15. public class Bank {
  16.  
  17. private Main main;
  18.  
  19. public boolean filledPouches = false;
  20.  
  21. public Bank(Main main) {
  22. setMain(main);
  23. }
  24.  
  25. public void setMain(Main main) {
  26. this.main = main;
  27. }
  28.  
  29. public Main getMain() {
  30. return main;
  31. }
  32.  
  33. public boolean performedBankTasks() {
  34. getMain().println("Checking health level...");
  35. if(Constants.isFoodRequired()) {
  36. getMain().println("Food is required.");
  37. return false;
  38. }
  39. getMain().println("Checking for house tab...");
  40. if(Inventory.getCount(Constants.HOUSE_TAB) <= 0) {
  41. getMain().println("House tab is required.");
  42. return false;
  43. }
  44. if(!Inventory.isFull()) {
  45. return false;
  46. }
  47. getMain().println("Checked inventory amount...");
  48. if(!filledPouches) {
  49. return false;
  50. }
  51. getMain().println("Checked for pouches...");
  52. //Methods.performAntiBan();
  53. if(Game.getRunEnergy() > abc.INT_TRACKER.NEXT_RUN_AT.next()) {
  54. Options.setRunOn(true);
  55. abc.INT_TRACKER.NEXT_RUN_AT.reset();
  56. }
  57. getMain().setState(State.TELEPORTING_TO_ABYSS);
  58. getMain().tabBroke = false;
  59. return true;
  60. }
  61.  
  62. public boolean attemptBankTasks() {
  63. if(performedBankTasks()) {
  64. return true;
  65. }
  66. if(openBank()) {
  67. int[] itemsToKeep = {
  68. Constants.HOUSE_TAB, Constants.ESSENCE,
  69. Constants.POUCHES[0], Constants.POUCHES[1], Constants.POUCHES[2], Constants.POUCHES[3],
  70. Constants.DAMAGED_POUCHES[0], Constants.DAMAGED_POUCHES[1], Constants.DAMAGED_POUCHES[2]
  71. };
  72. Banking.depositAllExcept(itemsToKeep);
  73. depositItems(Inventory.getAll().length, 1000);
  74. if(Constants.isFoodRequired()) {
  75. eatFood();
  76. return false;
  77. }
  78. if(Inventory.getCount(Constants.HOUSE_TAB) <= 2) {
  79. if(General.random(0, 1) == 1
  80. || Inventory.getCount(Constants.HOUSE_TAB) == 0) {
  81. withdrawItem(Constants.HOUSE_TAB, 20);
  82. }
  83. }
  84. if(!filledPouches) {
  85. if(!Inventory.isFull())
  86. withdrawItem(Constants.ESSENCE, getFreeSpace());
  87. if(closeBank()) {
  88. fillPouches();
  89. if(performedBankTasks()) {
  90. return true;
  91. }
  92. }
  93. }
  94. if(openBank()) {
  95. if(Inventory.isFull()) {
  96. Banking.depositAllExcept(itemsToKeep);
  97. }
  98. withdrawItem(Constants.ESSENCE, getFreeSpace());
  99. }
  100. return true;
  101. }
  102. return false;
  103. }
  104.  
  105. public boolean openBank() {
  106. if(Banking.isBankScreenOpen()) {
  107. return true;
  108. }
  109. /*if(!Player.getPosition().equals(Locations.BANK_WALK_TILE) && !Player.isMoving())
  110. WebWalking.walkTo(Locations.BANK_WALK_TILE);*/
  111.  
  112. Banking.openBank();
  113. General.sleep(abc.DELAY_TRACKER.ITEM_INTERACTION.next());
  114. abc.DELAY_TRACKER.ITEM_INTERACTION.reset();
  115. return isBankScreenOpen(1000);
  116. }
  117.  
  118. public boolean withdrawItem(int itemId, int withdrawAmount) {
  119. if(openBank()) {
  120. getMain().sleep(250, 500);
  121. RSItem[] item = Banking.find(itemId);
  122. if(item != null && item.length > 0) {
  123. Banking.withdraw(withdrawAmount, itemId);
  124. General.sleep(abc.DELAY_TRACKER.ITEM_INTERACTION.next());
  125. abc.DELAY_TRACKER.ITEM_INTERACTION.reset();
  126. if(isWithdrawingItem(2000, itemId, Inventory.getCount(itemId))) {
  127. return true;
  128. }
  129. } else {
  130. getMain().println("Can't find: " + itemId);
  131. }
  132. }
  133. return false;
  134. }
  135.  
  136. private boolean isEatingFood(int amt, int i) {
  137. long t = System.currentTimeMillis();
  138. while (Timing.timeFromMark(t) < i) {
  139. if (Inventory.getCount(getMain().getFoodId()) < amt) {
  140. return true;
  141. }
  142. getMain().sleep(50, 150);
  143. }
  144. return false;
  145. }
  146.  
  147. private boolean depositItems(int amt, int i) {
  148. long t = System.currentTimeMillis();
  149. while (Timing.timeFromMark(t) < i) {
  150. if (Inventory.getAll().length < amt) {
  151. return true;
  152. }
  153. getMain().sleep(50, 150);
  154. }
  155. return false;
  156. }
  157.  
  158. private boolean isWithdrawingItem(int i, int id, int amt) {
  159. long t = System.currentTimeMillis();
  160. while (Timing.timeFromMark(t) < i) {
  161. if (Inventory.getCount(id) > amt) {
  162. return true;
  163. }
  164. getMain().sleep(50, 150);
  165. }
  166. return false;
  167. }
  168.  
  169. private boolean filledPouch(int amt, int i) {
  170. long t = System.currentTimeMillis();
  171. while (Timing.timeFromMark(t) < i) {
  172. if (Inventory.getCount(Constants.ESSENCE) < amt) {
  173. return true;
  174. }
  175. getMain().sleep(50, 150);
  176. }
  177. return false;
  178. }
  179.  
  180. public boolean isBankScreenOpen(int i) {
  181. long t = System.currentTimeMillis();
  182. while (Timing.timeFromMark(t) < i) {
  183. if (Banking.isBankScreenOpen()) {
  184. return true;
  185. }
  186. getMain().sleep(50, 150);
  187. }
  188. return false;
  189. }
  190.  
  191. private int getFoodAmount() {
  192. return (int) Math.ceil(((Combat.getMaxHP() - Combat.getHP()) / getMain().getHealAmount()));
  193. }
  194.  
  195. private boolean eatFood() {
  196. int foodAmt = getFoodAmount();
  197. if(foodAmt == 0) {
  198. foodAmt = 1;
  199. }
  200. getMain().println("Food Amount Needed: " + foodAmt);
  201. if(openBank()) {
  202. int[] itemsToKeep = {
  203. Constants.HOUSE_TAB,
  204. Constants.POUCHES[0], Constants.POUCHES[1], Constants.POUCHES[2], Constants.POUCHES[3],
  205. Constants.DAMAGED_POUCHES[0], Constants.DAMAGED_POUCHES[1], Constants.DAMAGED_POUCHES[2]
  206. };
  207. Banking.depositAllExcept(itemsToKeep);
  208. depositItems(Inventory.getAll().length, 1000);
  209. if(!withdrawItem(getMain().getFoodId(), foodAmt)) {
  210. RSItem[] lob = Banking.find(getMain().getFoodId());
  211. if(lob == null || lob.length <= 0) {
  212. //getMain().setEndScript(true);
  213. getMain().println("Out of food.");
  214. return false;
  215. }
  216. }
  217. }
  218. if(closeBank()) {
  219. int count = Inventory.getCount(getMain().getFoodId());
  220. while(Inventory.getCount(getMain().getFoodId()) > 0 && Constants.isFoodRequired()) {
  221. RSItem[] lobster = Inventory.find(getMain().getFoodId());
  222. if(lobster != null && lobster.length > 0) {
  223. lobster[0].click("Eat");
  224. General.sleep(abc.DELAY_TRACKER.ITEM_INTERACTION.next());
  225. abc.DELAY_TRACKER.ITEM_INTERACTION.reset();
  226. isEatingFood(Inventory.getCount(getMain().getFoodId()), 2000);
  227. }
  228. getMain().sleep(50, 150);
  229. }
  230. int eaten = count - Inventory.getCount(getMain().getFoodId());
  231. int previousEaten = getMain().getLobstersEaten();
  232. getMain().setLobstersEaten(previousEaten + eaten);
  233.  
  234. }
  235. return true;
  236. }
  237.  
  238. private ABCUtil abc = new ABCUtil();
  239.  
  240. private int getFreeSpace() {
  241. int space = 0;
  242. for(int i = 0; i < Inventory.getAll().length; i++) {
  243. if(Inventory.getAll()[i] == null) {
  244. space++;
  245. }
  246. }
  247. return space;
  248. }
  249.  
  250. private boolean closeBank() {
  251. while(Banking.isBankScreenOpen()) {
  252. Banking.close();
  253. getMain().sleep(50, 150);
  254. }
  255. return !Banking.isBankScreenOpen();
  256. }
  257.  
  258. private void fillPouches() {
  259. if(Inventory.getCount(Constants.ESSENCE) > 0) {
  260. int essCount = Inventory.getCount(Constants.ESSENCE);
  261. filledPouches = true;
  262. RSItem[] giantPouch = Inventory.find(Constants.POUCHES[3]);
  263. RSItem[] largePouch = Inventory.find(Constants.POUCHES[2]);
  264. RSItem[] medPouch = Inventory.find(Constants.POUCHES[1]);
  265. RSItem[] smallPouch = Inventory.find(Constants.POUCHES[0]);
  266.  
  267. RSItem[] damagedGiant = Inventory.find(Constants.DAMAGED_POUCHES[2]);
  268. RSItem[] damagedLarge = Inventory.find(Constants.DAMAGED_POUCHES[1]);
  269. RSItem[] damagedMed = Inventory.find(Constants.DAMAGED_POUCHES[0]);
  270. boolean hasGiantPouch = false;
  271. if(giantPouch != null && giantPouch.length > 0) {
  272. hasGiantPouch = true;
  273. fillPouch(giantPouch);
  274. }
  275. if(damagedGiant != null && damagedGiant.length > 0) {
  276. hasGiantPouch = true;
  277. fillPouch(damagedGiant);
  278. }
  279. if(largePouch != null && largePouch.length > 0) {
  280. fillPouch(largePouch);
  281. }
  282. if(damagedLarge != null && damagedLarge.length > 0) {
  283. fillPouch(damagedLarge);
  284. }
  285. if(hasGiantPouch) {
  286. while(!Inventory.isFull()) {
  287. if(openBank()) {
  288. withdrawItem(Constants.ESSENCE, getFreeSpace());
  289. closeBank();
  290. }
  291. getMain().sleep(50, 150);
  292. }
  293. }
  294. if(medPouch != null && medPouch.length > 0) {
  295. fillPouch(medPouch);
  296. }
  297. if(damagedMed != null && damagedMed.length > 0) {
  298. fillPouch(damagedMed);
  299. }
  300. if(smallPouch != null && smallPouch.length > 0) {
  301. fillPouch(smallPouch);
  302. }
  303. if(essCount == Inventory.getCount(Constants.ESSENCE)) {
  304. if(performedBankTasks())
  305. getMain().setState(State.TELEPORTING_TO_ABYSS);
  306. }
  307. }
  308. }
  309.  
  310. private boolean fillPouch(RSItem[] pouch) {
  311. int essCount = Inventory.getCount(Constants.ESSENCE);
  312. if(pouch != null && pouch.length > 0) {
  313. pouch[0].click("Fill");
  314. filledPouch(essCount, 1000);
  315. General.sleep(abc.DELAY_TRACKER.ITEM_INTERACTION.next());
  316. abc.DELAY_TRACKER.ITEM_INTERACTION.reset();
  317. }
  318. return Inventory.getCount(Constants.ESSENCE) < essCount;
  319. }
  320.  
  321. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement