Advertisement
iant06

Untitled

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