Advertisement
Guest User

Untitled

a guest
Aug 19th, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.73 KB | None | 0 0
  1. package scripts.moneymaking.flaxpicker;
  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.Point;
  9. import java.io.BufferedReader;
  10. import java.io.InputStreamReader;
  11. import java.net.URL;
  12. import java.net.URLConnection;
  13. import java.text.DecimalFormat;
  14. import java.util.ArrayList;
  15. import java.util.Iterator;
  16. import java.util.LinkedList;
  17. import java.util.List;
  18. import java.util.regex.Matcher;
  19. import java.util.regex.Pattern;
  20.  
  21. import org.tribot.api.General;
  22. import org.tribot.api.Timing;
  23. import org.tribot.api.input.Mouse;
  24. import org.tribot.api.util.ABCUtil;
  25. import org.tribot.api2007.Banking;
  26. import org.tribot.api2007.Camera;
  27. import org.tribot.api2007.Game;
  28. import org.tribot.api2007.Inventory;
  29. import org.tribot.api2007.Options;
  30. import org.tribot.api2007.Player;
  31. import org.tribot.api2007.Walking;
  32. import org.tribot.api2007.WebWalking;
  33. import org.tribot.api2007.types.RSArea;
  34. import org.tribot.api2007.types.RSObject;
  35. import org.tribot.api2007.types.RSTile;
  36. import org.tribot.script.EnumScript;
  37. import org.tribot.script.ScriptManifest;
  38. import org.tribot.script.interfaces.MouseActions;
  39. import org.tribot.script.interfaces.MousePainting;
  40. import org.tribot.script.interfaces.MouseSplinePainting;
  41. import org.tribot.script.interfaces.Painting;
  42.  
  43. import scripts.methods.Methods;
  44.  
  45. @ScriptManifest(authors = { "Ian" }, category = "Money Making", name = "iFlaxPicker")
  46.  
  47. public class FlaxPicker extends EnumScript<FlaxState> implements Painting,
  48. MouseSplinePainting, MousePainting, MouseActions {
  49.  
  50. private FlaxState state;
  51.  
  52. private FlaxLocation location;
  53. private RSArea bankArea = null;
  54. private RSArea flaxArea = null;
  55. private RSTile flaxTile = null;
  56. private RSTile bankTile = null;
  57.  
  58. private int flaxCount = 0;
  59. private int tripCount = 0;
  60.  
  61. private int flaxPrice = -1;
  62.  
  63. private long timeout = 0,
  64. startTime = 0,
  65. lastTripTime = 0,
  66. currentTripTime = 0,
  67. averageTripTime = 0,
  68. totalTripTime = 0,
  69. lastPlayerRan = 0;
  70.  
  71. private DecimalFormat decimalFormat = new DecimalFormat("#.##");
  72.  
  73. private final String PAINT_PICTURE_URL = "http://i43.tinypic.com/2euha2g.png";
  74.  
  75. private final Image PAINT_IMAGE = Methods.getImage(PAINT_PICTURE_URL);
  76.  
  77. @Override
  78. public void onPaint(Graphics g) {
  79. ((Graphics2D)g).drawImage(PAINT_IMAGE, 7, 345, null);
  80.  
  81. g.setFont(new Font("Verdana", Font.BOLD, 11));
  82.  
  83. g.setColor(Color.WHITE);
  84.  
  85. g.drawString(getState().toString().replaceAll("_", " "), 11, 470);
  86.  
  87. int flaxPerHr = ((int) (getFlaxCount() / (getRunningTime() / 3600000D)));
  88.  
  89. double gpMade = ((double) (getFlaxCount() * getFlaxPrice()));
  90.  
  91. double gpPerHr = ((double) (gpMade / (getRunningTime() / 3600000D)));
  92.  
  93. g.drawString(getFlaxCount() + " (" +flaxPerHr+")", 125, 370);
  94.  
  95. g.drawString(setInMoneyFormat(gpMade) + " (" +setInMoneyFormat(gpPerHr)+")", 110, 390);
  96.  
  97. g.drawString(Timing.msToString(getRunningTime()), 127, 410);
  98.  
  99. int tripsPerHr = ((int) (getTripCount() / (getRunningTime() / 3600000D)));
  100.  
  101. g.drawString(getTripCount() + " (" + tripsPerHr + ")", 317, 370);
  102.  
  103. g.drawString(Timing.msToString(getLastTripTime()), 385, 390);
  104.  
  105. g.drawString(Timing.msToString(getAverageTripTime()), 415, 410);
  106. }
  107.  
  108. public void setArea() {
  109. if(FlaxConstants.GNOME_BANK_AREA.contains(Player.getPosition())
  110. || FlaxConstants.GNOME_FLAX_AREA.contains(Player.getPosition())) {
  111. setLocation(FlaxLocation.GNOME_STRONGHOLD);
  112. setBankArea(FlaxConstants.GNOME_BANK_AREA);
  113. setFlaxArea(FlaxConstants.GNOME_FLAX_AREA);
  114. setFlaxTile(FlaxConstants.GNOME_FLAX_TILE);
  115. setBankTile(FlaxConstants.GNOME_BANK_TILE);
  116. } else if(FlaxConstants.SEERS_BANK_AREA.contains(Player.getPosition())
  117. || FlaxConstants.SEERS_FLAX_AREA.contains(Player.getPosition())) {
  118. setLocation(FlaxLocation.SEERS_VILLAGE);
  119. setBankArea(FlaxConstants.SEERS_BANK_AREA);
  120. setFlaxArea(FlaxConstants.SEERS_FLAX_AREA);
  121. setFlaxTile(FlaxConstants.SEERS_FLAX_TILE);
  122. setBankTile(FlaxConstants.SEERS_BANK_TILE);
  123. }
  124. }
  125.  
  126. private String readUrl(String urlString) throws Exception {
  127. BufferedReader reader = null;
  128. URLConnection uc = null;
  129. try {
  130. URL url = new URL(urlString);
  131. uc = url.openConnection();
  132. uc.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
  133. uc.connect();
  134. reader = new BufferedReader(new InputStreamReader(uc.getInputStream()));
  135. StringBuffer buffer = new StringBuffer();
  136. int read;
  137. char[] chars = new char[1024];
  138. while ((read = reader.read(chars)) != -1)
  139. buffer.append(chars, 0, read);
  140. return buffer.toString();
  141. } finally {
  142. if (reader != null)
  143. reader.close();
  144. }
  145. }
  146.  
  147. public int getZybezPrice(String name) {
  148. String s = "";
  149. try {
  150. s = readUrl("http://forums.zybez.net/runescape-2007-prices/api/"+name.replaceAll("\\s","+"));
  151. } catch (Exception e) {
  152. e.printStackTrace();
  153. }
  154. Pattern pattern = Pattern.compile("(?<=\"average\":\")[0-9]+");
  155. Matcher matcher = pattern.matcher(s);
  156.  
  157. while (matcher.find()) {
  158. println(Integer.parseInt(matcher.group()));
  159. return(Integer.parseInt(matcher.group()));
  160. }
  161. return 1;
  162. }
  163.  
  164. private String setInMoneyFormat(double amount) {
  165. final int ONE_K = 1000;
  166. final int ONE_M = 1000000;
  167. if(amount >= ONE_M) {
  168. return decimalFormat.format(((double) amount / ONE_M)) + "M";
  169. }
  170. if(amount >= ONE_K) {
  171. return decimalFormat.format(((double) amount / ONE_K)) + "K";
  172. }
  173. return "" + decimalFormat.format(amount);
  174. }
  175.  
  176. @Override
  177. public FlaxState getInitialState() {
  178. setFlaxPrice(getZybezPrice("flax"));
  179. setArea();
  180. setStartTime(System.currentTimeMillis());
  181. Mouse.setSpeed(125 + General.random(0, 25));
  182. Walking.setWalkingTimeout(2000);
  183. if(getBankArea().contains(Player.getPosition())) {
  184. return FlaxState.BANKING;
  185. } else if(getFlaxArea().contains(Player.getPosition())) {
  186. if(!Inventory.isFull())
  187. return FlaxState.PICKING_FLAX;
  188. else
  189. return FlaxState.WALKING_TO_BANK;
  190. } else {
  191. if(!Inventory.isFull())
  192. return FlaxState.WALKING_TO_FLAX;
  193. else
  194. return FlaxState.WALKING_TO_BANK;
  195. }
  196. }
  197.  
  198. @Override
  199. public FlaxState handleState(FlaxState state) {
  200. checkPlayerRun();
  201.  
  202. switch(state) {
  203. case BANKING:
  204. if(getBankArea().contains(Player.getPosition())) {
  205. if(isFlaxBanked()) {
  206. return FlaxState.WALKING_TO_FLAX;
  207. }
  208. return FlaxState.BANKING;
  209. }
  210. return FlaxState.WALKING_TO_BANK;
  211. case WALKING_TO_FLAX:
  212. if(walkedToFlax()) {
  213. return FlaxState.PICKING_FLAX;
  214. }
  215. return FlaxState.BANKING;
  216. case PICKING_FLAX:
  217. if(getFlaxArea().contains(Player.getPosition())) {
  218. if(pickedFlax()) {
  219. return FlaxState.WALKING_TO_BANK;
  220. }
  221. return FlaxState.PICKING_FLAX;
  222. }
  223. return FlaxState.WALKING_TO_FLAX;
  224. case WALKING_TO_BANK:
  225. if(walkedToBank()) {
  226. return FlaxState.BANKING;
  227. }
  228. return FlaxState.PICKING_FLAX;
  229. }
  230. return null;
  231. }
  232.  
  233. private void bankFlax() {
  234. setState(FlaxState.BANKING);
  235. getTripInformation();
  236. if(!isInventoryEmpty()) {
  237. if(isBankScreenOpen()) {
  238. Banking.depositAll();
  239. }
  240. }
  241. }
  242.  
  243. private boolean isFlaxBanked() {
  244. Mouse.setSpeed(180);
  245. bankFlax();
  246. if(isInventoryEmpty()) {
  247. setState(FlaxState.WALKING_TO_FLAX);
  248. return true;
  249. }
  250. return isFlaxBanked();
  251. }
  252.  
  253.  
  254. private boolean walkedToFlax() {
  255. Mouse.setSpeed(150);
  256.  
  257. if(getCurrentTripTime() == 0)
  258. setCurrentTripTime(System.currentTimeMillis());
  259.  
  260. setTimeout(System.currentTimeMillis());
  261. while(!getFlaxArea().contains(Player.getPosition()) && !isTimedOut(30000, 60000)) {
  262.  
  263. if(Player.getPosition().getPlane() == 1) {
  264. RSObject staircase = Methods.findObjectByModelPoints(
  265. new int[] {
  266. FlaxConstants.STAIRCASE_DOWN_MODEL_POINT_COUNT
  267. });
  268. if(staircase != null) {
  269. WebWalking.walkTo(staircase);
  270. staircase.click("Climb-down");
  271. isDown(1000);
  272. }
  273. } else {
  274. Methods.performAntiBan();
  275. WebWalking.walkTo(getFlaxTile());
  276. walkedToFlax(3000);
  277. }
  278.  
  279. }
  280. if(getFlaxArea().contains(Player.getPosition())) {
  281. setState(FlaxState.PICKING_FLAX);
  282. return true;
  283. }
  284.  
  285. return walkedToFlax();
  286. }
  287.  
  288. private ABCUtil abc = new ABCUtil();
  289.  
  290. private boolean pickedFlax() {
  291. Mouse.setSpeed(180);
  292. final int FLAX = 1779;
  293. setState(FlaxState.PICKING_FLAX);
  294. Camera.setCameraAngle(General.random(80, 100));
  295. setTimeout(System.currentTimeMillis());
  296. while(!Inventory.isFull() && !isTimedOut(90000, 120000)) {
  297. RSObject flax = Methods.findObjectByModelPoints(new int[]{FlaxConstants.FLAX_MODEL_POINT_COUNT});
  298. if(flax != null) {
  299. if(!Player.isMoving()) {
  300. Methods.waitNewOrSwitchDelay(this.last_chopping_time, false);
  301. flax.click("Pick");
  302. this.last_chopping_time = System.currentTimeMillis();
  303. }
  304.  
  305. }
  306. }
  307.  
  308. if(Inventory.isFull()) {
  309. setState(FlaxState.WALKING_TO_BANK);
  310. setFlaxCount(getFlaxCount() + Inventory.getCount(FLAX));
  311. return true;
  312. }
  313. return pickedFlax();
  314. }
  315.  
  316.  
  317. private boolean walkedToBank() {
  318. Mouse.setSpeed(150);
  319. setState(FlaxState.WALKING_TO_BANK);
  320. setTimeout(System.currentTimeMillis());
  321. while(!getBankArea().contains(Player.getPosition()) && !isTimedOut(30000, 60000)) {
  322. Methods.performAntiBan();
  323. WebWalking.walkTo(getBankTile());
  324. walkedToBank(3000);
  325. if(getLocation().equals(FlaxLocation.GNOME_STRONGHOLD)) {
  326. RSObject staircase = Methods.findObjectByModelPoints(
  327. new int[] {
  328. FlaxConstants.STAIRCASE_UP_MODEL_POINT_COUNT
  329. });
  330. if(staircase != null) {
  331. staircase.click("Climb-up");
  332. isUp(1000);
  333. }
  334. }
  335. }
  336. if(getBankArea().contains(Player.getPosition())) {
  337. setState(FlaxState.BANKING);
  338. return true;
  339. }
  340. return walkedToBank();
  341. }
  342.  
  343. private void checkPlayerRun() {
  344. long ran = lastPlayerRan;
  345. long interval = 60000;
  346. if(!Game.isRunOn() && System.currentTimeMillis() - ran > interval) {
  347. if(Game.getRunEnergy() >= abc.INT_TRACKER.NEXT_RUN_AT.next()) {
  348. Options.setRunOn(true);
  349. Inventory.open();
  350. abc.INT_TRACKER.NEXT_RUN_AT.reset();
  351. }
  352.  
  353. }
  354.  
  355. if(Game.isRunOn()) {
  356. lastPlayerRan = System.currentTimeMillis();
  357. }
  358. }
  359.  
  360.  
  361.  
  362. private long last_chopping_time = 0L;
  363.  
  364.  
  365. private void getTripInformation() {
  366. if(getCurrentTripTime() == 0 && getTripCount() > 0) {
  367. return;
  368. }
  369. if(getTripCount() != 0) {
  370. setLastTripTime(System.currentTimeMillis() - getCurrentTripTime());
  371. setTotalTripTime(getTotalTripTime() + getLastTripTime());
  372. setAverageTripTime(getTotalTripTime() / getTripCount());
  373. setCurrentTripTime(0);
  374. setTripCount(getTripCount() + 1);
  375. } else {
  376. setTripCount(1);
  377. }
  378. }
  379.  
  380. private boolean isTimedOut(int min, int max) {
  381. if(System.currentTimeMillis() - getTimeout() < General.random(min, max)) {
  382. return false;
  383. }
  384. return true;
  385. }
  386.  
  387. private boolean isBankScreenOpen() {
  388. setTimeout(System.currentTimeMillis());
  389. while(!Banking.isBankScreenOpen() && !isTimedOut(12000, 15000)) {
  390. Banking.openBank();
  391. openedBank(2000);
  392. }
  393. return Banking.isBankScreenOpen();
  394. }
  395.  
  396. private boolean isInventoryEmpty() {
  397. return Inventory.getAll().length <= 0;
  398. }
  399.  
  400. private boolean isDown(int i) {
  401. long t = System.currentTimeMillis();
  402. while (Timing.timeFromMark(t) < i) {
  403. if (Player.getPosition().getPlane() == 0) {
  404. return true;
  405. }
  406. sleep(50, 150);
  407. }
  408. return false;
  409. }
  410.  
  411. private boolean isUp(int i) {
  412. long t = System.currentTimeMillis();
  413. while (Timing.timeFromMark(t) < i) {
  414. if (Player.getPosition().getPlane() == 1) {
  415. return true;
  416. }
  417. sleep(50, 150);
  418. }
  419. return false;
  420. }
  421.  
  422. private boolean openedBank(int i) {
  423. long t = System.currentTimeMillis();
  424. while (Timing.timeFromMark(t) < i) {
  425. if (Banking.isBankScreenOpen()) {
  426. return true;
  427. }
  428. sleep(50, 150);
  429. }
  430. return false;
  431. }
  432.  
  433. private boolean walkedToBank(int i) {
  434. long t = System.currentTimeMillis();
  435. while (Timing.timeFromMark(t) < i) {
  436. if (getBankArea().contains(Player.getPosition())) {
  437. return true;
  438. }
  439. if (!Player.isMoving()) {
  440. return false;
  441. }
  442. sleep(50, 150);
  443. }
  444. return false;
  445. }
  446.  
  447. private boolean walkedToFlax(int i) {
  448. long t = System.currentTimeMillis();
  449. while (Timing.timeFromMark(t) < i) {
  450. if (getFlaxArea().contains(Player.getPosition())) {
  451. return true;
  452. }
  453. if (!Player.isMoving()) {
  454. return false;
  455. }
  456. sleep(50, 150);
  457. }
  458. return false;
  459. }
  460.  
  461. public void setState(FlaxState state) {
  462. this.state = state;
  463. }
  464.  
  465. public FlaxState getState() {
  466. return state;
  467. }
  468.  
  469. public void setFlaxCount(int flaxCount) {
  470. this.flaxCount = flaxCount;
  471. }
  472.  
  473. public int getFlaxCount() {
  474. return flaxCount;
  475. }
  476.  
  477. public void setStartTime(long startTime) {
  478. this.startTime = startTime;
  479. }
  480.  
  481. public long getStartTime() {
  482. return startTime;
  483. }
  484.  
  485. public long getTimeout() {
  486. return timeout;
  487. }
  488.  
  489. public void setTimeout(long timeout) {
  490. this.timeout = timeout;
  491. }
  492.  
  493. public long getLastTripTime() {
  494. return lastTripTime;
  495. }
  496.  
  497. public void setLastTripTime(long lastTripTime) {
  498. this.lastTripTime = lastTripTime;
  499. }
  500.  
  501. public long getCurrentTripTime() {
  502. return currentTripTime;
  503. }
  504.  
  505. public void setCurrentTripTime(long currentTripTime) {
  506. this.currentTripTime = currentTripTime;
  507. }
  508.  
  509. public long getAverageTripTime() {
  510. return averageTripTime;
  511. }
  512.  
  513. public void setAverageTripTime(long averageTripTime) {
  514. this.averageTripTime = averageTripTime;
  515. }
  516.  
  517. public long getTotalTripTime() {
  518. return totalTripTime;
  519. }
  520.  
  521. public void setTotalTripTime(long totalTripTime) {
  522. this.totalTripTime = totalTripTime;
  523. }
  524.  
  525. public void setTripCount(int tripCount) {
  526. this.tripCount = tripCount;
  527. }
  528.  
  529. public int getTripCount() {
  530. return tripCount;
  531. }
  532.  
  533. public void setFlaxPrice(int flaxPrice) {
  534. this.flaxPrice = flaxPrice;
  535. }
  536.  
  537. public int getFlaxPrice() {
  538. return flaxPrice;
  539. }
  540.  
  541. private class Cross {
  542.  
  543. private final long time;
  544. private final Point location;
  545. private final double rot;
  546.  
  547. public Cross(long lifetime, long st, Point loc, double rot) {
  548. this.time = System.currentTimeMillis() + lifetime;
  549. location = loc;
  550. this.rot = rot;
  551. }
  552.  
  553. public long getAge() {
  554. return time - System.currentTimeMillis();
  555. }
  556.  
  557. public int getAlpha() {
  558. return Math.min(255,
  559. Math.max(0, (int) (256.0D * (getAge() / 1500.0D))));
  560. }
  561.  
  562. public boolean handle() {
  563. return System.currentTimeMillis() <= time;
  564. }
  565.  
  566. public double getRot() {
  567. return rot;
  568. }
  569.  
  570. public Point getLocation() {
  571. return location;
  572. }
  573.  
  574. @Override
  575. public boolean equals(Object o) {
  576. if (o instanceof Cross) {
  577. Cross oo = (Cross) o;
  578. return oo.location.equals(this.location);
  579. }
  580. return false;
  581. }
  582.  
  583. }
  584.  
  585. public double getRot() {
  586. return System.currentTimeMillis() % 3600 / 5.0D;
  587. }
  588.  
  589. private final List<Cross> clicks = new LinkedList<Cross>();
  590. private final Object lock = new Object();
  591.  
  592. private boolean paintClick;
  593.  
  594. public boolean isPaintClick() {
  595. return paintClick;
  596. }
  597.  
  598. public void setPaintClick(boolean paintClick) {
  599. this.paintClick = paintClick;
  600. }
  601.  
  602. @Override
  603. public void mouseDragged(Point arg0, int arg1, boolean arg2) {
  604. // TODO Auto-generated method stub
  605.  
  606. }
  607.  
  608. @Override
  609. public void mouseMoved(Point arg0, boolean arg1) {
  610. // TODO Auto-generated method stub
  611.  
  612. }
  613.  
  614. @Override
  615. public void mouseReleased(Point arg0, int arg1, boolean arg2) {
  616. // TODO Auto-generated method stub
  617.  
  618. }
  619.  
  620. @Override
  621. public void paintMouse(Graphics g, Point arg1, Point arg2) {
  622. final Point location = new Point(Mouse.getPos().x, Mouse.getPos().y);
  623. g.setColor(Color.GREEN);
  624. g.drawLine(location.x, location.y - 5, location.x, location.y + 5);
  625. g.drawLine(location.x - 5, location.y, location.x + 5, location.y);
  626. if (isPaintClick()) {
  627. setPaintClick(false);
  628. Cross newCross = new Cross(1500, General.random(40, 300), location,
  629. getRot());
  630. if (!clicks.contains(newCross)) {
  631. clicks.add(newCross);
  632. }
  633. }
  634. synchronized (lock) {
  635. Iterator<Cross> clickIterator = clicks.listIterator();
  636. while (clickIterator.hasNext()) {
  637. Cross toDraw = clickIterator.next();
  638. if (toDraw.handle()) {
  639. drawPoint(toDraw.getLocation(), toDraw.getRot(), g,
  640. toDraw.getAlpha());
  641. } else {
  642. clicks.remove(toDraw);
  643. }
  644. }
  645. }
  646.  
  647. }
  648.  
  649. private void drawPoint(Point location, double rot, Graphics g, int al) {
  650. Graphics2D g1 = (Graphics2D) g.create();
  651. g1.setColor(new Color(255, 0, 0, 155));
  652. g1.rotate(rot, location.x, location.y);
  653. g1.drawLine(location.x, location.y - 5, location.x, location.y + 5);
  654. g1.drawLine(location.x - 5, location.y, location.x + 5, location.y);
  655. }
  656. @Override
  657. public void mouseClicked(Point p, int button, boolean isBot) {
  658. setPaintClick(true);
  659. }
  660.  
  661. @Override
  662. public void paintMouseSpline(Graphics arg0, ArrayList<Point> arg1) {
  663. // TODO Auto-generated method stub
  664.  
  665. }
  666.  
  667. public void setLocation(FlaxLocation location) {
  668. this.location = location;
  669. }
  670.  
  671. public FlaxLocation getLocation() {
  672. return location;
  673. }
  674.  
  675. public void setBankArea(RSArea bankArea) {
  676. this.bankArea = bankArea;
  677. }
  678.  
  679. public RSArea getBankArea() {
  680. return bankArea;
  681. }
  682.  
  683. public void setFlaxArea(RSArea flaxArea) {
  684. this.flaxArea = flaxArea;
  685. }
  686.  
  687. public RSArea getFlaxArea() {
  688. return flaxArea;
  689. }
  690.  
  691. public void setFlaxTile(RSTile flaxTile) {
  692. this.flaxTile = flaxTile;
  693. }
  694.  
  695. public RSTile getFlaxTile() {
  696. return flaxTile;
  697. }
  698.  
  699. public void setBankTile(RSTile bankTile) {
  700. this.bankTile = bankTile;
  701. }
  702.  
  703. public RSTile getBankTile() {
  704. return bankTile;
  705. }
  706. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement