Advertisement
iant06

Untitled

Nov 4th, 2015
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.34 KB | None | 0 0
  1. package scripts.clues;
  2.  
  3. import org.tribot.api.General;
  4. import org.tribot.api.Timing;
  5. import org.tribot.api.types.generic.Condition;
  6. import org.tribot.api.util.ABCUtil;
  7. import org.tribot.api2007.Banking;
  8. import org.tribot.api2007.Equipment;
  9. import org.tribot.api2007.Inventory;
  10. import org.tribot.api2007.Player;
  11. import org.tribot.api2007.WebWalking;
  12. import org.tribot.api2007.types.RSArea;
  13. import org.tribot.api2007.types.RSItem;
  14. import org.tribot.api2007.types.RSTile;
  15.  
  16. import scripts.clues.types.EmoteClue;
  17. import scripts.clues.types.TeleportLocation;
  18. import scripts.clues.types.TeleportMethod;
  19. import scripts.methods.Item;
  20. import scripts.methods.Methods;
  21.  
  22. public class Bank {
  23.  
  24. private Main main;
  25.  
  26. private boolean bankTeleport = false;
  27.  
  28. private int tries = 0;
  29.  
  30. private long last_busy_time = System.currentTimeMillis();
  31.  
  32. private final ABCUtil abc = new ABCUtil();
  33.  
  34. public Bank(Main main) {
  35. setMain(main);
  36. }
  37.  
  38. public boolean openBank() {
  39.  
  40. getMain().getEquipped().checkEquipment();
  41.  
  42. if(Banking.isBankScreenOpen()) {
  43. return true;
  44. }
  45.  
  46. getMain().setStatus("Opening Bank");
  47.  
  48. abc.waitNewOrSwitchDelay(last_busy_time, false);
  49.  
  50. Banking.openBank();
  51.  
  52. last_busy_time = System.currentTimeMillis();
  53.  
  54. return Timing.waitCondition(new Condition() {
  55.  
  56. @Override
  57. public boolean active() {
  58. return Banking.isBankScreenOpen();
  59. }
  60.  
  61. }, General.random(4000, 6000));
  62. }
  63.  
  64. public boolean withdrawBankItem(int id, int amount) {
  65.  
  66. Item i = Methods.getData(id);
  67. int inventoryAmount = Inventory.getCount(id);
  68.  
  69. if(inventoryAmount < amount && Banking.isBankScreenOpen()) {
  70.  
  71. abc.waitNewOrSwitchDelay(last_busy_time, false);
  72.  
  73. RSItem[] item = Banking.find(id);
  74.  
  75. if(item.length <= 0) {
  76. getMain().println("Cannot find " + i.getName() + ".");
  77. getMain().setEndScript(true);
  78. return false;
  79. }
  80.  
  81. getMain().setStatus("Withdrawing " + i.getName());
  82.  
  83. General.sleep(abc.DELAY_TRACKER.ITEM_INTERACTION.next());
  84. abc.DELAY_TRACKER.ITEM_INTERACTION.reset();
  85. Banking.withdraw(amount, id);
  86. if(Timing.waitCondition(new Condition() {
  87.  
  88. @Override
  89. public boolean active() {
  90. return Inventory.getCount(id) > inventoryAmount;
  91. }
  92.  
  93. }, General.random(2000, 4000))) {
  94. return true;
  95. }
  96. }
  97. return Inventory.getCount(id) >= amount;
  98. }
  99.  
  100. public boolean withdrawBankItem(String id, int amount) {
  101.  
  102. int inventoryAmount = Inventory.getCount(id);
  103.  
  104. if(inventoryAmount < amount && Banking.isBankScreenOpen()) {
  105.  
  106. abc.waitNewOrSwitchDelay(last_busy_time, false);
  107.  
  108. RSItem[] item = Banking.find(id);
  109.  
  110. if(item.length <= 0) {
  111. getMain().println("Cannot find " + id + ".");
  112. getMain().setEndScript(true);
  113. return false;
  114. }
  115.  
  116. getMain().setStatus("Withdrawing " + id);
  117.  
  118. General.sleep(abc.DELAY_TRACKER.ITEM_INTERACTION.next());
  119. abc.DELAY_TRACKER.ITEM_INTERACTION.reset();
  120.  
  121. Banking.withdraw(amount, id);
  122.  
  123. if(Timing.waitCondition(new Condition() {
  124.  
  125. @Override
  126. public boolean active() {
  127. return Inventory.getCount(id) > inventoryAmount;
  128. }
  129.  
  130. }, General.random(2000, 4000))) {
  131. return true;
  132. }
  133.  
  134. }
  135.  
  136. return Inventory.getCount(id) >= amount;
  137. }
  138.  
  139. public boolean withdrawRequiredEquipment(String[] reqItems) {
  140.  
  141. getMain().setStatus("Depositing Items");
  142. Banking.depositAllExcept(getRequiredInventoryItems());
  143.  
  144. boolean[] hasItems = new boolean[reqItems.length];
  145. for(int i = 0; i < reqItems.length; i++) {
  146. hasItems[i] = Inventory.getCount(reqItems[i]) > 0
  147. || Equipment.isEquipped(reqItems[i]);
  148. }
  149.  
  150. for(int i = 0; i < hasItems.length; i++) {
  151. hasItems[i] = withdrawBankItem(reqItems[i], 1);
  152. }
  153.  
  154. for(boolean b : hasItems) {
  155. if(!b)
  156. return false;
  157. }
  158. return true;
  159. }
  160.  
  161. public boolean withdrawTabs() {
  162. boolean hasVar = withdrawBankItem(Constants.VARROCK_TAB_ID, 20);
  163. boolean hasLum = withdrawBankItem(Constants.LUMBRIDGE_TAB_ID, 20);
  164. boolean hasFal = withdrawBankItem(Constants.FALADOR_TAB_ID, 20);
  165. boolean hasCam = withdrawBankItem(Constants.CAMELOT_TAB_ID, 20);
  166.  
  167. return hasVar && hasLum && hasFal && hasCam;
  168. }
  169.  
  170. public boolean withdrawRunes() {
  171. boolean hasLaw = withdrawBankItem(Constants.LAW_RUNE_ID, 100);
  172. boolean hasAir = withdrawBankItem(Constants.AIR_RUNE_ID, 300);
  173. boolean hasWater = withdrawBankItem(Constants.WATER_RUNE_ID, 100);
  174. boolean hasEarth = withdrawBankItem(Constants.EARTH_RUNE_ID, 100);
  175. boolean hasFire = withdrawBankItem(Constants.FIRE_RUNE_ID, 100);
  176. return hasLaw && hasAir && hasWater && hasEarth && hasFire;
  177. }
  178.  
  179.  
  180. public boolean canPerform() {
  181.  
  182. boolean hasRing = Inventory.getCount(Constants.DUEL_RING_ID) > 0
  183. || Equipment.isEquipped(Constants.DUEL_RING_ID);
  184.  
  185. boolean hasNecklace = Inventory.getCount(Constants.GAMES_NECKLACE_ID) > 0
  186. || Equipment.isEquipped(Constants.GAMES_NECKLACE_ID);
  187.  
  188. boolean hasRunes = Inventory.getCount(Constants.LAW_RUNE_ID) > 3
  189. && Inventory.getCount(Constants.AIR_RUNE_ID) > 10
  190. && Inventory.getCount(Constants.WATER_RUNE_ID) > 10
  191. && Inventory.getCount(Constants.EARTH_RUNE_ID) > 10
  192. && Inventory.getCount(Constants.FIRE_RUNE_ID) > 10;
  193.  
  194. boolean hasTabs = Inventory.getCount(Constants.VARROCK_TAB_ID) >= 3
  195. && Inventory.getCount(Constants.LUMBRIDGE_TAB_ID) >= 3
  196. && Inventory.getCount(Constants.CAMELOT_TAB_ID) >= 3
  197. && Inventory.getCount(Constants.FALADOR_TAB_ID) >= 3;
  198.  
  199. boolean teleports = getMain().getTeleportMethod().equals(TeleportMethod.TABS)
  200. ? hasTabs : hasRunes;
  201.  
  202. boolean hasFood = getMain().getFoodAmount() > 0
  203. ? Inventory.getCount(getMain().getFoodName()) >= 2 : true;
  204.  
  205. boolean hasSpade = Inventory.getCount(Constants.SPADE) >= 0;
  206.  
  207. return hasRing && hasNecklace && teleports && hasFood && hasSpade;
  208. }
  209.  
  210. public boolean performBankTask() {
  211.  
  212. getMain().setStatus("Depositing Items");
  213. Banking.depositAllExcept(getRequiredInventoryItems());
  214.  
  215. if(getMain().getFoodName().equals("Trout"))
  216. depositNotedTrout(); //Deposit noted trout if we are using trout as food
  217.  
  218. boolean teleports = getMain().getTeleportMethod().equals(TeleportMethod.TABS)
  219. ? withdrawTabs() : withdrawRunes();
  220.  
  221. boolean ring = Inventory.getCount(Constants.DUEL_RING_ID) > 0
  222. || Equipment.isEquipped(Constants.DUEL_RING_ID);
  223.  
  224. boolean necklace = Inventory.getCount(Constants.DUEL_RING_ID) > 0
  225. || Equipment.isEquipped(Constants.DUEL_RING_ID);
  226.  
  227. boolean spade = Inventory.getCount(Constants.SPADE) > 0;
  228.  
  229. boolean food = true;
  230.  
  231. if(!ring)
  232. ring = withdrawBankItem(Constants.DUEL_RING_ID[0], 1);
  233.  
  234. if(!necklace)
  235. necklace = withdrawBankItem(Constants.GAMES_NECKLACE_ID[0], 1);
  236.  
  237. if(!spade)
  238. spade = withdrawBankItem(Constants.SPADE, 1);
  239.  
  240.  
  241. if(getMain().getFoodAmount() > 0) {
  242. if(Inventory.getCount(getMain().getFoodName()) <= 3) {
  243. food = withdrawBankItem(getMain().getFoodName(), getMain().getFoodAmount());
  244.  
  245. }
  246. }
  247.  
  248. checkForClue();
  249.  
  250. return teleports && ring && necklace && spade && food;
  251. }
  252.  
  253. public boolean bankForEquipment(ClueTask task, String[] requiredItems) {
  254.  
  255. if(!getMain().getClueScroll().isEmoteTeleport()) {
  256.  
  257. TeleportLocation loc = task.getTeleLocation();
  258. RSTile walk = task.getEmoteClue().getWalkLocation();
  259. RSArea teleArea = !getMain().getBank().isBankAtLocation(loc) ? TeleportLocation.FALADOR.getArea() : task.getTeleLocationArea();
  260. int dist = teleArea.getRandomTile().distanceTo(Player.getPosition());
  261. int walkDist = walk.distanceTo(Player.getPosition());
  262.  
  263. if(dist > walkDist && Player.getPosition().getPlane() == 0 && !Locations.inHamDungeon() && walkDist < 100) {
  264. getMain().println("Teleport Distance("+dist+") is greater than the Walking Distance("+walkDist+").");
  265. getMain().getClueScroll().setEmoteTeleport(true);
  266. return false;
  267. }
  268.  
  269. if(dist > 50) {
  270.  
  271. if(!getMain().getBank().isBankAtLocation(loc))
  272. getMain().getTeleporting().teleportTo(TeleportLocation.FALADOR);
  273. else {
  274. getMain().getTeleporting().teleportTo(loc);
  275. getMain().getClueScroll().setTeleported(true);
  276. }
  277.  
  278. getMain().getClueScroll().setEmoteTeleport(true);
  279. }
  280. }
  281.  
  282. checkPlane();
  283.  
  284. if(!requiredItems[0].equals("")) {
  285.  
  286. if(Banking.openBank()) {
  287. if((!getMain().getClueScroll().hasAllItems(task) && Banking.isBankScreenOpen())) {
  288. getMain().setStatus("Withdrawing Required Equipment");
  289. getMain().getBank().withdrawRequiredEquipment(requiredItems);
  290. }
  291. } else if(!Banking.isInBank()) {
  292. getMain().setStatus("Walking to Bank");
  293. WebWalking.walkToBank();
  294. }
  295.  
  296. if(Banking.isBankScreenOpen()) {
  297. Banking.close();
  298. }
  299. }
  300. return Inventory.getCount(requiredItems) >= requiredItems.length;
  301. }
  302.  
  303. public boolean checkPlane() {
  304.  
  305. if(Player.getPosition().getPlane() > 0
  306. && !Locations.LUMBRIDGE_CASLTE_SECOND_FLOOR.contains(Player.getPosition())) {
  307.  
  308. if(getMain().getClueScroll().tooManyTries(tries)) {
  309. tries = 0;
  310. getMain().getTeleporting().teleportTo(TeleportLocation.FALADOR);
  311. return true;
  312.  
  313. }
  314.  
  315. tries++;
  316.  
  317. abc.waitNewOrSwitchDelay(last_busy_time, false);
  318.  
  319. getMain().getClueScroll().climb(false);
  320.  
  321. last_busy_time = System.currentTimeMillis();
  322.  
  323. return true;
  324. }
  325.  
  326. return false;
  327.  
  328. }
  329.  
  330. public String[] getRequiredInventoryItems() {
  331.  
  332. String[] invItems = Constants.INVENTORY_ITEMS;
  333. String[] teleports = getMain().getTeleportMethod().equals(TeleportMethod.TABS)
  334. ? Constants.TABS : Constants.RUNES;
  335. String[] reqItems = new String[4];
  336. String[] equipment = new String[getMain().getEquipped().getPlayerEquipment().size()];
  337. String[] items = new String[invItems.length + reqItems.length + equipment.length + Constants.RUNES.length + Constants.EMOTE_EQUIPMENT.length + 10];
  338. int index = 0;
  339. int eIndex = 0;
  340. int tIndex = 0;
  341.  
  342. //set equipment array
  343. for(int i = 0; i < equipment.length; i++) {
  344. equipment[i] = getMain().getEquipped().getPlayerEquipment().get(i);
  345. }
  346.  
  347. //add inventory items to array
  348. for(int i = 0; i < invItems.length; i++) {
  349. items[i] = invItems[i];
  350. index = i;
  351. }
  352.  
  353. index++;
  354.  
  355. // add food to array
  356. items[index] = getMain().getFoodName();
  357.  
  358. index++;
  359.  
  360. // add teleports to array
  361. int start = index;
  362. for(int i = start; i < start + teleports.length; i++) {
  363. items[i] = teleports[tIndex++];
  364. index = i;
  365. }
  366.  
  367. index++;
  368.  
  369. //add start equipment to array
  370. start = index;
  371. for(int i = start; i < start + equipment.length; i++) {
  372. if(!Equipment.isEquipped(equipment[eIndex])) {
  373. items[i] = equipment[eIndex];
  374. }
  375. eIndex++;
  376. index = i;
  377. }
  378.  
  379. index++;
  380.  
  381. //add emote equipment to array
  382. if(getMain().getClueTask() != null) {
  383. EmoteClue e = getMain().getClueTask().getEmoteClue();
  384. if(e != null) {
  385. int length = e.getItems().length;
  386. int reqIndex = 0;
  387. start = index;
  388. for(int i = start; i < start + length; i++) {
  389. items[i] = e.getItems()[reqIndex++];
  390. index = i;
  391. }
  392. }
  393. return items;
  394. }
  395. return items;
  396. }
  397.  
  398. public boolean checkForClue() {
  399. if(!getMain().getClueScroll().hasClue()) {
  400. if(withdrawBankItem("Clue scroll (easy)", 1)) {
  401. return true;
  402. }
  403. }
  404.  
  405. if(!getMain().getClueScroll().hasCasket()) {
  406. if(withdrawBankItem("Casket (easy)", 1)) {
  407. return true;
  408. }
  409. }
  410.  
  411. return false;
  412. }
  413.  
  414. public boolean depositNotedTrout() {
  415. if(Banking.isBankScreenOpen()) {
  416. RSItem[] trout = Inventory.find(334);
  417. if(trout.length > 0) {
  418. if(trout[0].click("Deposit-All")) {
  419. return true;
  420. }
  421. }
  422. }
  423. return false;
  424. }
  425.  
  426. public boolean isBankAtLocation(TeleportLocation loc) {
  427. switch(loc) {
  428. case BURTHORPE:
  429. case LUMBRIDGE:
  430. return false;
  431. case DUELARENA:
  432. case ARDOUGNE:
  433. case CAMELOT:
  434. case CASTLEWARS:
  435. case FALADOR:
  436. case VARROCK:
  437. return true;
  438.  
  439. }
  440. return false;
  441. }
  442.  
  443. public boolean isInBank() {
  444. for (BankLocation bank : BankLocation.values())
  445. if (bank.contains(Player.getPosition()))
  446. return true;
  447. return false;
  448. }
  449.  
  450. public int getClosestBankDistance() {
  451. int distance = 500;
  452. for (BankLocation bank : BankLocation.values()) {
  453. if(bank.distanceTo(Player.getPosition()) < distance)
  454. distance = bank.distanceTo(Player.getPosition());
  455. }
  456. return distance;
  457. }
  458.  
  459. public enum BankLocation {
  460.  
  461. CASTLE_WARS(new RSArea(new RSTile(2443, 3082, 0), new RSTile(2441, 3085, 0))),
  462.  
  463. LUMBRIDGE(new RSArea(new RSTile(3210, 3216, 2), new RSTile(3207, 3220, 2))),
  464.  
  465. DRAYNOR(new RSArea(new RSTile(3092, 3246, 0), new RSTile(3095, 3240, 0))),
  466.  
  467. VARROCK_EAST(new RSArea(new RSTile(3257, 3419, 0), new RSTile(3250, 3423, 0))),
  468.  
  469. VARROCK_WEST(new RSArea(new RSTile(3185, 3433, 0), new RSTile(3180, 3447, 0))),
  470.  
  471. GRAND_EXCHANGE(new RSArea(new RSTile[] {
  472. new RSTile(3170, 3495, 0),
  473. new RSTile(3159, 3495, 0),
  474. new RSTile(3159, 3485, 0),
  475. new RSTile(3170, 3485, 0)
  476. })),
  477.  
  478. PORT_SARIM(new RSArea(new RSTile(3047, 3233, 0), new RSTile(3042, 3238, 0))),
  479.  
  480. FALADOR_EAST(new RSArea(new RSTile(3018, 3355, 0), new RSTile(3009, 3358, 0))),
  481.  
  482. FALADOR_WEST(new RSArea(new RSTile[]{new RSTile(2949, 3368, 0),
  483. new RSTile(2949, 3369, 0),
  484. new RSTile(2948, 3369, 0),
  485. new RSTile(2947, 3373, 0),
  486. new RSTile(2943, 3373, 0),
  487. new RSTile(2943, 3368, 0)
  488. })),
  489.  
  490. AL_KHARID(new RSArea(new RSTile(3272, 3162, 0), new RSTile(3269, 3171, 0))),
  491.  
  492. EDGEVILLE(new RSArea(new RSTile[]{
  493. new RSTile(3094, 3488, 0),
  494. new RSTile(3091, 3488, 0),
  495. new RSTile(3091, 3494, 0),
  496. new RSTile(3094, 3498, 0),
  497. new RSTile(3098, 3498, 0),
  498. new RSTile(3099, 3494, 0),
  499. new RSTile(3095, 3494, 0)
  500. })),
  501.  
  502. CATHERBY(new RSArea(new RSTile(2812, 3441, 0), new RSTile(2806, 3438, 0))),
  503.  
  504. SEERS_VILLAGE(new RSArea(new RSTile(2730, 3493, 0), new RSTile(2721, 3490, 0)));
  505.  
  506. private RSArea area;
  507.  
  508. BankLocation(RSArea area) {
  509. this.area = area;
  510. }
  511.  
  512. public RSArea getArea() {
  513. return area;
  514. }
  515.  
  516. public boolean contains(RSTile tile) {
  517. return getArea().contains(tile);
  518. }
  519.  
  520. public int distanceTo(RSTile tile) {
  521. return getArea().getRandomTile().distanceTo(tile);
  522. }
  523.  
  524. }
  525.  
  526. public Main getMain() {
  527. return main;
  528. }
  529.  
  530. public void setMain(Main main) {
  531. this.main = main;
  532. }
  533.  
  534. public boolean isBankTeleport() {
  535. return bankTeleport;
  536. }
  537.  
  538. public void setBankTeleport(boolean bankTeleport) {
  539. this.bankTeleport = bankTeleport;
  540. }
  541.  
  542. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement