Advertisement
Guest User

ok_StarterMiner

a guest
Dec 7th, 2013
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.80 KB | None | 0 0
  1. package scripts;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6.  
  7. import org.tribot.api.Timing;
  8. import org.tribot.api.General;
  9. import org.tribot.api2007.Screen;
  10. import org.tribot.api2007.types.RSTile;
  11. import org.tribot.api.DynamicClicking;
  12. import org.tribot.api.input.Mouse;
  13. import org.tribot.api.types.generic.Condition;
  14. import org.tribot.api2007.Camera;
  15. import org.tribot.api2007.Equipment;
  16. import org.tribot.api2007.GameTab;
  17. import org.tribot.api2007.GroundItems;
  18. import org.tribot.api2007.Inventory;
  19. import org.tribot.api2007.Login;
  20. import org.tribot.api2007.Objects;
  21. import org.tribot.api2007.Player;
  22. import org.tribot.api2007.Skills;
  23. import org.tribot.api2007.Walking;
  24. import org.tribot.api2007.GameTab.TABS;
  25. import org.tribot.api2007.types.RSGroundItem;
  26. import org.tribot.api2007.types.RSItem;
  27. import org.tribot.api2007.types.RSObject;
  28. import org.tribot.script.Script;
  29. import org.tribot.script.ScriptManifest;
  30. import org.tribot.script.interfaces.Painting;
  31. import org.tribot.script.interfaces.Pausing;
  32. import org.tribot.script.interfaces.RandomEvents;
  33.  
  34. @ScriptManifest(authors = { "Okokokok" }, category = "ok_StarterPack", name = "ok_StarterMiner")
  35. public class ok_StarterMiner extends Script implements Painting, Pausing, RandomEvents {
  36.  
  37. boolean paused = false;
  38.  
  39. private double version = 1.00;
  40.  
  41. private final int[] oreID = {7180, 7179, 7181, 7184, 7182, 7183},
  42. minedRockID = {10946, 10947, 10948};
  43.  
  44. private final int explodingRockID = 7158;
  45.  
  46. private final String mineOption = "Mine",
  47. pickAxeName = "Bronze pickaxe",
  48. wieldOption = "Wield",
  49. takeOption = "Take";
  50.  
  51. private final String[] oreNames = {"Tin ore", "Copper ore"},
  52. nothing = {""};
  53.  
  54. public RSArea miningArea = new RSArea (new RSTile(3219, 3144, 0), new RSTile(3232, 3149, 0)),
  55. walkingArea = new RSArea (new RSTile(3214, 3141, 0), new RSTile(3257, 3226, 0)),
  56. stairsArea = new RSArea (new RSTile(3223, 3211), new RSTile(3232, 3217));
  57.  
  58. private final RSTile[] miningPath = new RSTile[] {new RSTile(3225, 3214, 0),
  59. new RSTile(3227, 3217, 0),
  60. new RSTile(3232, 3216, 0),
  61. new RSTile(3233, 3212, 0),
  62. new RSTile(3235, 3208, 0),
  63. new RSTile(3236, 3204, 0),
  64. new RSTile(3240, 3200, 0),
  65. new RSTile(3242, 3196, 0),
  66. new RSTile(3244, 3192, 0),
  67. new RSTile(3242, 3188, 0),
  68. new RSTile(3239, 3184, 0),
  69. new RSTile(3236, 3180, 0),
  70. new RSTile(3234, 3176, 0),
  71. new RSTile(3232, 3172, 0),
  72. new RSTile(3231, 3168, 0),
  73. new RSTile(3230, 3164, 0),
  74. new RSTile(3231, 3158, 0),
  75. new RSTile(3231, 3154, 0),
  76. new RSTile(3230, 3149, 0),
  77. new RSTile(3226, 3146, 0)};
  78.  
  79.  
  80. // RANDOM METHODS
  81.  
  82. public boolean isExplodingRock(int distance, int explodingRockID){
  83. RSObject[] rock = Objects.find(distance, explodingRockID);
  84. return rock != null && rock.length > 0;
  85. }
  86.  
  87. public boolean randomTrue(){
  88. return paused;
  89. }
  90.  
  91. // MISC METHODS
  92.  
  93. public boolean waitFor(Condition c, long timeout) {
  94. Timer t = new Timer(timeout);
  95. while (t.isRunning()) {
  96. if (c.active()) {
  97. return true;
  98. }
  99. sleep(60, 80);
  100. }
  101. return false;
  102. }
  103.  
  104. public boolean loggedOut() {
  105. return (Login.getLoginState() == Login.STATE.LOGINSCREEN)
  106. && (!Screen.getColorAt(100, 200).equals(new Color(0, 0, 0)));
  107. }
  108.  
  109. public boolean logout() {
  110. if (Login.getLoginState() == Login.STATE.INGAME)
  111. {
  112. Login.logout();
  113. for(int x = 0; x < 6; x++)
  114. {
  115. if(loggedOut())
  116. {
  117. return true;
  118. }
  119. sleep(490,510);
  120. }
  121. }
  122. return false;
  123. }
  124.  
  125. public boolean havePickAxe(String pickaxename){
  126. RSItem[] pickAxe = Equipment.find(pickaxename);
  127. return pickAxe != null && pickAxe.length > 0;
  128. }
  129.  
  130. private boolean pickaxeground(){
  131. RSGroundItem[] pickaxe = GroundItems.find(pickAxeName);
  132. if (pickaxe != null && pickaxe.length > 0){
  133. return true;
  134. }
  135. return false;
  136. }
  137.  
  138.  
  139.  
  140. private void pickUpAxe(){
  141. RSGroundItem[] pickaxe = GroundItems.findNearest(pickAxeName);
  142. int plane = Player.getPosition().getPlane();
  143. if (plane == 2 && pickaxe != null && pickaxe.length > 0){
  144. if (pickaxe[0].click(takeOption)){
  145. waitFor(new Condition (){
  146. @Override
  147. public boolean active(){
  148. return pickAxeInInventory(pickAxeName);
  149. }
  150. }, 4000);
  151. }
  152. }
  153. }
  154.  
  155. private boolean pickAxeInInventory(String pickaxename){
  156. RSItem[] pickAxeInventory = Inventory.find(pickaxename);
  157. return pickAxeInventory != null && pickAxeInventory.length > 0;
  158. }
  159.  
  160. private void equipPickAxe(String pickaxename, String wieldOption){
  161. RSItem[] pickAxeInventory = Inventory.find(pickaxename);
  162. if (pickAxeInventory != null && pickAxeInventory.length > 0){
  163. if (pickAxeInventory[0].click(wieldOption)){
  164. waitFor(new Condition(){
  165. @Override
  166. public boolean active(){
  167. return havePickAxe(pickAxeName);
  168. }
  169. }, 4000);
  170. }
  171. }
  172. }
  173.  
  174. // ANTI-BAN BY SOKCRA
  175. public void antiBan(int rotation) {
  176. int number = General.random(1, 500);
  177. sleep(200);
  178. switch (number) {
  179. case 1:
  180. case 2:
  181. case 3:
  182. case 4:
  183. case 5:
  184. Camera.setCameraRotation(Camera.getCameraRotation() + rotation);
  185. break;
  186. case 20:
  187. case 21:
  188. case 22:
  189. case 23:
  190. case 24:
  191. case 25:
  192. case 26:
  193. case 27:
  194. case 28:
  195. case 29:
  196. case 30:
  197. case 31:
  198. Mouse.move(General.random(100, 200), General.random(200, 400));
  199. sleep(200);
  200. break;
  201. case 50:
  202. GameTab.open(TABS.INVENTORY);
  203. sleep(200);
  204. break;
  205. case 75:
  206. GameTab.open(TABS.STATS);
  207. sleep(300);
  208. Mouse.moveBox(678, 386, 725, 366);
  209. sleep(1000, 1500);
  210. GameTab.open(TABS.INVENTORY);
  211. break;
  212. case 76:
  213. GameTab.open(TABS.FRIENDS);
  214. sleep(2000, 3000);
  215. GameTab.open(TABS.INVENTORY);
  216. break;
  217. case 89:
  218. case 90:
  219. case 91:
  220. case 92:
  221. case 93:
  222. case 94:
  223. Camera.setCameraAngle(Camera.getCameraRotation() + rotation);
  224. sleep(200, 400);
  225. break;
  226. case 95:
  227. case 96:
  228. case 97:
  229. case 98:
  230. case 99:
  231. case 100:
  232. Camera.setCameraAngle(Camera.getCameraRotation() + rotation);
  233. sleep(200, 400);
  234. break;
  235. }
  236. }
  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 rockAvailable(int[] rockID){
  250. RSObject[] coalRock = Objects.findNearest(6, rockID);
  251. return coalRock != null && coalRock.length > 0 && coalRock[0].isOnScreen();
  252. }
  253.  
  254. private boolean mineRock(int[] rockID, String mineOption){
  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) || !havePickAxe(pickAxeName);
  263. }
  264. }, 30000);
  265. }
  266. }
  267. return false;
  268. }
  269.  
  270. // DROPPING METHODS
  271.  
  272. private void dropAll(){
  273. RSItem[] ores = Inventory.find(oreNames);
  274. if (Inventory.isFull() && ores != null && ores.length > 0){
  275. Inventory.dropAllExcept(nothing);
  276. }
  277. }
  278.  
  279. // DOOR METHODS
  280.  
  281. private RSTile getDoor(){
  282. RSObject[] door = Objects.findNearest(7, "Door");
  283. return door[0].getPosition();
  284. }
  285.  
  286. private boolean isDoorOpen(){
  287. RSObject[] door = Objects.findNearest(7, "Door");
  288. if (door != null && door.length > 0 && getDoor().equals(new RSTile(3227, 3214, 0))){
  289. return true;
  290. }
  291. return false;
  292. }
  293.  
  294. private void openDoor(){
  295. RSObject[] door = Objects.findNearest(7, "Door");
  296. if (door != null && door.length > 0 && !isDoorOpen()){
  297. if (DynamicClicking.clickRSObject(door[0], "Open")){
  298. waitFor(new Condition(){
  299. @Override
  300. public boolean active(){
  301. return isDoorOpen();
  302. }
  303. }, 4000);
  304. }
  305. }
  306. }
  307.  
  308. // LADDER METHODS
  309.  
  310. private void climbLadderUp(){
  311. RSObject[] ladder = Objects.findNearest(5, "Ladder");
  312. final int plane = Player.getPosition().getPlane();
  313. if (!havePickAxe(pickAxeName) && ladder != null && ladder.length > 0){
  314. if (plane == 0){
  315. if (DynamicClicking.clickRSObject(ladder[0], "Climb-up")){
  316. waitFor(new Condition(){
  317. @Override
  318. public boolean active(){
  319. return plane == 1;
  320. }
  321. }, 4000);
  322. }
  323. }
  324. if (plane == 1){
  325. if (DynamicClicking.clickRSObject(ladder[0], "Climb-Up")){
  326. waitFor(new Condition(){
  327. @Override
  328. public boolean active(){
  329. return plane == 2;
  330. }
  331. }, 4000);
  332. }
  333. }
  334. }
  335. }
  336.  
  337. private void climbLadderDown(){
  338. RSObject[] ladder = Objects.findNearest(5, "Ladder");
  339. final int plane = Player.getPosition().getPlane();
  340. if (havePickAxe(pickAxeName) && ladder != null && ladder.length > 0){
  341. if (plane == 2){
  342. if (DynamicClicking.clickRSObject(ladder[0], "Climb-down")){
  343. waitFor(new Condition(){
  344. @Override
  345. public boolean active(){
  346. return plane == 1;
  347. }
  348. }, 4000);
  349. }
  350. }
  351. if (plane == 1){
  352. if (DynamicClicking.clickRSObject(ladder[0], "Climb-Down")){
  353. waitFor(new Condition(){
  354. @Override
  355. public boolean active(){
  356. return plane == 0;
  357. }
  358. }, 4000);
  359. }
  360. }
  361. }
  362. }
  363.  
  364. // WALKING METHODS
  365.  
  366. private void walkingPickaxe(){
  367. final RSTile myPos = Player.getPosition();
  368. if (myPos != new RSTile(3225, 3214, 0)){
  369. if (Walking.walkPath(Walking.invertPath(miningPath))){
  370. waitFor(new Condition(){
  371. @Override
  372. public boolean active(){
  373. return stairsArea.contains(myPos);
  374. }
  375. }, 4000);
  376. }
  377. }
  378. }
  379.  
  380. private void walkingMining(){
  381. final RSTile myPos = Player.getPosition();
  382. if (myPos != new RSTile(3226, 3146, 0)){
  383. if (Walking.walkPath(miningPath)){
  384. waitFor(new Condition(){
  385. @Override
  386. public boolean active(){
  387. return miningArea.contains(myPos) || !isDoorOpen();
  388. }
  389. }, 4000);
  390. }
  391. }
  392. }
  393.  
  394. // STATE METHODS
  395.  
  396. public enum State{
  397. WALKING_TO_MINING_AREA, WALKING_TO_LADDER_AREA,
  398. CLIMBING_LADDER_UP, CLIMBING_LADDER_DOWN,
  399. OPENING_DOOR, PICKING_UP_PICKAXE, EQUIPPING_PICKAXE,
  400. MINING, DROPPING, SOLVING_RANDOM, LOGING_OUT;
  401. }
  402.  
  403. private boolean planeCheck0(){
  404. int plane = Player.getPosition().getPlane();
  405. return plane == 0;
  406. }
  407.  
  408. private boolean planeCheck1(){
  409. int plane = Player.getPosition().getPlane();
  410. return plane == 1;
  411. }
  412.  
  413. private State getState(){
  414. RSTile myPos = Player.getPosition();
  415. int plane = Player.getPosition().getPlane();
  416. if (paused){
  417. return State.SOLVING_RANDOM;
  418. }
  419. if (walkingArea.contains(myPos)){
  420. if (!havePickAxe(pickAxeName) && !pickAxeInInventory(pickAxeName) && !stairsArea.contains(myPos)){
  421. return State.WALKING_TO_LADDER_AREA;
  422. }
  423. if (planeCheck0() && !havePickAxe(pickAxeName) && !pickAxeInInventory(pickAxeName) && !isDoorOpen() && stairsArea.contains(myPos)){
  424. return State.OPENING_DOOR;
  425. }
  426. if (planeCheck0() && havePickAxe(pickAxeName) && pickAxeInInventory(pickAxeName) && stairsArea.contains(myPos)){
  427. return State.OPENING_DOOR;
  428. }
  429. if (planeCheck0() && !havePickAxe(pickAxeName) && !pickAxeInInventory(pickAxeName) && isDoorOpen() && stairsArea.contains(myPos)){
  430. return State.CLIMBING_LADDER_UP;
  431. }
  432. if (planeCheck1() && !havePickAxe(pickAxeName) && !pickAxeInInventory(pickAxeName) && stairsArea.contains(myPos)){
  433. return State.CLIMBING_LADDER_UP;
  434. }
  435. if (pickaxeground() && plane == 2 && !havePickAxe(pickAxeName) && !pickAxeInInventory(pickAxeName)){
  436. return State.PICKING_UP_PICKAXE;
  437. }
  438. if (!havePickAxe(pickAxeName) && pickAxeInInventory(pickAxeName) && stairsArea.contains(myPos)){
  439. return State.EQUIPPING_PICKAXE;
  440. }
  441. if (havePickAxe(pickAxeName) && plane != 0 && stairsArea.contains(myPos)){
  442. return State.CLIMBING_LADDER_DOWN;
  443. }
  444. if (havePickAxe(pickAxeName) && !miningArea.contains(myPos)){
  445. return State.WALKING_TO_MINING_AREA;
  446. }
  447. if (!havePickAxe(pickAxeName) && pickAxeInInventory(pickAxeName) && miningArea.contains(myPos)){
  448. return State.EQUIPPING_PICKAXE;
  449. }
  450. if (!Inventory.isFull() && havePickAxe(pickAxeName) && miningArea.contains(myPos) && rockAvailable(oreID)){
  451. return State.MINING;
  452. }
  453. if (Inventory.isFull() && havePickAxe(pickAxeName) && miningArea.contains(myPos)){
  454. return State.DROPPING;
  455. }
  456. }
  457. return State.LOGING_OUT;
  458. }
  459.  
  460.  
  461. @Override
  462. public void onRandom(RANDOM_SOLVERS arg0) {
  463. paused = true;
  464.  
  465. }
  466.  
  467. @Override
  468. public boolean randomFailed(RANDOM_SOLVERS arg0) {
  469. sleep(5000, 6000);
  470. paused = false;
  471. return false;
  472. }
  473.  
  474. @Override
  475. public void randomSolved(RANDOM_SOLVERS arg0) {
  476. sleep(5000, 6000);
  477. paused = false;
  478.  
  479. }
  480.  
  481. @Override
  482. public void onPause() {
  483. while(paused){
  484. sleep(100, 200);
  485. }
  486.  
  487. }
  488.  
  489. @Override
  490. public void onResume() {
  491. paused = false;
  492.  
  493. }
  494.  
  495. private static final long startTime = System.currentTimeMillis();
  496. Font font = new Font("Calibri", Font.BOLD, 16);
  497. private State SCRIPT_STATE = getState();
  498.  
  499.  
  500. @SuppressWarnings("deprecation")
  501. private final int startXP = Skills.getXP("mining");
  502. private int START_XP;
  503.  
  504. @SuppressWarnings("deprecation")
  505. @Override
  506. public void onPaint(Graphics g) {
  507.  
  508. long timeRan = System.currentTimeMillis() - startTime;
  509. double multiplier = timeRan / 3600000D;
  510. int xpGained = Skills.getXP("mining") - START_XP;
  511.  
  512. g.setFont(font);
  513. g.setColor(new Color(255, 255, 255));
  514. g.drawString("ok_StarterMiner V" + version, 558, 220);
  515. g.drawString("Action: " + SCRIPT_STATE, 558, 235);
  516. g.drawString("Time running: " + Timing.msToString(timeRan), 558, 250);
  517.  
  518. g.drawString("XP Gained p/h: " + (int) (xpGained / multiplier), 558, 265);
  519. g.drawString("XP Gained: " + (int) xpGained, 558, 280);
  520.  
  521. g.drawString("Ores p/h: " + (int)((xpGained / 17.5) / multiplier), 558, 295);
  522. g.drawString("Ores mined: " + (int) (xpGained / 17.5), 558, 310);
  523. }
  524.  
  525. @SuppressWarnings("deprecation")
  526. @Override
  527. public void run() {
  528. println("Started ok_StarterCombat from the StarterPack");
  529. START_XP = startXP;
  530. super.setRandomSolverState(true);
  531. Walking.setControlClick(true);
  532.  
  533.  
  534. while(true){
  535. if (loggedOut()) {
  536. super.setLoginBotState(active);
  537. } else {
  538. while (!loggedOut()) {
  539. SCRIPT_STATE = getState();
  540. int mSpeed = General.random(180, 200);
  541. Mouse.setSpeed(mSpeed);
  542. Walking.setControlClick(true);
  543.  
  544. switch (SCRIPT_STATE) {
  545.  
  546. case CLIMBING_LADDER_DOWN:
  547. climbLadderDown();
  548. sleep(200, 300);
  549. break;
  550.  
  551. case CLIMBING_LADDER_UP:
  552. climbLadderUp();
  553. sleep(200, 300);
  554. break;
  555.  
  556. case DROPPING:
  557. dropAll();
  558. sleep(200, 300);
  559. break;
  560.  
  561. case EQUIPPING_PICKAXE:
  562. equipPickAxe(pickAxeName, wieldOption);
  563. sleep(200, 300);
  564. break;
  565.  
  566. case LOGING_OUT:
  567. logout();
  568. stopScript();
  569. sleep(200, 300);
  570. break;
  571.  
  572. case MINING:
  573. mineRock(oreID, mineOption);
  574. sleep(200, 300);
  575.  
  576. int rotation5 = General.random(90, 200);
  577. antiBan(rotation5);
  578.  
  579. break;
  580.  
  581. case OPENING_DOOR:
  582. openDoor();
  583. sleep(200, 300);
  584. break;
  585.  
  586. case PICKING_UP_PICKAXE:
  587. pickUpAxe();
  588. sleep(200, 300);
  589. break;
  590.  
  591. case WALKING_TO_LADDER_AREA:
  592. walkingPickaxe();
  593. sleep(200, 300);
  594. break;
  595.  
  596. case WALKING_TO_MINING_AREA:
  597. walkingMining();
  598. sleep(200, 300);
  599. break;
  600.  
  601. case SOLVING_RANDOM:
  602. while(paused){
  603. sleep(100, 200);
  604. }
  605. break;
  606. }
  607. }
  608. }
  609. }
  610. }
  611. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement