Advertisement
Guest User

Untitled

a guest
Sep 17th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.46 KB | None | 0 0
  1. package scripts.smither;
  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.Equipment;
  8. import org.tribot.api2007.Inventory;
  9. import org.tribot.api2007.types.RSItem;
  10.  
  11. public class Bank {
  12.  
  13. private Main main;
  14. private ABCUtil abc = new ABCUtil();
  15. private BarType barType;
  16. private SmithLocation location;
  17. private Smithing item;
  18. private Forging forging;
  19. private ScriptTask task;
  20.  
  21. public Bank(Main main) {
  22. setMain(main);
  23. setBarType(main.getBarType());
  24. setLocation(main.getSmithLocation());
  25. setItem(main.getItem());
  26. setForging(main.getForging());
  27. setTask(main.getTask());
  28. }
  29.  
  30. public boolean canPerform() {
  31. int[] ores = getBarType().getOres();
  32. int[] amounts = getBarType().getAmounts();
  33. boolean hasFirstOre = Inventory.getCount(ores[0]) >= amounts[0];
  34. boolean hasSecondOre = Inventory.getCount(ores[1]) >= amounts[1];
  35. boolean mould = Inventory.getCount(Constants.CANNONBALL_MOULD) > 0;
  36. boolean steel = Inventory.getCount(Constants.STEEL_BAR) > 0;
  37. boolean hammer = Inventory.getCount(Constants.HAMMER) > 0;
  38. boolean bars = Inventory.getCount(getBarType().getItemId()) >= getItem().getBarsRequired();
  39.  
  40. switch(getTask()) {
  41. case SMITHING:
  42. if(!getItem().equals(Smithing.CANNONBALLS)) {
  43. return hammer && bars;
  44. } else {
  45. return mould && steel;
  46. }
  47.  
  48. case CANNONBALLS:
  49. if(mould) {
  50. if(hasFirstOre && hasSecondOre)
  51. return true;
  52. else {
  53. if(steel)
  54. return true;
  55. }
  56. }
  57. return false;
  58. case SMELTING:
  59. if(!getItem().equals(Smithing.CANNONBALLS)) {
  60. return hammer && bars;
  61. } else {
  62. return hasFirstOre && hasSecondOre;
  63. }
  64. }
  65. return false;
  66. }
  67.  
  68. public boolean performedBankTask() {
  69. int[] ores = getBarType().getOres();
  70. int[] amounts = getOreWithdrawAmount();
  71. boolean hammer = Inventory.getCount(Constants.HAMMER) > 0;
  72. boolean bars = Inventory.getCount(getBarType().getItemId()) >= getItem().getBarsRequired();
  73. boolean ammomould = Inventory.getCount(Constants.CANNONBALL_MOULD) > 0;
  74. boolean forging = getForging().equals(Forging.YES);
  75. boolean mould = Inventory.getCount(Constants.CANNONBALL_MOULD) > 0;
  76. int ran = General.random(0, 1);
  77. boolean hasFirstOre;
  78. boolean hasSecondOre;
  79. switch(getTask()) {
  80. case SMITHING:
  81. if(Banking.isBankScreenOpen()) {
  82. int count = Inventory.getAll().length;
  83. Banking.depositAllExcept(Constants.HAMMER, getBarType().getItemId(), Constants.CANNONBALL_MOULD);
  84. if(isItemDeposited(count, 1000)) {
  85. getMain().sleep();
  86. }
  87. }
  88.  
  89. if(!hammer && !getItem().equals(Smithing.CANNONBALLS)) {
  90. if(openBank()) {
  91. if(Inventory.getCount(Constants.HAMMER) <= 0) {
  92. if(withdrawItem(Constants.HAMMER, 1)) {
  93. hammer = Inventory.getCount(Constants.HAMMER) > 0;
  94. }
  95. }
  96. }
  97. }
  98. if(getItem().equals(Smithing.CANNONBALLS)) {
  99. if(!ammomould) {
  100. if(openBank()) {
  101. if(withdrawItem(Constants.CANNONBALL_MOULD, 1)) {
  102. ammomould = Inventory.getCount(Constants.CANNONBALL_MOULD) > 0;
  103. }
  104. }
  105. }
  106. }
  107. if(!bars) {
  108. if(openBank()) {
  109. if(withdrawItem(getBarType().getItemId(), (28 - Inventory.getAll().length))) {
  110. bars = Inventory.getCount(getBarType().getItemId()) >= getItem().getBarsRequired();
  111. }
  112. }
  113. }
  114. if(getItem().equals(Smithing.CANNONBALLS)) {
  115. if(ammomould && bars) {
  116. return true;
  117. }
  118. } else {
  119. if(hammer && bars) {
  120. return true;
  121. }
  122. }
  123. return false;
  124. case SMELTING:
  125.  
  126. if(ran == 0) {
  127. hasFirstOre = Inventory.getCount(ores[0]) >= amounts[0];
  128. hasSecondOre = Inventory.getCount(ores[1]) >= amounts[1];
  129. } else {
  130. hasFirstOre = Inventory.getCount(ores[1]) >= amounts[1];
  131. hasSecondOre = Inventory.getCount(ores[0]) >= amounts[0];
  132. }
  133.  
  134. if(Banking.isBankScreenOpen()) {
  135. Banking.depositAllExcept(getBarType().getOres());
  136. }
  137.  
  138. if(forging) {
  139. if(!Equipment.isEquipped(Constants.RING_OF_FORGING)) {
  140. equipForgingRing();
  141. }
  142. }
  143.  
  144. if(ran == 0) {
  145.  
  146. if(!hasFirstOre) {
  147. if(openBank()) {
  148. if(withdrawItem(ores[0], amounts[0])) {
  149. hasFirstOre = Inventory.getCount(ores[0]) >= amounts[0];
  150. }
  151. }
  152. }
  153.  
  154. if(amounts[1] > 0) {
  155. if(!hasSecondOre) {
  156. if(openBank()) {
  157. if(withdrawItem(ores[1], amounts[1])) {
  158. hasSecondOre = Inventory.getCount(ores[1]) >= amounts[1];
  159. }
  160. }
  161. }
  162. }
  163. } else {
  164. if(amounts[1] > 0) {
  165. if(!hasSecondOre) {
  166. if(openBank()) {
  167. if(withdrawItem(ores[1], amounts[1])) {
  168. hasSecondOre = Inventory.getCount(ores[1]) >= amounts[1];
  169. }
  170. }
  171. }
  172. }
  173. if(!hasFirstOre) {
  174. if(openBank()) {
  175. if(withdrawItem(ores[0], amounts[0])) {
  176. hasFirstOre = Inventory.getCount(ores[0]) >= amounts[0];
  177. }
  178. }
  179. }
  180. }
  181.  
  182.  
  183. return hasFirstOre && hasSecondOre;
  184.  
  185. case CANNONBALLS:
  186. if(ran == 0) {
  187. hasFirstOre = Inventory.getCount(ores[0]) >= amounts[0];
  188. hasSecondOre = Inventory.getCount(ores[1]) >= amounts[1];
  189. } else {
  190. hasFirstOre = Inventory.getCount(ores[1]) >= amounts[1];
  191. hasSecondOre = Inventory.getCount(ores[0]) >= amounts[0];
  192. }
  193. if(Banking.isBankScreenOpen())
  194. Banking.depositAllExcept(Constants.CANNONBALL_MOULD, ores[0], ores[1]);
  195.  
  196. if(!mould) {
  197. if(openBank()) {
  198. if(Inventory.getCount(Constants.CANNONBALL_MOULD) <= 0) {
  199. if(withdrawItem(Constants.CANNONBALL_MOULD, 1)) {
  200. mould = Inventory.getCount(Constants.CANNONBALL_MOULD) > 0;
  201. }
  202. }
  203. }
  204. }
  205.  
  206. if(ran == 0) {
  207.  
  208. if(!hasFirstOre) {
  209. if(openBank()) {
  210. if(withdrawItem(ores[0], amounts[0])) {
  211. hasFirstOre = Inventory.getCount(ores[0]) >= amounts[0];
  212. }
  213. }
  214. }
  215.  
  216. if(amounts[1] > 0) {
  217. if(!hasSecondOre) {
  218. if(openBank()) {
  219. if(withdrawItem(ores[1], amounts[1])) {
  220. hasSecondOre = Inventory.getCount(ores[1]) >= amounts[1];
  221. }
  222. }
  223. }
  224. }
  225. } else {
  226. if(amounts[1] > 0) {
  227. if(!hasSecondOre) {
  228. if(openBank()) {
  229. if(withdrawItem(ores[1], amounts[1])) {
  230. hasSecondOre = Inventory.getCount(ores[1]) >= amounts[1];
  231. }
  232. }
  233. }
  234. }
  235. if(!hasFirstOre) {
  236. if(openBank()) {
  237. if(withdrawItem(ores[0], amounts[0])) {
  238. hasFirstOre = Inventory.getCount(ores[0]) >= amounts[0];
  239. }
  240. }
  241. }
  242. }
  243.  
  244. if(mould && hasFirstOre && hasSecondOre) {
  245. return true;
  246. }
  247. return false;
  248. }
  249. return false;
  250. }
  251.  
  252. public boolean equipForgingRing() {
  253. boolean hasRing = Inventory.getCount(Constants.RING_OF_FORGING) > 0;
  254. if(!hasRing) {
  255. if(openBank()) {
  256. if(withdrawItem(Constants.RING_OF_FORGING, 1)) {
  257. hasRing = Inventory.getCount(Constants.RING_OF_FORGING) > 0;
  258. }
  259. }
  260. }
  261.  
  262. if(hasRing) {
  263. if(Banking.close()) {
  264. getMain().sleep();
  265. RSItem[] ring = Inventory.find(Constants.RING_OF_FORGING);
  266. if(ring != null && ring.length > 0) {
  267. if(ring[0].click("Wear")) {
  268. getMain().sleep();
  269. if(wearingRing(2000)) {
  270. int ringsUsed = getMain().getRingsUsed();
  271. getMain().setRingsUsed(ringsUsed++);
  272. return true;
  273. }
  274. }
  275. }
  276. }
  277. }
  278.  
  279. return false;
  280. }
  281.  
  282. public int[] getOreWithdrawAmount() {
  283. switch(getBarType()) {
  284. case ADAMANT:
  285. return new int[] { 4, 24 };
  286. case BRONZE:
  287. return new int[] { 14, 14 };
  288. case GOLD:
  289. return new int[] { 28, 0 };
  290. case IRON:
  291. return new int[] { 28, 0 };
  292. case MITHRIL:
  293. return new int[] { 5, 20};
  294. case RUNE:
  295. return new int[] { 3, 24 };
  296. case SILVER:
  297. return new int[] { 28, 0 };
  298. case STEEL:
  299. return new int[] { 9, 18 };
  300. }
  301. return new int[] { 0, 0 };
  302. }
  303.  
  304. public boolean openBank() {
  305. if(isBankScreenOpen(100)) {
  306. return true;
  307. }
  308. Banking.openBank();
  309. General.sleep(abc.DELAY_TRACKER.ITEM_INTERACTION.next());
  310. abc.DELAY_TRACKER.ITEM_INTERACTION.reset();
  311. return isBankScreenOpen(2000);
  312. }
  313.  
  314. public boolean withdrawItem(int itemId, int withdrawAmount) {
  315. if(openBank()) {
  316. getMain().sleep(250, 500);
  317. RSItem[] item = Banking.find(itemId);
  318. if(item != null && item.length > 0) {
  319. Banking.withdraw(withdrawAmount, itemId);
  320. General.sleep(abc.DELAY_TRACKER.ITEM_INTERACTION.next());
  321. abc.DELAY_TRACKER.ITEM_INTERACTION.reset();
  322. if(isItemWithdrawn(2000, itemId, Inventory.getCount(itemId))) {
  323. return true;
  324. }
  325. } else {
  326. if(!withdrawItem(itemId, withdrawAmount)) {
  327. getMain().println("Can't find: " + itemId);
  328. getMain().setEndScript(true);
  329. return false;
  330. }
  331. }
  332. }
  333. return false;
  334. }
  335.  
  336. public boolean wearingRing(int i) {
  337. long t = System.currentTimeMillis();
  338. while (Timing.timeFromMark(t) < i) {
  339. if(Equipment.isEquipped(Constants.RING_OF_FORGING)) {
  340. return true;
  341. }
  342. getMain().sleep(50, 150);
  343. }
  344. return false;
  345. }
  346.  
  347. public boolean isBankScreenOpen(int i) {
  348. long t = System.currentTimeMillis();
  349. while (Timing.timeFromMark(t) < i) {
  350. if (Banking.isBankScreenOpen()) {
  351. return true;
  352. }
  353. getMain().sleep(50, 150);
  354. }
  355. return false;
  356. }
  357.  
  358. private boolean isItemWithdrawn(int i, int id, int amt) {
  359. long t = System.currentTimeMillis();
  360. while (Timing.timeFromMark(t) < i) {
  361. if (Inventory.getCount(id) > amt) {
  362. return true;
  363. }
  364. getMain().sleep(50, 150);
  365. }
  366. return false;
  367. }
  368.  
  369. private boolean isItemDeposited(int amt, int i) {
  370. long t = System.currentTimeMillis();
  371. while (Timing.timeFromMark(t) < i) {
  372. if (Inventory.getAll().length < amt) {
  373. return true;
  374. }
  375. getMain().sleep(50, 150);
  376. }
  377. return false;
  378. }
  379.  
  380. public Main getMain() {
  381. return main;
  382. }
  383.  
  384. public void setMain(Main main) {
  385. this.main = main;
  386. }
  387.  
  388. public BarType getBarType() {
  389. return barType;
  390. }
  391.  
  392. public void setBarType(BarType barType) {
  393. this.barType = barType;
  394. }
  395.  
  396. public SmithLocation getLocation() {
  397. return location;
  398. }
  399.  
  400. public void setLocation(SmithLocation location) {
  401. this.location = location;
  402. }
  403.  
  404. public Smithing getItem() {
  405. return item;
  406. }
  407.  
  408. public void setItem(Smithing item) {
  409. this.item = item;
  410. }
  411.  
  412. public Forging getForging() {
  413. return forging;
  414. }
  415.  
  416. public void setForging(Forging forging) {
  417. this.forging = forging;
  418. }
  419.  
  420. public ScriptTask getTask() {
  421. return task;
  422. }
  423.  
  424. public void setTask(ScriptTask task) {
  425. this.task = task;
  426. }
  427.  
  428. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement