Advertisement
Guest User

potato v2

a guest
Dec 16th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.86 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 org.tribot.api.Timing;
  13. import org.tribot.api.General;
  14. import org.tribot.api2007.Screen;
  15. import org.tribot.api2007.types.RSTile;
  16.  
  17. import javax.imageio.ImageIO;
  18.  
  19. import org.tribot.api.DynamicClicking;
  20. import org.tribot.api.input.Mouse;
  21. import org.tribot.api.types.generic.Condition;
  22. import org.tribot.api2007.Banking;
  23. import org.tribot.api2007.Camera;
  24. import org.tribot.api2007.GameTab;
  25. import org.tribot.api2007.Inventory;
  26. import org.tribot.api2007.Login;
  27. import org.tribot.api2007.Objects;
  28. import org.tribot.api2007.Player;
  29. import org.tribot.api2007.Walking;
  30. import org.tribot.api2007.GameTab.TABS;
  31. import org.tribot.api2007.types.RSArea;
  32. import org.tribot.api2007.types.RSItem;
  33. import org.tribot.api2007.types.RSObject;
  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_Potato")
  41. public class ok_Potato extends Script implements Painting, Pausing, RandomEvents {
  42.  
  43. private boolean paused = false;
  44.  
  45. private int potatoesCollected;
  46.  
  47. private final double version = 1.03;
  48.  
  49. private final String gateName = "Gate",
  50. gateOption = "Open",
  51. potatoName = "Potato",
  52. potatoOption = "Pick";
  53.  
  54. private final String[] seedName = {"Potato seed"};
  55.  
  56. private final RSTile bankTile = new RSTile (2618, 3332, 0),
  57. gateFrontTile = new RSTile (2635, 3361, 0),
  58. potatoTile = new RSTile (2631, 3360, 0);
  59.  
  60. private final Polygon potatoArea = new Polygon(
  61. new int[] {2624, 2635, 2635, 2624},
  62. new int[] {3372, 3372, 3352, 3352},
  63. 4),
  64. ardyArea = new Polygon(
  65. new int[] {2609, 2641, 2641, 2609},
  66. new int[] {3372, 3372, 3327, 3327},
  67. 4),
  68. gateFrontArea = new Polygon(
  69. new int[] {2635, 2641, 2641, 2635},
  70. new int[] {3365, 3365, 3357, 3357},
  71. 4),
  72. gateBackArea = new Polygon(
  73. new int[] {2630, 2635, 2635, 2630},
  74. new int[] {3364, 3364, 3358, 3358},
  75. 4),
  76. bankAreas = new Polygon(
  77. new int[] {2612, 2622, 2622, 2612},
  78. new int[] {3337, 3337, 3330, 3330},
  79. 4);
  80.  
  81.  
  82. private RSArea bankArea = new RSArea(new RSTile(2612, 3330, 0), new RSTile(2621, 3336, 0)),
  83. walkingArea = new RSArea(new RSTile(2609, 3327, 0), new RSTile(2643, 3370, 0));
  84.  
  85. private final RSTile [] bankPath = new RSTile[] { new RSTile (2635, 3359, 0),
  86. new RSTile (2635, 3354, 0),
  87. new RSTile (2635, 3347, 0),
  88. new RSTile (2635, 3340, 0),
  89. new RSTile (2631, 3336, 0),
  90. new RSTile (2625, 3336, 0),
  91. new RSTile (2620, 3337, 0),
  92. new RSTile (2616, 3334, 0),
  93. new RSTile (2617, 3332, 0)},
  94. potatoPath = new RSTile[] { new RSTile (2616, 3334, 0),
  95. new RSTile (2620, 3337, 0),
  96. new RSTile (2625, 3336, 0),
  97. new RSTile (2631, 3336, 0),
  98. new RSTile (2635, 3340, 0),
  99. new RSTile (2635, 3347, 0),
  100. new RSTile (2635, 3354, 0),
  101. new RSTile (2635, 3359, 0),
  102. new RSTile (2635, 3361, 0)};
  103.  
  104.  
  105. // MISC METHODS
  106.  
  107. public boolean logout()
  108. {
  109. if (Login.getLoginState() == Login.STATE.INGAME)
  110. {
  111. Login.logout();
  112. for(int x = 0; x < 6; x++)
  113. {
  114. if(loggedOut())
  115. {
  116. return true;
  117. }
  118. sleep(490,510);
  119. }
  120. }
  121. return false;
  122. }
  123.  
  124. public boolean waitFor(Condition c, long timeout) {
  125. Timer t = new Timer(timeout);
  126. while (t.isRunning()) {
  127. if (c.active()) {
  128. return true;
  129. }
  130. sleep(60, 80);
  131. }
  132. return false;
  133. }
  134.  
  135. public boolean loggedOut() {
  136. return (Login.getLoginState() == Login.STATE.LOGINSCREEN)
  137. && (!Screen.getColorAt(100, 200).equals(new Color(0, 0, 0)));
  138. }
  139.  
  140. public void antiBan(int rotation) {
  141. int number = General.random(1, 500);
  142. sleep(200);
  143. switch (number) {
  144. case 1:
  145. case 2:
  146. case 3:
  147. case 4:
  148. case 5:
  149. Camera.setCameraRotation(Camera.getCameraRotation() + rotation);
  150. break;
  151. case 20:
  152. case 21:
  153. case 22:
  154. case 23:
  155. case 24:
  156. case 25:
  157. case 26:
  158. case 27:
  159. case 28:
  160. case 29:
  161. case 30:
  162. case 31:
  163. Mouse.move(General.random(100, 200), General.random(200, 400));
  164. sleep(200);
  165. break;
  166. case 50:
  167. GameTab.open(TABS.INVENTORY);
  168. sleep(200);
  169. break;
  170. case 75:
  171. GameTab.open(TABS.STATS);
  172. sleep(300);
  173. Mouse.moveBox(678, 386, 725, 366);
  174. sleep(1000, 1500);
  175. GameTab.open(TABS.INVENTORY);
  176. break;
  177. case 76:
  178. GameTab.open(TABS.FRIENDS);
  179. sleep(2000, 3000);
  180. GameTab.open(TABS.INVENTORY);
  181. break;
  182. case 89:
  183. case 90:
  184. case 91:
  185. case 92:
  186. case 93:
  187. case 94:
  188. Camera.setCameraAngle(Camera.getCameraRotation() + rotation);
  189. sleep(200, 400);
  190. break;
  191. case 95:
  192. case 96:
  193. case 97:
  194. case 98:
  195. case 99:
  196. case 100:
  197. Camera.setCameraAngle(Camera.getCameraRotation() + rotation);
  198. sleep(200, 400);
  199. break;
  200. }
  201. }
  202.  
  203. // BANKING METHODS
  204.  
  205. private void openBank() {
  206. if (!Banking.isBankScreenOpen()) {
  207. Banking.openBankBanker();
  208. }
  209. }
  210.  
  211. private void depositItem(String itemName){
  212. RSItem[] item = Inventory.find(itemName);
  213. if (item != null && item.length > 0){
  214. Banking.depositAll();
  215. sleep(500, 600);
  216. }
  217. }
  218.  
  219.  
  220. // WALKING METHODS
  221.  
  222. private void walkDestination(final RSTile[] whichPath, final RSTile whichTile, final Polygon whichArea, final int radius) {
  223. RSTile myPos = Player.getPosition();
  224. if (myPos != whichTile && !Player.isMoving()) {
  225. if (Walking.walkPath(whichPath)) {
  226. waitFor(new Condition() {
  227. @Override
  228. public boolean active() {
  229. return areaContainsPlayer(whichArea) && isCloseToDestination(whichTile, radius) && !Player.isMoving();
  230. }
  231. }, 15000);
  232. }
  233. }
  234. }
  235.  
  236. private void walkTile(final Polygon whichArea, RSTile destination){
  237. RSTile myPos2 = Player.getPosition();
  238. if (myPos2.distanceTo(destination) != 0){
  239. if (Walking.walkTo(destination)){
  240. waitFor(new Condition(){
  241. @Override
  242. public boolean active(){
  243. return areaContainsPlayer(whichArea) && !Player.isMoving();
  244. }
  245. }, 3000);
  246. }
  247. }
  248. }
  249.  
  250. // AREA CHECKS
  251.  
  252. private boolean isCloseToDestination(RSTile whichTile, int radius){
  253. RSTile myPos = Player.getPosition();
  254. return myPos.distanceTo(whichTile) < radius;
  255. }
  256.  
  257. private boolean areaContainsPlayer(Polygon area){
  258. return area.contains(Player.getPosition().getX(), Player.getPosition().getY());
  259. }
  260.  
  261. private boolean noInAnyArea(){
  262. RSTile myPos = Player.getPosition();
  263. if (areaContainsPlayer(ardyArea) && !bankArea.contains(myPos) &&
  264. !areaContainsPlayer(gateFrontArea) && !areaContainsPlayer(gateBackArea) &&
  265. !areaContainsPlayer(potatoArea)){
  266. return true;
  267. }
  268. return false;
  269. }
  270.  
  271. // GATE METHODS
  272.  
  273. private boolean isGateOpen(){
  274. RSObject[] gate = Objects.findNearest(5, "Gate");
  275. return gate.length > 0 && (getGateTile().equals(new RSTile(2635, 3361, 0)) || getGateTile().equals(new RSTile(2636, 3361, 0)));
  276. }
  277.  
  278. private RSTile getGateTile(){
  279. RSObject[] gate = Objects.find(5, "Gate");
  280. return gate[0].getPosition();
  281. }
  282.  
  283. private void openGate(int distance, String name, String option){
  284. RSObject[] gate = Objects.find(distance, name);
  285. boolean open = org.tribot.api2007.Game.isUptext(gateOption);
  286. if (gate != null && gate.length > 0){
  287. if (gate[0].hover()){
  288. if (open){
  289. if (DynamicClicking.clickRSObject(gate[0], "Open")){
  290. waitFor(new Condition(){
  291. @Override
  292. public boolean active(){
  293. return isGateOpen();
  294. }
  295. }, 20000);
  296. }
  297. }
  298. }
  299. }
  300. }
  301.  
  302. // POTATO METHODS
  303.  
  304.  
  305. private RSTile getPotatoTile(int amount, String itemName){
  306. RSObject[] potato = Objects.findNearest(amount, itemName);
  307. return potato[0].getPosition();
  308. }
  309.  
  310. private boolean pickedPotato(int amount, String itemName){
  311. RSTile myPos = Player.getPosition();
  312. RSObject[] potato = Objects.findNearest(amount, itemName);
  313. if (potato != null && potato.length > 0){
  314. return myPos == getPotatoTile(7, potatoName);
  315. }
  316. return false;
  317. }
  318.  
  319. private boolean arePotatoesThere(int amount, String itemName){
  320. RSObject[] potato = Objects.findNearest(amount, itemName);
  321. return potato != null && potato.length > 0 && potato[0].isOnScreen();
  322. }
  323.  
  324. private void pickPotato(int amount, String itemName, String option){
  325. RSObject[] potato = Objects.findNearest(amount, itemName);
  326. if (potato != null && potato.length > 0 && potato[0].isOnScreen()){
  327. if (DynamicClicking.clickRSObject(potato[0], option)){
  328. waitFor(new Condition(){
  329. @Override
  330. public boolean active(){
  331. return pickedPotato(15, potatoName) || Inventory.isFull();
  332. }
  333. }, 1900);
  334. }
  335. }
  336. }
  337.  
  338. // DROPPING METHODS
  339.  
  340. private boolean haveSeed(){
  341. RSItem[] seed = Inventory.find("Potato seed");
  342. return seed != null && seed.length > 0;
  343. }
  344.  
  345. private void dropSeed(){
  346. RSItem[] seed = Inventory.find("Potato seed");
  347. if(seed.length > 0){
  348. Inventory.drop(seedName);
  349. sleep(500, 600);
  350. }
  351. }
  352.  
  353. // PAINT
  354.  
  355. private Image getImage(String url) {
  356. try {
  357. return ImageIO.read(new URL(url));
  358. } catch (IOException e) {
  359. return null;
  360. }
  361. }
  362.  
  363. private final Image img = getImage("http://i42.tinypic.com/2zgx8j8.jpg");
  364. private static final long startTime = System.currentTimeMillis();
  365. Font font = new Font("Calibri", Font.BOLD, 16);
  366. private State SCRIPT_STATE = getState();
  367.  
  368. @Override
  369. public void onPaint(Graphics g) {
  370.  
  371. Graphics2D gg = (Graphics2D) g;
  372. gg.drawImage(img, 9, 345, null);
  373.  
  374.  
  375. long timeRan = System.currentTimeMillis() - startTime;
  376. double multiplier = timeRan / 3600000D;
  377. int potatoes = potatoesCollected;
  378.  
  379. g.setFont(font);
  380. g.setColor(new Color(254, 229, 53));
  381. g.drawString("ok_Potato V" + version, 14, 360);
  382. g.drawString("Action: " + SCRIPT_STATE, 14, 425);
  383. g.drawString("Time running: " + Timing.msToString(timeRan), 14, 440);
  384. g.drawString("Potatoes p/h: " + (int) (potatoes / multiplier) + " p/h", 14, 455);
  385. g.drawString("Potatoes collected: " + potatoes, 14, 470);
  386. }
  387.  
  388. public enum State{
  389. WALKING_TO_BANK, WALKING_TO_POTATOES,
  390. WALKING_TO_FIELD, OPENING_GATE,
  391. OPENING_BANK, DEPOSITING_POTATOES,
  392. CLOSING_BANK, PICKING_POTATOES,
  393. WALKING_PAST_GATE, DROPPING_SEEDS,
  394. LOGING_OUT;
  395. }
  396.  
  397. private State getState(){
  398. RSTile myPos = Player.getPosition();
  399. if (bankArea.contains(myPos)){
  400. if(!Banking.isBankScreenOpen()){
  401. if(Inventory.isFull() && !Player.isMoving()){
  402. return State.OPENING_BANK;
  403. }
  404. if(!Inventory.isFull()){
  405. return State.WALKING_TO_FIELD;
  406. }
  407. }
  408. if(Banking.isBankScreenOpen()){
  409. if(Inventory.isFull()){
  410. return State.DEPOSITING_POTATOES;
  411. }
  412. if(!Inventory.isFull()){
  413. return State.CLOSING_BANK;
  414. }
  415. }
  416. }
  417. if (areaContainsPlayer(gateFrontArea)){
  418. if(!Inventory.isFull()){
  419. if(!isGateOpen()){
  420. return State.OPENING_GATE;
  421. }
  422. if(isGateOpen()){
  423. return State.WALKING_TO_POTATOES;
  424. }
  425. }
  426. if(Inventory.isFull()){
  427. return State.WALKING_TO_BANK;
  428. }
  429. }
  430. if (areaContainsPlayer(potatoArea)){
  431. if(haveSeed()){
  432. return State.DROPPING_SEEDS;
  433. }
  434. if(!Inventory.isFull()){
  435. if(arePotatoesThere(10, potatoName)){
  436. return State.PICKING_POTATOES;
  437. }
  438. if(!arePotatoesThere(10, potatoName)){
  439. return State.WALKING_TO_POTATOES;
  440. }
  441. }
  442. if(Inventory.isFull()){
  443. if(!areaContainsPlayer(gateBackArea)){
  444. if(!isGateOpen()){
  445. return State.WALKING_TO_POTATOES;
  446. }
  447. }
  448. if(areaContainsPlayer(gateBackArea)){
  449. if(!isGateOpen()){
  450. return State.OPENING_GATE;
  451. }
  452. if(isGateOpen()){
  453. return State.WALKING_PAST_GATE;
  454. }
  455. }
  456. }
  457. }
  458. if (noInAnyArea()){
  459. if(walkingArea.contains(myPos)){
  460. if (!Inventory.isFull()){
  461. return State.WALKING_TO_FIELD;
  462. }
  463. if (Inventory.isFull()){
  464. return State.WALKING_TO_BANK;
  465. }
  466. }
  467. }
  468. return State.LOGING_OUT;
  469. }
  470.  
  471. @SuppressWarnings("deprecation")
  472. @Override
  473. public void run() {
  474. println("Okokokok: Goodluck getting your Potatoes!");
  475. Walking.setControlClick(true);
  476.  
  477. while (true) {
  478. if (loggedOut()) {
  479. super.setLoginBotState(active);
  480. } else {
  481. while (!loggedOut()) {
  482. SCRIPT_STATE = getState();
  483. int mSpeed = General.random(130, 160);
  484. Mouse.setSpeed(mSpeed);
  485.  
  486. switch (SCRIPT_STATE) {
  487.  
  488. case CLOSING_BANK:
  489. Banking.close();
  490. sleep (50, 100);
  491. break;
  492.  
  493. case DEPOSITING_POTATOES:
  494. depositItem(potatoName);
  495. sleep (50, 100);
  496. break;
  497.  
  498. case LOGING_OUT:
  499. logout();
  500. stopScript();
  501. break;
  502.  
  503. case OPENING_BANK:
  504. int rotation = General.random(90, 200);
  505. antiBan(rotation);
  506.  
  507. openBank();
  508. sleep (50, 100);
  509. potatoesCollected += Inventory.getCount(1942);
  510. break;
  511.  
  512. case OPENING_GATE:
  513. int rotation1 = General.random(90, 200);
  514. antiBan(rotation1);
  515.  
  516. openGate(6, gateName, gateOption);
  517. break;
  518.  
  519. case PICKING_POTATOES:
  520. int rotation11 = General.random(90, 200);
  521. antiBan(rotation11);
  522.  
  523. pickPotato(15, potatoName, potatoOption);
  524. sleep (50, 100);
  525. break;
  526.  
  527. case WALKING_PAST_GATE:
  528. walkTile(gateBackArea, gateFrontTile);
  529. sleep (50, 100);
  530. break;
  531.  
  532. case WALKING_TO_BANK:
  533. walkDestination(bankPath, bankTile, bankAreas, 6);
  534. break;
  535.  
  536. case WALKING_TO_FIELD:
  537.  
  538. walkDestination(potatoPath, gateFrontTile, gateFrontArea, 6);
  539. break;
  540.  
  541. case WALKING_TO_POTATOES:
  542.  
  543. walkTile(gateBackArea, potatoTile);
  544. break;
  545.  
  546. case DROPPING_SEEDS:
  547. dropSeed();
  548. break;
  549. }
  550. }
  551. }
  552. }
  553.  
  554. }
  555.  
  556. @Override
  557. public void onRandom(RANDOM_SOLVERS arg0) {
  558. paused = true;
  559.  
  560. }
  561.  
  562. @Override
  563. public boolean randomFailed(RANDOM_SOLVERS arg0) {
  564. paused = false;
  565. return false;
  566. }
  567.  
  568. @Override
  569. public void randomSolved(RANDOM_SOLVERS arg0) {
  570. paused = false;
  571.  
  572. }
  573.  
  574. @Override
  575. public void onPause() {
  576. paused = true;
  577.  
  578. while(paused){
  579. sleep(100, 200);
  580. }
  581.  
  582. }
  583.  
  584. @Override
  585. public void onResume() {
  586. paused = false;
  587.  
  588. }
  589. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement