Advertisement
Guest User

ok_MiningGuilder

a guest
Dec 7th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.65 KB | None | 0 0
  1. package scripts;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.awt.Graphics2D;
  7. import java.awt.Image;
  8. import java.awt.Polygon;
  9. import java.io.IOException;
  10. import java.net.URL;
  11.  
  12. import javax.imageio.ImageIO;
  13.  
  14. import org.tribot.api.DynamicClicking;
  15. import org.tribot.api.General;
  16. import org.tribot.api.Timing;
  17. import org.tribot.api.input.Mouse;
  18. import org.tribot.api.types.generic.Condition;
  19. import org.tribot.api2007.Banking;
  20. import org.tribot.api2007.Camera;
  21. import org.tribot.api2007.Equipment;
  22. import org.tribot.api2007.GameTab;
  23. import org.tribot.api2007.Inventory;
  24. import org.tribot.api2007.Login;
  25. import org.tribot.api2007.Objects;
  26. import org.tribot.api2007.Player;
  27. import org.tribot.api2007.Screen;
  28. import org.tribot.api2007.Skills;
  29. import org.tribot.api2007.Walking;
  30. import org.tribot.api2007.GameTab.TABS;
  31. import org.tribot.api2007.types.RSItem;
  32. import org.tribot.api2007.types.RSObject;
  33. import org.tribot.api2007.types.RSTile;
  34. import org.tribot.script.Script;
  35. import org.tribot.script.ScriptManifest;
  36. import org.tribot.script.interfaces.Painting;
  37. import org.tribot.script.interfaces.Pausing;
  38. import org.tribot.script.interfaces.RandomEvents;
  39.  
  40. @ScriptManifest(authors = { "Okokokok" }, category = "ok_Scripts", name = "ok_miningGuilder")
  41. public class ok_miningGuilder extends Script implements Painting, Pausing, RandomEvents {
  42.  
  43. private final Polygon bankArea = new Polygon(
  44. new int[] {3009, 3019, 3019, 3009},
  45. new int[] {3359, 3359, 3354, 3354},
  46. 4),
  47. ladderUpArea = new Polygon(
  48. new int[] {3014, 3025, 3025, 3014},
  49. new int[] {3343, 3343, 3336, 3336},
  50. 4),
  51. ladderDownArea = new Polygon(
  52. new int[] {3024, 3018, 3018, 3024},
  53. new int[] {9743, 9743, 9737, 9737},
  54. 4),
  55. faladorArea = new Polygon(
  56. new int[] {3007, 3034, 3034, 3007},
  57. new int[] {3365, 3365, 3332, 3332},
  58. 4);
  59.  
  60. boolean paused;
  61.  
  62. private final String mineOption = "Mine",
  63. coalOreName = "Coal",
  64. ladderName = "Ladder",
  65. pickAxeName = "Rune pickaxe",
  66. wieldOption = "Wield";
  67.  
  68. private final int coalOreID = 453,
  69. explodingRockID = 2496;
  70.  
  71. private final double version = 1.03;
  72.  
  73. private final int[] coalRockID = {14915, 14916},
  74. minedRockID = {10796, 10798};
  75.  
  76. private final RSTile bankTile = new RSTile (3012, 3356, 0),
  77. ladderUpTile = new RSTile (3022, 3338, 0),
  78. ladderDownTile = new RSTile (3021, 9738, 0),
  79. secondGuildTile = new RSTile (3037, 9736, 0),
  80. myPos = Player.getPosition();
  81.  
  82. private final RSTile[] ladderUpPath = new RSTile[] { new RSTile (3012, 3356, 0),
  83. new RSTile (3019, 3361, 0),
  84. new RSTile (3023, 3356, 0),
  85. new RSTile (3024, 3350, 0),
  86. new RSTile (3029, 3342, 0),
  87. new RSTile (3028, 3336, 0),
  88. new RSTile (3022, 3338, 0)},
  89.  
  90. guildPath = new RSTile[] { new RSTile (3021, 9738, 0),
  91. new RSTile (3031, 9738, 0),
  92. new RSTile (3037, 9736, 0),
  93. new RSTile (3042, 9738, 0)},
  94.  
  95. ladderDownPath = new RSTile[] { new RSTile (3042, 9738, 0),
  96. new RSTile (3036, 9737, 0),
  97. new RSTile (3029, 9737, 0),
  98. new RSTile (3021, 9739, 0)},
  99.  
  100. bankPath = new RSTile[] { new RSTile (3022, 3338, 0),
  101. new RSTile (3025, 3337, 0),
  102. new RSTile (3030, 3341, 0),
  103. new RSTile (3030, 3345, 0),
  104. new RSTile (3025, 3350, 0),
  105. new RSTile (3023, 3356, 0),
  106. new RSTile (3015, 3359, 0),
  107. new RSTile (3013, 3356, 0)};
  108.  
  109. // RANDOM METHODS
  110.  
  111. public boolean isExplodingRock(int distance, int explodingRockID){
  112. RSObject[] rock = Objects.find(distance, explodingRockID);
  113. return rock != null && rock.length > 0;
  114. }
  115.  
  116. // MISC METHODS
  117.  
  118. public boolean waitFor(Condition c, long timeout) {
  119. Timer t = new Timer(timeout);
  120. while (t.isRunning()) {
  121. if (c.active()) {
  122. return true;
  123. }
  124. sleep(60, 80);
  125. }
  126. return false;
  127. }
  128.  
  129. public boolean loggedOut() {
  130. return (Login.getLoginState() == Login.STATE.LOGINSCREEN)
  131. && (!Screen.getColorAt(100, 200).equals(new Color(0, 0, 0)));
  132. }
  133.  
  134. public boolean havePickAxe(String pickaxename){
  135. RSItem[] pickAxe = Equipment.find(pickaxename);
  136. return pickAxe != null && pickAxe.length > 0;
  137. }
  138.  
  139. private void withdrawPickAxe(int withdrawPickAxeAmount, String pickaxename){
  140. RSItem[] pickAxeBank = Banking.find(pickAxeName);
  141. if (pickAxeBank != null && pickAxeBank.length > 0){
  142. if (Banking.withdraw(withdrawPickAxeAmount, pickaxename)){
  143. waitFor(new Condition (){
  144. @Override
  145. public boolean active(){
  146. return pickAxeInInventory(pickAxeName);
  147. }
  148. }, 4000);
  149. }
  150. }
  151. }
  152.  
  153. private boolean pickAxeInInventory(String pickaxename){
  154. RSItem[] pickAxeInventory = Inventory.find(pickaxename);
  155. return pickAxeInventory != null && pickAxeInventory.length > 0;
  156. }
  157.  
  158. private void equipPickAxe(String pickaxename, String wieldOption){
  159. RSItem[] pickAxeInventory = Inventory.find(pickaxename);
  160. if (pickAxeInventory != null && pickAxeInventory.length > 0){
  161. if (pickAxeInventory[0].click(wieldOption)){
  162. waitFor(new Condition(){
  163. @Override
  164. public boolean active(){
  165. return havePickAxe(pickAxeName);
  166. }
  167. }, 4000);
  168. }
  169. }
  170. }
  171.  
  172. // ANTI-BAN BY SOKCRA
  173. public void antiBan(int rotation) {
  174. int number = General.random(1, 500);
  175. sleep(200);
  176. switch (number) {
  177. case 1:
  178. case 2:
  179. case 3:
  180. case 4:
  181. case 5:
  182. Camera.setCameraRotation(Camera.getCameraRotation() + rotation);
  183. break;
  184. case 20:
  185. case 21:
  186. case 22:
  187. case 23:
  188. case 24:
  189. case 25:
  190. case 26:
  191. case 27:
  192. case 28:
  193. case 29:
  194. case 30:
  195. case 31:
  196. Mouse.move(General.random(100, 200), General.random(200, 400));
  197. sleep(200);
  198. break;
  199. case 50:
  200. GameTab.open(TABS.INVENTORY);
  201. sleep(200);
  202. break;
  203. case 75:
  204. GameTab.open(TABS.STATS);
  205. sleep(300);
  206. Mouse.moveBox(678, 386, 725, 366);
  207. sleep(1000, 1500);
  208. GameTab.open(TABS.INVENTORY);
  209. break;
  210. case 76:
  211. GameTab.open(TABS.FRIENDS);
  212. sleep(2000, 3000);
  213. GameTab.open(TABS.INVENTORY);
  214. break;
  215. case 89:
  216. case 90:
  217. case 91:
  218. case 92:
  219. case 93:
  220. case 94:
  221. Camera.setCameraAngle(Camera.getCameraRotation() + rotation);
  222. sleep(200, 400);
  223. break;
  224. case 95:
  225. case 96:
  226. case 97:
  227. case 98:
  228. case 99:
  229. case 100:
  230. Camera.setCameraAngle(Camera.getCameraRotation() + rotation);
  231. sleep(200, 400);
  232. break;
  233. }
  234. }
  235.  
  236. // COLOR RELATED METHODS
  237.  
  238. // MINING RELATED METHODS
  239.  
  240. private boolean minedRock(int[] ID){
  241. RSObject[] minedRock = Objects.findNearest(1, ID);
  242. return minedRock != null && minedRock.length > 0 && Player.getAnimation() == -1;
  243. }
  244.  
  245. public int invCount(){
  246. return Inventory.getAll().length;
  247. }
  248.  
  249. private boolean coalAvailable(int[] rockID){
  250. RSObject[] coalRock = Objects.findNearest(6, rockID);
  251. return coalRock != null && coalRock.length > 0 && coalRock[0].isOnScreen();
  252. }
  253.  
  254. private boolean mineCoal(int[] rockID, String mineOption, int oreID){
  255. RSObject[] coalRock = Objects.findNearest(6, rockID);
  256. if (coalRock != null && coalRock.length > 0){
  257. if (coalRock[0].click(mineOption)){
  258. sleep(1500, 2000);
  259. waitFor(new Condition(){
  260. @Override
  261. public boolean active(){
  262. return minedRock(minedRockID) || isExplodingRock(1, explodingRockID);
  263. }
  264. }, 9000);
  265. }
  266. }
  267. return false;
  268. }
  269.  
  270. //BANKING METHODS
  271.  
  272. private boolean openBank() {
  273. if (!Banking.isBankScreenOpen()) {
  274. return Banking.openBankBooth();
  275. } else {
  276. if (Banking.isBankScreenOpen());
  277. return false;
  278. }
  279. }
  280.  
  281. private void depositCoal(String coalName) {
  282. RSItem[] coal = Inventory.find(coalName);
  283. if (coal != null && coal.length > 0 && Banking.isBankScreenOpen()) {
  284. Banking.depositAll();
  285. sleep (300, 400);
  286. }
  287. }
  288.  
  289. //LADDER METHODS
  290.  
  291. private void climbLadder(String ladderName) {
  292. RSObject[] ladder = Objects.findNearest(10, ladderName);
  293. if (ladder != null && ladder.length > 0 && areaContainsPlayer(ladderUpArea)) {
  294. if (DynamicClicking.clickRSObject(ladder[0], "Climb-down")) {
  295. waitFor(new Condition() {
  296. @Override
  297. public boolean active() {
  298. return areaContainsPlayer(ladderUpArea) && !Player.isMoving();
  299. }
  300. }, 4000);
  301. }
  302. }
  303. if (ladder != null && ladder.length > 0 && areaContainsPlayer(ladderDownArea)){
  304. if (DynamicClicking.clickRSObject(ladder[0], "Climb-Up")){
  305. waitFor(new Condition() {
  306. @Override
  307. public boolean active() {
  308. return areaContainsPlayer(ladderDownArea) && !Player.isMoving() && Inventory.isFull();
  309. }
  310. }, 4000);
  311. }
  312. }
  313. }
  314.  
  315. //AREA CHECKS
  316.  
  317. private boolean atGuild(RSTile guild){
  318. return myPos.distanceTo(guild) < 28;
  319. }
  320.  
  321. private boolean closeToDestination(RSTile whichTile, int radius){
  322. return myPos.distanceTo(whichTile) < radius;
  323. }
  324.  
  325. private boolean areaContainsPlayer(Polygon area){
  326. return area.contains(Player.getPosition().getX(), Player.getPosition().getY());
  327. }
  328.  
  329. //WALKING METHODS
  330.  
  331. private void walkDestination(final RSTile[] whichPath, final RSTile whichTile, final Polygon whichArea, final int radius) {
  332. if (myPos != whichTile && !Player.isMoving()) {
  333. if (Walking.walkPath(whichPath)) {
  334. waitFor(new Condition() {
  335. @Override
  336. public boolean active() {
  337. return areaContainsPlayer(whichArea) && closeToDestination(whichTile, radius) && !Player.isMoving();
  338. }
  339. }, 4000);
  340. }
  341. }
  342. }
  343.  
  344. private void walkDestinationCustom(final RSTile[] whichPath, final RSTile whichTile, final int radius) {
  345. if (myPos != whichTile && !Player.isMoving()) {
  346. if (Walking.walkPath(whichPath)) {
  347. waitFor(new Condition() {
  348. @Override
  349. public boolean active() {
  350. return closeToDestination(whichTile, radius) && !Player.isMoving();
  351. }
  352. }, 4000);
  353. }
  354. }
  355. }
  356.  
  357. public enum State {
  358. OPENING_BANK, BANKING_COAL, CLOSING_BANK,
  359. WALKING_TO_LADDER_UP, WALKING_TO_LADDER_DOWN,
  360. WALKING_TO_GUILD, WALKING_TO_BANK,
  361. CLIMBING_LADDER, MINING, EQUIPING_PICKAXE,
  362. WITHDRAWING_PICKAXE, PAUSING;
  363. }
  364.  
  365. private State getState(){
  366. if (paused){
  367. return State.PAUSING;
  368. }
  369. if (areaContainsPlayer(bankArea)){
  370. if (Inventory.isFull() && !Banking.isBankScreenOpen() && !havePickAxe(pickAxeName)){
  371. return State.OPENING_BANK;
  372. }
  373. if (Inventory.isFull() && Banking.isBankScreenOpen() && !havePickAxe(pickAxeName)){
  374. return State.BANKING_COAL;
  375. }
  376. if (Inventory.isFull() && Banking.isBankScreenOpen() && havePickAxe(pickAxeName)){
  377. return State.BANKING_COAL;
  378. }
  379. if (!havePickAxe(pickAxeName) && !Banking.isBankScreenOpen() && !pickAxeInInventory(pickAxeName)){
  380. return State.OPENING_BANK;
  381. }
  382. if (!havePickAxe(pickAxeName) && !Banking.isBankScreenOpen() && pickAxeInInventory(pickAxeName)){
  383. return State.EQUIPING_PICKAXE;
  384. }
  385. if (!havePickAxe(pickAxeName) && Banking.isBankScreenOpen() && !pickAxeInInventory(pickAxeName)){
  386. return State.WITHDRAWING_PICKAXE;
  387. }
  388. if (!havePickAxe(pickAxeName) && Banking.isBankScreenOpen() && pickAxeInInventory(pickAxeName)){
  389. return State.CLOSING_BANK;
  390. }
  391. if (Inventory.isFull() && !Banking.isBankScreenOpen() && havePickAxe(pickAxeName)){
  392. return State.OPENING_BANK;
  393. }
  394. if (!Inventory.isFull() && !Banking.isBankScreenOpen() && havePickAxe(pickAxeName)){
  395. return State.WALKING_TO_LADDER_UP;
  396. }
  397. if (!Inventory.isFull() && Banking.isBankScreenOpen() && havePickAxe(pickAxeName)){
  398. return State.CLOSING_BANK;
  399. }
  400. }
  401. if (areaContainsPlayer(ladderUpArea)){
  402. if (!Inventory.isFull() && havePickAxe(pickAxeName)){
  403. return State.CLIMBING_LADDER;
  404. }
  405. if (Inventory.isFull() || !havePickAxe(pickAxeName)){
  406. return State.WALKING_TO_BANK;
  407. }
  408. }
  409. if (areaContainsPlayer(ladderDownArea)){
  410. if (!Inventory.isFull() && havePickAxe(pickAxeName)){
  411. return State.WALKING_TO_GUILD;
  412. }
  413. if (Inventory.isFull() || !havePickAxe(pickAxeName)){
  414. return State.CLIMBING_LADDER;
  415. }
  416. }
  417. if (atGuild(secondGuildTile)){
  418. if (isExplodingRock(1, explodingRockID)){
  419. return State.WALKING_TO_GUILD;
  420. }
  421. if (!havePickAxe(pickAxeName)){
  422. return State.WALKING_TO_LADDER_DOWN;
  423. }
  424. if (!Inventory.isFull() && havePickAxe(pickAxeName) && coalAvailable(coalRockID)){
  425. return State.MINING;
  426. }
  427. if (Inventory.isFull()){
  428. return State.WALKING_TO_LADDER_DOWN;
  429. }
  430. if (!Inventory.isFull() || !coalAvailable(coalRockID) && havePickAxe(pickAxeName)){
  431. return State.WALKING_TO_GUILD;
  432. }
  433. }
  434. if (areaContainsPlayer(faladorArea)){
  435. if (!Inventory.isFull() && havePickAxe(pickAxeName)){
  436. return State.WALKING_TO_LADDER_UP;
  437. }
  438. if (Inventory.isFull() || !havePickAxe(pickAxeName)){
  439. return State.WALKING_TO_BANK;
  440. }
  441. }
  442. return null;
  443. }
  444.  
  445.  
  446. private Image getImage(String url) {
  447. try {
  448. return ImageIO.read(new URL(url));
  449. } catch (IOException e) {
  450. return null;
  451. }
  452. }
  453.  
  454. private final Image img = getImage("http://i44.tinypic.com/2cmtbgo.jpg");
  455. private static final long startTime = System.currentTimeMillis();
  456. private State SCRIPT_STATE = getState();
  457.  
  458. Font font = new Font("Calibri", Font.BOLD, 16);
  459.  
  460.  
  461. @SuppressWarnings("deprecation")
  462. private final int startXP = Skills.getXP("mining");
  463.  
  464. private int START_XP;
  465.  
  466. @SuppressWarnings("deprecation")
  467. @Override
  468. public void onPaint(Graphics g) {
  469.  
  470. Graphics2D gg = (Graphics2D) g;
  471. gg.drawImage(img, 9, 345, null);
  472.  
  473. long timeRan = System.currentTimeMillis() - startTime;
  474. double multiplier = timeRan / 3600000D;
  475. int price = 200;
  476. int currentLvl = Skills.getActualLevel("mining");
  477. int xpToNextLvl = Skills.getXPToNextLevel("mining");
  478. int xpGained = Skills.getXP("mining") - START_XP;
  479. double coal = xpGained / 50;
  480.  
  481. g.setFont(font);
  482. g.setColor(new Color(149, 26, 12));
  483. g.drawString("ok_miningGuilder V" + version, 18, 360);
  484. g.drawString("Action: " + SCRIPT_STATE, 18, 375);
  485. g.drawString("Time running: " + Timing.msToString(timeRan), 18, 390);
  486. g.drawString("Coal p/h: " + (int) (coal / multiplier) + " p/h", 330, 420);
  487. g.drawString("Profit p/h: " + (int) ((coal / multiplier) * price) + " K", 330, 435);
  488. g.drawString("Coal mined: " + coal, 330, 450);
  489. g.drawString("Profit made: " + (double) ((coal * price) / 1000) + " K", 330, 465);
  490.  
  491. g.drawString("XP Gained p/h: " + (int) (xpGained / multiplier), 330, 360);
  492. g.drawString("XP Gained: " + (int) xpGained, 330, 375);
  493. g.drawString("Current level: " + currentLvl, 330, 390);
  494. g.drawString("XP to Next Level: " + xpToNextLvl, 330, 405);
  495.  
  496. }
  497.  
  498. @Override
  499. public void run() {
  500. println("Started ok_miningGuilder");
  501. super.setRandomSolverState(true);
  502. Walking.setControlClick(true);
  503.  
  504. while(true){
  505. if (loggedOut()) {
  506. super.setLoginBotState(active);
  507. } else {
  508. while (!loggedOut()) {
  509. START_XP = startXP;
  510. SCRIPT_STATE = getState();
  511. int mSpeed = General.random(120, 130);
  512. Mouse.setSpeed(mSpeed);
  513. Walking.setControlClick(true);
  514.  
  515. switch (SCRIPT_STATE) {
  516.  
  517. case BANKING_COAL:
  518. int rotation = General.random(90, 200);
  519. antiBan(rotation);
  520.  
  521. depositCoal(coalOreName);
  522. sleep (400, 800);
  523. break;
  524.  
  525. case CLIMBING_LADDER:
  526. int rotation9 = General.random(90, 200);
  527. antiBan(rotation9);
  528.  
  529. climbLadder(ladderName);
  530. sleep (400, 800);
  531. break;
  532.  
  533. case CLOSING_BANK:
  534. int rotation8 = General.random(90, 200);
  535. antiBan(rotation8);
  536.  
  537. Banking.close();
  538. sleep (400, 800);
  539. break;
  540.  
  541. case MINING:
  542. int rotation7 = General.random(90, 200);
  543. antiBan(rotation7);
  544.  
  545. mineCoal(coalRockID, mineOption, coalOreID);
  546. break;
  547.  
  548. case OPENING_BANK:
  549. int rotation6 = General.random(90, 200);
  550. antiBan(rotation6);
  551.  
  552. openBank();
  553. sleep (400, 800);
  554. break;
  555.  
  556. case WALKING_TO_BANK:
  557. int rotation1 = General.random(90, 200);
  558. antiBan(rotation1);
  559.  
  560. walkDestination(bankPath, bankTile, bankArea, 8);
  561. sleep (400, 800);
  562. break;
  563.  
  564. case WALKING_TO_GUILD:
  565. int rotation3 = General.random(90, 200);
  566. antiBan(rotation3);
  567.  
  568. walkDestinationCustom(guildPath, secondGuildTile, 24);
  569. sleep (400, 800);
  570. break;
  571.  
  572. case WALKING_TO_LADDER_DOWN:
  573. int rotation4 = General.random(90, 200);
  574. antiBan(rotation4);
  575.  
  576. walkDestination(ladderDownPath, ladderDownTile, ladderDownArea, 8);
  577. sleep (400, 800);
  578. break;
  579.  
  580. case WALKING_TO_LADDER_UP:
  581. int rotation5 = General.random(90, 200);
  582. antiBan(rotation5);
  583.  
  584. walkDestination(ladderUpPath, ladderUpTile, ladderUpArea, 8);
  585. sleep (400, 800);
  586. break;
  587.  
  588. case EQUIPING_PICKAXE:
  589. equipPickAxe(pickAxeName, wieldOption);
  590. break;
  591.  
  592. case WITHDRAWING_PICKAXE:
  593. withdrawPickAxe(1, pickAxeName);
  594. break;
  595.  
  596. case PAUSING:
  597. sleep (100, 200);
  598. }
  599. }
  600. }
  601. }
  602. }
  603.  
  604. @Override
  605. public void onPause() {
  606. paused = true;
  607. while (paused){
  608. sleep (100, 200);
  609. }
  610.  
  611. }
  612.  
  613. @Override
  614. public void onResume() {
  615. paused = false;
  616. sleep (100, 200);
  617.  
  618. }
  619.  
  620. @Override
  621. public void onRandom(RANDOM_SOLVERS arg0) {
  622. onPause();
  623.  
  624. }
  625.  
  626. @Override
  627. public boolean randomFailed(RANDOM_SOLVERS arg0) {
  628. return false;
  629. }
  630.  
  631. @Override
  632. public void randomSolved(RANDOM_SOLVERS arg0) {
  633. onResume();
  634.  
  635. }
  636.  
  637. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement