Advertisement
Guest User

Untitled

a guest
Aug 10th, 2014
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.56 KB | None | 0 0
  1. package scripts.wbBlastFurnace;
  2.  
  3. import java.awt.*;
  4.  
  5. import org.tribot.api.Clicking;
  6. import org.tribot.api.DynamicClicking;
  7. import org.tribot.api.General;
  8. import org.tribot.api.Timing;
  9. import org.tribot.api.input.Mouse;
  10. import org.tribot.api.types.generic.Condition;
  11. import org.tribot.api2007.Banking;
  12. import org.tribot.api2007.Camera;
  13. import org.tribot.api2007.Interfaces;
  14. import org.tribot.api2007.Inventory;
  15. import org.tribot.api2007.NPCChat;
  16. import org.tribot.api2007.NPCs;
  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.types.RSInterfaceChild;
  23. import org.tribot.api2007.types.RSInterfaceMaster;
  24. import org.tribot.api2007.types.RSNPC;
  25. import org.tribot.api2007.types.RSObject;
  26. import org.tribot.api2007.types.RSTile;
  27. import org.tribot.script.Script;
  28. import org.tribot.script.ScriptManifest;
  29. import org.tribot.script.interfaces.Painting;
  30.  
  31. @ScriptManifest(authors = { "WillB" }, category = "Smithing", name = "wbBlastFurnace")
  32. public class wbBlastFurnace extends Script implements Painting {
  33.  
  34. boolean running = true;
  35. boolean addedOre = false;
  36.  
  37. int addedCoal = 0;
  38. int addedCoalAmm = 1;
  39. int barsMade = 0;
  40. int smithingStartXp;
  41.  
  42. long startTime;
  43.  
  44. public enum State {
  45. BANKING, ADDING_COAL, ADDING_ORE, WAITING_FOR_BARS, COLLECTING_BARS, FILLING_BUCKET, UNKNOWN
  46. };
  47.  
  48. @Override
  49. public void run() {
  50. smithingStartXp = SKILLS.SMITHING.getXP();
  51. startTime = System.currentTimeMillis();
  52.  
  53. while (running) {
  54. sleep(loop());
  55. }
  56. }
  57.  
  58. private int loop() {
  59. switch (getState()) {
  60. case ADDING_COAL:
  61. addOre("Coal");
  62. break;
  63.  
  64. case ADDING_ORE:
  65. addOre("Iron ore");
  66. break;
  67.  
  68. case BANKING:
  69. bank();
  70. break;
  71.  
  72. case COLLECTING_BARS:
  73. collectBars();
  74. break;
  75.  
  76. case WAITING_FOR_BARS:
  77. waitForBars();
  78. break;
  79.  
  80. case FILLING_BUCKET:
  81. fillBucket();
  82. break;
  83.  
  84. case UNKNOWN:
  85. break;
  86.  
  87. }
  88. return 100;
  89. }
  90.  
  91. private State getState() {
  92. if (Inventory.getCount("Bucket of water") == 0
  93. && Interfaces.get(28) == null) {
  94. return State.FILLING_BUCKET;
  95. }
  96.  
  97. if (Inventory.isFull()) {
  98. if (Inventory.getCount("Coal") > 0 && !addedCoal()) {
  99. return State.ADDING_COAL;
  100. } else if (Inventory.getCount("Iron ore") > 0 && !addedOre) {
  101. return State.ADDING_ORE;
  102. } else if (!addedCoal() && !addedOre
  103. || Inventory.getCount("Steel bar") > 0) {
  104. return State.BANKING;
  105. }
  106. } else {
  107. if (checkBars() == null || !checkBars().equals("Search")) {
  108. return State.COLLECTING_BARS;
  109. } else if (addedCoal() && addedOre) {
  110. return State.WAITING_FOR_BARS;
  111. } else if (!addedCoal() || !addedOre) {
  112. return State.BANKING;
  113. }
  114. }
  115. return State.UNKNOWN;
  116. }
  117.  
  118. private boolean fillBucket() {
  119. final RSObject[] sink = Objects.find(15, "Sink");
  120.  
  121. if (sink.length > 0 && sink[0] != null) {
  122. if (Player.getPosition().distanceTo(sink[0]) > 5) {
  123. if (!Walking.clickTileMM(sink[0], 1)) {
  124. return false;
  125. }
  126. } else {
  127. if (!sink[0].isOnScreen()) {
  128. Camera.turnToTile(sink[0]);
  129.  
  130. Timing.waitCondition(new Condition() {
  131.  
  132. @Override
  133. public boolean active() {
  134. General.sleep(50, 100);
  135.  
  136. return sink[0].isOnScreen();
  137. }
  138.  
  139. }, General.random(2000, 3000));
  140. }
  141. if (!DynamicClicking.clickRSObject(sink[0], "Fill-bucket")) {
  142. return false;
  143. }
  144. }
  145. }
  146. return Timing.waitCondition(new Condition() {
  147.  
  148. @Override
  149. public boolean active() {
  150. General.sleep(50, 100);
  151.  
  152. return Inventory.getCount("Bucket of water") > 0;
  153. }
  154.  
  155. }, General.random(2000, 6000));
  156. }
  157.  
  158. private boolean addedCoal() {
  159. return addedCoal == addedCoalAmm;
  160. }
  161.  
  162. private String checkBars() {
  163. RSObject[] barDispenser = Objects.find(15, "Bar dispenser");
  164.  
  165. if (barDispenser.length > 0 && barDispenser[0] != null) {
  166. if (barDispenser[0].getDefinition().getActions().length > 0
  167. && barDispenser[0].getDefinition().getActions()[0] != null) {
  168. return barDispenser[0].getDefinition().getActions()[0];
  169. }
  170. }
  171. return null;
  172. }
  173.  
  174. private boolean addOre(final String oreName) {
  175. final RSObject[] conveyor = Objects.find(16, 9100);
  176. final RSInterfaceChild addOreInterface = Interfaces.get(228, 1);
  177.  
  178. if (addOreInterface == null) {
  179. if (conveyor.length > 0 && conveyor[0] != null) {
  180. if (Player.getPosition().distanceTo(conveyor[0]) > 5) {
  181. if (!Walking.clickTileMM(new RSTile(conveyor[0]
  182. .getPosition().getX() - General.random(1, 4),
  183. conveyor[0].getPosition().getY()), 1)) {
  184. return false;
  185. } else {
  186. Timing.waitCondition(new Condition() {
  187.  
  188. @Override
  189. public boolean active() {
  190. General.sleep(50, 100);
  191.  
  192. return Player.getPosition().distanceTo(
  193. conveyor[0]) <= 8;
  194. }
  195.  
  196. }, General.random(2000, 3000));
  197. }
  198. } else {
  199. if (!conveyor[0].isOnScreen()) {
  200. Camera.turnToTile(conveyor[0]);
  201. }
  202. Timing.waitCondition(new Condition() {
  203.  
  204. @Override
  205. public boolean active() {
  206. General.sleep(50, 100);
  207.  
  208. return conveyor[0].isOnScreen();
  209. }
  210.  
  211. }, General.random(2000, 3000));
  212. }
  213. if (!DynamicClicking.clickRSObject(conveyor[0], "Put-ore-on")) {
  214. return false;
  215. }
  216. }
  217. } else {
  218. if (!addOreInterface.click()) {
  219. return false;
  220. } else {
  221. if (oreName == "Coal") {
  222. addedCoal++;
  223. } else {
  224. addedOre = true;
  225. }
  226. }
  227. }
  228. return Timing.waitCondition(new Condition() {
  229.  
  230. @Override
  231. public boolean active() {
  232. General.sleep(50, 100);
  233.  
  234. return addOreInterface != null || !Inventory.isFull();
  235. }
  236.  
  237. }, General.random(2000, 5500));
  238. }
  239.  
  240. private boolean bank() {
  241. if (!Banking.isBankScreenOpen()) {
  242. if (!Banking.openBank()) {
  243. return false;
  244. }
  245. }
  246.  
  247. if (Inventory.isFull()) {
  248. if (Banking.depositAllExcept("Coins", "Bucket", "Bucket of water") < 1) {
  249. return false;
  250. }
  251. }
  252.  
  253. if (addedCoal != addedCoalAmm) {
  254. if (!Banking.withdraw(28 - Inventory.getAll().length, "Coal")) {
  255. return false;
  256. }
  257. } else if (addedCoal == addedCoalAmm && !addedOre) {
  258. if (!Banking.withdraw(28 - Inventory.getAll().length, "Iron ore")) {
  259. return false;
  260. }
  261. }
  262.  
  263. Banking.close();
  264.  
  265. return Timing.waitCondition(new Condition() {
  266.  
  267. @Override
  268. public boolean active() {
  269. General.sleep(50, 100);
  270. return !Banking.isBankScreenOpen();
  271. }
  272.  
  273. }, General.random(3000, 5000));
  274. }
  275.  
  276. private boolean waitForBars() {
  277. RSObject[] barDispenser = Objects.find(15, "Bar dispenser");
  278.  
  279. if (!addedOre || addedCoal != addedCoalAmm) {
  280. return false;
  281. }
  282.  
  283. if (Player.getPosition().distanceTo(barDispenser[0].getPosition()) > 2) {
  284. if (!Walking.clickTileMM(barDispenser[0], 1)) {
  285. return false;
  286. }
  287. } else {
  288. Mouse.leaveGame(true);
  289. }
  290.  
  291. return Timing.waitCondition(new Condition() {
  292.  
  293. @Override
  294. public boolean active() {
  295. General.sleep(50, 100);
  296. return addedOre && addedCoal == addedCoalAmm
  297. && checkBars() != "Search";
  298. }
  299.  
  300. }, General.random(3000, 5000));
  301. }
  302.  
  303. private boolean collectBars() {
  304. final RSObject[] barDispenser = Objects.find(15, "Bar dispenser");
  305. RSInterfaceMaster barInterface = Interfaces.get(28);
  306.  
  307. if (barInterface == null) {
  308. if (barDispenser.length > 0 && barDispenser[0] != null) {
  309. if (Player.getPosition().distanceTo(barDispenser[0]) > 8) {
  310. if (!Walking.clickTileMM(barDispenser[0], 1)) {
  311. return false;
  312. }
  313. } else {
  314. if (barDispenser[0].getDefinition().getActions().length < 1) {
  315. if (!Inventory.find("Bucket of water")[0].click("Use")) {
  316. return false;
  317. }
  318. }
  319. if (!DynamicClicking.clickRSObject(barDispenser[0], 1)) {
  320. return false;
  321. }
  322. Timing.waitCondition(new Condition() {
  323.  
  324. @Override
  325. public boolean active() {
  326. General.sleep(50, 100);
  327. return barDispenser[0].getDefinition().getActions().length > 0
  328. || Inventory.getCount("Steel bar") > 0;
  329. }
  330. }, General.random(3000, 5000));
  331. }
  332. }
  333. } else {
  334. if (barInterface.getChild(110) != null) {
  335. if (!barInterface.getChild(110).click()) {
  336. return false;
  337. } else {
  338. addedCoal = 0;
  339. addedOre = false;
  340. barsMade = barsMade + Inventory.getCount("Steel bar");
  341. }
  342. }
  343. }
  344. return Timing.waitCondition(new Condition() {
  345.  
  346. @Override
  347. public boolean active() {
  348. General.sleep(50, 100);
  349. return Inventory.getCount("Steel bar") > 0;
  350. }
  351.  
  352. }, General.random(1000, 2000));
  353. }
  354.  
  355. private boolean talkToNPC() {
  356. RSNPC[] foreman = NPCs.find("Blast Furnace Foreman");
  357.  
  358. if (NPCChat.getMessage() == null || NPCChat.getOptions().length > 0) {
  359. if (foreman.length > 0 && foreman[0] != null) {
  360. if (Player.getPosition().distanceTo(foreman[0]) > 5) {
  361. if (!Walking.clickTileMM(foreman[0], 1)) {
  362. return false;
  363. }
  364. } else {
  365. if (!DynamicClicking.clickRSNPC(foreman[0], 1)) {
  366. return false;
  367. }
  368. }
  369. }
  370. } else {
  371. if (NPCChat.getMessage() != null) {
  372. if (!NPCChat.clickContinue(true)) {
  373. return false;
  374. }
  375. }
  376. if (NPCChat.getOptions().length > 0) {
  377. if (NPCChat.getOptions()[0] != null
  378. && NPCChat.getOptions()[0].equals("What?")) {
  379. if (!Clicking.click(NPCChat.getOptions()[0])) {
  380. return false;
  381. }
  382. } else if (NPCChat.getOptions()[0] != null
  383. && NPCChat.getOptions()[0].equals("Okay.")) {
  384. if (!Clicking.click(NPCChat.getOptions()[0])) {
  385. return false;
  386. }
  387. } else if (NPCChat.getOptions()[2] != null
  388. && NPCChat.getOptions()[2].contains("Can I use the")) {
  389. if (!Clicking.click(NPCChat.getOptions()[2])) {
  390. return false;
  391. }
  392. }
  393. }
  394. }
  395. return true;
  396. }
  397.  
  398. private String getRuntime() {
  399. return Timing.msToString(System.currentTimeMillis() - startTime);
  400. }
  401.  
  402. private final Color color1 = new Color(51, 51, 51);
  403. private final Color color2 = new Color(255, 255, 255);
  404.  
  405. private final BasicStroke stroke1 = new BasicStroke(1);
  406.  
  407. private final Font font1 = new Font("Arial Black", 0, 14);
  408.  
  409. public void onPaint(Graphics g1) {
  410. Graphics2D g = (Graphics2D) g1;
  411.  
  412. int xpGained = SKILLS.SMITHING.getXP() - smithingStartXp;
  413.  
  414. g.setColor(color1);
  415. g.fillRect(6, 344, 208, 129);
  416. g.setStroke(stroke1);
  417. g.drawRect(6, 344, 208, 129);
  418. g.setFont(font1);
  419. g.setColor(color2);
  420. g.drawString("Runtime: " + getRuntime(), 12, 378);
  421. g.drawString("Bars made: " + barsMade, 12, 418);
  422. g.drawString("Exp gained: " + xpGained, 12, 457);
  423. }
  424. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement