Advertisement
iant06

Untitled

Sep 17th, 2015
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.08 KB | None | 0 0
  1. package scripts.firemaker;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.text.DecimalFormat;
  7.  
  8. import org.tribot.api.General;
  9. import org.tribot.api.Timing;
  10. import org.tribot.api.input.Mouse;
  11. import org.tribot.api.util.ABCUtil;
  12. import org.tribot.api2007.Banking;
  13. import org.tribot.api2007.Game;
  14. import org.tribot.api2007.GroundItems;
  15. import org.tribot.api2007.Inventory;
  16. import org.tribot.api2007.NPCChat;
  17. import org.tribot.api2007.Objects;
  18. import org.tribot.api2007.Player;
  19. import org.tribot.api2007.Skills;
  20. import org.tribot.api2007.Skills.SKILLS;
  21. import org.tribot.api2007.Walking;
  22. import org.tribot.api2007.WebWalking;
  23. import org.tribot.api2007.types.RSGroundItem;
  24. import org.tribot.api2007.types.RSItem;
  25. import org.tribot.api2007.types.RSObject;
  26. import org.tribot.api2007.types.RSTile;
  27. import org.tribot.script.EnumScript;
  28. import org.tribot.script.ScriptManifest;
  29. import org.tribot.script.interfaces.Painting;
  30.  
  31. import scripts.methods.Methods;
  32.  
  33. @ScriptManifest(authors = { "iant06" }, category = "Firemaking", name = "iFireMaker Pro")
  34.  
  35. public class Main extends EnumScript<State> implements Painting {
  36.  
  37. private Bank bank = null;
  38.  
  39. private GUI gui = null;
  40.  
  41. private State state = null;
  42.  
  43. private LogType logType = null;
  44.  
  45. private Cities city = null;
  46.  
  47. private int logId = -1;
  48.  
  49. private int startXp = -1;
  50.  
  51. private int startLevel = -1;
  52.  
  53. private int logsBurned = 0;
  54.  
  55. private boolean endScript = false;
  56.  
  57. private int desiredLevel = 99;
  58.  
  59. @Override
  60. public void onPaint(Graphics g) {
  61. int burn = (int) ((int) (Skills.getXP(Skills.SKILLS.FIREMAKING) - getStartXp()) / getLogType().getXp());
  62. int burnHr = (int) (burn / ((getRunningTime()) / 3600000D));
  63. int xpMade = (int) (Skills.getXP(Skills.SKILLS.FIREMAKING) - getStartXp());
  64. int xpHr = (int) (xpMade / ((getRunningTime()) / 3600000D));
  65. int fmLevel = Skills.getLevelByXP(Skills.getXP(SKILLS.FIREMAKING));
  66. g.setColor(Color.BLACK);
  67. g.setFont(new Font("default", Font.BOLD, 12));
  68. g.drawString("Logs Burned: " + burn + " (" + burnHr + ")", 325, 355);
  69. g.drawString("Level: " + fmLevel + " (" + (fmLevel - getStartLevel()) + ")", 325, 370);
  70. g.drawString("XP Gain: " + setInMoneyFormat(xpMade) + " (" + setInMoneyFormat(xpHr) + ")", 325, 385);
  71. g.drawString("Burning: " + Methods.correctCapitalization(getLogType().toString()), 325, 400);
  72. g.drawString("Location: " + Methods.correctCapitalization(getCity().toString()), 325, 415);
  73. g.drawString("State: " + Methods.correctCapitalization(getState().toString()), 325, 430);
  74. g.drawString("Running for: " + Timing.msToString(getRunningTime()), 325, 445);
  75. }
  76.  
  77. @Override
  78. public State getInitialState() {
  79. if(gui == null) {
  80. setGui(new GUI(this));
  81. }
  82. while(getGui().isVisible()) {
  83. sleep(50, 150);
  84. }
  85. if(bank == null) {
  86. setBank(new Bank(this));
  87. }
  88. if(Player.getPosition().equals(getCity().getTile())) {
  89. setState(State.LIGHTING_LOGS);
  90. return State.LIGHTING_LOGS;
  91. }
  92. if(getBank().performedBankTask()) {
  93. setState(State.WALKING_TO_START_POINT);
  94. return State.WALKING_TO_START_POINT;
  95. }
  96. setState(State.BANKING);
  97. return State.BANKING;
  98. }
  99.  
  100. @Override
  101. public State handleState(State state) {
  102. if(isEndScript()) {
  103. Thread.currentThread().interrupt();
  104. return null;
  105. }
  106. if(Skills.getActualLevel(SKILLS.FIREMAKING) >= getDesiredLevel()) {
  107. int xpMade = (int) (Skills.getXP(SKILLS.FIREMAKING) - getStartXp());
  108. int burn = (int) ((int) (Skills.getXP(Skills.SKILLS.FIREMAKING) - getStartXp()) / getLogType().getXp());
  109. int lvls = Skills.getActualLevel(SKILLS.FIREMAKING) - getStartLevel();
  110. println("[iFireMaker Pro]Achieved desired level of " + getDesiredLevel() + " firemaking!");
  111. println("Burned a total of " + burn + " " + getLogType().toString() + " logs for " + setInMoneyFormat(xpMade) + " XP(" + lvls + " levels).");
  112. Thread.currentThread().interrupt();
  113. return null;
  114. }
  115. state = getState() != null ? getState() : getInitialState();
  116. switch(state) {
  117. case BANKING:
  118. if(getBank().isBankScreenOpen(100)) {
  119. if(getBank().performedBankTask()) {
  120. setState(State.WALKING_TO_START_POINT);
  121. return State.WALKING_TO_START_POINT;
  122. }
  123. }
  124. if(Banking.openBank()) {
  125. if(getBank().performedBankTask()) {
  126. setState(State.WALKING_TO_START_POINT);
  127. return State.WALKING_TO_START_POINT;
  128. }
  129. }
  130. if(!usingGrandExchange()) {
  131. WebWalking.walkToBank();
  132. } else {
  133. RSTile[] path = Walking.generateStraightPath(Locations.GRAND_EXCHANGE_BANK);
  134. Walking.walkPath(path);
  135. }
  136. return State.BANKING;
  137. case WALKING_TO_START_POINT:
  138. if(!Player.getPosition().equals(getCity().getTile())) {
  139. if(Game.getDestination() == null && !Player.isMoving()) {
  140. if(!usingGrandExchange())
  141. WebWalking.walkTo(getCity().getTile());
  142. else {
  143. RSTile[] path = Walking.generateStraightPath(getCity().getTile());
  144. Walking.walkPath(path);
  145. }
  146. }
  147. }
  148. int distance = Methods.distanceTo(this, getCity().getTile());
  149. if(distance <= 0) {
  150. setState(State.LIGHTING_LOGS);
  151. return State.LIGHTING_LOGS;
  152. }
  153. return State.WALKING_TO_START_POINT;
  154. case LIGHTING_LOGS:
  155. if(standingOnFire()) {
  156. moveSouth();
  157. }
  158. lightLogs();
  159. return State.LIGHTING_LOGS;
  160. }
  161. return null;
  162. }
  163.  
  164. public boolean usingGrandExchange() {
  165. if(getCity().equals(Cities.GRAND_EXCHANGE_NORTH)
  166. || getCity().equals(Cities.GRAND_EXCHANGE_SOUTH)) {
  167. return true;
  168. }
  169. return false;
  170. }
  171.  
  172. public boolean waitForFire() {
  173. RSTile tile = Player.getPosition();
  174. RSItem[] logs = Inventory.find(getLogType().getLogId());
  175. RSItem[] tinderbox = Inventory.find(Constants.TINDERBOX);
  176. time = System.currentTimeMillis();
  177. boolean hovercheck = false;
  178. while(Player.getPosition().equals(tile) && !isTimedOut(10000, 12000)) {
  179. if(Game.getItemSelectionState() == 1 && !hovercheck) {
  180. break;
  181. }
  182. if(!hovercheck) {
  183. hovercheck = true;
  184. General.sleep(abc.DELAY_TRACKER.SWITCH_OBJECT.next());
  185. abc.DELAY_TRACKER.SWITCH_OBJECT.reset();
  186. if(logs.length > 1) {
  187. if(logs[1].click("Use")) {
  188. logsClicked = true;
  189. General.sleep(abc.DELAY_TRACKER.SWITCH_OBJECT.next());
  190. abc.DELAY_TRACKER.SWITCH_OBJECT.reset();
  191. //if(abc.BOOL_TRACKER.HOVER_NEXT.next()) {
  192. //abc.BOOL_TRACKER.HOVER_NEXT.reset();
  193. tinderbox[0].hover();
  194. //}
  195. }
  196. }
  197. }
  198. if(NPCChat.getMessage() != null
  199. || NPCChat.getOptions() != null
  200. || NPCChat.getClickContinueInterface() != null) {
  201. return false;
  202. }
  203. Methods.performAntiBan(this);
  204. sleep(50, 150);
  205. }
  206. if(!Player.getPosition().equals(tile)) {
  207. return true;
  208. }
  209. return false;
  210. }
  211.  
  212. private ABCUtil abc = new ABCUtil();
  213.  
  214. public boolean checkLogsOnGround() {
  215. RSGroundItem[] groundLogs = GroundItems.find(getLogType().getName());
  216. if(groundLogs != null && groundLogs.length > 0) {
  217. for(int i = 0; i < groundLogs.length; i++) {
  218. if(groundLogs[i].getPosition().equals(Player.getPosition())) {
  219. if(Game.getItemSelectionState() == 1) {
  220. Mouse.click(1);
  221. }
  222. if(groundLogs[i].click("Light")) {
  223. return waitForFire();
  224. }
  225. }
  226. }
  227. }
  228. return false;
  229. }
  230.  
  231. public boolean lightLogs() {
  232. if(Player.getAnimation() == 733) {
  233. return false;
  234. }
  235. if(standingOnFire()) {
  236. moveSouth();
  237. return false;
  238. }
  239. RSItem[] tinderbox = Inventory.find(Constants.TINDERBOX);
  240. RSItem[] logs = Inventory.find(getLogType().getLogId());
  241. if(tinderbox == null || tinderbox.length <= 0) {
  242. setState(State.BANKING);
  243. return false;
  244. }
  245. if(logs == null || logs.length <= 0) {
  246. setState(State.BANKING);
  247. return false;
  248. }
  249. if(logsClicked) {
  250. logsClicked = false;
  251. if(Inventory.getCount(getLogType().getLogId()) <= 0) {
  252. return false;
  253. }
  254. if(Game.getItemSelectionState() == 1) {
  255. if(tinderbox.length > 0) {
  256. tinderbox[0].click("Use");
  257. return waitForFire();
  258. }
  259. }
  260. return false;
  261. } else {
  262. if(Game.getItemSelectionState() == 1) {
  263. logsClicked = true;
  264. return false;
  265. }
  266. if(logs[0].click("Use")) {
  267. General.sleep(abc.DELAY_TRACKER.SWITCH_OBJECT.next());
  268. abc.DELAY_TRACKER.SWITCH_OBJECT.reset();
  269. if(Inventory.getCount(getLogType().getLogId()) <= 0) {
  270. return false;
  271. }
  272. if(tinderbox[0].click("Use")) {
  273. return waitForFire();
  274. }
  275. return false;
  276. }
  277. }
  278. return false;
  279. }
  280.  
  281. private boolean logsClicked = false;
  282.  
  283. private long time;
  284.  
  285. public boolean isTimedOut(int i, int j) {
  286. if(System.currentTimeMillis() - time >= General.random(i, j)) {
  287. return true;
  288. }
  289. return false;
  290. }
  291.  
  292. private String[] badObjects = {
  293. "Fire",
  294. "Fern",
  295. "Daisies",
  296. "Tree",
  297. "Wilderness Sign"
  298. };
  299.  
  300. public boolean standingOnFire() {
  301. RSObject[] all = Objects.getAll(3);
  302. if(all != null && all.length > 0) {
  303. RSTile tile = Player.getPosition();
  304. RSTile eastTile = new RSTile(Player.getPosition().getX() - 1, Player.getPosition().getY());
  305. for(int i = 0; i < all.length; i++) {
  306. if(all[i].getPosition().equals(tile)
  307. || all[i].getPosition().equals(eastTile)) {
  308. for(int j = 0; j < badObjects.length; j++) {
  309. if(all[i].getDefinition().getName().equals(badObjects[j])) {
  310. return true;
  311. }
  312. }
  313. }
  314. }
  315. }
  316. return false;
  317. }
  318.  
  319. public static final DecimalFormat decimalFormat = new DecimalFormat("#.##");
  320.  
  321. public String setInMoneyFormat(double amount) {
  322. final int ONE_K = 1000;
  323. final int ONE_M = 1000000;
  324. if(amount >= ONE_M) {
  325. return decimalFormat.format(((double) amount / ONE_M)) + "M";
  326. }
  327. if(amount >= ONE_K) {
  328. return decimalFormat.format(((double) amount / ONE_K)) + "K";
  329. }
  330. return "" + decimalFormat.format(amount);
  331. }
  332.  
  333. public void moveSouth() {
  334. int lanes = getCity().getLanes();
  335. boolean objectToSouth = false;
  336. RSTile southTile = new RSTile(Player.getPosition().getX(), Player.getPosition().getY() - 1);
  337. RSObject[] all = Objects.getAll(3);
  338. if(all != null && all.length > 0) {
  339. for(int i = 0; i < all.length; i++) {
  340. if(all[i].getPosition().equals(southTile)) {
  341. for(int j = 0; j < badObjects.length; j++) {
  342. if(all[i].getDefinition().getName().equals(badObjects[j])) {
  343. objectToSouth = true;
  344. break;
  345. }
  346. }
  347. if(objectToSouth)
  348. break;
  349. }
  350. }
  351. }
  352. RSTile south = new RSTile(Player.getPosition().getX(), Player.getPosition().getY() - (objectToSouth ? 2 : 1));
  353. if((Player.getPosition().getY() - getCity().getTile().getY() > 0)
  354. || (getCity().getTile().getY() - Player.getPosition().getY() > lanes)) {
  355. RSTile tile = new RSTile(Player.getPosition().getX(), getCity().getTile().getY());
  356. WebWalking.walkTo(tile);
  357. } else
  358. Walking.walkTo(south);
  359. }
  360.  
  361. public GUI getGui() {
  362. return gui;
  363. }
  364.  
  365. public void setGui(GUI gui) {
  366. this.gui = gui;
  367. }
  368.  
  369. public Bank getBank() {
  370. return bank;
  371. }
  372.  
  373. public void setBank(Bank bank) {
  374. this.bank = bank;
  375. }
  376.  
  377. public State getState() {
  378. return state;
  379. }
  380.  
  381. public void setState(State state) {
  382. this.state = state;
  383. }
  384.  
  385. public LogType getLogType() {
  386. return logType;
  387. }
  388.  
  389. public void setLogType(LogType logType) {
  390. this.logType = logType;
  391. }
  392.  
  393. public Cities getCity() {
  394. return city;
  395. }
  396.  
  397. public void setCity(Cities city) {
  398. this.city = city;
  399. }
  400.  
  401. public int getLogId() {
  402. return logId;
  403. }
  404.  
  405. public void setLogId(int logId) {
  406. this.logId = logId;
  407. }
  408.  
  409. public int getStartXp() {
  410. return startXp;
  411. }
  412.  
  413. public void setStartXp(int startXp) {
  414. this.startXp = startXp;
  415. }
  416.  
  417. public int getStartLevel() {
  418. return startLevel;
  419. }
  420.  
  421. public void setStartLevel(int startLevel) {
  422. this.startLevel = startLevel;
  423. }
  424.  
  425. public int getLogsBurned() {
  426. return logsBurned;
  427. }
  428.  
  429. public void setLogsBurned(int logsBurned) {
  430. this.logsBurned = logsBurned;
  431. }
  432.  
  433. public boolean isEndScript() {
  434. return endScript;
  435. }
  436.  
  437. public void setEndScript(boolean endScript) {
  438. this.endScript = endScript;
  439. }
  440.  
  441. public int getDesiredLevel() {
  442. return desiredLevel;
  443. }
  444.  
  445. public void setDesiredLevel(int desiredLevel) {
  446. this.desiredLevel = desiredLevel;
  447. }
  448.  
  449.  
  450. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement