Advertisement
Guest User

ok_Potato

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