Thondar

PowerMiner

Jul 5th, 2012
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.76 KB | None | 0 0
  1. import org.powerbot.concurrent.Task;
  2. import org.powerbot.concurrent.strategy.Condition;
  3. import org.powerbot.concurrent.strategy.Strategy;
  4. import org.powerbot.game.api.ActiveScript;
  5. import org.powerbot.game.api.Manifest;
  6. import org.powerbot.game.api.methods.Tabs;
  7. import org.powerbot.game.api.methods.interactive.Players;
  8. import org.powerbot.game.api.methods.node.SceneEntities;
  9. import org.powerbot.game.api.methods.tab.Inventory;
  10. import org.powerbot.game.api.methods.tab.Skills;
  11. import org.powerbot.game.api.util.Filter;
  12. import org.powerbot.game.api.util.Time;
  13. import org.powerbot.game.api.wrappers.node.SceneObject;
  14. import org.powerbot.game.bot.event.MessageEvent;
  15. import org.powerbot.game.bot.event.listener.MessageListener;
  16. import org.powerbot.game.bot.event.listener.PaintListener;
  17.  
  18. import java.awt.BasicStroke;
  19. import java.awt.Color;
  20. import java.awt.Font;
  21. import java.awt.Graphics;
  22. import java.awt.Graphics2D;
  23. import java.awt.GridBagConstraints;
  24. import java.awt.GridBagLayout;
  25. import java.awt.Image;
  26. import java.awt.Insets;
  27. import java.awt.Point;
  28. import java.awt.Rectangle;
  29. import java.awt.event.ActionEvent;
  30. import java.awt.event.ActionListener;
  31. import java.awt.event.MouseEvent;
  32. import java.awt.event.MouseListener;
  33. import java.io.BufferedReader;
  34. import java.io.IOException;
  35. import java.io.InputStreamReader;
  36. import java.net.URL;
  37. import java.text.DecimalFormat;
  38.  
  39. import javax.imageio.ImageIO;
  40. import javax.swing.*;
  41. import javax.swing.border.EmptyBorder;
  42.  
  43. @Manifest(authors = { "Gene" }, name = "First Script", description = "Don't Judge", version = 1.0)
  44. public class Script extends ActiveScript implements PaintListener, MessageListener, MouseListener{
  45. int[] dropID = { 440, 1607, 1623, 1621, 1619 };
  46. int MouseX, MouseY;
  47. int mined;
  48. int gemCollected;
  49. int gainLvl;
  50. int startLvl;
  51. int MININGCurrentLvl = 0;
  52. int oN;
  53. int ironProfit;
  54. int iron = 440;
  55. int mineLvl;
  56. int timeRun;
  57. int startXP;
  58. long expHour = 0;
  59. long startTime;
  60. long sec, min, hr;
  61. long elapsedTime;
  62. long xpTime;
  63. String xptime;
  64. long xphr;
  65. long xpmin;
  66. long xpsec;
  67. boolean guiWait = true;
  68. boolean showPaint = true;
  69. String time;
  70. gui gui;
  71. //START: Code generated using Enfilade's Easel
  72. private final Color color1 = new Color(255, 102, 0, 127);
  73. private final Color color2 = new Color(0, 0, 0);
  74. private final Color color3 = new Color(255, 102, 0, 188);
  75. private final Color color4 = new Color(255, 102, 0);
  76. private final Color color5 = new Color(238, 255, 0);
  77. private final Color color6 = new Color(213, 93, 6);
  78.  
  79.  
  80. public String timeRun() {
  81. elapsedTime = System.currentTimeMillis() - startTime;
  82. time = "";
  83. hr = elapsedTime / (1000 * 60 * 60);
  84. min = (elapsedTime % (1000 * 60 * 60)) / (1000 * 60);
  85. sec = ((elapsedTime % (1000 * 60 * 60)) % (1000 * 60)) / 1000;
  86.  
  87. if (hr < 10)
  88. time += "0" + hr + ":";
  89. else
  90. time += hr + ":";
  91.  
  92. if (min < 10)
  93. time += "0" + min + ":";
  94. else
  95. time += min + ":";
  96. if (sec < 10)
  97. time += "0" + sec;
  98. else
  99. time += sec;
  100. return time;
  101. }
  102.  
  103.  
  104. int getPrice(int id) throws IOException {
  105. String price;
  106. URL url = new URL("http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=" + id);
  107. java.net.URLConnection con = url.openConnection();
  108. BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  109. String line;
  110. while ((line = in.readLine()) != null) {
  111. if (line.contains("<td>")) {
  112. price = line.substring(line.indexOf(">") + 1, line.indexOf("/") - 1);
  113. price = price.replace(",", "");
  114. try {
  115. return Integer.parseInt(price);
  116. } catch (Exception e) {
  117. return -1;
  118. }
  119. }
  120. }
  121. return -1;
  122. }
  123. private class WaitGui implements Task, Condition {
  124.  
  125. @Override
  126. public void run() {
  127. while (guiWait) {
  128. Time.sleep(500);
  129.  
  130. }
  131. }
  132.  
  133. public boolean validate() {
  134. return guiWait;
  135. }
  136.  
  137. }
  138.  
  139. @Override
  140. protected void setup() {
  141. final Mine mine = new Mine();
  142. final Strategy mineAction = new Strategy(mine, mine);
  143. final Drop drop = new Drop();
  144. final Strategy dropAction = new Strategy (drop, drop);
  145. final WaitGui guiTask = new WaitGui();
  146. provide(new Strategy(guiTask, guiTask));
  147. provide(mineAction);
  148. provide(dropAction);
  149. startXP = Skills.getExperience(Skills.MINING);
  150. startLvl = Skills.getLevel(Skills.MINING);
  151. mineLvl = Skills.getLevel(Skills.MINING);
  152. startTime = System.currentTimeMillis();
  153. Tabs.INVENTORY.open();
  154. SwingUtilities.invokeLater(new Runnable() {
  155. public void run() {
  156. try {
  157. gui = new gui();
  158. gui.setVisible(true);
  159. } catch (Exception gui) {
  160. log.warning("Can't open the GUI: ");
  161. stop();
  162. }
  163. }
  164. });
  165. log.info("Author: Gene");
  166. log.info("Welcome to my first script!");
  167. }
  168. public void messageReceived(MessageEvent e) {
  169. String txt = e.getMessage().toLowerCase();
  170. if(txt.contains("just found")) {
  171. System.out.println("You have found a gem!");
  172. ++gemCollected;
  173. }
  174. if(txt.contains("manage to mine")) {
  175. ++mined;
  176. }
  177. }
  178.  
  179.  
  180. private Image getImage(String url) {
  181. try {
  182. return ImageIO.read(new URL(url));
  183. } catch (IOException e) {
  184. return null;
  185. }
  186. }
  187.  
  188. private final Image img1 = getImage("http://img442.imageshack.us/img442/258/bg2d.png");
  189. private final Image img2 = getImage("http://img98.imageshack.us/img98/7050/showbc.png");
  190. private final Image img3 = getImage("http://img72.imageshack.us/img72/8359/ironv.png");
  191. private final Image img4 = getImage("http://img339.imageshack.us/img339/3108/progressbar.png");
  192.  
  193. private final BasicStroke stroke1 = new BasicStroke(1);
  194.  
  195. private final Font font1 = new Font("Calibri", 1, 18);
  196. private final Font font2 = new Font("Calibri", 0, 12);
  197.  
  198. private final Color orange = new Color(227, 127, 20);
  199.  
  200. public void onRepaint(Graphics g1) {
  201. Graphics2D g2d = (Graphics2D)g1;
  202.  
  203. DecimalFormat format = new DecimalFormat("#.##");
  204.  
  205. int ironHour = (int) ((mined * 3600000D) / (elapsedTime));
  206. int gemHour = (int) ((gemCollected * 3600000D) / (elapsedTime));
  207. gainLvl = (Skills.getLevel(Skills.MINING) - startLvl);
  208.  
  209. int xpGain = (Skills.getExperience(Skills.MINING) - startXP);
  210.  
  211. int xpHour = (int) ((xpGain) * 3600000D / (System
  212. .currentTimeMillis() - startTime));
  213.  
  214. int currentLvl = (Skills.getLevel(Skills.MINING));
  215.  
  216. int lvlGained = (currentLvl - startLvl);
  217.  
  218. int level = Skills.getLevel(Skills.MINING);
  219. int startXP = Skills.getExperienceRequired(level);
  220. int nextXP = Skills.getExperienceRequired(level + 1);
  221. double rangeXP = nextXP-startXP;
  222. double currentRelativeXP = Skills.getExperience(Skills.MINING) - startXP;
  223. double currentXPleft = nextXP - Skills.getExperience(Skills.MINING);
  224. double percentA = currentRelativeXP/rangeXP;
  225. double percentToLvl = ((percentA) * 100D);
  226.  
  227. double percent = (int) ((percentA) * 372D);
  228.  
  229.  
  230. xpTime = (long) ((currentXPleft / xpHour) * 3600000D);
  231. xptime = "";
  232.  
  233. if(mined == 0) {
  234. xphr = 0;
  235. xpmin = 0;
  236. xpsec = 0;
  237. }
  238. if(mined >= 1) {
  239. xphr = xpTime / (1000 * 60 * 60);
  240. xpmin = (xpTime % (1000 * 60 * 60)) / (1000 * 60);
  241. xpsec = ((xpTime % (1000 * 60 * 60)) % (1000 * 60)) / 1000;
  242. }
  243.  
  244.  
  245.  
  246. if (showPaint) {
  247. g2d.setColor(orange);
  248. g2d.setFont(font2);
  249. g2d.drawImage(img1, -2, 295, null);
  250. g2d.drawString("" + mined, 120, 389);
  251. g2d.drawString("" + ironHour, 116, 406);
  252. g2d.drawString("" + gemCollected, 128, 427);
  253. g2d.drawString("" + gemHour, 120, 444);
  254. g2d.drawString("" + currentLvl, 349, 389);
  255. g2d.drawString("" + lvlGained, 349, 407);
  256. g2d.drawString("" + xpGain, 328, 429);
  257. g2d.drawString("" + xpHour, 313, 446);
  258. g2d.drawString(timeRun(), 315, 489);
  259. g2d.drawString(xphr + ":" + xpmin + ":" + xpsec, 77, 352);
  260.  
  261. g2d.setColor(Color.BLACK);
  262. g2d.drawImage(img4, 145, 332,(int) (percent), 29, null);
  263. g2d.setFont(font1);
  264. g2d.drawString (String.format("%.2f",percentToLvl) + "%" , 310, 352);
  265.  
  266.  
  267. }
  268.  
  269. else {
  270. g2d.drawImage(img2, 459, 472, null);
  271.  
  272.  
  273.  
  274.  
  275. }
  276.  
  277.  
  278. }
  279.  
  280.  
  281. private class Mine implements Task, Condition {
  282. @Override
  283. public void run() {
  284. SceneObject rock = SceneEntities.getNearest(new Filter<SceneObject>() {
  285.  
  286. public boolean accept(SceneObject entity) {
  287. return entity.getId() == 11955 || entity.getId() == 11956;
  288. }
  289. });
  290.  
  291. try {
  292. ironProfit = (mined*getPrice(iron));
  293. } catch (IOException e) {
  294. e.printStackTrace();
  295. }
  296.  
  297. if (rock !=null) {
  298. if (rock.isOnScreen()) {
  299. rock.interact("Mine");
  300. Time.sleep(1700);
  301. }
  302. }
  303. }
  304. @Override
  305. public boolean validate() {
  306. return Inventory.getCount() < 28 && Players.getLocal().getAnimation() == -1;
  307. }
  308. }
  309.  
  310.  
  311.  
  312. private class Drop implements Task, Condition {
  313. @Override
  314. public void run() {
  315. log.info("Dropping...");
  316. for(;
  317. Inventory.getItem(iron).getWidgetChild().interact("Drop");
  318. Time.sleep(1000));
  319.  
  320. }
  321. @Override
  322. public boolean validate() {
  323. return Inventory.getCount() == 28;
  324. }
  325. }
  326.  
  327. @SuppressWarnings("serial")
  328. public class gui extends JFrame {
  329.  
  330. private JPanel contentPane;
  331.  
  332. /**
  333. * Create the frame.
  334. */
  335.  
  336. public gui() {
  337. setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
  338. setBounds(100, 100, 450, 300);
  339. contentPane = new JPanel();
  340. contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  341. setContentPane(contentPane);
  342. GridBagLayout gbl_contentPane = new GridBagLayout();
  343. gbl_contentPane.columnWidths = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  344. gbl_contentPane.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0};
  345. gbl_contentPane.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
  346. gbl_contentPane.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
  347. contentPane.setLayout(gbl_contentPane);
  348.  
  349. JButton btnStart = new JButton("Start");
  350. btnStart.addActionListener(new ActionListener() {
  351. public void actionPerformed(ActionEvent arg0) {
  352. System.out.println("Bro. Try this.");
  353. gui.setVisible(false);
  354. guiWait = false;
  355. dispose();
  356. }
  357. });
  358. GridBagConstraints gbc_btnStart = new GridBagConstraints();
  359. gbc_btnStart.insets = new Insets(150, 175, 5, 5);
  360. gbc_btnStart.gridx = 6;
  361. gbc_btnStart.gridy = 4;
  362. contentPane.add(btnStart, gbc_btnStart);
  363. }
  364. }
  365.  
  366.  
  367. @Override
  368. public void mouseClicked(MouseEvent e) {
  369. Point a = e.getPoint();
  370. Rectangle area = new Rectangle(464, 478, 48, 17);
  371. if (area.contains(a)) {
  372. showPaint = !showPaint;
  373. }
  374. }
  375.  
  376. @Override
  377. public void mouseEntered(MouseEvent e) {
  378. }
  379.  
  380. @Override
  381. public void mouseExited(MouseEvent e) {
  382. }
  383.  
  384. @Override
  385. public void mousePressed(MouseEvent e) {
  386. }
  387.  
  388. @Override
  389. public void mouseReleased(MouseEvent e) {
  390. }
  391.  
  392. }
Advertisement
Add Comment
Please, Sign In to add comment