Advertisement
iant06

Untitled

Sep 17th, 2015
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.03 KB | None | 0 0
  1. package scripts.moneymaking.iplankfarmer.banking;
  2.  
  3. import org.tribot.api.General;
  4. import org.tribot.api.Timing;
  5. import org.tribot.api.input.Mouse;
  6. import org.tribot.api2007.Banking;
  7. import org.tribot.api2007.Camera;
  8. import org.tribot.api2007.Equipment;
  9. import org.tribot.api2007.Game;
  10. import org.tribot.api2007.Equipment.SLOTS;
  11. import org.tribot.api2007.Inventory;
  12. import org.tribot.api2007.Player;
  13. import org.tribot.api2007.WebWalking;
  14. import org.tribot.api2007.types.RSItem;
  15. import org.tribot.api2007.types.RSObject;
  16.  
  17. import scripts.methods.Methods;
  18. import scripts.moneymaking.iplankfarmer.Script;
  19. import scripts.moneymaking.iplankfarmer.types.EnergyPotion;
  20. import scripts.moneymaking.iplankfarmer.types.Plank;
  21. import scripts.moneymaking.iplankfarmer.types.ScriptTask;
  22. import scripts.moneymaking.iplankfarmer.types.State;
  23. import scripts.moneymaking.iplankfarmer.utils.Constants;
  24. import scripts.moneymaking.iplankfarmer.utils.Locations;
  25.  
  26. public class Bank {
  27.  
  28. private Script script;
  29.  
  30. public Bank(Script script) {
  31. setScript(script);
  32. }
  33.  
  34. public void setScript(Script script) {
  35. this.script = script;
  36. }
  37.  
  38. public Script getScript() {
  39. return script;
  40. }
  41.  
  42. private int logAmount = 0;
  43. private boolean drankPotions = false;
  44.  
  45. public boolean drankPotions() {
  46. return drankPotions;
  47. }
  48.  
  49. public void setDrankPotions(boolean drankPotions) {
  50. this.drankPotions = drankPotions;
  51. }
  52.  
  53. public boolean performBankTask() {
  54. getScript().setState(State.BANKING);
  55. getScript().getData().getTripInformation();
  56. getScript().getData().setTimeout(System.currentTimeMillis());
  57. getScript().getPotions().setPotionDrank(0);
  58.  
  59. while((Locations.isInsideBank() || Locations.isInsideCastleWars()) && !getScript().getData().isTimedOut(10000, 15000)) {
  60. if(getScript().isEndScript()) {
  61. return false;
  62. }
  63. getScript().println("Performing Bank Task");
  64. if(Locations.isInsideCastleWars()) {
  65. if(Methods.distanceTo(getScript(), Locations.CASTLE_WARS_TILE) > 4) {
  66. WebWalking.walkToBank();
  67. Methods.performAntiBan(getScript());
  68. getScript().getData().checkPlayerRun();
  69. }
  70. }
  71.  
  72. if(openBankScreen()) {
  73.  
  74. depositItems();
  75.  
  76. final Plank PLANK = getScript().getPlank();
  77. final ScriptTask TASK = getScript().getTask();
  78. if(TASK.equals(ScriptTask.CHOP_LOGS)) {
  79. RSItem[] ring = Equipment.find(SLOTS.RING);
  80. if(ring == null || ring.length <= 0) {
  81. if(getScript().getDuelRing().withdraw()) {
  82. Banking.close();
  83. getScript().getDuelRing().equip();
  84. }
  85. }
  86. }
  87. if(TASK.equals(ScriptTask.CHOP_AND_PLANK) && PLANK.equals(Plank.TEAK)) {
  88. if(!Locations.isInsideCastleWars()) {
  89. int logAmount = getLogAmount();
  90. while(logAmount < 20 && !Locations.isInsideCastleWars()) {
  91. if(getScript().getDuelRing().isWearing()) {
  92. Banking.close();
  93. getScript().getDuelRing().rub();
  94. } else if(getScript().getDuelRing().withdraw()) {
  95. Banking.close();
  96. getScript().getDuelRing().equip();
  97. getScript().getDuelRing().rub();
  98. }
  99. }
  100. } else {
  101. getScript().println("TEAK CHOP AND PLANK: VARROC BANK DUEL RING");
  102. RSItem[] ring = Equipment.find(SLOTS.RING);
  103. if(ring == null || ring.length <= 0) {
  104. getScript().getVarrockTab().withdraw();
  105. }
  106. }
  107. }
  108. if(!getScript().getEnergyPotion().equals(EnergyPotion.NONE)) {
  109. if(!drankPotions) {
  110. getScript().getPotions().handleEnergyPotions();
  111. }
  112. }
  113. withdrawRequiredItems();
  114.  
  115. if(!isFinished()) {
  116. int logAmount = Inventory.getCount(getScript().getPlank().getLogId());
  117. if(Inventory.getCount(995) < (logAmount * getScript().getPlank().getPricePerPlank())) {
  118. withdrawMoney();
  119. isMoneyWithdrawn(1000);
  120. }
  121. }
  122. }
  123.  
  124. if(isFinished()) {
  125. drankPotions = false;
  126. getScript().setState(State.WALKING_TO_TREE);
  127. return true;
  128. }
  129. }
  130. return false;
  131. }
  132.  
  133. private int getLogAmount() {
  134. final Plank PLANK = getScript().getPlank();
  135. final int LOG_ID = PLANK.getLogId();
  136. RSItem[] logs = Banking.find(LOG_ID);
  137. if(logs != null && logs.length > 0) {
  138. return logs[0].getStack();
  139. }
  140. return 0;
  141. }
  142.  
  143. private void withdrawRequiredItems() {
  144. switch(getScript().getTask()) {
  145. case CHOP_LOGS:
  146. if(!getScript().getAxe().setAxe()) {
  147. getScript().println("Out of axes.");
  148. getScript().setEndScript(true);
  149. }
  150. break;
  151. case CHOP_AND_PLANK:
  152. if(getScript().getPlank().equals(Plank.TEAK) && Locations.isInsideBank()) {
  153. int amount = getLogAmount();
  154. if(amount > 20) {
  155. amount = amount > 27 ? 27 : amount;
  156. if(Inventory.getCount(getScript().getPlank().getLogId()) < amount) {
  157. withdrawLogs();
  158. }
  159. }
  160. break;
  161. }
  162. if(!getScript().getAxe().setAxe()) {
  163. getScript().println("Out of axes.");
  164. getScript().setEndScript(true);
  165. }
  166. break;
  167. case MAKE_PLANKS:
  168. int amount = getLogAmount();
  169. amount = amount > 27 ? 27 : amount;
  170. if(Inventory.getCount(getScript().getPlank().getLogId()) < amount) {
  171. withdrawLogs();
  172. }
  173. break;
  174. }
  175. }
  176.  
  177. public boolean isItemWithdrawn(int id, int i) {
  178. long t = System.currentTimeMillis();
  179. while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
  180. RSItem[] item = Inventory.find(id);
  181. if (item != null && item.length > 0) {
  182. return true;
  183. }
  184. getScript().sleep(50, 150);
  185. }
  186. return false;
  187. }
  188.  
  189. private boolean isMoneyWithdrawn(int i) {
  190. long t = System.currentTimeMillis();
  191. int count = getScript().getPlank().getPricePerPlank() * (getScript().getAxe().wearing() ? 27 : 26);
  192. while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
  193. if (Inventory.getCount(Constants.GOLD) >= count) {
  194. return true;
  195. }
  196. getScript().sleep(50, 150);
  197. }
  198. return false;
  199. }
  200.  
  201. private boolean withdrawLogs() {
  202. final Plank PLANK = getScript().getPlank();
  203. int logId = PLANK.getLogId();
  204. if(openBankScreen()) {
  205. RSItem[] logs = Banking.find(logId);
  206. if(logs != null && logs.length > 0) {
  207. int amt = logs[0].getStack();
  208. amt = amt > 27 ? 27 : amt;
  209. logAmount = amt;
  210. Banking.withdraw(logAmount, logId);
  211. return isLogWithdrawn(1000);
  212. } else {
  213. getScript().println("Out of logs.");
  214. getScript().setEndScript(true);
  215. return false;
  216. }
  217. }
  218. return false;
  219. }
  220.  
  221. public int leastAmountNeeded = getPricePerPlank() * 27;
  222.  
  223. private int getPricePerPlank() {
  224. try {
  225. switch(getScript().getPlank()) {
  226. case REGULAR:
  227. return Constants.GOLD_PER_REG_PLANK;
  228. case OAK:
  229. return Constants.GOLD_PER_OAK_PLANK;
  230. case TEAK:
  231. return Constants.GOLD_PER_TEAK_PLANK;
  232. case MAHOGANY:
  233. return Constants.GOLD_PER_MAHOGANY_PLANK;
  234.  
  235. }
  236. return 0;
  237. } catch(NullPointerException e) {
  238.  
  239. }
  240. return 0;
  241. }
  242.  
  243. private int goldWithdrawAmount = 0;
  244.  
  245. private int bankGoldAmount() {
  246. RSItem[] gold = Banking.find(995);
  247. if(gold != null && gold.length > 0) {
  248. return gold[0].getStack();
  249. }
  250. return 0;
  251. }
  252.  
  253. private void withdrawMoney() {
  254. int plankAmount = getPlankAmount();
  255. int[] goldcount = { 200000, 100000, 50000, 25000 };
  256. if(goldWithdrawAmount == 0 || bankGoldAmount() < goldWithdrawAmount) {
  257. for(int i = 0; i < goldcount.length; i++) {
  258. if(bankGoldAmount() > goldcount[i]) {
  259. goldWithdrawAmount = goldcount[i];
  260. break;
  261. }
  262. }
  263. }
  264. int goldCount = Inventory.getCount(Constants.GOLD);
  265. if(goldCount < goldWithdrawAmount) {
  266. if(openBankScreen()) {
  267. RSItem[] gold = Banking.find(Constants.GOLD);
  268. if(gold != null && gold.length > 0) {
  269. if(gold[0].getStack() >= goldWithdrawAmount) {
  270. Banking.withdraw(goldWithdrawAmount, Constants.GOLD);
  271. } else {
  272. getScript().println("Not enough gold.");
  273. getScript().setEndScript(true);
  274. return;
  275. }
  276. }
  277. }
  278. }
  279. }
  280.  
  281. public int getPlankAmount() {
  282. int plankAmount = 0;
  283. switch(getScript().getTask()) {
  284. case CHOP_AND_PLANK:
  285. boolean wearingAxe = getScript().getAxe().wearing();
  286. if(getScript().getPlank().equals(Plank.TEAK)) {
  287. plankAmount = 27;
  288. } else {
  289. plankAmount = wearingAxe ? 27 : 26;
  290. }
  291. break;
  292. case MAKE_PLANKS:
  293. plankAmount = Inventory.getCount(getScript().getPlank().getLogId());
  294. break;
  295. }
  296. return plankAmount;
  297. }
  298.  
  299. public int getFreeInventorySpace() {
  300. int taken = 0;
  301. for(RSItem i : Inventory.getAll()) {
  302. if(i != null) {
  303. taken++;
  304. continue;
  305. }
  306. }
  307. return 28 - taken;
  308. }
  309.  
  310. public boolean isFinished() {
  311. int goldAmount;
  312. int spaces;
  313. int logAmount = Inventory.getCount(getScript().getPlank().getLogId());
  314. switch(getScript().getTask()) {
  315. case CHOP_LOGS:
  316. spaces = 28 - (getScript().getAxe().wearing() ? 0 : 1);
  317. if(getScript().getAxe().hasAxe()) {
  318. if(getFreeInventorySpace() == spaces) {
  319. return true;
  320. }
  321. }
  322. return false;
  323.  
  324. case CHOP_AND_PLANK:
  325. spaces = 27 - (getScript().getAxe().wearing() ? 0 : 1);
  326. if(getScript().getPlank().equals(Plank.TEAK)) {
  327. if(Locations.isInsideCastleWars()) {
  328. RSItem[] ring = Equipment.find(SLOTS.RING);
  329. if(ring != null && ring.length > 0) {
  330. spaces++;
  331. }
  332. if(getScript().getAxe().hasAxe()) {
  333. if(getFreeInventorySpace() == spaces) {
  334. return true;
  335. }
  336. }
  337. }
  338. if(Locations.isInsideBank()) {
  339. final Plank PLANK = getScript().getPlank();
  340. final int logId = PLANK.getLogId();
  341.  
  342. goldAmount = logAmount * PLANK.getPricePerPlank();
  343. return Inventory.getCount(logId) >= logAmount && Inventory.getCount(Constants.GOLD) >= goldAmount;
  344. }
  345. }
  346. goldAmount = spaces * getScript().getPlank().getPricePerPlank();
  347. if(getScript().getAxe().hasAxe()) {
  348. if(Inventory.getCount(Constants.GOLD) >= goldAmount) {
  349. if(getFreeInventorySpace() == spaces) {
  350. return true;
  351. }
  352. }
  353. }
  354. break;
  355. case MAKE_PLANKS:
  356. final Plank PLANK = getScript().getPlank();
  357. final int logId = PLANK.getLogId();
  358. goldAmount = 27 * PLANK.getPricePerPlank();
  359. if(Inventory.getCount(logId) > 0
  360. && Inventory.getCount(Constants.GOLD) >= goldAmount) {
  361. return true;
  362. }
  363. return false;
  364. }
  365. return false;
  366. }
  367.  
  368. public boolean walkToBooth() {
  369. Mouse.setSpeed(110 + General.random(10, 20));
  370. WebWalking.setUseAStar(true);
  371. WebWalking.walkTo(Locations.BANK_TILE);
  372. Methods.performAntiBan(getScript());
  373. getScript().getData().checkPlayerRun();
  374. if(isInBank(3000)) {
  375. getScript().setState(State.BANKING);
  376. return true;
  377. }
  378. return false;
  379. }
  380.  
  381. private boolean isInBank(int i) {
  382. long t = System.currentTimeMillis();
  383. while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
  384. if (Locations.isInsideBank()) {
  385. Camera.setCameraAngle(General.random(60, 80));
  386. return true;
  387. }
  388. if (Locations.isInsideCastleWars()) {
  389. Camera.setCameraAngle(General.random(60, 80));
  390. return true;
  391. }
  392. if (!Player.isMoving()) {
  393. return false;
  394. }
  395. getScript().sleep(50, 150);
  396. }
  397. return false;
  398. }
  399.  
  400. public boolean openBankScreen() {
  401. getScript().getData().setTimeout(System.currentTimeMillis());
  402. while(!Banking.isBankScreenOpen() && !getScript().getData().isTimedOut(7000, 8000)) {
  403. RSObject bank = Methods.findObjectByModelPoints(new int[]{Constants.BANK_BOOTH, Constants.BANK_CHEST});
  404. if(bank != null) {
  405. Banking.openBank();
  406. if(isPinScreenOpen(1000)) {
  407. if(Banking.isPinScreenOpen()) {
  408. if(!Banking.inPin()) {
  409. return false;
  410. }
  411. }
  412. }
  413. }
  414. }
  415. return Banking.isBankScreenOpen();
  416. }
  417.  
  418. private boolean depositItems() {
  419. final Plank SET_PLANK = getScript().getPlank();
  420. switch(getScript().getTask()) {
  421. case CHOP_LOGS:
  422. Banking.depositAllExcept(new int[]{getScript().getData().getAxeId()});
  423. break;
  424. case CHOP_AND_PLANK:
  425. if(SET_PLANK.equals(Plank.TEAK) && Locations.isInsideBank()) {
  426. Banking.depositAll();
  427. } else {
  428. Banking.depositAllExcept(new int[]{getScript().getData().getAxeId()});
  429. }
  430. break;
  431. case MAKE_PLANKS:
  432. Banking.depositAllExcept(new int[]{ 995, getScript().getPlank().getLogId() });
  433. break;
  434. }
  435. return isAllItemsDeposited(1000);
  436. }
  437.  
  438. private boolean isPinScreenOpen(int i) {
  439. long t = System.currentTimeMillis();
  440. while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
  441. if (Banking.isBankScreenOpen()) {
  442. return false;
  443. }
  444. if (Banking.isPinScreenOpen()) {
  445. return true;
  446. }
  447. getScript().sleep(50, 150);
  448. }
  449. return false;
  450. }
  451.  
  452. private boolean isAllItemsDeposited(int i) {
  453. long t = System.currentTimeMillis();
  454. while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
  455. int space = getScript().getAxe().wearing() ? 28 : 27;
  456. if(getFreeInventorySpace() == space) {
  457. return true;
  458. }
  459. getScript().sleep(50, 150);
  460. }
  461. return false;
  462. }
  463.  
  464. private boolean isLogWithdrawn(int i) {
  465. long t = System.currentTimeMillis();
  466. while (Timing.timeFromMark(t) < i + General.random(100, 200)) {
  467. if(Inventory.getCount(getScript().getPlank().getLogId()) == logAmount) {
  468. return true;
  469. }
  470. getScript().sleep(50, 150);
  471. }
  472. return false;
  473. }
  474.  
  475. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement