Created
July 9, 2012 01:20
-
-
Save phl0w/3073707 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.awt.Color; | |
| import java.awt.Font; | |
| import java.awt.Graphics; | |
| import java.awt.Graphics2D; | |
| import java.awt.Image; | |
| import java.awt.event.ActionEvent; | |
| import java.awt.event.ActionListener; | |
| import java.io.IOException; | |
| import java.net.URL; | |
| import javax.imageio.ImageIO; | |
| import javax.swing.DefaultComboBoxModel; | |
| import javax.swing.GroupLayout; | |
| import javax.swing.JButton; | |
| import javax.swing.JCheckBox; | |
| import javax.swing.JComboBox; | |
| import javax.swing.JLabel; | |
| import javax.swing.JPanel; | |
| import javax.swing.LayoutStyle; | |
| import javax.swing.SwingUtilities; | |
| import org.powerbot.concurrent.Task; | |
| import org.powerbot.concurrent.strategy.Strategy; | |
| import org.powerbot.game.api.ActiveScript; | |
| import org.powerbot.game.api.Manifest; | |
| import org.powerbot.game.api.methods.Calculations; | |
| import org.powerbot.game.api.methods.Widgets; | |
| import org.powerbot.game.api.methods.input.Mouse; | |
| import org.powerbot.game.api.methods.interactive.Players; | |
| import org.powerbot.game.api.methods.node.SceneEntities; | |
| import org.powerbot.game.api.methods.tab.Inventory; | |
| import org.powerbot.game.api.methods.tab.Skills; | |
| import org.powerbot.game.api.methods.widget.Camera; | |
| import org.powerbot.game.api.util.Filter; | |
| import org.powerbot.game.api.util.Random; | |
| import org.powerbot.game.api.util.Time; | |
| import org.powerbot.game.api.wrappers.node.SceneObject; | |
| import org.powerbot.game.bot.event.listener.PaintListener; | |
| @Manifest(authors = { "Tlhc15" }, name = "Powerminer", description = "Test.", version = 1.0) | |
| public class UPower extends ActiveScript implements PaintListener { | |
| private int rockId[]; | |
| private final int COPPER_ID[] = { 2090, 2091, 2097, 3027, 3229, 5779, 5780, 5781, 9708, 9709, 9710, 11936, 11937, 11938, 11960, 11961, | |
| 11962, 14906, 14907, 21284, 21285, 21286 }; | |
| private final int TIN_ID[] = { 2094, 2095, 3038, 3245, 5776, 5777, 5778, 9714, 9716, 11933, 11934, 11935, 11957, 11958, 11959, 14902, | |
| 14903, 21293, 21294, 21295 }; | |
| private final int IRON_ID[] = { 2092, 2093, 5773, 5774, 5775, 9717, 9718, 9719, 11954, 11955, 11956, 14099, 14107, 14913, 14914, 21281, | |
| 21282, 21283, 37307, 37308, 37309 }; | |
| private final int COAL_ID[] = { 2096, 2097, 3032, 3233, 5770, 5771, 5772, 10948, 11930, 11931, 11932, 14850, 14851, 21287, 21288, | |
| 21289, 29215, 29216, 29217, 32426, 32427, 32428 }; | |
| private final int CLAY_ID[] = { 46320, 46322, 46324 }; | |
| private final int SILVER_ID[] = { 2311, 11186, 11187, 11188, 11948, 11949, 11950, 15580, 15581, 29224, 29225, 29226, 32444, 32445, | |
| 32446, 37304, 37305, 37306 }; | |
| private final int GOLD_ID[] = { 5768, 5769, 9720, 9722, 10574, 10575, 10576, 11183, 11184, 11185, 11943, 15576, 15577, 15578, 32432, | |
| 32433, 32434, 45067, 45068 }; | |
| private final int MITHRIL_ID[] = { 2102, 2103, 3041, 3280, 5784, 5785, 5786, 11942, 11943, 11944, 21278, 21279, 21280, 32438, 32439, | |
| 32440 }; | |
| private final int ADAM_ID[] = { 3040, 3273, 5782, 5783, 11939, 11941, 21275, 21276, 21277, 29233, 29235, 32425, 32436, 32437 }; | |
| private final int RUNITE_ID[] = { 14859, 33078, 33079, 45069, 45070 }; | |
| private final int DROP_ID[] = { 440, 438, 436, 442, 444, 453, 447, 434, 449, 450, 451, 452 }; | |
| private final int DROP_NO_GEMS_ID[] = { 440, 438, 436, 442, 444, 453, 447, 434, 449, 450, 451, 452, 1617, 1619, 1621, 1623 }; | |
| private int oreNo, startXp, startLevel, xpGained, xpHour, levelsGained; | |
| private long startTime; | |
| private String status; | |
| private Image img1, img2, img3, img4; | |
| private boolean guiWait = true, keepGems; | |
| @Override | |
| protected void setup() { | |
| log.info("Welcome."); | |
| startXp = Skills.getExperience(Skills.MINING); | |
| startLevel = Skills.getLevel(Skills.MINING); | |
| startTime = System.currentTimeMillis(); | |
| img1 = getImage("http://a.imageshack.us/img84/1865/hillh.jpg"); | |
| img2 = getImage("http://a.imageshack.us/img641/985/20110920222021gildeddra.png"); | |
| img3 = getImage("http://a.imageshack.us/img221/5681/cooltext726290580.png"); | |
| img4 = getImage("http://a.imageshack.us/img834/2149/statusbar.jpg"); | |
| provide(new Mine()); | |
| provide(new Drop()); | |
| provide(new Antiban()); | |
| log.info("Launching GUI..."); | |
| SwingUtilities.invokeLater(new Runnable() { | |
| public void run() { | |
| try { | |
| UGui g = new UGui(); | |
| g.setVisible(true); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| }); | |
| } | |
| private class Mine extends Strategy implements Task { | |
| final SceneObject rock = SceneEntities.getNearest(new Filter<SceneObject>() { | |
| public boolean accept(SceneObject SceneObject) { | |
| for (int i : rockId) { | |
| if (SceneObject.getId() == i && Calculations.distanceTo(SceneObject) < 5) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| }); | |
| @Override | |
| public void run() { | |
| if (rock != null) { | |
| if (rock.isOnScreen() && Players.getLocal().getAnimation() == -1) { | |
| Camera.turnTo(rock); | |
| rock.interact("Mine"); | |
| status = "Mining ores..."; | |
| Time.sleep(Random.nextInt(2400, 3000)); | |
| } | |
| } else { | |
| status = "Finding rocks nearby..."; | |
| } | |
| } | |
| @Override | |
| public boolean validate() { | |
| return !guiWait && Inventory.getCount() < oreNo; | |
| } | |
| } | |
| private class Drop extends Strategy implements Task { | |
| @Override | |
| public void run() { | |
| if (keepGems) { | |
| Inventory.getItem(DROP_ID).getWidgetChild().interact("Drop"); | |
| Time.sleep(50, 100); | |
| } else if (!keepGems) { | |
| Inventory.getItem(DROP_NO_GEMS_ID).getWidgetChild().interact("Drop"); | |
| Time.sleep(50, 100); | |
| } | |
| } | |
| @Override | |
| public boolean validate() { | |
| return !guiWait && Inventory.getCount() == oreNo && Players.getLocal().getAnimation() == -1 && Widgets.get(679).validate(); | |
| } | |
| } | |
| private class Antiban extends Strategy implements Task { | |
| @Override | |
| public void run() { | |
| switch (Random.nextInt(0, 100)) { | |
| case 0: | |
| status = "Moving camera..."; | |
| Camera.setAngle(Random.nextInt(14, 304)); | |
| break; | |
| case 1: | |
| status = "Moving camera..."; | |
| Camera.setAngle(Random.nextInt(90, 124)); | |
| break; | |
| case 2: | |
| status = "Moving camera..."; | |
| Camera.setAngle(Random.nextInt(140, 217)); | |
| break; | |
| case 3: | |
| status = "Moving camera..."; | |
| Camera.setAngle(Random.nextInt(14, 304)); | |
| break; | |
| case 4: | |
| status = "Examining rock..."; | |
| SceneEntities.getNearest(rockId).interact("examine"); | |
| case 5: | |
| status = "Moving mouse..."; | |
| Mouse.hop(Random.nextInt(50, 130), Random.nextInt(50, 130)); | |
| Mouse.hop(Random.nextInt(247, 17), Random.nextInt(246, 36)); | |
| } | |
| } | |
| @Override | |
| public boolean validate() { | |
| return Players.getLocal().getInteracting() == null && !Players.getLocal().isMoving(); | |
| } | |
| } | |
| private Image getImage(String url) { | |
| try { | |
| return ImageIO.read(new URL(url)); | |
| } catch (IOException e) { | |
| return null; | |
| } | |
| } | |
| public void onRepaint(Graphics g1) { | |
| Color color1 = new Color(0, 0, 0); | |
| Font font1 = new Font("Bradley Hand ITC", 0, 20); | |
| Font font2 = new Font("Arial", 1, 11); | |
| xpGained = (Skills.getExperience(Skills.MINING) - startXp); | |
| xpHour = (int) ((xpGained) * 3600000D / (System.currentTimeMillis() - startTime)); | |
| levelsGained = (Skills.getLevel(Skills.MINING) - startLevel); | |
| Graphics2D g = (Graphics2D) g1; | |
| g.drawImage(img1, 213, 351, null); | |
| g.drawImage(img2, 119, 303, null); | |
| g.drawImage(img3, 191, 313, null); | |
| g.setFont(font1); | |
| g.setColor(color1); | |
| g.drawString("Time running:" + Time.format(System.currentTimeMillis() - startTime), 215, 380); | |
| g.drawString("Experience gained:" + xpGained + "(" + levelsGained + ")", 214, 404); | |
| g.drawString("Exp/ hour:" + xpHour, 215, 425); | |
| g.drawImage(img4, 8, 458, null); | |
| g.setFont(font2); | |
| g.drawString("Status:" + status, 219, 470); | |
| } | |
| @SuppressWarnings("serial") | |
| public class UGui extends JPanel { | |
| public UGui() { | |
| initComponents(); | |
| } | |
| private void OreActionPerformed(ActionEvent e) { | |
| String chosen = comboBox1.getSelectedItem().toString(); | |
| if (chosen.equals("Iron")) { | |
| rockId = IRON_ID; | |
| } else if (chosen.equals("Tin")) { | |
| rockId = TIN_ID; | |
| } else if (chosen.equals("Copper")) { | |
| rockId = COPPER_ID; | |
| } else if (chosen.equals("Clay")) { | |
| rockId = CLAY_ID; | |
| } else if (chosen.equals("Silver")) { | |
| rockId = SILVER_ID; | |
| } else if (chosen.equals("Gold")) { | |
| rockId = GOLD_ID; | |
| } else if (chosen.equals("Coal")) { | |
| rockId = COAL_ID; | |
| } else if (chosen.equals("Mithril")) { | |
| rockId = MITHRIL_ID; | |
| } else if (chosen.equals("Adamantite")) { | |
| rockId = ADAM_ID; | |
| } else if (chosen.equals("Runite")) { | |
| rockId = RUNITE_ID; | |
| } | |
| } | |
| private void SettingsActionPerformed(ActionEvent e) { | |
| String chosen = comboBox2.getSelectedItem().toString(); | |
| if (chosen.equals("Full inventory")) { | |
| oreNo = 28; | |
| } else if (chosen.equals("M1D1")) { | |
| oreNo = 1; | |
| } else if (chosen.equals("M2D2")) { | |
| oreNo = 2; | |
| } | |
| } | |
| private void StartActionPerformed(ActionEvent e) { | |
| guiWait = false; | |
| this.setVisible(false); | |
| } | |
| private void gemActionPerformed(ActionEvent e) { | |
| if (checkBox1.isSelected()) { | |
| keepGems = true; | |
| } | |
| } | |
| private void initComponents() { | |
| label1 = new JLabel(); | |
| comboBox1 = new JComboBox(); | |
| label2 = new JLabel(); | |
| button1 = new JButton(); | |
| comboBox2 = new JComboBox(); | |
| label3 = new JLabel(); | |
| checkBox1 = new JCheckBox(); | |
| // JFormDesigner evaluation mark | |
| setBorder(new javax.swing.border.CompoundBorder(new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, | |
| 0), "JFormDesigner Evaluation", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.BOTTOM, | |
| new java.awt.Font("Dialog", java.awt.Font.BOLD, 12), java.awt.Color.red), getBorder())); | |
| addPropertyChangeListener(new java.beans.PropertyChangeListener() { | |
| public void propertyChange(java.beans.PropertyChangeEvent e) { | |
| if ("border".equals(e.getPropertyName())) | |
| throw new RuntimeException(); | |
| } | |
| }); | |
| // ---- label1 ---- | |
| label1.setText("Powerminer"); | |
| label1.setFont(new Font("Bauhaus 93", Font.PLAIN, 30)); | |
| // ---- comboBox1 ---- | |
| comboBox1.setFont(new Font("Calibri", Font.PLAIN, 18)); | |
| comboBox1.setModel(new DefaultComboBoxModel(new String[] { "Iron", "Tin", "Copper", "Clay", "Silver", "Gold", "Coal", | |
| "Mithril", "Adamantite", "Runite" })); | |
| comboBox1.addActionListener(new ActionListener() { | |
| @Override | |
| public void actionPerformed(ActionEvent e) { | |
| OreActionPerformed(e); | |
| } | |
| }); | |
| // ---- label2 ---- | |
| label2.setText("Ore:"); | |
| label2.setFont(new Font("Calibri", Font.PLAIN, 20)); | |
| // ---- button1 ---- | |
| button1.setText("Start"); | |
| button1.setFont(new Font("Calibri", Font.PLAIN, 12)); | |
| button1.addActionListener(new ActionListener() { | |
| @Override | |
| public void actionPerformed(ActionEvent e) { | |
| StartActionPerformed(e); | |
| } | |
| }); | |
| // ---- comboBox2 ---- | |
| comboBox2.setFont(new Font("Calibri", Font.PLAIN, 18)); | |
| comboBox2.setModel(new DefaultComboBoxModel(new String[] { "Full inventory", "M1D1", "M2D2" })); | |
| comboBox2.addActionListener(new ActionListener() { | |
| @Override | |
| public void actionPerformed(ActionEvent e) { | |
| SettingsActionPerformed(e); | |
| } | |
| }); | |
| // ---- label3 ---- | |
| label3.setText("Settings:"); | |
| label3.setFont(new Font("Calibri", Font.PLAIN, 20)); | |
| // ---- checkBox1 ---- | |
| checkBox1.setText("Keep gems?"); | |
| checkBox1.setFont(new Font("Calibri", Font.PLAIN, 14)); | |
| checkBox1.addActionListener(new ActionListener() { | |
| @Override | |
| public void actionPerformed(ActionEvent e) { | |
| gemActionPerformed(e); | |
| } | |
| }); | |
| GroupLayout layout = new GroupLayout(this); | |
| setLayout(layout); | |
| layout.setHorizontalGroup(layout.createParallelGroup().addGroup( | |
| layout.createSequentialGroup() | |
| .addGroup( | |
| layout.createParallelGroup() | |
| .addGroup( | |
| layout.createSequentialGroup() | |
| .addContainerGap(78, Short.MAX_VALUE) | |
| .addGroup( | |
| layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false) | |
| .addComponent(label2, GroupLayout.DEFAULT_SIZE, | |
| GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) | |
| .addComponent(label3, GroupLayout.DEFAULT_SIZE, | |
| GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) | |
| .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) | |
| .addGroup( | |
| layout.createParallelGroup() | |
| .addGroup( | |
| layout.createParallelGroup( | |
| GroupLayout.Alignment.LEADING, false) | |
| .addComponent(comboBox1) | |
| .addComponent(comboBox2)) | |
| .addGroup( | |
| layout.createSequentialGroup() | |
| .addComponent(checkBox1) | |
| .addPreferredGap( | |
| LayoutStyle.ComponentPlacement.RELATED, | |
| 25, Short.MAX_VALUE) | |
| .addComponent(button1, | |
| GroupLayout.PREFERRED_SIZE, 103, | |
| GroupLayout.PREFERRED_SIZE)))) | |
| .addGroup( | |
| layout.createSequentialGroup() | |
| .addGap(47, 47, 47) | |
| .addComponent(label1, GroupLayout.PREFERRED_SIZE, 295, | |
| GroupLayout.PREFERRED_SIZE).addGap(0, 38, Short.MAX_VALUE))) | |
| .addContainerGap())); | |
| layout.setVerticalGroup(layout.createParallelGroup().addGroup( | |
| layout.createSequentialGroup() | |
| .addGap(22, 22, 22) | |
| .addComponent(label1) | |
| .addGap(18, 18, 18) | |
| .addGroup( | |
| layout.createParallelGroup() | |
| .addGroup( | |
| layout.createSequentialGroup() | |
| .addComponent(comboBox1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, | |
| GroupLayout.PREFERRED_SIZE) | |
| .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) | |
| .addGroup( | |
| layout.createParallelGroup(GroupLayout.Alignment.BASELINE) | |
| .addComponent(comboBox2, GroupLayout.PREFERRED_SIZE, | |
| GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) | |
| .addComponent(label3))).addComponent(label2)) | |
| .addGroup( | |
| layout.createParallelGroup() | |
| .addGroup( | |
| layout.createSequentialGroup() | |
| .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) | |
| .addComponent(checkBox1)) | |
| .addGroup( | |
| layout.createSequentialGroup() | |
| .addGap(38, 38, 38) | |
| .addComponent(button1, GroupLayout.PREFERRED_SIZE, 39, | |
| GroupLayout.PREFERRED_SIZE))).addContainerGap(11, Short.MAX_VALUE))); | |
| } | |
| private JLabel label1; | |
| private JComboBox comboBox1; | |
| private JLabel label2; | |
| private JButton button1; | |
| private JComboBox comboBox2; | |
| private JLabel label3; | |
| private JCheckBox checkBox1; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment