Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.88 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.Color;
  3. import java.awt.Container;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.awt.GridBagConstraints;
  7. import java.awt.GridBagLayout;
  8. import java.awt.Insets;
  9. import java.awt.event.ActionEvent;
  10. import java.awt.event.ActionListener;
  11. import java.awt.event.KeyAdapter;
  12. import java.awt.event.KeyEvent;
  13. import java.awt.event.WindowAdapter;
  14. import java.awt.event.WindowEvent;
  15. import java.io.BufferedReader;
  16. import java.io.BufferedWriter;
  17. import java.io.File;
  18. import java.io.FileReader;
  19. import java.io.FileWriter;
  20. import java.io.IOException;
  21.  
  22. import javax.swing.DefaultComboBoxModel;
  23. import javax.swing.JButton;
  24. import javax.swing.JCheckBox;
  25. import javax.swing.JComboBox;
  26. import javax.swing.JEditorPane;
  27. import javax.swing.JFrame;
  28. import javax.swing.JLabel;
  29. import javax.swing.JPanel;
  30. import javax.swing.JTextField;
  31. import javax.swing.SwingConstants;
  32. import javax.swing.WindowConstants;
  33.  
  34. import org.rsbot.event.events.ServerMessageEvent;
  35. import org.rsbot.event.listeners.PaintListener;
  36. import org.rsbot.event.listeners.ServerMessageListener;
  37. import org.rsbot.script.Script;
  38. import org.rsbot.script.ScriptManifest;
  39. import org.rsbot.script.methods.Skills;
  40. import org.rsbot.script.wrappers.GEItemInfo;
  41. import org.rsbot.script.wrappers.RSObject;
  42. import org.rsbot.script.wrappers.RSTile;
  43. import org.rsbot.util.GlobalConfiguration;
  44.  
  45. @ScriptManifest(authors = { "Taha" }, keywords = { "Smart", "Smelt", "Smelter",
  46. "Taha" }, name = "Smart Smelter", description = "Smelts all bars at most locations.", version = 3.01)
  47. public class SmartSmelter extends Script implements PaintListener,
  48. ServerMessageListener {
  49.  
  50. private boolean start, runScript, shutDown;
  51. private String bar, state = "Loading";
  52. private RSTile[] toBank, toFurnace;
  53. private int primaryOreID, secondaryOreID,
  54. numberOfPrimaryOresNeededForSmelting,
  55. numberOfSecondaryOresNeededForSmelting,
  56. numberOfPrimaryOresNeededForWithdrawal, numberToSmelt,
  57. furnaceObjectID, primaryChild, copperOreID = 436, tinOreID = 438,
  58. ironOreID = 440, silverOreID = 442, coalOreID = 453,
  59. goldOreID = 444, mithrilOreID = 447, adamantOreID = 449,
  60. runeOreID = 451, oreSelectionInterface = 916, startLvl, startExp,
  61. barsSmelted, nextStep = 18;
  62. private GEItemInfo profitPerBar;
  63. private long startTime;
  64.  
  65. protected int getMouseSpeed() {
  66. return random(6, 11);
  67. }
  68.  
  69. private enum State {
  70. BANK, SMELT, WALK_TO_BANK, WALK_TO_FURNACE, TOGGLE_RUN, WAIT, STOP, OPEN_DOOR
  71. }
  72.  
  73. private State getState() {
  74. if (barsSmelted >= numberToSmelt) {
  75. return State.STOP;
  76. } else if ((walking.getEnergy() > 40 && random(0, 5) == 0 || walking
  77. .getEnergy() > 80)
  78. && !bank.isOpen()
  79. && !walking.isRunEnabled()
  80. && !interfaces.get(oreSelectionInterface).isValid()) {
  81. return State.TOGGLE_RUN;
  82. } else if (objects.getNearest(5244) != null
  83. && calc.tileOnScreen(objects.getNearest(5244).getLocation())) {
  84. return State.OPEN_DOOR;
  85. } else if (inventory.getCount(primaryOreID) >= numberOfPrimaryOresNeededForSmelting
  86. && inventory.getCount(secondaryOreID) >= numberOfSecondaryOresNeededForSmelting
  87. && calc.distanceTo(toBank[0]) > 3) {
  88. return State.WALK_TO_FURNACE;
  89. } else if (calc.distanceTo(toFurnace[0]) > 5
  90. && (inventory.getCount(primaryOreID) < numberOfPrimaryOresNeededForSmelting || inventory
  91. .getCount(secondaryOreID) < numberOfSecondaryOresNeededForSmelting)) {
  92. return State.WALK_TO_BANK;
  93. } else if (inventory.getCount(primaryOreID) < numberOfPrimaryOresNeededForSmelting
  94. || inventory.getCount(secondaryOreID) < numberOfSecondaryOresNeededForSmelting) {
  95. return State.BANK;
  96. } else if (!isSmelting()) {
  97. return State.SMELT;
  98. } else {
  99. return State.WAIT;
  100. }
  101. }
  102.  
  103. public boolean onStart() {
  104. new SmartSmelterGUI().setVisible(true);
  105. while (!start) {
  106. sleep(100);
  107. }
  108. startTime = System.currentTimeMillis();
  109. return runScript;
  110. }
  111.  
  112. public int loop() {
  113. try {
  114. if (game.isLoggedIn()) {
  115. camera.setPitch(true);
  116. switch (getState()) {
  117. case TOGGLE_RUN:
  118. state = "Enabling Run Mode";
  119. walking.setRun(true);
  120. break;
  121.  
  122. case BANK:
  123. state = "Banking";
  124. if (!bank.isOpen()) {
  125. bank.open();
  126. sleep(random(500, 1000));
  127. } else {
  128. if (inventory.getCountExcept(primaryOreID,
  129. secondaryOreID) > 0) {
  130. bank.depositAll();
  131. sleep(random(200, 400));
  132. }
  133. if (inventory.getCount(primaryOreID) > numberOfPrimaryOresNeededForWithdrawal) {
  134. bank.deposit(
  135. primaryOreID,
  136. inventory.getCount(primaryOreID)
  137. - numberOfPrimaryOresNeededForWithdrawal);
  138. }
  139. if (inventory.getCount(secondaryOreID) > (28 - numberOfPrimaryOresNeededForWithdrawal)) {
  140. bank.deposit(
  141. secondaryOreID,
  142. inventory.getCount(secondaryOreID)
  143. - (28 - numberOfPrimaryOresNeededForWithdrawal));
  144. }
  145. if (!bankContainsEnoughOres()) {
  146. log("Not enough ores!");
  147. bank.close();
  148. stopScript();
  149. return -1;
  150. }
  151. if (inventory.getCount(primaryOreID) < oresToWithdraw()
  152. && bankContainsEnoughOres()) {
  153. bank.withdraw(primaryOreID, oresToWithdraw()
  154. - inventory.getCount(primaryOreID));
  155. }
  156. if (!bar.equals("Iron") && !bar.equals("Silver")
  157. && !bar.equals("Gold")
  158. && inventory.getCount(primaryOreID) > 0) {
  159. bank.withdraw(secondaryOreID, 0);
  160. }
  161. sleep(random(200, 400));
  162. }
  163. break;
  164.  
  165. case SMELT:
  166. state = "Smelting";
  167. RSObject furnace = objects.getNearest(furnaceObjectID);
  168. if (furnace != null) {
  169. if (!calc.tileOnScreen(furnace.getLocation())) {
  170. int t = 0;
  171. while (t < 6) {
  172. camera.turnToTile(furnace.getLocation());
  173. if (calc.tileOnScreen(furnace.getLocation())) {
  174. break;
  175. } else {
  176. t++;
  177. }
  178. }
  179. if (t > 5) {
  180. while (step(toFurnace) != toFurnace.length) {
  181. sleep(50, 100);
  182. }
  183. }
  184. }
  185. if (!interfaces.get(oreSelectionInterface).isValid()) {
  186. furnace.doAction("Smelt");
  187. sleep(random(25, 50));
  188. }
  189. if (interfaces.get(oreSelectionInterface).isValid()) {
  190. while (!interfaces
  191. .getComponent(oreSelectionInterface, 17)
  192. .getText().equals("All")) {
  193. interfaces.getComponent(oreSelectionInterface,
  194. 19).doAction("+1");
  195. sleep(random(50, 100));
  196. }
  197. interfaces.getComponent(905, primaryChild)
  198. .doAction("Make all");
  199. }
  200. }
  201. break;
  202.  
  203. case WALK_TO_BANK:
  204. state = "Walking to Bank";
  205. while (step(toBank) != toBank.length) {
  206. sleep(100, 200);
  207. }
  208. break;
  209.  
  210. case WALK_TO_FURNACE:
  211. state = "Walking to Furnace";
  212. while (step(toFurnace) != toFurnace.length) {
  213. sleep(100, 200);
  214. }
  215. break;
  216.  
  217. case OPEN_DOOR:
  218. state = "Opening Door";
  219. objects.getNearest(5244).doAction("Open");
  220. return random(1200, 1400);
  221.  
  222. case WAIT:
  223. state = "Waiting";
  224. break;
  225.  
  226. case STOP:
  227. stopScript();
  228. return -1;
  229. }
  230. }
  231. } catch (Exception e) {
  232. e.printStackTrace();
  233. }
  234. return random(300, 400);
  235. }
  236.  
  237. public void onFinish() {
  238. log("Gained: " + (skills.getCurrentLevel(Skills.SMITHING) - startLvl)
  239. + " Smithing Levels");
  240. log.info("Profit: " + barsSmelted * profitPerBar.getMarketPrice()
  241. + " GP");
  242. if (shutDown) {
  243. try {
  244. Runtime.getRuntime()
  245. .exec("shutdown -s -t 120 -c \"Smart Smelter automatic shutdown has initiliazed. Please wait 120 seconds...\"");
  246. } catch (IOException e) {
  247. e.printStackTrace();
  248. }
  249. }
  250. }
  251.  
  252. private int oresToWithdraw() {
  253. return numberToSmelt - barsSmelted > numberOfPrimaryOresNeededForWithdrawal ? numberOfPrimaryOresNeededForWithdrawal
  254. : numberToSmelt - barsSmelted;
  255. }
  256.  
  257. private boolean bankContainsEnoughOres() {
  258. if (bank.isOpen()
  259. && bank.getCount(primaryOreID)
  260. + inventory.getCount(primaryOreID) >= numberOfPrimaryOresNeededForSmelting
  261. && bank.getCount(secondaryOreID)
  262. + inventory.getCount(secondaryOreID) >= numberOfSecondaryOresNeededForSmelting) {
  263. return true;
  264. }
  265. return false;
  266. }
  267.  
  268. private boolean isSmelting() {
  269. for (int i = 0; i < 8; i++) {
  270. if (inventory.getCount(primaryOreID) < numberOfPrimaryOresNeededForSmelting
  271. || inventory.getCount(secondaryOreID) < numberOfSecondaryOresNeededForSmelting) {
  272. return false;
  273. } else if (getMyPlayer().getAnimation() == 3243) {
  274. return true;
  275. }
  276. sleep(250);
  277. }
  278. return false;
  279. }
  280.  
  281. public void serverMessageRecieved(ServerMessageEvent e) {
  282. if (e.getMessage().contains("You retrieve a bar of")) {
  283. barsSmelted++;
  284. }
  285. if (e.getMessage().contains("magic of the Varrock armour")) {
  286. barsSmelted++;
  287. }
  288. if (e.getMessage().contains("members' server to use this furnace")) {
  289. log("Use a F2P furnace!");
  290. stopScript();
  291. }
  292. }
  293.  
  294. public void onRepaint(Graphics g) {
  295. if (game.isLoggedIn()) {
  296. long runTime = System.currentTimeMillis() - startTime;
  297. int seconds = (int) (runTime / 1000 % 60);
  298. int minutes = (int) (runTime / 1000 / 60) % 60;
  299. int hours = (int) (runTime / 1000 / 60 / 60) % 60;
  300.  
  301. StringBuilder b = new StringBuilder();
  302. if (hours < 10) {
  303. b.append('0');
  304. }
  305. b.append(hours);
  306. b.append(':');
  307. if (minutes < 10) {
  308. b.append('0');
  309. }
  310. b.append(minutes);
  311. b.append(':');
  312. if (seconds < 10) {
  313. b.append('0');
  314. }
  315. b.append(seconds);
  316.  
  317. if (startLvl <= 0 || startExp <= 0) {
  318. startLvl = skills.getCurrentLevel(Skills.SMITHING);
  319. startExp = skills.getCurrentExp(Skills.SMITHING);
  320. }
  321.  
  322. int x = 294;
  323. int y = 4;
  324. int xl = 222;
  325. int yl = 85;
  326.  
  327. g.setColor(new Color(0, 0, 0, 120));
  328. g.fillRect(x, y, xl, yl);
  329. g.setColor(new Color(248, 237, 22));
  330. g.drawRect(x, y, xl, yl);
  331.  
  332. g.setFont(new Font("Comic Sans MS", Font.PLAIN, 12));
  333. g.drawString(getClass().getAnnotation(ScriptManifest.class).name()
  334. + " v"
  335. + getClass().getAnnotation(ScriptManifest.class).version(),
  336. x + 10, y += 15);
  337. g.drawString(
  338. "Gained: "
  339. + (skills.getCurrentExp(Skills.SMITHING) - startExp < 1000 ? skills
  340. .getCurrentExp(Skills.SMITHING) - startExp
  341. : Math.round((skills
  342. .getCurrentExp(Skills.SMITHING) - startExp) * 10) / 10)
  343. + " Exp"
  344. + " || Exp/Hour: "
  345. + (int) ((skills.getCurrentExp(Skills.SMITHING) - startExp) * 3600000D / ((double) System
  346. .currentTimeMillis() - (double) startTime)),
  347. x + 10, y += 15);
  348. g.drawString("Smelted: " + barsSmelted + " " + bar + " Bars",
  349. x + 10, y += 15);
  350. g.drawString("Time Running: " + b, x + 10, y += 15);
  351. g.drawString("Current State: ", x + 10, y += 15);
  352. g.setColor(Color.RED);
  353. g.drawString(state, x + 95, y);
  354. }
  355. }
  356.  
  357. private boolean tileInNextRange(RSTile t) {
  358. return calc.distanceBetween(t, getMyPlayer().getLocation()) < nextStep;
  359. }
  360.  
  361. private int step(RSTile[] path) {
  362. if (calc.distanceTo(path[path.length - 1]) < 3
  363. || (walking.getDestination() != null && calc.distanceBetween(
  364. walking.getDestination(), path[path.length - 1]) < 3)) {
  365. return path.length;
  366. }
  367. RSTile dest = walking.getDestination();
  368. int index = -1;
  369. int shortestDist = 0, dist, shortest = -1;
  370. if (dest != null)
  371. for (int i = 0; i < path.length; i++) {
  372. dist = (int) calc.distanceBetween(path[i], dest);
  373. if (shortest < 0 || shortestDist > dist) {
  374. shortest = i;
  375. shortestDist = dist;
  376. }
  377. }
  378. for (int i = path.length - 1; i >= 0; i--)
  379. if (tileInNextRange(path[i])) {
  380. index = i;
  381. break;
  382. }
  383. if (index != -1
  384. && (dest == null || (index > shortest) || !getMyPlayer()
  385. .isMoving())) {
  386. walking.walkTileMM(path[index]);
  387. nextStep = random(16, 19);
  388. return index;
  389. }
  390. return -1;
  391. }
  392.  
  393. private class SmartSmelterGUI extends JFrame {
  394. private File settingsFile = new File(new File(
  395. GlobalConfiguration.Paths.getSettingsDirectory()),
  396. "SmartSmelterSettings.txt");
  397.  
  398. private static final long serialVersionUID = 1L;
  399.  
  400. // GEN-BEGIN:variables
  401. private JLabel label1;
  402. private JPanel buttonPanel;
  403. private JButton startButton;
  404. private JButton exitButton;
  405. private JPanel panel1;
  406. private JLabel label14;
  407. private JComboBox locComboBox;
  408. private JLabel label3;
  409. private JComboBox barComboBox;
  410. private JLabel label4;
  411. private JTextField numberTextField;
  412. private JCheckBox shutDownCheckBox;
  413. private JEditorPane description;
  414.  
  415. // GEN-END:variables
  416. private SmartSmelterGUI() {
  417. initComponents();
  418. description.setEditable(false);
  419. }
  420.  
  421. private void barComboBoxActionPerformed(final ActionEvent e) {
  422. updateDescription();
  423. }
  424.  
  425. private void exitButtonActionPerformed(final ActionEvent e) {
  426. if (exitButton.getText().equals("Exit!")) {
  427. dispose();
  428. runScript = false;
  429. start = true;
  430. } else {
  431. stopScript();
  432. dispose();
  433. }
  434. }
  435.  
  436. private void initComponents() {
  437. // GEN-BEGIN:initComponents
  438. label1 = new JLabel();
  439. buttonPanel = new JPanel();
  440. startButton = new JButton();
  441. exitButton = new JButton();
  442. panel1 = new JPanel();
  443. label14 = new JLabel();
  444. locComboBox = new JComboBox();
  445. label3 = new JLabel();
  446. barComboBox = new JComboBox();
  447. label4 = new JLabel();
  448. numberTextField = new JTextField();
  449. shutDownCheckBox = new JCheckBox();
  450. description = new JEditorPane();
  451.  
  452. // ======== this ========
  453. setTitle("Smart Smelter Script Options");
  454. setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  455. final Container contentPane = getContentPane();
  456. contentPane.setLayout(new BorderLayout(0, 5));
  457. addWindowListener(new WindowAdapter() {
  458. public void windowClosing(final WindowEvent ev) {
  459. if (exitButton.getText().equals("Exit!")) {
  460. dispose();
  461. start = true;
  462. } else {
  463. setVisible(false);
  464. }
  465. }
  466. });
  467.  
  468. // ---- label1 ----
  469. label1.setText("Smart Smelter Script Options");
  470. label1.setFont(new Font("Century Gothic", Font.PLAIN, 22));
  471. label1.setHorizontalAlignment(SwingConstants.CENTER);
  472. contentPane.add(label1, BorderLayout.NORTH);
  473.  
  474. // ======== buttonPanel ========
  475. {
  476. buttonPanel.setLayout(new GridBagLayout());
  477. ((GridBagLayout) buttonPanel.getLayout()).columnWidths = new int[] {
  478. 90, 85 };
  479. ((GridBagLayout) buttonPanel.getLayout()).rowHeights = new int[] {
  480. 3, 0 };
  481. ((GridBagLayout) buttonPanel.getLayout()).rowWeights = new double[] {
  482. 1.0, 1.0E-4 };
  483.  
  484. // ---- startButton ----
  485. startButton.setText("Start!");
  486. startButton.setFont(new Font("Comic Sans MS", Font.PLAIN, 12));
  487. startButton.setFocusable(false);
  488. startButton.addActionListener(new ActionListener() {
  489. public void actionPerformed(final ActionEvent e) {
  490. startButtonActionPerformed(e);
  491. }
  492. });
  493. buttonPanel.add(startButton, new GridBagConstraints(0, 0, 1, 1,
  494. 0.0, 0.0, GridBagConstraints.CENTER,
  495. GridBagConstraints.BOTH, new Insets(0, 0, 0, 5), 0, 0));
  496.  
  497. // ---- exitButton ----
  498. exitButton.setText("Exit!");
  499. exitButton.setFont(new Font("Comic Sans MS", Font.PLAIN, 12));
  500. exitButton.setFocusable(false);
  501. exitButton.addActionListener(new ActionListener() {
  502. public void actionPerformed(final ActionEvent e) {
  503. exitButtonActionPerformed(e);
  504. }
  505. });
  506. buttonPanel.add(exitButton, new GridBagConstraints(1, 0, 1, 1,
  507. 0.0, 0.0, GridBagConstraints.CENTER,
  508. GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  509. }
  510. contentPane.add(buttonPanel, BorderLayout.SOUTH);
  511.  
  512. // ======== panel1 ========
  513. {
  514. panel1.setFocusable(false);
  515. panel1.setLayout(new GridBagLayout());
  516. ((GridBagLayout) panel1.getLayout()).columnWidths = new int[] {
  517. 47, 139, 35, 33, 0 };
  518. ((GridBagLayout) panel1.getLayout()).rowHeights = new int[] {
  519. 18, 10, 18, 16, 34, 0, 0 };
  520. ((GridBagLayout) panel1.getLayout()).columnWeights = new double[] {
  521. 0.0, 0.0, 0.0, 1.0, 1.0E-4 };
  522. ((GridBagLayout) panel1.getLayout()).rowWeights = new double[] {
  523. 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0E-4 };
  524.  
  525. // ---- label14 ----
  526. label14.setText("Location:");
  527. label14.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));
  528. label14.setHorizontalAlignment(SwingConstants.RIGHT);
  529. panel1.add(label14, new GridBagConstraints(0, 0, 2, 1, 0.0,
  530. 0.0, GridBagConstraints.CENTER,
  531. GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  532.  
  533. // ---- locComboBox ----
  534. locComboBox.setFont(new Font("Comic Sans MS", Font.PLAIN, 12));
  535. locComboBox.setFocusable(false);
  536. locComboBox.setModel(new DefaultComboBoxModel(new String[] {
  537. "Falador", "Al Kharid", "Edgeville" }));
  538. panel1.add(locComboBox, new GridBagConstraints(3, 0, 1, 1, 0.0,
  539. 0.0, GridBagConstraints.CENTER,
  540. GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  541.  
  542. // ---- label3 ----
  543. label3.setHorizontalAlignment(SwingConstants.RIGHT);
  544. label3.setText("Bar:");
  545. label3.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));
  546. panel1.add(label3, new GridBagConstraints(0, 1, 2, 1, 0.0, 0.0,
  547. GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  548. new Insets(0, 0, 0, 0), 0, 0));
  549.  
  550. // ---- barComboBox ----
  551. barComboBox.setFocusable(false);
  552. barComboBox.setModel(new DefaultComboBoxModel(new String[] {
  553. "Bronze", "Iron", "Silver", "Steel", "Gold", "Mithril",
  554. "Adamant", "Rune" }));
  555. barComboBox.setFont(new Font("Comic Sans MS", Font.PLAIN, 12));
  556. barComboBox.addActionListener(new ActionListener() {
  557. public void actionPerformed(final ActionEvent e) {
  558. barComboBoxActionPerformed(e);
  559. }
  560. });
  561. panel1.add(barComboBox, new GridBagConstraints(3, 1, 1, 1, 0.0,
  562. 0.0, GridBagConstraints.CENTER,
  563. GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  564.  
  565. // ---- label4 ----
  566. label4.setText("Numbers of bars to smelt:");
  567. label4.setHorizontalAlignment(SwingConstants.RIGHT);
  568. label4.setFont(new Font("Comic Sans MS", Font.PLAIN, 14));
  569. panel1.add(label4, new GridBagConstraints(0, 2, 2, 1, 0.0, 0.0,
  570. GridBagConstraints.CENTER, GridBagConstraints.BOTH,
  571. new Insets(0, 0, 0, 0), 0, 0));
  572.  
  573. // ---- numberTextField ----
  574. numberTextField.setFont(new Font("Comic Sans MS", Font.PLAIN,
  575. 12));
  576. numberTextField.setText("100");
  577. numberTextField.addKeyListener(new KeyAdapter() {
  578. public void keyTyped(final KeyEvent e) {
  579. numberTextFieldKeyTyped(e);
  580. }
  581.  
  582. public void keyReleased(final KeyEvent e) {
  583. numberTextFieldKeyReleased(e);
  584. }
  585. });
  586. panel1.add(numberTextField, new GridBagConstraints(3, 2, 1, 1,
  587. 0.0, 0.0, GridBagConstraints.CENTER,
  588. GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  589.  
  590. // ---- shutDownCheckBox ----
  591. shutDownCheckBox.setText("Turn off the computer when finished");
  592. shutDownCheckBox.setFont(new Font("Comic Sans MS", Font.PLAIN,
  593. 12));
  594. shutDownCheckBox.setFocusable(false);
  595. shutDownCheckBox.addActionListener(new ActionListener() {
  596. public void actionPerformed(final ActionEvent e) {
  597. shutDownCheckBoxActionPerformed(e);
  598. }
  599. });
  600. panel1.add(shutDownCheckBox, new GridBagConstraints(1, 4, 3, 1,
  601. 0.0, 0.0, GridBagConstraints.CENTER,
  602. GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  603.  
  604. // ---- description ----
  605. description.setBorder(null);
  606. description.setOpaque(false);
  607. description.setFont(new Font("Comic Sans MS", Font.PLAIN, 12));
  608. panel1.add(description, new GridBagConstraints(0, 5, 4, 1, 0.0,
  609. 0.0, GridBagConstraints.CENTER,
  610. GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
  611. }
  612.  
  613. contentPane.add(panel1, BorderLayout.CENTER);
  614. setSize(400, 300);
  615. setLocationRelativeTo(getOwner());
  616. // FINAL TOUCHES
  617. try {
  618. settingsFile.createNewFile();
  619. BufferedReader in;
  620. in = new BufferedReader(new FileReader(settingsFile));
  621. String line;
  622. String[] opts = {};
  623. while ((line = in.readLine()) != null) {
  624. if (line.contains(":")) {
  625. opts = line.split(":");
  626. }
  627. }
  628. in.close();
  629. if (opts.length == 4) {
  630. locComboBox.setSelectedItem(opts[0]);
  631. barComboBox.setSelectedItem(opts[1]);
  632. numberTextField.setText(opts[2]);
  633. if (opts[3].equals("true")) {
  634. shutDownCheckBox.setSelected(true);
  635. }
  636. }
  637. } catch (final IOException ignored) {
  638. }
  639. updateDescription();
  640. // GEN-END:initComponents
  641. }
  642.  
  643. private void numberTextFieldKeyTyped(final KeyEvent e) {
  644. if (e.getKeyChar() != '0' && e.getKeyChar() != '1'
  645. && e.getKeyChar() != '2' && e.getKeyChar() != '3'
  646. && e.getKeyChar() != '4' && e.getKeyChar() != '5'
  647. && e.getKeyChar() != '6' && e.getKeyChar() != '7'
  648. && e.getKeyChar() != '8' && e.getKeyChar() != '9'
  649. || numberTextField.getText().length() >= 6) {
  650. e.consume();
  651. }
  652. }
  653.  
  654. private void numberTextFieldKeyReleased(final KeyEvent e) {
  655. updateDescription();
  656. }
  657.  
  658. private void shutDownCheckBoxActionPerformed(final ActionEvent e) {
  659. updateDescription();
  660. }
  661.  
  662. private void startButtonActionPerformed(final ActionEvent e) {
  663. setVisible(false);
  664. bar = barComboBox.getSelectedItem().toString();
  665. numberToSmelt = Integer.parseInt(numberTextField.getText());
  666. shutDown = shutDownCheckBox.isSelected();
  667. if (locComboBox.getSelectedItem().toString().equals("Falador")) {
  668. toFurnace = new RSTile[] { new RSTile(2945, 3368),
  669. new RSTile(2945, 3371), new RSTile(2946, 3375),
  670. new RSTile(2949, 3376), new RSTile(2952, 3378),
  671. new RSTile(2954, 3379), new RSTile(2957, 3379),
  672. new RSTile(2960, 3379), new RSTile(2962, 3379),
  673. new RSTile(2965, 3379), new RSTile(2968, 3379),
  674. new RSTile(2970, 3378), new RSTile(2971, 3376),
  675. new RSTile(2972, 3374), new RSTile(2973, 3372),
  676. new RSTile(2973, 3370) };
  677. toBank = walking.reversePath(toFurnace);
  678. furnaceObjectID = 11666;
  679. }
  680. if (locComboBox.getSelectedItem().toString().equals("Al Kharid")) {
  681. toFurnace = new RSTile[] { new RSTile(3269, 3167),
  682. new RSTile(3271, 3167), new RSTile(3273, 3167),
  683. new RSTile(3275, 3168), new RSTile(3276, 3170),
  684. new RSTile(3276, 3173), new RSTile(3277, 3175),
  685. new RSTile(3278, 3178), new RSTile(3279, 3181),
  686. new RSTile(3281, 3183), new RSTile(3280, 3185),
  687. new RSTile(3276, 3186) };
  688. toBank = walking.reversePath(toFurnace);
  689. furnaceObjectID = 11666;
  690. }
  691. if (locComboBox.getSelectedItem().toString().equals("Edgeville")) {
  692. toFurnace = new RSTile[] { new RSTile(3097, 3495),
  693. new RSTile(3109, 3501) };
  694. toBank = walking.reversePath(toFurnace);
  695. furnaceObjectID = 26814;
  696. }
  697. if (bar.equals("Bronze")) {
  698. primaryOreID = copperOreID;
  699. secondaryOreID = tinOreID;
  700. numberOfPrimaryOresNeededForSmelting = 1;
  701. numberOfSecondaryOresNeededForSmelting = 1;
  702. numberOfPrimaryOresNeededForWithdrawal = 14;
  703. primaryChild = 14;
  704. profitPerBar = grandExchange.loadItemInfo(2349);
  705. }
  706. if (bar.equals("Iron")) {
  707. primaryOreID = ironOreID;
  708. numberOfPrimaryOresNeededForSmelting = 1;
  709. numberOfPrimaryOresNeededForWithdrawal = 28;
  710. primaryChild = 16;
  711. profitPerBar = grandExchange.loadItemInfo(2351);
  712. }
  713. if (bar.equals("Silver")) {
  714. primaryOreID = silverOreID;
  715. numberOfPrimaryOresNeededForSmelting = 1;
  716. numberOfPrimaryOresNeededForWithdrawal = 28;
  717. primaryChild = 17;
  718. profitPerBar = grandExchange.loadItemInfo(2355);
  719. }
  720. if (bar.equals("Steel")) {
  721. primaryOreID = ironOreID;
  722. secondaryOreID = coalOreID;
  723. numberOfPrimaryOresNeededForSmelting = 1;
  724. numberOfSecondaryOresNeededForSmelting = 2;
  725. numberOfPrimaryOresNeededForWithdrawal = 10;
  726. primaryChild = 18;
  727. profitPerBar = grandExchange.loadItemInfo(2353);
  728. }
  729. if (bar.equals("Gold")) {
  730. primaryOreID = goldOreID;
  731. numberOfPrimaryOresNeededForSmelting = 1;
  732. numberOfPrimaryOresNeededForWithdrawal = 28;
  733. primaryChild = 19;
  734. profitPerBar = grandExchange.loadItemInfo(2357);
  735. }
  736. if (bar.equals("Mithril")) {
  737. primaryOreID = mithrilOreID;
  738. secondaryOreID = coalOreID;
  739. numberOfPrimaryOresNeededForSmelting = 1;
  740. numberOfSecondaryOresNeededForSmelting = 4;
  741. numberOfPrimaryOresNeededForWithdrawal = 5;
  742. primaryChild = 20;
  743. profitPerBar = grandExchange.loadItemInfo(2359);
  744. }
  745. if (bar.equals("Adamant")) {
  746. primaryOreID = adamantOreID;
  747. secondaryOreID = coalOreID;
  748. numberOfPrimaryOresNeededForSmelting = 1;
  749. numberOfSecondaryOresNeededForSmelting = 6;
  750. numberOfPrimaryOresNeededForWithdrawal = 4;
  751. primaryChild = 21;
  752. profitPerBar = grandExchange.loadItemInfo(2361);
  753. }
  754. if (bar.equals("Rune")) {
  755. primaryOreID = runeOreID;
  756. secondaryOreID = coalOreID;
  757. numberOfPrimaryOresNeededForSmelting = 1;
  758. numberOfSecondaryOresNeededForSmelting = 8;
  759. numberOfPrimaryOresNeededForWithdrawal = 3;
  760. primaryChild = 22;
  761. profitPerBar = grandExchange.loadItemInfo(2363);
  762. }
  763. try {
  764. final BufferedWriter out = new BufferedWriter(new FileWriter(
  765. settingsFile));
  766. out.write(locComboBox.getSelectedItem().toString() + ":"
  767. + barComboBox.getSelectedItem().toString() + ":"
  768. + Integer.parseInt(numberTextField.getText()) + ":"
  769. + (shutDownCheckBox.isSelected() ? "true" : "false"));
  770. out.close();
  771. } catch (final Exception z) {
  772. z.printStackTrace();
  773. }
  774.  
  775. start = true;
  776. runScript = true;
  777. }
  778.  
  779. private void updateDescription() {
  780. final String loc = locComboBox.getSelectedItem().toString();
  781. if (shutDownCheckBox.isSelected()) {
  782. description
  783. .setText("You will be smelting "
  784. + numberTextField.getText()
  785. + " "
  786. + barComboBox.getSelectedItem().toString()
  787. .toLowerCase()
  788. + " bars at "
  789. + loc
  790. + ". Your computer will shutdown itself when the task is finished.");
  791. } else {
  792. description.setText("You will be smelting "
  793. + numberTextField.getText()
  794. + " "
  795. + barComboBox.getSelectedItem().toString()
  796. .toLowerCase() + " bars at " + loc + ".");
  797. }
  798. }
  799. }
  800.  
  801. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement