Advertisement
iant06

Untitled

Sep 17th, 2015
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.83 KB | None | 0 0
  1. package scripts.moneymaking.iplankfarmer;
  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.text.DecimalFormat;
  10. import java.util.ArrayList;
  11. import java.util.Iterator;
  12. import java.util.LinkedList;
  13. import java.util.List;
  14.  
  15. import org.tribot.api.General;
  16. import org.tribot.api.Timing;
  17. import org.tribot.api.input.Mouse;
  18. import org.tribot.api2007.Game;
  19. import org.tribot.api2007.Inventory;
  20. import org.tribot.api2007.Login;
  21. import org.tribot.api2007.Login.STATE;
  22. import org.tribot.api2007.Objects;
  23. import org.tribot.api2007.Screen;
  24. import org.tribot.api2007.Skills;
  25. import org.tribot.api2007.Walking;
  26. import org.tribot.api2007.WebWalking;
  27. import org.tribot.api2007.types.RSObject;
  28. import org.tribot.script.EnumScript;
  29. import org.tribot.script.ScriptManifest;
  30. import org.tribot.script.interfaces.MouseActions;
  31. import org.tribot.script.interfaces.MousePainting;
  32. import org.tribot.script.interfaces.MouseSplinePainting;
  33. import org.tribot.script.interfaces.Painting;
  34.  
  35. import scripts.methods.Methods;
  36. import scripts.moneymaking.iplankfarmer.banking.Bank;
  37. import scripts.moneymaking.iplankfarmer.banking.Potions;
  38. import scripts.moneymaking.iplankfarmer.banking.VarrockTab;
  39. import scripts.moneymaking.iplankfarmer.equipment.Axe;
  40. import scripts.moneymaking.iplankfarmer.equipment.DuelRing;
  41. import scripts.moneymaking.iplankfarmer.player.Data;
  42. import scripts.moneymaking.iplankfarmer.sawmill.Sawmill;
  43. import scripts.moneymaking.iplankfarmer.types.EnergyPotion;
  44. import scripts.moneymaking.iplankfarmer.types.LoginState;
  45. import scripts.moneymaking.iplankfarmer.types.Plank;
  46. import scripts.moneymaking.iplankfarmer.types.ScriptTask;
  47. import scripts.moneymaking.iplankfarmer.types.State;
  48. import scripts.moneymaking.iplankfarmer.utils.AntiBan;
  49. import scripts.moneymaking.iplankfarmer.utils.Constants;
  50. import scripts.moneymaking.iplankfarmer.utils.Locations;
  51. import scripts.moneymaking.iplankfarmer.woodcutting.Woodcutting;
  52.  
  53. @ScriptManifest(authors = { "iant06" }, category = "Money Making", name = "iPlankFarmer")
  54.  
  55. public class Script extends EnumScript<State> implements Painting,
  56. MouseSplinePainting, MousePainting, MouseActions {
  57.  
  58. private AntiBan antiBan = null;
  59. private Axe axe = null;
  60. private Bank banking = null;
  61. private Data data = null;
  62. private DuelRing duelRing = null;
  63. private Potions potions = null;
  64. private Sawmill sawmill = null;
  65. private Woodcutting woodcutting = null;
  66. private VarrockTab varrockTab = null;
  67. private GUI gui = null;
  68. private EnergyPotion energyPotion = null;
  69. private DecimalFormat decimalFormat = new DecimalFormat("#.##");
  70.  
  71. private ScriptTask task;
  72. private Plank plank;
  73. private State state;
  74.  
  75. private double plankPrice = -1;
  76. private double logPrice = -1;
  77. private double energyPotionPrice = -1;
  78. private double crushedNestPrice = -1;
  79. private double duelRingPrice = -1;
  80. private double hoursToRun = -1;
  81.  
  82. private boolean endScript = false;
  83.  
  84. public final String PAINT_PICTURE_URL = "http://i42.tinypic.com/2i9ines.png";
  85.  
  86. public final Image PAINT_IMG = Methods.getImage(PAINT_PICTURE_URL);
  87.  
  88.  
  89. @Override
  90. public void onPaint(Graphics g) {
  91. ((Graphics2D)g).drawImage(PAINT_IMG, 1, 265, null);
  92. g.setColor(Color.WHITE);
  93. g.setFont(new Font("default", Font.BOLD, 12));
  94. g.drawString(Methods.correctCapitalization(getState().toString()), 190, 358);
  95. g.drawString(Methods.correctCapitalization(getPlank().toString()), 115, 377);
  96. int planksPerHr = (int) (getData().getPlanksMade() / ((getRunningTime()) / 3600000D));
  97. g.drawString(getData().getPlanksMade() + " (" + planksPerHr + ")", 160, 397);
  98. double moneyMade = getData().getMoneyMade();
  99. double moneySpent = getData().getMoneySpent();
  100. double gpMade = (moneyMade - moneySpent);
  101. double gpPerHour = (double) (gpMade / ((getRunningTime()) / 3600000D));
  102. g.drawString(setInMoneyFormat(gpMade) + " (" + setInMoneyFormat(gpPerHour) + ")", 136, 417);
  103. g.drawString("Running for: " + Timing.msToString(getRunningTime()), 77, 455);
  104.  
  105. int tripsPerHr = (int) (getData().getTripCount() / ((getRunningTime()) / 3600000D));
  106. g.drawString(getData().getTripCount() + " (" + tripsPerHr + ")", 157, 437);
  107. g.drawString(Timing.msToString(getData().getLastTripTime()), 436, 377);
  108. g.drawString(Timing.msToString(getData().getAverageTripTime()), 436, 397);
  109.  
  110. g.drawString("" + getData().getEntsDetected(), 436, 417);
  111. g.setFont(new Font("default", Font.BOLD, 14));
  112. g.drawString("" + getData().getNestsFound(), 315, 446);
  113. g.drawString(Game.getRunEnergy() + "%", 415, 446);
  114. }
  115.  
  116. @Override
  117. public State getInitialState() {
  118. setGui(new GUI(this));
  119. while(getGui().isVisible()) {
  120. sleep(50, 100);
  121. }
  122. if(data == null) {
  123. setData(new Data(this));
  124. }
  125. if(banking == null) {
  126. setBanking(new Bank(this));
  127. }
  128. if(duelRing == null) {
  129. setDuelRing(new DuelRing(this));
  130. }
  131. if(potions == null) {
  132. setPotions(new Potions(this));
  133. }
  134. if(axe == null) {
  135. setAxe(new Axe(this));
  136. }
  137. if(sawmill == null) {
  138. setSawmill(new Sawmill(this));
  139. }
  140. if(woodcutting == null) {
  141. setWoodcutting(new Woodcutting(this));
  142. }
  143. if(varrockTab == null) {
  144. setVarrockTab(new VarrockTab(this));
  145. }
  146. if(antiBan == null) {
  147. setAntiBan(new AntiBan(this));
  148. }
  149. //Walking.setControlClick(true);
  150. //WebWalking.setUseRun(true);
  151. println("Script Task: " + getTask().toString() + " Plank Type: " + getPlank().toString());
  152. println("Log Price: " + getLogPrice() + " Plank Price: " + getPlankPrice());
  153. setEnergyPotionPrice(grabEnergyPotionPrice());
  154. setCrushedNestPrice(grabCrushedNestPrice());
  155. setDuelRingPrice(grabDuelRingPrice());
  156. getData().getInitialData();
  157. Mouse.setSpeed(125 + General.random(10, 25));
  158. if(getAxe().isAxeBroken()) {
  159. setState(State.WALKING_TO_BOB);
  160. return State.WALKING_TO_BOB;
  161. }
  162. if(getWoodcutting().isInsideForest()) {
  163. setState(State.CHOPPING_DOWN_TREE);
  164. return State.CHOPPING_DOWN_TREE;
  165. }
  166. setState(State.WALKING_TO_BANK);
  167. return State.WALKING_TO_BANK;
  168. }
  169.  
  170.  
  171.  
  172. @Override
  173. public State handleState(State state) {
  174. if(isEndScript()) {
  175. getData().endScriptPrint();
  176. Thread.currentThread().interrupt();
  177. return null;
  178. }
  179. if(!isOnBreak() && !isPaused()) {
  180.  
  181. if(Game.getCurrentWorld() >= 380) {
  182. Login.logout();
  183. openWorldScreen();
  184. if(isWorldScreenOpen()) {
  185. selectWorld(randomWorlds[General.random(0, randomWorlds.length - 1)]);
  186. }
  187. }
  188.  
  189. long t = 0;
  190. switch (LoginState()) {
  191.  
  192. case WELCOME_SCREEN:
  193. case LOGIN_SCREEN:
  194. Login.login();
  195. break;
  196.  
  197. case HOW_TO_PLAY:
  198. Mouse.moveBox(13, 470, 97, 491);
  199. General.sleep(100, 300);
  200. Mouse.click(1);
  201. t = System.currentTimeMillis();
  202. while (Timing.timeFromMark(t) < General.random(7000, 10000) && LoginState().equals(LoginState.HOW_TO_PLAY)) {
  203. General.sleep(300);
  204. }
  205. General.sleep(100);
  206. break;
  207.  
  208. case LOBBY:
  209. Mouse.moveBox(280, 296, 495, 374);
  210. General.sleep(100, 300);
  211. Mouse.click(1);
  212. t = System.currentTimeMillis();
  213. while (Timing.timeFromMark(t) < General.random(7000, 10000) && LoginState().equals(LoginState.LOBBY)) {
  214. General.sleep(300);
  215. }
  216. General.sleep(100);
  217. break;
  218. }
  219. state = getState() != null ? getState() : getInitialState();
  220. getData().setCurrentXP(Skills.getXP(Skills.SKILLS.MINING));
  221. getData().setCurrentLevel(Skills.getActualLevel(Skills.SKILLS.MINING));
  222. getData().checkPlayerRun();
  223. if(Game.getPlane() >= 1) {
  224. RSObject[] stairs = Objects.findNearest(10, "Staircase");
  225. if(stairs != null && stairs.length > 0) {
  226. if(stairs[0].click("Climb-down")) {
  227. println("Successfully climbed down stairs");
  228. }
  229. } else {
  230. println("Not correct height level, can't find stairs.");
  231. }
  232. }
  233. switch(state) {
  234. case BANKING:
  235. if(Locations.isInsideBank() || Locations.isInsideCastleWars()) {
  236. getBanking().performBankTask();
  237. if(getBanking().isFinished()) {
  238. switch(getTask()) {
  239. case CHOP_LOGS:
  240. setState(State.WALKING_TO_TREE);
  241. return State.WALKING_TO_TREE;
  242. case CHOP_AND_PLANK:
  243. if(getPlank().equals(Plank.TEAK)) {
  244. if(Locations.isInsideBank()) {
  245. setState(State.WALKING_TO_SAWMILL);
  246. return State.WALKING_TO_SAWMILL;
  247. }
  248. }
  249. setState(State.WALKING_TO_TREE);
  250. return State.WALKING_TO_TREE;
  251. case MAKE_PLANKS:
  252. setState(State.WALKING_TO_SAWMILL);
  253. return State.WALKING_TO_SAWMILL;
  254. }
  255. }
  256. }
  257. setState(State.BANKING);
  258. return State.BANKING;
  259.  
  260. case WALKING_TO_TREE:
  261. getWoodcutting().walkToForest();
  262. return State.WALKING_TO_TREE;
  263.  
  264. case CHOPPING_DOWN_TREE:
  265. if(getWoodcutting().canChop()) {
  266. getWoodcutting().chopTree(getWoodcutting().getClosestTree());
  267. return State.CHOPPING_DOWN_TREE;
  268. }
  269. switch(getTask()) {
  270. case CHOP_LOGS:
  271. case CHOP_AND_PLANK:
  272. if(getPlank().equals(Plank.TEAK)) {
  273. if(getDuelRing().isWearing()) {
  274. getDuelRing().rub();
  275. } else {
  276. getVarrockTab().teleport();
  277. }
  278. setState(State.WALKING_TO_BANK);
  279. return State.WALKING_TO_BANK;
  280. }
  281. setState(State.WALKING_TO_SAWMILL);
  282. return State.WALKING_TO_SAWMILL;
  283.  
  284. }
  285. setState(State.CHOPPING_DOWN_TREE);
  286. return State.CHOPPING_DOWN_TREE;
  287.  
  288. case WALKING_TO_SAWMILL:
  289. if(!inventorySetup()) {
  290. setState(State.WALKING_TO_BANK);
  291. return State.WALKING_TO_BANK;
  292. }
  293. getSawmill().walkToOperator();
  294. return State.WALKING_TO_SAWMILL;
  295.  
  296. case MAKING_PLANKS:
  297. if(Locations.isInsideSawmill()) {
  298. getSawmill().performSawmillTask();
  299. if(getSawmill().isFinished()) {
  300. setState(State.WALKING_TO_BANK);
  301. return State.WALKING_TO_BANK;
  302. }
  303. return State.MAKING_PLANKS;
  304. }
  305. setState(State.WALKING_TO_SAWMILL);
  306. return State.WALKING_TO_SAWMILL;
  307.  
  308. case WALKING_TO_BANK:
  309. getBanking().walkToBooth();
  310. return State.WALKING_TO_BANK;
  311.  
  312. case WALKING_TO_BOB:
  313. getAxe().walkToShop();
  314. return State.WALKING_TO_BOB;
  315.  
  316. case REPAIRING_AXE:
  317. getAxe().repairAxe();
  318. return State.REPAIRING_AXE;
  319.  
  320. }
  321. return null;
  322. }
  323. return State.WAITING;
  324. }
  325.  
  326. private boolean inventorySetup() {
  327. int amt = getAxe().wearing() ? 0 : 1;
  328. int logAmount = Inventory.getCount(getPlank().getLogId());
  329. switch(getTask()) {
  330. case MAKE_PLANKS:
  331. if(logAmount > 0) {
  332. if(Inventory.getCount(995) >= (logAmount * getPlank().getPricePerPlank())) {
  333. return true;
  334. }
  335. }
  336. return false;
  337. case CHOP_LOGS:
  338. return Inventory.getAll().length == amt;
  339. case CHOP_AND_PLANK:
  340. int plankPrice = getPlank().getPricePerPlank();
  341. return (Inventory.getAll().length
  342. == (amt + 1)
  343. && Inventory.getCount(995)
  344. >= (logAmount * plankPrice));
  345.  
  346. }
  347. return false;
  348. }
  349.  
  350. private String getStateToString() {
  351. switch(getState()) {
  352. case BANKING:
  353. return "Banking";
  354. case WALKING_TO_TREE:
  355. return "Walking to Tree";
  356. case CHOPPING_DOWN_TREE:
  357. return "Chopping Down Tree";
  358. case WALKING_TO_SAWMILL:
  359. return "Walking to Sawmill";
  360. case MAKING_PLANKS:
  361. return "Making Planks";
  362. case WALKING_TO_BANK:
  363. return "Walking to Bank";
  364. case WALKING_TO_BOB:
  365. return "Walking to Bob";
  366. case REPAIRING_AXE:
  367. return "Repairing Axe";
  368. case WAITING:
  369. return "Waiting";
  370. }
  371. return "Waiting";
  372. }
  373.  
  374. final int[] randomWorlds = {303,304,305,306,309,310,311,312,313,314,317,318,
  375. 319,320,321,322,326,327,328,329,333,334,335,336,338,
  376. 341,342,343,344,345,346,349,350,351,352,353,354,357,358,359,360,
  377. 361,362,366,367,368,369,370,373,374,375,376,377,378
  378. };
  379.  
  380. final int[] WORLD_COLUMN_1 = {301,302,303,304,305,306,308,309,310,311,312,313,314,316,317,318},
  381. WORLD_COLUMN_2 = {319,320,321,322,325,326,327,328,329,330,333,334,335,336,337,338},
  382. WORLD_COLUMN_3 = {341,342,343,344,345,346,349,350,351,352,353,354,357,358,359,360},
  383. WORLD_COLUMN_4 = {361,362,365,366,367,368,369,370,373,374,375,376,377,378};
  384.  
  385.  
  386.  
  387. final int[][] WORLD_LIST = { WORLD_COLUMN_1, WORLD_COLUMN_2, WORLD_COLUMN_3, WORLD_COLUMN_4 };
  388.  
  389. final int topX = 220,
  390. topY = 80,
  391. X_MULTIPLIER = 100,
  392. Y_MULTIPLIER = 24;
  393.  
  394. private boolean isLoggedOut() {
  395. return !(Login.getLoginState() == STATE.INGAME);
  396. }
  397.  
  398. private void openWorldScreen(){
  399. if(isLoggedOut()){
  400. Mouse.clickBox(10, 471, 88, 488, 1);
  401. sleep(1000,1500);
  402. }
  403. }
  404.  
  405. private boolean isWorldScreenOpen(){
  406. Color wScreen = Screen.getColorAt(100, 100);
  407. return (wScreen.getRed() == 0 && wScreen.getGreen() == 0 && wScreen.getBlue() == 0);
  408. }
  409.  
  410. private boolean selectWorld(int world) {
  411. int wNum = 0,
  412. xPos = 0,
  413. yPos = 0;
  414. for(int x = 0; x < WORLD_LIST.length; x++){
  415. for(int y = 0; y < WORLD_LIST[x].length; y++){
  416. wNum = WORLD_LIST[x][y];
  417. if(wNum == world){
  418. xPos = x * X_MULTIPLIER + topX;
  419. yPos = y * Y_MULTIPLIER + topY;
  420.  
  421. Mouse.click(xPos, yPos, 1);
  422. sleep(1000, 1500);
  423. return true;
  424. }
  425. }
  426. }
  427. return false;
  428. }
  429.  
  430.  
  431. private String getPlankToString() {
  432. switch(getPlank()) {
  433. case REGULAR:
  434. return "Regular Planks";
  435. case OAK:
  436. return "Oak Planks";
  437. case TEAK:
  438. return "Teak Planks";
  439. case MAHOGANY:
  440. return "Mahogany Planks";
  441. }
  442. return "";
  443. }
  444.  
  445. private int grabDuelRingPrice() {
  446. return Methods.getPrice(Constants.DUEL_RING[0]);
  447. }
  448.  
  449. private int grabEnergyPotionPrice() {
  450. int averagePrice = 0;
  451. switch(getEnergyPotion()) {
  452. case REGULAR:
  453. averagePrice = Methods.getPrice(Constants.ENERGY_POTION[3]);
  454. break;
  455. case SUPER:
  456. averagePrice = Methods.getPrice(Constants.SUPER_ENERGY_POTION[3]);
  457. break;
  458. }
  459. return averagePrice;
  460. }
  461.  
  462. private int grabCrushedNestPrice() {
  463. return Methods.getPrice(Constants.CRUSHED_NEST);
  464. }
  465.  
  466. public String setInMoneyFormat(double amount) {
  467. final int ONE_K = 1000;
  468. final int ONE_M = 1000000;
  469. if(amount >= ONE_M) {
  470. return decimalFormat.format(((double) amount / ONE_M)) + "M";
  471. }
  472. if(amount >= ONE_K) {
  473. return decimalFormat.format(((double) amount / ONE_K)) + "K";
  474. }
  475. return "" + decimalFormat.format(amount);
  476. }
  477.  
  478. public LoginState LoginState() {
  479.  
  480. if (Screen.getColorAt(98, 129).equals(new Color(0, 0, 0))) {
  481. return LoginState.WORLD_MENU;
  482. } else if (Screen.getColorAt(423, 248).equals(new Color(255, 255, 0))) {
  483. return LoginState.WELCOME_SCREEN;
  484. } else if (Screen.getColorAt(534, 341).equals(new Color(11, 11, 11))) {
  485. return LoginState.LOGIN_SCREEN;
  486. } else if (Screen.getColorAt(382, 323).equals(new Color(255, 255, 255))) {
  487. return LoginState.HOW_TO_PLAY;
  488. } else if (Screen.getColorAt(365, 340).equals(new Color(255, 255, 255))) {
  489. return LoginState.LOBBY;
  490. } else {
  491. return LoginState.ERROR;
  492. }
  493. }
  494.  
  495.  
  496. public Bank getBanking() {
  497. return banking;
  498. }
  499.  
  500. public void setBanking(Bank banking) {
  501. this.banking = banking;
  502. }
  503.  
  504. public Data getData() {
  505. return data;
  506. }
  507.  
  508. public void setData(Data data) {
  509. this.data = data;
  510. }
  511.  
  512. public Sawmill getSawmill() {
  513. return sawmill;
  514. }
  515.  
  516. public void setSawmill(Sawmill sawmill) {
  517. this.sawmill = sawmill;
  518. }
  519.  
  520. public Woodcutting getWoodcutting() {
  521. return woodcutting;
  522. }
  523.  
  524. public void setWoodcutting(Woodcutting woodcutting) {
  525. this.woodcutting = woodcutting;
  526. }
  527.  
  528. public void setState(State state) {
  529. this.state = state;
  530. }
  531.  
  532. public State getState() {
  533. return state;
  534. }
  535.  
  536. public void setPlank(Plank plank) {
  537. this.plank = plank;
  538. }
  539.  
  540. public Plank getPlank() {
  541. return plank;
  542. }
  543.  
  544. public Axe getAxe() {
  545. return axe;
  546. }
  547.  
  548. public void setAxe(Axe axe) {
  549. this.axe = axe;
  550. }
  551.  
  552. public void setPlankPrice(double plankPrice) {
  553. this.plankPrice = plankPrice;
  554. }
  555.  
  556. public double getPlankPrice() {
  557. return plankPrice;
  558. }
  559.  
  560. public void setEndScript(boolean endScript) {
  561. this.endScript = endScript;
  562. }
  563.  
  564. public boolean isEndScript() {
  565. if(getRunningTime() >= (getHoursToRun() * 3600000)) {
  566. return true;
  567. }
  568. return endScript;
  569. }
  570.  
  571. public double getHoursToRun() {
  572. return hoursToRun;
  573. }
  574.  
  575. public void setHoursToRun(double hoursToRun) {
  576. this.hoursToRun = hoursToRun;
  577. }
  578.  
  579. public void setGui(GUI gui) {
  580. this.gui = gui;
  581. }
  582.  
  583. public GUI getGui() {
  584. return gui;
  585. }
  586.  
  587. public void setEnergyPotion(EnergyPotion energyPotion) {
  588. this.energyPotion = energyPotion;
  589. }
  590.  
  591. public EnergyPotion getEnergyPotion() {
  592. return energyPotion;
  593. }
  594.  
  595. public void setEnergyPotionPrice(int energyPotionPrice) {
  596. this.energyPotionPrice = energyPotionPrice;
  597. }
  598.  
  599. public double getEnergyPotionPrice() {
  600. return energyPotionPrice;
  601. }
  602.  
  603. public ScriptTask getTask() {
  604. return task;
  605. }
  606.  
  607. public void setTask(ScriptTask task) {
  608. this.task = task;
  609. }
  610.  
  611. public void setLogPrice(double logPrice) {
  612. this.logPrice = logPrice;
  613. }
  614.  
  615. public double getLogPrice() {
  616. return logPrice;
  617. }
  618.  
  619. public void setCrushedNestPrice(double crushedNestPrice) {
  620. this.crushedNestPrice = crushedNestPrice;
  621. }
  622.  
  623. public double getCrushedNestPrice() {
  624. return crushedNestPrice;
  625. }
  626.  
  627. public DuelRing getDuelRing() {
  628. return duelRing;
  629. }
  630.  
  631. public void setDuelRing(DuelRing duelRing) {
  632. this.duelRing = duelRing;
  633. }
  634.  
  635. public double getDuelRingPrice() {
  636. return duelRingPrice;
  637. }
  638.  
  639. public void setDuelRingPrice(double duelRingPrice) {
  640. this.duelRingPrice = duelRingPrice;
  641. }
  642.  
  643. public void setPotions(Potions potions) {
  644. this.potions = potions;
  645. }
  646.  
  647. public Potions getPotions() {
  648. return potions;
  649. }
  650.  
  651. public VarrockTab getVarrockTab() {
  652. return varrockTab;
  653. }
  654.  
  655. public void setVarrockTab(VarrockTab varrockTab) {
  656. this.varrockTab = varrockTab;
  657. }
  658.  
  659. public void setAntiBan(AntiBan antiBan) {
  660. this.antiBan = antiBan;
  661. }
  662.  
  663. public AntiBan getAntiBan() {
  664. return antiBan;
  665. }
  666.  
  667. private class Cross {
  668.  
  669. private final long time;
  670. private final Point location;
  671. private final double rot;
  672.  
  673. public Cross(long lifetime, long st, Point loc, double rot) {
  674. this.time = System.currentTimeMillis() + lifetime;
  675. location = loc;
  676. this.rot = rot;
  677. }
  678.  
  679. public long getAge() {
  680. return time - System.currentTimeMillis();
  681. }
  682.  
  683. public int getAlpha() {
  684. return Math.min(255,
  685. Math.max(0, (int) (256.0D * (getAge() / 1500.0D))));
  686. }
  687.  
  688. public boolean handle() {
  689. return System.currentTimeMillis() <= time;
  690. }
  691.  
  692. public double getRot() {
  693. return rot;
  694. }
  695.  
  696. public Point getLocation() {
  697. return location;
  698. }
  699.  
  700. @Override
  701. public boolean equals(Object o) {
  702. if (o instanceof Cross) {
  703. Cross oo = (Cross) o;
  704. return oo.location.equals(this.location);
  705. }
  706. return false;
  707. }
  708.  
  709. }
  710.  
  711. public double getRot() {
  712. return System.currentTimeMillis() % 3600 / 5.0D;
  713. }
  714.  
  715. private final List<Cross> clicks = new LinkedList<Cross>();
  716. private final Object lock = new Object();
  717.  
  718. private boolean paintClick;
  719.  
  720. public boolean isPaintClick() {
  721. return paintClick;
  722. }
  723.  
  724. public void setPaintClick(boolean paintClick) {
  725. this.paintClick = paintClick;
  726. }
  727.  
  728. @Override
  729. public void mouseDragged(Point arg0, int arg1, boolean arg2) {
  730. // TODO Auto-generated method stub
  731.  
  732. }
  733.  
  734. @Override
  735. public void mouseMoved(Point arg0, boolean arg1) {
  736. // TODO Auto-generated method stub
  737.  
  738. }
  739.  
  740. @Override
  741. public void mouseReleased(Point arg0, int arg1, boolean arg2) {
  742. // TODO Auto-generated method stub
  743.  
  744. }
  745.  
  746. @Override
  747. public void paintMouse(Graphics g, Point arg1, Point arg2) {
  748. final Point location = new Point(Mouse.getPos().x, Mouse.getPos().y);
  749. g.setColor(Color.GREEN);
  750. g.drawLine(location.x, location.y - 5, location.x, location.y + 5);
  751. g.drawLine(location.x - 5, location.y, location.x + 5, location.y);
  752. if (isPaintClick()) {
  753. setPaintClick(false);
  754. Cross newCross = new Cross(1500, General.random(40, 300), location,
  755. getRot());
  756. if (!clicks.contains(newCross)) {
  757. clicks.add(newCross);
  758. }
  759. }
  760. synchronized (lock) {
  761. Iterator<Cross> clickIterator = clicks.listIterator();
  762. while (clickIterator.hasNext()) {
  763. Cross toDraw = clickIterator.next();
  764. if (toDraw.handle()) {
  765. drawPoint(toDraw.getLocation(), toDraw.getRot(), g,
  766. toDraw.getAlpha());
  767. } else {
  768. clicks.remove(toDraw);
  769. }
  770. }
  771. }
  772.  
  773. }
  774.  
  775. private void drawPoint(Point location, double rot, Graphics g, int al) {
  776. Graphics2D g1 = (Graphics2D) g.create();
  777. g1.setColor(new Color(255, 0, 0, 155));
  778. g1.rotate(rot, location.x, location.y);
  779. g1.drawLine(location.x, location.y - 5, location.x, location.y + 5);
  780. g1.drawLine(location.x - 5, location.y, location.x + 5, location.y);
  781. }
  782. @Override
  783. public void mouseClicked(Point p, int button, boolean isBot) {
  784. setPaintClick(true);
  785. }
  786.  
  787. @Override
  788. public void paintMouseSpline(Graphics arg0, ArrayList<Point> arg1) {
  789. // TODO Auto-generated method stub
  790.  
  791. }
  792.  
  793. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement