Advertisement
iant06

Untitled

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