Guest User

Untitled

a guest
Nov 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 23.38 KB | None | 0 0
  1. package org.rsbot.script.methods;
  2.  
  3. import org.rsbot.script.util.Filter;
  4. import org.rsbot.script.wrappers.*;
  5.  
  6. import java.awt.*;
  7.  
  8. /**
  9. * Bank related operations.
  10. */
  11. public class Bank extends MethodProvider {
  12. public static final Filter<RSObject> OBJECT_BANKS = new Filter<RSObject>() {
  13. private final String[] bankNames = {"Bank Booth", "Bank Chest", "Counter"};
  14.  
  15. public boolean accept(final RSObject rsObject) {
  16. final String name = rsObject != null ? rsObject.getName() : null;
  17. for (String bankName : bankNames) {
  18. if (name.equalsIgnoreCase(bankName)) {
  19. return true;
  20. }
  21. }
  22. return false;
  23. }
  24. };
  25.  
  26. public static final Filter<RSObject> OBJECT_DEPOSIT_BOX = new Filter<RSObject>() {
  27. private final String[] depositBoxNames = {"Deposit Box"};
  28.  
  29. public boolean accept(final RSObject rsObject) {
  30. final String name = rsObject != null ? rsObject.getName() : null;
  31. for (String bankName : depositBoxNames) {
  32. if (name.equalsIgnoreCase(bankName)) {
  33. return true;
  34. }
  35. }
  36. return false;
  37. }
  38. };
  39.  
  40. public static final Filter<RSNPC> NPC_BANKERS = new Filter<RSNPC>() {
  41. private final String[] bankerNames = {"Banker"};
  42.  
  43. public boolean accept(final RSNPC rsNPC) {
  44. final String name = rsNPC != null ? rsNPC.getName() : null;
  45. for (String bankName : bankerNames) {
  46. if (name.equalsIgnoreCase(bankName)) {
  47. return true;
  48. }
  49. }
  50. return false;
  51. }
  52. };
  53.  
  54. public static final int INTERFACE_BANK = 762;
  55. public static final int INTERFACE_BANK_BUTTON_CLOSE = 43;
  56. public static final int INTERFACE_BANK_BUTTON_DEPOSIT_BEAST_INVENTORY = 38;
  57. public static final int INTERFACE_BANK_BUTTON_DEPOSIT_CARRIED_ITEMS = 34;
  58. public static final int INTERFACE_BANK_BUTTON_DEPOSIT_WORN_ITEMS = 36;
  59. public static final int INTERFACE_BANK_BUTTON_HELP = 44;
  60. public static final int INTERFACE_BANK_BUTTON_INSERT = 15;
  61. public static final int INTERFACE_BANK_BUTTON_ITEM = 19;
  62. public static final int INTERFACE_BANK_BUTTON_NOTE = 19;
  63. public static final int INTERFACE_BANK_BUTTON_SEARCH = 17;
  64. public static final int INTERFACE_BANK_BUTTON_SWAP = 15;
  65. public static final int INTERFACE_BANK_BUTTON_OPEN_EQUIP = 117;
  66. public static final int INTERFACE_BANK_INVENTORY = 93;
  67. public static final int INTERFACE_BANK_ITEM_FREE_COUNT = 29;
  68. public static final int INTERFACE_BANK_ITEM_FREE_MAX = 30;
  69. public static final int INTERFACE_BANK_ITEM_MEMBERS_COUNT = 31;
  70. public static final int INTERFACE_BANK_ITEM_MEMBERS_MAX = 32;
  71. public static final int INTERFACE_BANK_SCROLLBAR = 114;
  72. public static final int INTERFACE_BANK_SEARCH = 752;
  73. public static final int INTERFACE_BANK_SEARCH_INPUT = 5;
  74.  
  75. public static final int INTERFACE_EQUIPMENT = 667;
  76. public static final int INTERFACE_EQUIPMENT_COMPONENT = 7;
  77.  
  78. public static final int INTERFACE_COLLECTION_BOX = 105;
  79. public static final int INTERFACE_COLLECTION_BOX_CLOSE = 13;
  80.  
  81. public static final int[] INTERFACE_BANK_TAB = {63, 61, 59, 57, 55, 53, 51, 49, 47};
  82. public static final int[] INTERFACE_BANK_TAB_FIRST_ITEM = {78, 79, 80, 81, 82, 83, 84, 85, 86};
  83.  
  84. public static final int INTERFACE_DEPOSIT_BOX = 11;
  85. public static final int INTERFACE_DEPOSIT_BOX_BUTTON_CLOSE = 15;
  86. public static final int INTERFACE_DEPOSIT_BUTTON_DEPOSIT_BEAST_INVENTORY = 22;
  87. public static final int INTERFACE_DEPOSIT_BUTTON_DEPOSIT_CARRIED_ITEMS = 18;
  88. public static final int INTERFACE_DEPOSIT_BUTTON_DEPOSIT_WORN_ITEMS = 20;
  89.  
  90.  
  91. Bank(final MethodContext ctx) {
  92. super(ctx);
  93. }
  94.  
  95. /**
  96. * Closes the bank interface. Supports deposit boxes.
  97. *
  98. * @return <tt>true</tt> if the bank interface is no longer open.
  99. */
  100. public boolean close() {
  101. if (isOpen()) {
  102. methods.interfaces.getComponent(INTERFACE_BANK, INTERFACE_BANK_BUTTON_CLOSE).doClick();
  103. sleep(random(500, 600));
  104. return !isOpen();
  105. }
  106. if (isDepositOpen()) {
  107. methods.interfaces.getComponent(INTERFACE_DEPOSIT_BOX, INTERFACE_DEPOSIT_BOX_BUTTON_CLOSE).doClick();
  108. sleep(random(500, 600));
  109. return !isDepositOpen();
  110. }
  111. return false;
  112. }
  113.  
  114. /**
  115. * If bank is open, deposits specified amount of an item into the bank.
  116. * Supports deposit boxes.
  117. *
  118. * @param itemID The ID of the item.
  119. * @param number The amount to deposit. 0 deposits All. 1,5,10 deposit
  120. * corresponding amount while other numbers deposit X.
  121. * @return <tt>true</tt> if successful; otherwise <tt>false</tt>.
  122. */
  123. public boolean deposit(final int itemID, final int number) {
  124. if (isOpen() || isDepositOpen()) {
  125. if (number < 0) {
  126. throw new IllegalArgumentException("number < 0 (" + number + ")");
  127. }
  128. RSComponent item = null;
  129. int itemCount = 0;
  130. final int invCount = isOpen() ? methods.inventory.getCount(true) : getBoxCount();
  131. if (!isOpen()) {
  132. boolean match = false;
  133. for (int i = 0; i < 28; i++) {
  134. final RSComponent comp = methods.interfaces.get(11).getComponent(17).getComponent(i);
  135. if (comp.getComponentID() == itemID) {
  136. itemCount += comp.getComponentStackSize();
  137. if (!match) {
  138. item = comp;
  139. match = true;
  140. }
  141. }
  142. if (itemCount > 1) {
  143. break;
  144. }
  145. }
  146. } else {
  147. item = methods.inventory.getItem(itemID).getComponent();
  148. itemCount = methods.inventory.getCount(true, itemID);
  149. }
  150. if (item == null) {
  151. return true;
  152. }
  153. switch (number) {
  154. case 0:
  155. item.interact(itemCount > 1 ? "Deposit-All" : "Deposit");
  156. break;
  157. case 1:
  158. item.interact("Deposit");
  159. break;
  160. case 5:
  161. item.interact("Deposit-" + number);
  162. break;
  163. default:
  164. if (!item.interact("Deposit-" + number)) {
  165. if (item.interact("Deposit-X")) {
  166. sleep(random(1000, 1300));
  167. methods.inputManager.sendKeys(String.valueOf(number), true);
  168. }
  169. }
  170. break;
  171. }
  172. sleep(300);
  173. final int cInvCount = isOpen() ? methods.inventory.getCount(true) : getBoxCount();
  174. return cInvCount < invCount || cInvCount == 0;
  175. }
  176. return false;
  177. }
  178.  
  179. /**
  180. * Deposits all items in methods.inventory. Supports deposit boxes.
  181. *
  182. * @return <tt>true</tt> on success.
  183. */
  184. public boolean depositAll() {
  185. if (isOpen()) {
  186. return methods.interfaces.getComponent(INTERFACE_BANK, INTERFACE_BANK_BUTTON_DEPOSIT_CARRIED_ITEMS).doClick();
  187. }
  188. return isDepositOpen() && methods.interfaces.getComponent(INTERFACE_DEPOSIT_BOX, INTERFACE_DEPOSIT_BUTTON_DEPOSIT_CARRIED_ITEMS).doClick();
  189. }
  190.  
  191. /**
  192. * Deposits all items in inventory except for the given IDs. Supports
  193. * deposit boxes.
  194. *
  195. * @param items The items not to deposit.
  196. * @return true on success.
  197. */
  198. public boolean depositAllExcept(final int... items) {
  199. if (isOpen() || isDepositOpen()) {
  200. boolean deposit = true;
  201. int invCount = isOpen() ? methods.inventory.getCount(true) : getBoxCount();
  202. outer:
  203. for (int i = 0; i < 28; i++) {
  204. final RSComponent item = isOpen() ? methods.inventory.getItemAt(i).getComponent() : methods.interfaces.get(11).getComponent(17).getComponent(i);
  205. if (item != null && item.getComponentID() != -1) {
  206. for (final int id : items) {
  207. if (item.getComponentID() == id) {
  208. continue outer;
  209. }
  210. }
  211. for (int tries = 0; tries < 5; tries++) {
  212. deposit(item.getComponentID(), 0);
  213. sleep(random(600, 900));
  214. final int cInvCount = isOpen() ? methods.inventory.getCount(true) : getBoxCount();
  215. if (cInvCount < invCount) {
  216. invCount = cInvCount;
  217. continue outer;
  218. }
  219. }
  220. deposit = false;
  221. }
  222. }
  223. return deposit;
  224. }
  225. return false;
  226. }
  227.  
  228. /**
  229. * Deposit everything your player has equipped. Supports deposit boxes.
  230. *
  231. * @return <tt>true</tt> on success.
  232. * @since 6 March 2009.
  233. */
  234. public boolean depositAllEquipped() {
  235. if (isOpen()) {
  236. return methods.interfaces.getComponent(INTERFACE_BANK, INTERFACE_BANK_BUTTON_DEPOSIT_WORN_ITEMS).doClick();
  237. }
  238. return isDepositOpen() && methods.interfaces.getComponent(INTERFACE_DEPOSIT_BOX, INTERFACE_DEPOSIT_BUTTON_DEPOSIT_WORN_ITEMS).doClick();
  239. }
  240.  
  241. /**
  242. * Deposits everything your familiar is carrying. Supports deposit boxes.
  243. *
  244. * @return <tt>true</tt> on success
  245. * @since 6 March 2009.
  246. */
  247. public boolean depositAllFamiliar() {
  248. if (isOpen()) {
  249. return methods.interfaces.getComponent(INTERFACE_BANK, INTERFACE_BANK_BUTTON_DEPOSIT_BEAST_INVENTORY).doClick();
  250. }
  251. return isDepositOpen() && methods.interfaces.getComponent(INTERFACE_DEPOSIT_BOX, INTERFACE_DEPOSIT_BUTTON_DEPOSIT_BEAST_INVENTORY).doClick();
  252. }
  253.  
  254. /**
  255. * Returns the sum of the count of the given items in the bank.
  256. *
  257. * @param items The array of items.
  258. * @return The sum of the stacks of the items.
  259. */
  260. public int getCount(final int... items) {
  261. int itemCount = 0;
  262. final RSItem[] inventoryArray = getItems();
  263. for (final RSItem item : inventoryArray) {
  264. for (final int id : items) {
  265. if (item.getID() == id) {
  266. itemCount += item.getStackSize();
  267. }
  268. }
  269. }
  270. return itemCount;
  271. }
  272.  
  273. /**
  274. * Get current tab open in the bank.
  275. *
  276. * @return int of tab (0-8), or -1 if none are selected (bank is not open).
  277. */
  278. public int getCurrentTab() {
  279. for (int i = 0; i < INTERFACE_BANK_TAB.length; i++) {
  280. if (methods.interfaces.get(INTERFACE_BANK).getComponent(INTERFACE_BANK_TAB[i] - 1).getBackgroundColor() == 1419) {
  281. return i;
  282. }
  283. }
  284. return -1;
  285. }
  286.  
  287. /**
  288. * Gets the bank interface.
  289. *
  290. * @return The bank <code>RSInterface</code>.
  291. */
  292. public RSInterface getInterface() {
  293. return methods.interfaces.get(INTERFACE_BANK);
  294. }
  295.  
  296. /**
  297. * Gets the deposit box interface.
  298. *
  299. * @return The deposit box <code>RSInterface</code>.
  300. */
  301. public RSInterface getBoxInterface() {
  302. return methods.interfaces.get(INTERFACE_BANK);
  303. }
  304.  
  305. /**
  306. * Gets the <code>RSComponent</code> of the given item at the specified index.
  307. *
  308. * @param index The index of the item.
  309. * @return <code>RSComponent</code> if item is found at index; otherwise null.
  310. */
  311. public RSItem getItemAt(final int index) {
  312. final RSItem[] items = getItems();
  313. if (items != null) {
  314. for (final RSItem item : items) {
  315. if (item.getComponent().getComponentIndex() == index) {
  316. return item;
  317. }
  318. }
  319. }
  320.  
  321. return null;
  322. }
  323.  
  324. /**
  325. * Gets the first item with the provided ID in the bank.
  326. *
  327. * @param id ID of the item to get.
  328. * @return The component of the item; otherwise null.
  329. */
  330. public RSItem getItem(final int id) {
  331. final RSItem[] items = getItems();
  332. if (items != null) {
  333. for (final RSItem item : items) {
  334. if (item.getID() == id) {
  335. return item;
  336. }
  337. }
  338. }
  339. return null;
  340. }
  341.  
  342. /**
  343. * Gets the point on the screen for a given item. Numbered left to right then top to bottom.
  344. *
  345. * @param slot The index of the item.
  346. * @return The point of the item or new Point(-1, -1) if null.
  347. */
  348. public Point getItemPoint(final int slot) {
  349. if (slot < 0) {
  350. throw new IllegalArgumentException("slot < 0 " + slot);
  351. }
  352. final RSItem item = getItemAt(slot);
  353. if (item != null) {
  354. return item.getComponent().getLocation();
  355. }
  356. return new Point(-1, -1);
  357. }
  358.  
  359. /**
  360. * Gets all the items in the bank's inventory.
  361. *
  362. * @return an <code>RSItem</code> array of the bank's inventory interface.
  363. */
  364. public RSItem[] getItems() {
  365. if (getInterface() == null || getInterface().getComponent(INTERFACE_BANK_INVENTORY) == null) {
  366. return new RSItem[0];
  367. }
  368. final RSComponent[] components = getInterface().getComponent(INTERFACE_BANK_INVENTORY).getComponents();
  369. final RSItem[] items = new RSItem[components.length];
  370. for (int i = 0; i < items.length; ++i) {
  371. items[i] = new RSItem(methods, components[i]);
  372. }
  373. return items;
  374. }
  375.  
  376. /**
  377. * Checks whether or not the bank is open.
  378. *
  379. * @return <tt>true</tt> if the bank interface is open; otherwise <tt>false</tt>.
  380. */
  381. public boolean isOpen() {
  382. return getInterface().isValid();
  383. }
  384.  
  385. /**
  386. * Checks whether or not the deposit box is open.
  387. *
  388. * @return <tt>true</tt> if the deposit box interface is open; otherwise <tt>false</tt>.
  389. */
  390. public boolean isDepositOpen() {
  391. return methods.interfaces.get(INTERFACE_DEPOSIT_BOX).isValid();
  392. }
  393.  
  394. /**
  395. * Opens one of the supported banker NPCs, booths, or chests nearby. If they
  396. * are not nearby, and they are not null, it will automatically walk to the
  397. * closest one.
  398. *
  399. * @return <tt>true</tt> if the bank was opened; otherwise <tt>false</tt>.
  400. */
  401. public boolean open() {
  402. if (isOpen()) {
  403. return true;
  404. }
  405. try {
  406. if (methods.menu.isOpen()) {
  407. methods.mouse.moveSlightly();
  408. sleep(random(20, 30));
  409. }
  410. RSObject bankBooth = methods.objects.getNearest(OBJECT_BANKS);
  411. RSNPC banker = methods.npcs.getNearest(NPC_BANKERS);
  412. /* Find closest one, others are set to null. Remember distance and tile. */
  413. int lowestDist = Integer.MAX_VALUE;
  414. RSTile tile = null;
  415. if (bankBooth != null) {
  416. tile = bankBooth.getLocation();
  417. lowestDist = methods.calc.distanceTo(tile);
  418. }
  419. if (banker != null && methods.calc.distanceTo(banker) < lowestDist) {
  420. tile = banker.getLocation();
  421. lowestDist = methods.calc.distanceTo(tile);
  422. bankBooth = null;
  423. }
  424. /* Open closest one, if any found */
  425. if (lowestDist < 5 && methods.calc.tileOnMap(tile) && methods.calc.canReach(tile, true)) {
  426. boolean didAction = false;
  427. if (bankBooth != null) {
  428. didAction = bankBooth.interact("Use-quickly");
  429. } else if (banker != null) {
  430. didAction = banker.interact("Bank Banker");
  431. }
  432. if (didAction) {
  433. int count = 0;
  434. while (!isOpen() && ++count < 10) {
  435. sleep(random(200, 400));
  436. if (methods.players.getMyPlayer().isMoving()) {
  437. count = 0;
  438. }
  439. }
  440. } else {
  441. methods.camera.turnTo(tile);
  442. }
  443. } else if (tile != null) {
  444. methods.walking.walkTileMM(tile);
  445. }
  446. return isOpen();
  447. } catch (final Exception e) {
  448. e.printStackTrace();
  449. return false;
  450. }
  451. }
  452.  
  453. /**
  454. * Opens one of the supported deposit boxes nearby. If they are not nearby, and they are not null,
  455. * it will automatically walk to the closest one.
  456. *
  457. * @return <tt>true</tt> if the deposit box was opened; otherwise
  458. * <tt>false</tt>.
  459. */
  460. public boolean openDepositBox() {
  461. try {
  462. if (!isDepositOpen()) {
  463. if (methods.menu.isOpen()) {
  464. methods.mouse.moveSlightly();
  465. sleep(random(20, 30));
  466. }
  467. final RSObject depositBox = methods.objects.getNearest(OBJECT_DEPOSIT_BOX);
  468. if (depositBox != null && methods.calc.distanceTo(depositBox) < 8 && methods.calc.tileOnMap(depositBox.getLocation()) && methods.calc.canReach(depositBox.getLocation(), true)) {
  469. if (depositBox.interact("Deposit")) {
  470. int count = 0;
  471. while (!isDepositOpen() && ++count < 10) {
  472. sleep(random(200, 400));
  473. if (methods.players.getMyPlayer().isMoving()) {
  474. count = 0;
  475. }
  476. }
  477. } else {
  478. methods.camera.turnTo(depositBox, 20);
  479. }
  480. } else {
  481. if (depositBox != null) {
  482. methods.walking.walkTo(depositBox.getLocation());
  483. }
  484. }
  485. }
  486. return isDepositOpen();
  487. } catch (final Exception e) {
  488. e.printStackTrace();
  489. return false;
  490. }
  491. }
  492.  
  493. /**
  494. * Opens the bank tab.
  495. *
  496. * @param tabNumber The tab number - e.g. view all is 1.
  497. * @return <tt>true</tt> on success.
  498. */
  499. public boolean openTab(final int tabNumber) {
  500. return isOpen() && methods.interfaces.getComponent(INTERFACE_BANK, INTERFACE_BANK_TAB[tabNumber - 1]).doClick();
  501. }
  502.  
  503. /**
  504. * @return <tt>true</tt> if currently searching the bank.
  505. */
  506. public boolean isSearchOpen() {
  507. // Setting 1248 is -2147483648 when search is enabled and -2013265920
  508. return methods.settings.getSetting(1248) == -2147483648;
  509. }
  510.  
  511. /**
  512. * Searches for an item in the bank. Returns true if succeeded (does not
  513. * necessarily mean it was found).
  514. *
  515. * @param itemName The item name to find.
  516. * @return <tt>true</tt> on success.
  517. */
  518. public boolean searchItem(final String itemName) {
  519. if (!isOpen()) {
  520. return false;
  521. }
  522. methods.interfaces.getComponent(INTERFACE_BANK, INTERFACE_BANK_BUTTON_SEARCH).interact("Search");
  523. sleep(random(1000, 1500));
  524. if (!isSearchOpen()) {
  525. sleep(500);
  526. }
  527. if (isOpen() && isSearchOpen()) {
  528. methods.inputManager.sendKeys(itemName, false);
  529. sleep(random(300, 700));
  530. return true;
  531. }
  532. return false;
  533. }
  534.  
  535. /**
  536. * Sets the bank rearrange mode to insert.
  537. *
  538. * @return <tt>true</tt> on success.
  539. */
  540. public boolean setRearrangeModeToInsert() {
  541. if (!isOpen()) {
  542. return false;
  543. }
  544. if (methods.settings.getSetting(Settings.SETTING_BANK_TOGGLE_REARRANGE_MODE) != 1) {
  545. methods.interfaces.getComponent(INTERFACE_BANK, INTERFACE_BANK_BUTTON_INSERT).doClick();
  546. sleep(random(500, 700));
  547. }
  548. return methods.settings.getSetting(Settings.SETTING_BANK_TOGGLE_REARRANGE_MODE) == 1;
  549. }
  550.  
  551. /**
  552. * Sets the bank rearrange mode to swap.
  553. *
  554. * @return <tt>true</tt> on success.
  555. */
  556. public boolean setRearrangeModeToSwap() {
  557. if (!isOpen()) {
  558. return false;
  559. }
  560. if (methods.settings.getSetting(Settings.SETTING_BANK_TOGGLE_REARRANGE_MODE) != 0) {
  561. methods.interfaces.getComponent(INTERFACE_BANK, INTERFACE_BANK_BUTTON_SWAP).doClick();
  562. sleep(random(500, 700));
  563. }
  564. return methods.settings.getSetting(Settings.SETTING_BANK_TOGGLE_REARRANGE_MODE) == 0;
  565. }
  566.  
  567. /**
  568. * Sets the bank withdraw mode to item.
  569. *
  570. * @return <tt>true</tt> on success.
  571. */
  572. public boolean setWithdrawModeToItem() {
  573. if (!isOpen()) {
  574. return false;
  575. }
  576. if (methods.settings.getSetting(Settings.SETTING_BANK_TOGGLE_WITHDRAW_MODE) != 0) {
  577. methods.interfaces.getComponent(INTERFACE_BANK, INTERFACE_BANK_BUTTON_ITEM).doClick();
  578. sleep(random(500, 700));
  579. }
  580. return methods.settings.getSetting(Settings.SETTING_BANK_TOGGLE_WITHDRAW_MODE) == 0;
  581. }
  582.  
  583. /**
  584. * Sets the bank withdraw mode to note.
  585. *
  586. * @return <tt>true</tt> on success.
  587. */
  588. public boolean setWithdrawModeToNote() {
  589. if (!isOpen()) {
  590. return false;
  591. }
  592. if (methods.settings.getSetting(Settings.SETTING_BANK_TOGGLE_WITHDRAW_MODE) != 1) {
  593. methods.interfaces.getComponent(INTERFACE_BANK, INTERFACE_BANK_BUTTON_NOTE).doClick();
  594. sleep(random(500, 700));
  595. }
  596. return methods.settings.getSetting(Settings.SETTING_BANK_TOGGLE_WITHDRAW_MODE) == 1;
  597. }
  598.  
  599. /**
  600. * Tries to withdraw an item.
  601. * 0 is All. 1,5,10 use Withdraw 1,5,10 while other numbers Withdraw X.
  602. *
  603. * @param itemID The ID of the item.
  604. * @param count The number to withdraw.
  605. * @return <tt>true</tt> on success.
  606. */
  607. public boolean withdraw(final int itemID, final int count) {
  608. if (!isOpen()) {
  609. return false;
  610. }
  611. if (count < 0) {
  612. throw new IllegalArgumentException("count (" + count + ") < 0");
  613. }
  614. final RSItem rsi = getItem(itemID);
  615. if (rsi == null || rsi.getID() == -1) {
  616. return false;
  617. }
  618. final RSComponent item = rsi.getComponent();
  619. if (item == null) {
  620. return false;
  621. }
  622. int t = 0;
  623. while (item.getRelativeX() == 0 && methods.bank.getCurrentTab() != 0 && t < 5) {
  624. if (methods.interfaces.getComponent(Bank.INTERFACE_BANK, Bank.INTERFACE_BANK_TAB[0]).doClick()) {
  625. sleep(random(800, 1300));
  626. }
  627. t++;
  628. }
  629. if (!methods.interfaces.scrollTo(item, (Bank.INTERFACE_BANK << 16) + Bank.INTERFACE_BANK_SCROLLBAR)) {
  630. return false;
  631. }
  632. final int invCount = methods.inventory.getCount(true);
  633. item.doClick(count == 1 ? true : false);
  634. final String defaultAction = "Withdraw-" + count;
  635. String action = null;
  636. switch (count) {
  637. case 0:
  638. action = "Withdraw-All";
  639. break;
  640. case 1:
  641. break;
  642. case 5:
  643. action = defaultAction;
  644. break;
  645. case 10:
  646. action = defaultAction;
  647. break;
  648. default:
  649. int i = -1;
  650. try {
  651. i = Integer.parseInt(item.getActions()[3].toLowerCase().trim().replaceAll("\\D", ""));
  652. } catch (final Exception e) {
  653. e.printStackTrace();
  654. }
  655. if (i == count) {
  656. action = defaultAction;
  657. } else if (item.interact("Withdraw-X")) {
  658. sleep(random(1000, 1300));
  659. methods.keyboard.sendText(String.valueOf(count), true);
  660. }
  661. }
  662. if (action != null && item.interact(action)) {
  663. sleep(random(1000, 1300));
  664. }
  665. final int newInvCount = methods.inventory.getCount(true);
  666. return newInvCount > invCount;
  667. }
  668.  
  669. /**
  670. * Gets the count of all the items in the inventory with the any of the
  671. * specified IDs while deposit box is open.
  672. *
  673. * @param ids the item IDs to include
  674. * @return The count.
  675. */
  676. public int getBoxCount(final int... ids) {
  677. if (!isDepositOpen()) {
  678. return -1;
  679. }
  680. int count = 0;
  681. for (int i = 0; i < 28; ++i) {
  682. for (final int id : ids) {
  683. if (methods.interfaces.get(11).getComponent(17).isValid() && methods.interfaces.get(11).getComponent(17).getComponent(i).getComponentID() == id) {
  684. count++;
  685. }
  686. }
  687. }
  688. return count;
  689. }
  690.  
  691. /**
  692. * Gets the count of all items in your inventory ignoring stack sizes while
  693. * deposit box is open.
  694. *
  695. * @return The count.
  696. */
  697. public int getBoxCount() {
  698. if (!isDepositOpen()) {
  699. return -1;
  700. }
  701. int count = 0;
  702. for (int i = 0; i < 28; i++) {
  703. if (methods.interfaces.get(11).getComponent(17).isValid() && methods.interfaces.get(11).getComponent(17).getComponent(i).getComponentID() != -1) {
  704. count++;
  705. }
  706. }
  707. return count;
  708. }
  709.  
  710. /**
  711. * Gets the equipment items from the bank interface.
  712. *
  713. * @return All equipment items that are being worn.
  714. * @author LastCoder
  715. */
  716. public RSItem[] getEquipmentItems() {
  717. if (methods.interfaces.get(INTERFACE_EQUIPMENT).getComponent(INTERFACE_EQUIPMENT_COMPONENT).isValid()) {
  718. return new RSItem[0];
  719. }
  720. final RSComponent[] components = methods.interfaces.get(INTERFACE_EQUIPMENT).getComponent(INTERFACE_EQUIPMENT_COMPONENT).getComponents();
  721. final RSItem[] items = new RSItem[components.length];
  722. for (int i = 0; i < items.length; i++) {
  723. items[i] = new RSItem(methods, components[i]);
  724. }
  725. return items;
  726. }
  727.  
  728. /**
  729. * Gets a equipment item from the bank interface.
  730. *
  731. * @param id ID of the item.
  732. * @return RSItem
  733. */
  734. public RSItem getEquipmentItem(final int id) {
  735. final RSItem[] items = getEquipmentItems();
  736. if (items != null) {
  737. for (final RSItem item : items) {
  738. if (item.getID() == id) {
  739. return item;
  740. }
  741. }
  742. }
  743. return null;
  744. }
  745.  
  746. /**
  747. * Gets the ID of a equipment item based on name.
  748. *
  749. * @param name Name of the item.
  750. * @return -1 if item is not found.
  751. */
  752. public int getEquipmentItemID(final String name) {
  753. final RSItem[] items = getEquipmentItems();
  754. if (items != null) {
  755. for (final RSItem item : items) {
  756. if (item.getName().contains(name)) {
  757. return item.getID();
  758. }
  759. }
  760. }
  761. return -1;
  762. }
  763.  
  764. /**
  765. * Opens the equipment interface.
  766. *
  767. * @return <tt>true</tt> if opened.
  768. */
  769. public boolean openEquipment() {
  770. return getInterface().getComponent(INTERFACE_BANK_BUTTON_OPEN_EQUIP).isValid() && getInterface().getComponent(INTERFACE_BANK_BUTTON_OPEN_EQUIP).doClick();
  771. }
  772.  
  773. /**
  774. * Gets the item ID of a item side the bank.
  775. *
  776. * @param name Name of the item.
  777. * @return -1 if item is not found.
  778. */
  779. public int getItemID(final String name) {
  780. final RSItem[] items = getItems();
  781. if (items != null) {
  782. for (final RSItem item : items) {
  783. if (item.getName().toLowerCase().equals(name.toLowerCase())) {
  784. return item.getID();
  785. }
  786. }
  787. for (final RSItem item : items) {
  788. if (item.getName().toLowerCase().contains(name.toLowerCase())) {
  789. return item.getID();
  790. }
  791. }
  792. }
  793. return -1;
  794. }
  795. }
Add Comment
Please, Sign In to add comment