Advertisement
Guest User

Untitled

a guest
Aug 11th, 2014
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.86 KB | None | 0 0
  1. package scripts.wbSteelBars;
  2.  
  3. import org.tribot.api.General;
  4. import org.tribot.api.Timing;
  5. import org.tribot.api.input.Keyboard;
  6. import org.tribot.api.input.Mouse;
  7. import org.tribot.api.rs3.ItemCreation;
  8. import org.tribot.api2007.Banking;
  9. import org.tribot.api2007.Equipment;
  10. import org.tribot.api2007.Game;
  11. import org.tribot.api2007.Interfaces;
  12. import org.tribot.api2007.Inventory;
  13. import org.tribot.api2007.Login;
  14. import org.tribot.api2007.Magic;
  15. import org.tribot.api2007.Objects;
  16. import org.tribot.api2007.Options;
  17. import org.tribot.api2007.Player;
  18. import org.tribot.api2007.Skills.*;
  19. import org.tribot.api2007.Walking;
  20. import org.tribot.api2007.types.*;
  21. import org.tribot.script.Script;
  22. import org.tribot.script.ScriptManifest;
  23. import org.tribot.script.interfaces.*;
  24.  
  25. import java.awt.*;
  26.  
  27. import javax.imageio.ImageIO;
  28.  
  29. import java.io.IOException;
  30. import java.net.URL;
  31. import java.text.DecimalFormat;
  32. import java.text.NumberFormat;
  33.  
  34. @ScriptManifest(authors = { "WillB" }, category = "Smithing", name = "wbSmelterAIO")
  35. public class wbSmelterAIO extends Script implements MessageListening07,
  36. Painting {
  37.  
  38. // *****RSTiles*****//
  39. private final RSTile[] pathToFurnace = new RSTile[] {
  40. new RSTile(3270, 3166, 0), new RSTile(3276, 3174, 0),
  41. new RSTile(3281, 3183, 0), new RSTile(3280, 3186, 0),
  42. new RSTile(3277, 3186, 0) };
  43.  
  44. private final RSTile[] pathToPortFurnace = new RSTile[] {
  45. new RSTile(3689, 3468, 0), new RSTile(3687, 3478, 0),
  46. new RSTile(3687, 3479, 0) };
  47.  
  48. // *****RSAreas*****//
  49. private final RSArea alKharidBankArea = new RSArea(
  50. new RSTile(3265, 3174, 0), new RSTile(3273, 3160, 0));
  51.  
  52. private final RSArea alKharidFurnaceArea = new RSArea(new RSTile(3280,
  53. 3184, 0), new RSTile(3271, 3190, 0));
  54.  
  55. private final RSArea portFurnaceArea = new RSArea(
  56. new RSTile(3690, 3482, 0), new RSTile(3681, 4376, 0));
  57.  
  58. private final RSArea portBankArea = new RSArea(new RSTile(3685, 3472, 0),
  59. new RSTile(3695, 3461, 0));
  60.  
  61. // *****Strings*****//
  62.  
  63. private String status;
  64.  
  65. // *****Integers*****//
  66. private int barsSmelted;
  67.  
  68. private final int startSmithingXp = SKILLS.SMITHING.getXP();
  69.  
  70. // *****Enums*****//
  71. public enum State {
  72. BANKING, SMITHING, SMELTING
  73. };
  74.  
  75. private long startTime;
  76.  
  77. GUI gui = new GUI();
  78.  
  79. @Override
  80. public void run() {
  81.  
  82. startTime = System.currentTimeMillis();
  83.  
  84. status = "Starting";
  85.  
  86. gui.setVisible(true);
  87.  
  88. while (!UserVariables.running) {
  89. sleep(General.random(300, 500));
  90. }
  91.  
  92. while (UserVariables.running) {
  93. Mouse.setSpeed(UserVariables.mouseSpeed);
  94. sleep(loop());
  95. }
  96. }
  97.  
  98. public int loop() {
  99.  
  100. switch (getState()) {
  101.  
  102. case SMELTING:
  103.  
  104. if (inFurnaceArea()) {
  105.  
  106. smeltBars();
  107. } else {
  108.  
  109. walkPathToFurnace();
  110. }
  111.  
  112. break;
  113.  
  114. case BANKING:
  115.  
  116. if (inBankArea()) {
  117.  
  118. bank();
  119. } else {
  120.  
  121. walkPathToBank();
  122. }
  123.  
  124. break;
  125.  
  126. case SMITHING:
  127.  
  128. // performIdleAB();
  129.  
  130. break;
  131. }
  132.  
  133. return 100;
  134. }
  135.  
  136. /*
  137. *
  138. * Smelts the ores into steel bars
  139. */
  140. private void smeltBars() {
  141. RSObject[] furnace = Objects.find(6, new int[] {1,2,3});
  142. RSInterface smeltInterface = Interfaces.get(311, UserVariables.childID);
  143.  
  144. status = "Smelting bars";
  145.  
  146. if (smeltInterface != null) {
  147.  
  148. smeltInterface.click("Smelt x");
  149. sleep(1000, 1500);
  150.  
  151. if (Interfaces.get(548, 94) != null) {
  152.  
  153. Keyboard.typeSend(String.valueOf(General.random(28, 999)));
  154. sleep(1000);
  155. for (int i = 0; i < 200; i++) {
  156. if (Player.getAnimation() != -1) {
  157. Mouse.leaveGame(true);
  158. i = 0;
  159. }
  160. if (Inventory.getCount(UserVariables.barName) <= 0) {
  161. break;
  162. }
  163. sleep(20, 30);
  164. }
  165. sleep(1000);
  166. }
  167. } else {
  168.  
  169. if (furnace.length > 0 && furnace[0] != null) {
  170.  
  171. furnace[0].click("Smelt");
  172. sleep(300, 500);
  173. while (Player.isMoving()) {
  174. sleep(100);
  175.  
  176. }
  177. }
  178. }
  179. }
  180.  
  181. /*
  182. *
  183. * Walks to the bank
  184. */
  185. private void walkPathToBank() {
  186. RSTile[] pathToBank = Walking.invertPath(getPath());
  187. status = "Walking to bank";
  188. while (!inBankArea()) {
  189. Walking.walkPath(pathToBank);
  190. if (Game.getRunEnergy() > 10)
  191. Options.setRunOn(true);
  192. sleep(50, 100);
  193. }
  194. }
  195.  
  196. /*
  197. *
  198. * Walks to the furnace
  199. */
  200. private void walkPathToFurnace() {
  201. status = "Walking to furnace";
  202. while (!inFurnaceArea()) {
  203. Walking.walkPath(getPath());
  204. sleep(50, 100);
  205. }
  206.  
  207. }
  208.  
  209. /*
  210. *
  211. * Returns the path to bankis dependant on which location you chose
  212. */
  213. private RSTile[] getPath() {
  214. if (UserVariables.alKharid) {
  215. return this.pathToFurnace;
  216. } else {
  217. return this.pathToPortFurnace;
  218. }
  219. }
  220.  
  221. /*
  222. *
  223. * Deposit bars and withdraw ores Will get out and equip ROF depending on if
  224. * you chose it or not
  225. */
  226.  
  227. private void bank() {
  228. status = "Banking";
  229. if (Banking.isBankScreenOpen()) {
  230. if (UserVariables.usingRof && isRingOfForgingEquipped()
  231. || !UserVariables.usingRof) {
  232. if (Inventory.getAll().length > 0) {
  233. Banking.depositAll();
  234. }
  235. if (UserVariables.usingTwoOres) {
  236. Banking.withdraw(UserVariables.oreOneWithdrawAmt,
  237. UserVariables.oreOneName);
  238. sleep(200, 400);
  239. Banking.withdraw(UserVariables.oreTwoWithdrawAmt,
  240. UserVariables.oreTwoName);
  241. } else {
  242. Banking.withdraw(UserVariables.oreOneWithdrawAmt,
  243. UserVariables.oreOneName);
  244. sleep(200, 400);
  245. }
  246.  
  247. } else {
  248. if (Inventory.getCount("Ring of forging") == 0) {
  249. if (Inventory.getAll().length > 0) {
  250. Banking.depositAll();
  251. }
  252. sleep(500, 1000);
  253. Banking.withdraw(1, "Ring of forging");
  254. Banking.close();
  255. sleep(300, 1000);
  256. }
  257. if (Inventory.getCount("Ring of forging") >= 1) {
  258.  
  259. Inventory.find("Ring of forging")[0].click();
  260. }
  261. Banking.close();
  262. }
  263. } else {
  264. Banking.openBank();
  265. }
  266. }
  267.  
  268. /*
  269. *
  270. * Checks if we are in the furnace area depends on which location was chosen
  271. */
  272. private boolean inFurnaceArea() {
  273.  
  274. if (UserVariables.alKharid) {
  275. return alKharidFurnaceArea.contains(Player.getPosition());
  276. } else if (UserVariables.port) {
  277. return portFurnaceArea.contains(Player.getPosition());
  278. }
  279. return false;
  280. }
  281.  
  282. /*
  283. *
  284. * Checks if we are in the bank area depends on which location was chosen
  285. */
  286. private boolean inBankArea() {
  287.  
  288. if (UserVariables.alKharid) {
  289. return alKharidBankArea.contains(Player.getPosition());
  290. } else if (UserVariables.port) {
  291. return portBankArea.contains(Player.getPosition());
  292. }
  293. return false;
  294. }
  295.  
  296. private boolean isRingOfForgingEquipped() {
  297. return Equipment.isEquipped("Ring of forging");
  298. }
  299.  
  300. /*
  301. *
  302. * Returns the current state of the script
  303. */
  304. public State getState() {
  305. if (Inventory.getCount(UserVariables.oreOneName) > 0
  306. && !UserVariables.usingTwoOres) {
  307.  
  308. return State.SMELTING;
  309. } else if (UserVariables.usingTwoOres
  310. && Inventory.getCount(UserVariables.oreTwoName) > 0
  311. && Inventory.getCount(UserVariables.oreOneName) >= UserVariables.oreTwoAmmountNeeded) {
  312.  
  313. return State.SMELTING;
  314.  
  315. } else if (Inventory.getCount(UserVariables.oreOneName) == 0) {
  316.  
  317. return State.BANKING;
  318. }
  319. return State.SMITHING;
  320. }
  321.  
  322. // *****Paint*****//
  323.  
  324. private Image getImage(String url) {
  325. try {
  326. return ImageIO.read(new URL(url));
  327. } catch (IOException e) {
  328. return null;
  329. }
  330. }
  331.  
  332. private final Color color1 = new Color(255, 255, 255);
  333.  
  334. private final Font font1 = new Font("Arial", 0, 12);
  335.  
  336. private final Image img1 = getImage("http://i.imgur.com/Ywd4iDu.png");
  337.  
  338. @Override
  339. public void onPaint(Graphics g1) {
  340.  
  341. NumberFormat xpFormat = new DecimalFormat("###,###,###");
  342.  
  343. int currentSmithingLevel = SKILLS.SMITHING.getActualLevel();
  344. int currentSmithingXp = SKILLS.SMITHING.getXP() - startSmithingXp;
  345. int xpHour = (int) ((currentSmithingXp) * 3600000D / (System
  346. .currentTimeMillis() - startTime));
  347. int barsSmeltedHour = (int) ((barsSmelted) * 3600000D / (System
  348. .currentTimeMillis() - startTime));
  349.  
  350. int profitPerBar = UserVariables.profitPerBar;
  351.  
  352. int profitHour = (barsSmeltedHour * profitPerBar);
  353.  
  354. Graphics2D g = (Graphics2D) g1;
  355. g.drawImage(img1, 1, 275, null);
  356. g.setFont(font1);
  357. g.setColor(color1);
  358. g.drawString(getRuntime(), 132, 370);
  359. g.drawString(status, 127, 392);
  360. g.drawString(String.valueOf(barsSmelted + "(" + barsSmeltedHour + ")"),
  361. 146, 415);
  362. g.drawString(String.valueOf(currentSmithingLevel), 150, 437);
  363. g.drawString("" + currentSmithingXp + "(" + xpFormat.format(xpHour)
  364. + ")", 396, 371);
  365. g.drawString(String.valueOf(profitHour), 368, 392);
  366. }
  367.  
  368. /*
  369. *
  370. * Gets the runtime
  371. */
  372. private String getRuntime() {
  373. try {
  374. long millis = System.currentTimeMillis() - startTime;
  375. long hours = millis / (1000 * 60 * 60);
  376. millis -= hours * (1000 * 60 * 60);
  377. long minutes = millis / (1000 * 60);
  378. millis -= minutes * (1000 * 60);
  379. long seconds = millis / 1000;
  380. return ("" + (hours < 10 ? "0" : "") + hours + ":"
  381. + (minutes < 10 ? "0" : "") + minutes + ":"
  382. + (seconds < 10 ? "0" : "") + seconds + "");
  383. } catch (Exception e) {
  384. return "";
  385. }
  386. }
  387.  
  388. // *****Message Listening*****//
  389.  
  390. @Override
  391. public void clanMessageReceived(String arg0, String arg1) {
  392. // TODO Auto-generated method stub
  393.  
  394. }
  395.  
  396. @Override
  397. public void duelRequestReceived(String arg0, String arg1) {
  398. // TODO Auto-generated method stub
  399.  
  400. }
  401.  
  402. @Override
  403. public void personalMessageReceived(String arg0, String arg1) {
  404. // TODO Auto-generated method stub
  405.  
  406. }
  407.  
  408. @Override
  409. public void playerMessageReceived(String arg0, String arg1) {
  410. // TODO Auto-generated method stub
  411.  
  412. }
  413.  
  414. @Override
  415. public void serverMessageReceived(String gameMessage) {
  416. if (gameMessage.toLowerCase().contains("you retrieve")) {
  417. barsSmelted++;
  418. }
  419. }
  420.  
  421. @Override
  422. public void tradeRequestReceived(String arg0) {
  423. // TODO Auto-generated method stub
  424.  
  425. }
  426.  
  427. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement