Advertisement
Guest User

ok_StarterFisher

a guest
Dec 7th, 2013
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.44 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.Banking;
  15. import org.tribot.api2007.Camera;
  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.NPCs;
  21. import org.tribot.api2007.Objects;
  22. import org.tribot.api2007.Player;
  23. import org.tribot.api2007.Skills;
  24. import org.tribot.api2007.Walking;
  25. import org.tribot.api2007.GameTab.TABS;
  26. import org.tribot.api2007.types.RSGroundItem;
  27. import org.tribot.api2007.types.RSItem;
  28. import org.tribot.api2007.types.RSNPC;
  29. import org.tribot.api2007.types.RSObject;
  30. import org.tribot.script.Script;
  31. import org.tribot.script.ScriptManifest;
  32. import org.tribot.script.interfaces.Painting;
  33. import org.tribot.script.interfaces.Pausing;
  34. import org.tribot.script.interfaces.RandomEvents;
  35.  
  36. @ScriptManifest(authors = { "Okokokok" }, category = "ok_StarterPack", name = "ok_StarterFisher")
  37. public class ok_StarterFisher extends Script implements Painting, Pausing, RandomEvents {
  38.  
  39. boolean paused,
  40. bank = false,
  41. drop = true;
  42.  
  43. private int plane = Player.getPosition().getPlane();
  44.  
  45. final int planes = Player.getPosition().getPlane();
  46.  
  47. private double version = 1.00;
  48.  
  49. private final String netName = "Small fishing net",
  50. fishingSpotName = "Fishing spot",
  51. fishingSpotOption = "Net",
  52. shrimpName = "Raw shrimps",
  53. anchoviesName = "Raw anchovies",
  54. stairsName = "Staircase",
  55. stairsUpOption = "Climb-up",
  56. stairsDownOption = "Climb-down",
  57. takeOption = "Take";
  58.  
  59. private final String[] fishNames = {shrimpName, anchoviesName};
  60.  
  61. public RSArea deathArea = new RSArea(new RSTile(3216, 3208, 0), new RSTile(3226, 3224, 0)),
  62. bankArea = new RSArea(new RSTile(3207, 3215, 2), new RSTile(3210, 3221, 2)),
  63. fishingArea = new RSArea(new RSTile(3236, 3140, 0), new RSTile(3247, 3161, 0)),
  64. stairArea = new RSArea(new RSTile(3204, 3207), new RSTile(3209, 3211)),
  65. walkArea = new RSArea(new RSTile(3204, 3140, 0), new RSTile(3246, 3227, 0)),
  66. noFishArea = new RSArea(new RSTile(3244, 3156, 0), new RSTile(3245, 3158, 0));
  67.  
  68. private final RSTile noFishTile = new RSTile(3246, 3157, 0),
  69. netsTile = new RSTile(3243, 3155, 0);
  70.  
  71. private final RSTile[] stairsPathUp = new RSTile[] {new RSTile(3207, 3219, 2),
  72. new RSTile(3206, 3216, 2),
  73. new RSTile(3205, 3210, 2)},
  74. fishingSpotPath = new RSTile[] {new RSTile(3207, 3209, 0),
  75. new RSTile(3209, 3210, 0),
  76. new RSTile(3214, 3211, 0),
  77. new RSTile(3214, 3216, 0),
  78. new RSTile(3219, 3219, 0),
  79. new RSTile(3228, 3217, 0),
  80. new RSTile(3232, 3215, 0),
  81. new RSTile(3234, 3210, 0),
  82. new RSTile(3235, 3206, 0),
  83. new RSTile(3239, 3199, 0),
  84. new RSTile(3241, 3193, 0),
  85. new RSTile(3243, 3186, 0),
  86. new RSTile(3243, 3179, 0),
  87. new RSTile(3243, 3173, 0),
  88. new RSTile(3243, 3167, 0),
  89. new RSTile(3243, 3159, 0),
  90. new RSTile(3245, 3156, 0)};
  91.  
  92.  
  93. // MISC METHODS
  94.  
  95. public boolean waitFor(Condition c, long timeout) {
  96. Timer t = new Timer(timeout);
  97. while (t.isRunning()) {
  98. if (c.active()) {
  99. return true;
  100. }
  101. sleep(60, 80);
  102. }
  103. return false;
  104. }
  105.  
  106. public boolean loggedOut() {
  107. return (Login.getLoginState() == Login.STATE.LOGINSCREEN)
  108. && (!Screen.getColorAt(100, 200).equals(new Color(0, 0, 0)));
  109. }
  110.  
  111. public boolean logout() {
  112. if (Login.getLoginState() == Login.STATE.INGAME)
  113. {
  114. Login.logout();
  115. for(int x = 0; x < 6; x++)
  116. {
  117. if(loggedOut())
  118. {
  119. return true;
  120. }
  121. sleep(490,510);
  122. }
  123. }
  124. return false;
  125. }
  126.  
  127. public void antiBan(int rotation) {
  128. int number = General.random(1, 500);
  129. sleep(200);
  130. switch (number) {
  131. case 1:
  132. case 2:
  133. case 3:
  134. case 4:
  135. case 5:
  136. Camera.setCameraRotation(Camera.getCameraRotation() + rotation);
  137. break;
  138. case 20:
  139. case 21:
  140. case 22:
  141. case 23:
  142. case 24:
  143. case 25:
  144. case 26:
  145. case 27:
  146. case 28:
  147. case 29:
  148. case 30:
  149. case 31:
  150. Camera.setCameraRotation(Camera.getCameraRotation() + rotation);
  151. sleep(200);
  152. break;
  153. case 50:
  154. GameTab.open(TABS.INVENTORY);
  155. sleep(200);
  156. break;
  157. case 75:
  158. case 76:
  159. break;
  160. case 89:
  161. case 90:
  162. case 91:
  163. case 92:
  164. case 93:
  165. case 94:
  166. Camera.setCameraAngle(Camera.getCameraRotation() + rotation);
  167. sleep(200, 400);
  168. break;
  169. case 95:
  170. case 96:
  171. case 97:
  172. case 98:
  173. case 99:
  174. case 100:
  175. Camera.setCameraAngle(Camera.getCameraRotation() + rotation);
  176. sleep(200, 400);
  177. break;
  178. }
  179. }
  180.  
  181. // NET AND BANKING METHODS
  182.  
  183. private void openBank(){
  184. RSTile myPos = Player.getPosition();
  185. if (bankArea.contains(myPos)){
  186. if (!Banking.isBankScreenOpen()){
  187. Banking.openBankBooth();
  188. }
  189. if (Banking.isBankScreenOpen()){
  190. sleep(20, 30);
  191. }
  192. }
  193. }
  194.  
  195. private void closeBank(){
  196. if (Banking.isBankScreenOpen()){
  197. Banking.close();
  198. }
  199. }
  200.  
  201. private void depositFish(){
  202. RSItem[] fish = Inventory.find(fishNames);
  203. if (fish != null && fish.length > 0){
  204. Banking.depositAllExcept(netName);
  205. }
  206. }
  207.  
  208. private boolean haveNet(){
  209. RSItem[] net = Inventory.find(netName);
  210. return net != null && net.length > 0;
  211. }
  212.  
  213. private boolean isNetOnground(){
  214. RSGroundItem[] net = GroundItems.findNearest(netName);
  215. return net != null && net.length > 0 && net[0].isOnScreen();
  216. }
  217.  
  218. private void pickingUpNet(){
  219. RSGroundItem[] net = GroundItems.findNearest(netName);
  220. if (net != null && net.length > 0){
  221. if (net[0].click(takeOption)){
  222. waitFor(new Condition(){
  223. @Override
  224. public boolean active(){
  225. return haveNet();
  226. }
  227. }, 4000);
  228. }
  229. }
  230. }
  231.  
  232. // FISHING METHODS
  233.  
  234. private boolean isFishSpot(){
  235. RSNPC[] spot = NPCs.findNearest(fishingSpotName);
  236. return spot != null && spot.length > 0 && spot[0].isOnScreen();
  237. }
  238.  
  239. private RSTile fishingPosition(){
  240. RSNPC[] spot = NPCs.findNearest(fishingSpotName);
  241. if (spot != null && spot.length > 0){
  242. return spot[0].getPosition();
  243. }
  244. return null;
  245. }
  246.  
  247. private void startFishing(){
  248. RSNPC[] spot = NPCs.findNearest(fishingSpotName);
  249. if (spot != null && spot.length > 0){
  250. if (DynamicClicking.clickRSNPC(spot[0], fishingSpotOption)){
  251. sleep(500, 600);
  252. waitFor(new Condition(){
  253. @Override
  254. public boolean active(){
  255. return !Player.isMoving() && Player.getAnimation() == -1 || Inventory.isFull();
  256. }
  257. }, 20000);
  258. }
  259. }
  260. }
  261.  
  262. // RAW FISH METHODS
  263.  
  264. private boolean haveFish(){
  265. RSItem[] fish = Inventory.find(fishNames);
  266. return fish != null && fish.length > 0;
  267. }
  268.  
  269. private void dropFish(){
  270. String[] netName = {"Small fishing net", "Fishing"};
  271. RSItem[] fish = Inventory.find(fishNames);
  272. if (fish != null && fish.length > 0){
  273. Inventory.dropAllExcept(netName);
  274. }
  275. }
  276.  
  277. // WALK METHODS
  278.  
  279. private void toFishingSpot(){
  280. final RSTile myPos = Player.getPosition();
  281. if (!fishingArea.contains(myPos)){
  282. if (Walking.walkPath(fishingSpotPath)){
  283. waitFor(new Condition(){
  284. @Override
  285. public boolean active(){
  286. return fishingArea.contains(myPos) && !Player.isMoving();
  287. }
  288. }, 4000);
  289. }
  290. }
  291. }
  292.  
  293. private void toNets(){
  294. final RSTile myPos = Player.getPosition();
  295. if (myPos.distanceTo(netsTile) > 3){
  296. if (Walking.walkTo(netsTile)){
  297. waitFor(new Condition(){
  298. @Override
  299. public boolean active(){
  300. return myPos.distanceTo(netsTile) < 3 && !Player.isMoving();
  301. }
  302. }, 10000);
  303. }
  304. }
  305. }
  306.  
  307. private void toSpot(){
  308. final RSTile myPos = Player.getPosition();
  309. if (myPos.distanceTo(fishingPosition()) > 3){
  310. if (Walking.walkTo(fishingPosition())){
  311. waitFor(new Condition(){
  312. @Override
  313. public boolean active(){
  314. return myPos.distanceTo(fishingPosition()) < 3 && !Player.isMoving();
  315. }
  316. }, 10000);
  317. }
  318. }
  319. }
  320.  
  321. private void toSpot2(){
  322. final RSTile myPos = Player.getPosition();
  323. if (myPos.distanceTo(new RSTile(3241, 3149, 0)) > 3){
  324. if (Walking.walkTo(new RSTile(3241, 3149, 0))){
  325. waitFor(new Condition(){
  326. @Override
  327. public boolean active(){
  328. return myPos.distanceTo(new RSTile(3241, 3149, 0)) < 3 && !Player.isMoving();
  329. }
  330. }, 10000);
  331. }
  332. }
  333. }
  334.  
  335. private void toBank(){
  336. final RSTile myPos = Player.getPosition();
  337. if (!bankArea.contains(myPos)){
  338. if (Walking.walkPath(Walking.invertPath(stairsPathUp))){
  339. waitFor(new Condition(){
  340. @Override
  341. public boolean active(){
  342. return bankArea.contains(myPos) && !Player.isMoving();
  343. }
  344. }, 4000);
  345. }
  346. }
  347. }
  348.  
  349. private void toStairs(){
  350. final RSTile myPos = Player.getPosition();
  351. if (!stairArea.contains(myPos)){
  352. if (Walking.walkPath(stairsPathUp)){
  353. waitFor(new Condition(){
  354. @Override
  355. public boolean active(){
  356. return stairArea.contains(myPos) && !Player.isMoving();
  357. }
  358. }, 4000);
  359. }
  360. }
  361. }
  362.  
  363. // STAIR METHODS
  364.  
  365. private void climbUp(){
  366. RSObject[] stairs = Objects.findNearest(10, stairsName);
  367. int plane = Player.getPosition().getPlane();
  368. final int planes = Player.getPosition().getPlane();
  369. if (stairs != null && stairs.length > 0){
  370. if (plane == 0){
  371. if (DynamicClicking.clickRSObject(stairs[0], stairsUpOption)){
  372. waitFor(new Condition(){
  373. @Override
  374. public boolean active(){
  375. return planes == 1;
  376. }
  377. }, 3000);
  378. }
  379. }
  380. if (plane == 1){
  381. if (DynamicClicking.clickRSObject(stairs[0], stairsUpOption)){
  382. waitFor(new Condition(){
  383. @Override
  384. public boolean active(){
  385. return planes == 2;
  386. }
  387. }, 3000);
  388. }
  389. }
  390. if (plane == 2){
  391. sleep (20, 30);
  392. }
  393. }
  394. }
  395.  
  396. private void climbDown(){
  397. RSObject[] stairs = Objects.findNearest(10, stairsName);
  398. int plane = Player.getPosition().getPlane();
  399. final int planes = Player.getPosition().getPlane();
  400. if (stairs != null && stairs.length > 0){
  401. if (plane == 2){
  402. if (DynamicClicking.clickRSObject(stairs[0], stairsDownOption)){
  403. waitFor(new Condition(){
  404. @Override
  405. public boolean active(){
  406. return planes == 1;
  407. }
  408. }, 3000);
  409. }
  410. }
  411. if (plane == 1){
  412. if (DynamicClicking.clickRSObject(stairs[0], stairsDownOption)){
  413. waitFor(new Condition(){
  414. @Override
  415. public boolean active(){
  416. return planes == 0;
  417. }
  418. }, 3000);
  419. }
  420. }
  421. if (plane == 0){
  422. sleep (20, 30);
  423. }
  424. }
  425. }
  426.  
  427. // STATES
  428.  
  429. public enum State{
  430. OPENING_BANK, BANKING_FISH, DROPPING_FISH,
  431. FISHING, WALKING_TO_FISHING_SPOT, WALKING_TO_BANK,
  432. PICKING_UP_FISHING_NET, WALKING_TO_SPOT, WALKING_TO_SPOT2,
  433. WALKING_TO_STAIRS, CLIMBING_DOWN, CLIMBING_UP,
  434. CLOSING_BANK, WALKING_TO_NETS, LOGING_OUT;
  435. }
  436.  
  437. private State getState(){
  438. RSTile myPos = Player.getPosition();
  439. if (walkArea.contains(myPos) && fishingArea.contains(myPos)){
  440. if (fishingPosition().equals(noFishTile)){
  441. return State.WALKING_TO_SPOT2;
  442. }
  443. if (!Inventory.isFull() && haveNet() && isFishSpot()){
  444. return State.FISHING;
  445. }
  446. if (!Inventory.isFull() && haveNet() && !isFishSpot()){
  447. return State.WALKING_TO_SPOT;
  448. }
  449. if (!Inventory.isFull() && !haveNet() && isNetOnground()){
  450. return State.PICKING_UP_FISHING_NET;
  451. }
  452. if (!Inventory.isFull() && !haveNet() && !isNetOnground()){
  453. return State.WALKING_TO_NETS;
  454. }
  455. if (Inventory.isFull() && bank && !drop){
  456. return State.WALKING_TO_BANK;
  457. }
  458. if (Inventory.isFull() && !bank && drop){
  459. return State.DROPPING_FISH;
  460. }
  461. }
  462. if (walkArea.contains(myPos) && !fishingArea.contains(myPos) && !stairArea.contains(myPos)){
  463. if (!Inventory.isFull()){
  464. return State.WALKING_TO_FISHING_SPOT;
  465. }
  466. if (Inventory.isFull()){
  467. return State.WALKING_TO_BANK;
  468. }
  469. }
  470. if (walkArea.contains(myPos) && stairArea.contains(myPos)){
  471. if (Inventory.isFull() && plane != 2){
  472. return State.CLIMBING_UP;
  473. }
  474. if (Inventory.isFull() && plane == 2 && !bankArea.contains(myPos)){
  475. return State.WALKING_TO_BANK;
  476. }
  477. if (!Inventory.isFull() && plane != 0){
  478. return State.CLIMBING_DOWN;
  479. }
  480. if (!Inventory.isFull() && plane == 0){
  481. return State.WALKING_TO_FISHING_SPOT;
  482. }
  483. }
  484. if (walkArea.contains(myPos) && bankArea.contains(myPos) && plane == 2){
  485. if (!Banking.isBankScreenOpen() && Inventory.isFull()){
  486. return State.OPENING_BANK;
  487. }
  488. if (Banking.isBankScreenOpen() && haveFish()){
  489. return State.BANKING_FISH;
  490. }
  491. if (Banking.isBankScreenOpen() && !haveFish()){
  492. return State.CLOSING_BANK;
  493. }
  494.  
  495. }
  496. return State.LOGING_OUT;
  497. }
  498.  
  499.  
  500.  
  501. @Override
  502. public void onRandom(RANDOM_SOLVERS arg0) {
  503. paused = true;
  504.  
  505. }
  506.  
  507. @Override
  508. public boolean randomFailed(RANDOM_SOLVERS arg0) {
  509. paused = false;
  510. return false;
  511. }
  512.  
  513. @Override
  514. public void randomSolved(RANDOM_SOLVERS arg0) {
  515. paused = false;
  516.  
  517. }
  518.  
  519. @Override
  520. public void onPause() {
  521. paused = true;
  522. while (paused){
  523. sleep(100, 200);
  524. }
  525.  
  526. }
  527.  
  528. @Override
  529. public void onResume() {
  530. sleep(2000, 3000);
  531. paused = false;
  532.  
  533. }
  534.  
  535. private static final long startTime = System.currentTimeMillis();
  536. Font font = new Font("Calibri", Font.BOLD, 16);
  537. private State SCRIPT_STATE = getState();
  538.  
  539.  
  540. @SuppressWarnings("deprecation")
  541. private final int startXP = Skills.getXP("fishing");
  542. private int START_XP;
  543.  
  544. @SuppressWarnings("deprecation")
  545. @Override
  546. public void onPaint(Graphics g) {
  547.  
  548. long timeRan = System.currentTimeMillis() - startTime;
  549. double multiplier = timeRan / 3600000D;
  550. int xpGained = Skills.getXP("fishing") - START_XP;
  551.  
  552. g.setFont(font);
  553. g.setColor(new Color(255, 255, 255));
  554. g.drawString("ok_StarterFishing V" + version, 558, 220);
  555. g.drawString("Action: " + SCRIPT_STATE, 558, 235);
  556. g.drawString("Time running: " + Timing.msToString(timeRan), 558, 250);
  557.  
  558. g.drawString("XP Gained p/h: " + (int) (xpGained / multiplier), 558, 265);
  559. g.drawString("XP Gained: " + (int) xpGained, 558, 280);
  560. }
  561.  
  562. @SuppressWarnings("deprecation")
  563. @Override
  564. public void run() {
  565. println("Started ok_StarterCombat from the StarterPack");
  566. START_XP = startXP;
  567. super.setRandomSolverState(true);
  568. Walking.setControlClick(true);
  569.  
  570. while(true){
  571. if (loggedOut()) {
  572. super.setLoginBotState(active);
  573. } else {
  574. while (!loggedOut()) {
  575. SCRIPT_STATE = getState();
  576. int mSpeed = General.random(180, 200);
  577. Mouse.setSpeed(mSpeed);
  578. Walking.setControlClick(true);
  579.  
  580. switch (SCRIPT_STATE) {
  581.  
  582. case BANKING_FISH:
  583. depositFish();
  584. sleep(100, 200);
  585. break;
  586.  
  587. case CLIMBING_DOWN:
  588. climbDown();
  589. sleep(100, 200);
  590. break;
  591.  
  592. case CLIMBING_UP:
  593. climbUp();
  594. sleep(100, 200);
  595. break;
  596.  
  597. case DROPPING_FISH:
  598. dropFish();
  599. sleep(100, 200);
  600. break;
  601.  
  602. case FISHING:
  603. int rotation5 = General.random(90, 200);
  604. antiBan(rotation5);
  605.  
  606. startFishing();
  607. sleep(100, 200);
  608. break;
  609.  
  610. case LOGING_OUT:
  611. logout();
  612. stopScript();
  613. break;
  614.  
  615. case OPENING_BANK:
  616. openBank();
  617. sleep(100, 200);
  618. break;
  619.  
  620. case PICKING_UP_FISHING_NET:
  621. pickingUpNet();
  622. sleep(100, 200);
  623. break;
  624.  
  625. case WALKING_TO_BANK:
  626. toBank();
  627. sleep(100, 200);
  628. break;
  629.  
  630. case WALKING_TO_FISHING_SPOT:
  631. toFishingSpot();
  632. sleep(100, 200);
  633. break;
  634.  
  635. case WALKING_TO_SPOT:
  636. toSpot();
  637. sleep(100, 200);
  638. break;
  639.  
  640. case WALKING_TO_STAIRS:
  641. toStairs();
  642. sleep(100, 200);
  643. break;
  644.  
  645. case CLOSING_BANK:
  646. closeBank();
  647. sleep(100, 200);
  648. break;
  649.  
  650. case WALKING_TO_SPOT2:
  651. toSpot2();
  652. sleep(100, 200);
  653. break;
  654.  
  655. case WALKING_TO_NETS:
  656. toNets();
  657. sleep(150, 200);
  658. break;
  659. }
  660. }
  661. }
  662. }
  663. }
  664. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement