package com.paradigm.script; import java.awt.Container; import java.awt.Dimension; import java.awt.FontMetrics; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Insets; import java.awt.Point; import java.awt.Rectangle; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.geom.AffineTransform; import java.util.ArrayList; import java.util.Arrays; import javax.swing.Icon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JScrollPane; import javax.swing.JSlider; import javax.swing.SwingConstants; import javax.swing.plaf.basic.BasicLabelUI; import com.paradigm.script.struct.Methods; import com.paradigm.script.struct.ProScript; import com.rsbuddy.event.events.MessageEvent; import com.rsbuddy.script.Manifest; import com.rsbuddy.script.methods.Calculations; import com.rsbuddy.script.methods.Inventory; import com.rsbuddy.script.methods.Mouse; import com.rsbuddy.script.methods.Objects; import com.rsbuddy.script.methods.Players; import com.rsbuddy.script.methods.Walking; import com.rsbuddy.script.methods.Widgets; import com.rsbuddy.script.util.Filter; import com.rsbuddy.script.util.Random; import com.rsbuddy.script.util.Timer; import com.rsbuddy.script.wrappers.GameObject; import com.rsbuddy.script.wrappers.Item; import com.rsbuddy.script.wrappers.Tile; @Manifest(name = "ProPowerMiner", authors = {"Paradigm"}, version = 2.4, keywords = {"powerminer", "powermining", "paradigm"}, description = "Powermines ore anywhere!") public class ProPowerMiner extends ProScript { private String mining = null; private Timer timeout = null; private static final int[] CLAY_ROCK_IDS = {9711, 9713, 15503, 15504, 15505, 31062, 31063}, COPPER_ROCK_IDS = {3229, 3027, 9708, 9709, 9710, 11936, 11937, 11938, 11960, 11961, 11962, 11963, 31080, 31082, 29230, 29231, 5780, 5779, 5781}, TIN_ROCK_IDS = { 3038, 3245, 9714, 9716, 11933, 11934, 11935, 11957, 11958, 11959, 31077, 31078, 31079, 5776, 5777, 5778}, IRON_ROCK_IDS = {2092, 2093, 5773, 5774, 5775, 9717, 9718, 9719, 11954, 11955, 11956, 14913, 14914, 31071, 31072, 31073, 37307, 37308, 37309, 29221, 29222, 14856, 14857, 14858, 32443, 32441, 32442}, SILVER_ROCK_IDS = {2311, 9714, 9716, 11948, 11949, 11950, 37304, 37305, 37306, 29225, 29224, 29226, 29227}, COAL_ROCK_IDS = {2096, 2097, 5770, 5771, 5772, 11930, 11931, 11932, 11963, 11964, 14850, 14851, 14852, 31068, 31069, 31070, 32426, 29215, 29216, 29217}, GOLD_ROCK_IDS = {9720, 9722, 11183, 11184, 11185, 15503, 15505, 31065, 31066, 37310, 37312, 37313, 5769, 5768, 2098, 2099}, MITHRIL_ROCK_IDS = {5784, 5785, 5786, 11942, 11943, 11944, 32438, 32439, 31086, 31088, 29236, 5758}, ADAMANTITE_ROCK_IDS = {11939, 11940, 11941, 31083, 31084, 31085, 32435, 32436, 29235, 29233, 5782, 14853, 14854, 14855, 14862, 14863, 14864}, RUNITE_ROCK_IDS = {14895, 33078, 33079}; private static final int[][] ALL_IDS = {CLAY_ROCK_IDS, COPPER_ROCK_IDS, TIN_ROCK_IDS, IRON_ROCK_IDS, SILVER_ROCK_IDS, COAL_ROCK_IDS, GOLD_ROCK_IDS, MITHRIL_ROCK_IDS, ADAMANTITE_ROCK_IDS, RUNITE_ROCK_IDS}; private boolean stay; private boolean[] mine = new boolean[ALL_IDS.length]; private ArrayList ids = new ArrayList(); private Tile start = null; private Filter ROCK_FILTER = new Filter() { @Override public boolean accept(GameObject go) { return go != null && ids.contains(go.getId()) && (!stay || Calculations.distanceBetween(Players.getLocal().getLocation(), go.getLocation()) <= 1); } }; @Override public boolean onStart() { if (!super.onStart()) { return false; } timeout = new Timer(2000); for (int idx = 0; idx < ALL_IDS.length; idx++) { int[] array = ALL_IDS[idx]; if (mine[idx]) { for (int i : array) { ids.add(i); } } } start = Players.getLocal().getLocation(); return true; } @Override public int script() { if (Players.getLocal().isMoving()) { return 250; } if (timeout.isRunning()) { if (isMining()) { return 100; } } if (Widgets.canContinue()) { Widgets.clickContinue(); } if (!Walking.isRunEnabled() && Walking.getEnergy() > 25) { Walking.setRun(true); } if (Inventory.isFull()) { for (int i = 0; i < 10; i++) { boolean clicked = false; for (Item it : Inventory.getItems()) { String name; if (it != null && it.getId() != -1 && (name = it.getName()) != null && !name.contains("pickaxe")) { clicked = true; it.interact(Random.nextInt(0, 50) == 0 ? "Examine" : "Drop"); } } if (clicked) { sleep(600); } } } GameObject rock = Objects.getNearest(ROCK_FILTER); if (rock == null) { Tile t = Walking.getTileOnMap(start); if (t != null && !Players.getLocal().getLocation().equals(start)) { t.clickOnMap(); timeout.setEndIn(10000); } return 1500; } if (!rock.isOnScreen()) { Tile t = Walking.getTileOnMap(rock.getLocation()); if (t != null) { t.clickOnMap(); } return 1500; } try { Mouse.click(rock.getModel().getNextPoint(), true); } catch (Exception e) { rock.interact("Mine"); } timeout.setEndIn(10000); return 1500; } private boolean isMining() { int orient = roundOrient(Players.getLocal().getOrientation()); Tile p = Players.getLocal().getLocation(), r = null; switch (orient) { case 0: r = new Tile(p.getX() + 1, p.getY()); break; case 1: r = new Tile(p.getX(), p.getY() + 1); break; case 2: r = new Tile(p.getX() - 1, p.getY()); break; case 3: r = new Tile(p.getX(), p.getY() - 1); break; } return ROCK_FILTER.accept(Objects.getTopAt(r)); } private static int roundOrient(int n) { int i = n % 90; int off = 0; if (i >= 45) { off = 90 - i; } else { off = 0 - i; } n += off; return n / 90; } @Override public void messageReceived(MessageEvent me) { if (me.getMessage().contains("manage to mine")) { done++; } else if (me.getMessage().contains("do not have")) { log("No pickaxe!"); stop(); } } @Override protected String[] getPaintData() { return new String[] { "Mining:", "-" + mining, "Mined: " + Methods.format(done) + " (" + Methods.format(Methods.getHourly(done, runTimer.getElapsed())) + "/hr)", "%sMining"}; } @Override protected Runnable makeGUI() { return new Runnable() { @Override public void run() { final JFrame frame = new JFrame("ProPowerMiner"); JScrollPane scrollPane1 = new JScrollPane(); JButton button1 = new JButton("Start"); final JList list1 = new JList(new String[] {"Clay", "Copper", "Tin", "Iron", "Silver", "Coal", "Gold", "Mithril", "Adamantite", "Runite"}); JLabel label1 = new JLabel("Ctrl+click to select:"), label2 = new JLabel( "Mouse speed (lower is faster):"); final JSlider speedSlider = new JSlider(1, 10); final JCheckBox stayBox = new JCheckBox("Do not move"); label2.setUI(new VerticalLabelUI(false)); speedSlider.setOrientation(SwingConstants.VERTICAL); speedSlider.setMajorTickSpacing(1); speedSlider.setPaintTicks(true); speedSlider.setPaintLabels(true); speedSlider.setSnapToTicks(true); speedSlider.setValue(mouseSpeed); Container contentPane = frame.getContentPane(); contentPane.setLayout(null); scrollPane1.setViewportView(list1); contentPane.add(scrollPane1); scrollPane1.setBounds(5, 25, 115, 126); contentPane.add(stayBox); stayBox.setSize(stayBox.getPreferredSize()); stayBox.setLocation(5, 153); contentPane.add(button1); button1.setBounds(5, 175, 115, button1.getPreferredSize().height); contentPane.add(label1); label1.setBounds(new Rectangle(new Point(10, 5), label1.getPreferredSize())); contentPane.setPreferredSize(new Dimension(20, 150)); frame.add(label2); label2.setBounds(125, 40, label2.getPreferredSize().width, label2.getPreferredSize().height); frame.add(speedSlider); speedSlider.setBounds(145, 4, speedSlider.getPreferredSize().width, speedSlider.getPreferredSize().height - 9); frame.setSize(200, 231); frame.setLocationRelativeTo(frame.getOwner()); button1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { for (int i : list1.getSelectedIndices()) { mine[i] = true; } mining = Arrays.toString(list1.getSelectedValues()); mouseSpeed = speedSlider.getValue(); stay = stayBox.isSelected(); frame.dispose(); initialized = true; } }); frame.setVisible(true); } }; } private static class VerticalLabelUI extends BasicLabelUI { protected boolean clockwise; public VerticalLabelUI(boolean clockwise) { super(); labelUI = this; this.clockwise = clockwise; } @Override public Dimension getPreferredSize(JComponent c) { Dimension dim = super.getPreferredSize(c); return new Dimension(dim.height, dim.width); } private Rectangle paintIconR = new Rectangle(); private Rectangle paintTextR = new Rectangle(); private Rectangle paintViewR = new Rectangle(); private Insets paintViewInsets = new Insets(0, 0, 0, 0); @Override public void paint(Graphics g, JComponent c) { JLabel label = (JLabel) c; String text = label.getText(); Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon(); if ((icon == null) && (text == null)) { return; } FontMetrics fm = g.getFontMetrics(); paintViewInsets = c.getInsets(paintViewInsets); paintViewR.x = paintViewInsets.left; paintViewR.y = paintViewInsets.top; // Use inverted height & width paintViewR.height = c.getWidth() - (paintViewInsets.left + paintViewInsets.right); paintViewR.width = c.getHeight() - (paintViewInsets.top + paintViewInsets.bottom); paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0; paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0; String clippedText = layoutCL(label, fm, text, icon, paintViewR, paintIconR, paintTextR); Graphics2D g2 = (Graphics2D) g; AffineTransform tr = g2.getTransform(); if (clockwise) { g2.rotate(Math.PI / 2); g2.translate(0, -c.getWidth()); } else { g2.rotate(-Math.PI / 2); g2.translate(-c.getHeight(), 0); } if (icon != null) { icon.paintIcon(c, g, paintIconR.x, paintIconR.y); } if (text != null) { int textX = paintTextR.x; int textY = paintTextR.y + fm.getAscent(); if (label.isEnabled()) { paintEnabledText(label, g, clippedText, textX, textY); } else { paintDisabledText(label, g, clippedText, textX, textY); } } g2.setTransform(tr); } } }