SHOW:
|
|
- or go back to the newest paste.
| 1 | @ScriptManifest(name = "PowerMiner", authors = "AlphaDog", category = "Mining") | |
| 2 | public class PowerMiner extends Script implements Painting, EventBlockingOverride, MessageListening07 {
| |
| 3 | private static final Color MENU_COLOR = new Color(0, 0, 0, 95); | |
| 4 | ||
| 5 | private static final Filter<RSItem> ORE_FILTER = Filters.Items.nameContains("ore", "Clay");
| |
| 6 | private static final Filter<RSItem> PICKAXE_FILTER = Filters.Items.nameContains("pickaxe");
| |
| 7 | ||
| 8 | private Filter<RSObject> rockFilter = new Filter<RSObject>() {
| |
| 9 | @Override | |
| 10 | public boolean accept(RSObject rsObject) {
| |
| 11 | for (RSTile tile : rocks.keySet()) {
| |
| 12 | if (rsObject.getPosition().equals(tile)) {
| |
| 13 | RSObjectDefinition def = rsObject.getDefinition(); | |
| 14 | if (def == null) return false; | |
| 15 | short[] colors = def.getModifiedColors(); | |
| 16 | return colors != null && colors.length > 1 && colors[0] != colors[1] && !smokingRockFilter.accept(rsObject); | |
| 17 | } | |
| 18 | } | |
| 19 | ||
| 20 | return false; | |
| 21 | } | |
| 22 | }; | |
| 23 | ||
| 24 | private final Filter<RSObject> smokingRockFilter = new Filter<RSObject>() {
| |
| 25 | @Override | |
| 26 | public boolean accept(RSObject rsObject) {
| |
| 27 | RSModel model = rsObject.getModel(); | |
| 28 | return model != null && Math.abs(rocks.get(rsObject.getPosition()) - model.getVertexCount()) > 20; | |
| 29 | } | |
| 30 | }; | |
| 31 | ||
| 32 | private final ConcurrentHashMap<RSTile, Integer> rocks = new ConcurrentHashMap<>(); | |
| 33 | ||
| 34 | private AtomicInteger amountMined = new AtomicInteger(); | |
| 35 | private RSTile lastLocation; | |
| 36 | private long startTime; | |
| 37 | private int startExp; | |
| 38 | ||
| 39 | @Override | |
| 40 | public void run() {
| |
| 41 | MessageListener.addListener(this); | |
| 42 | Mouse.setSpeed(800); | |
| 43 | ||
| 44 | while (rocks.size() == 0) | |
| 45 | sleep(100); | |
| 46 | ||
| 47 | startExp = Skills.getXP(Skills.SKILLS.MINING); | |
| 48 | startTime = System.currentTimeMillis(); | |
| 49 | ||
| 50 | while (true) {
| |
| 51 | if (Inventory.find(PICKAXE_FILTER).length == 0 && !Equipment.isEquipped(PICKAXE_FILTER)) {
| |
| 52 | System.out.println("No pickaxe, logging out");
| |
| 53 | Login.logout(); | |
| 54 | return; | |
| 55 | } | |
| 56 | ||
| 57 | if (Game.getItemSelectionState() == 1) {
| |
| 58 | Interfaces.get(548, 50).click(); //deselect item | |
| 59 | sleep(200); | |
| 60 | continue; | |
| 61 | } | |
| 62 | ||
| 63 | if (Player.getAnimation() != -1) {
| |
| 64 | if (!checkSmokingRock()) {
| |
| 65 | sleep(100, 200); | |
| 66 | continue; | |
| 67 | } | |
| 68 | System.out.println("Smoking rock detected!");
| |
| 69 | } | |
| 70 | ||
| 71 | if (Inventory.isFull()) | |
| 72 | Inventory.drop(Inventory.find(ORE_FILTER)); | |
| 73 | else if (ChooseOption.isOpen()) | |
| 74 | ChooseOption.select(ChooseOption.getOptions()[1]); | |
| 75 | else if (clickRock()) | |
| 76 | openDropMenu(); | |
| 77 | else sleep(100); | |
| 78 | } | |
| 79 | } | |
| 80 | ||
| 81 | /** | |
| 82 | * Checks the last clicked rock is smoking by using the smoking rock filter | |
| 83 | * @return <tt>true</tt> if the rock is smoking | |
| 84 | */ | |
| 85 | private boolean checkSmokingRock() {
| |
| 86 | if (lastLocation == null) return false; | |
| 87 | RSObject[] rock = Objects.getAt(lastLocation); | |
| 88 | return rock.length > 0 && smokingRockFilter.accept(rock[0]); | |
| 89 | } | |
| 90 | ||
| 91 | /** | |
| 92 | * Opens the option menu for any ore in your inventory | |
| 93 | * @return <tt>true</tt> if the option menu is successfully opened | |
| 94 | */ | |
| 95 | private boolean openDropMenu() {
| |
| 96 | RSItem[] ores = Inventory.find(ORE_FILTER); | |
| 97 | if (ores.length == 0 || !ores[0].hover()) | |
| 98 | return false; | |
| 99 | ||
| 100 | Mouse.click(MouseEvent.BUTTON3); | |
| 101 | sleep(200); | |
| 102 | return ChooseOption.isOpen(); | |
| 103 | } | |
| 104 | ||
| 105 | /** | |
| 106 | * Clicks with the nearest rock | |
| 107 | * @return <tt>true</tt> if the rock has successfully been clicked | |
| 108 | */ | |
| 109 | private boolean clickRock() {
| |
| 110 | RSObject[] rock = Objects.findNearest(10, rockFilter); | |
| 111 | if (rock.length == 0 || !rock[0].click()) | |
| 112 | return false; | |
| 113 | ||
| 114 | if (!Timing.waitCondition(new Condition() {
| |
| 115 | @Override | |
| 116 | public boolean active() {
| |
| 117 | return Game.getCrosshairState() == 2; | |
| 118 | } | |
| 119 | }, 300)) {
| |
| 120 | Mouse.move(Mouse.getPos().x + General.random(-10, 10), Mouse.getPos().y + General.random(-10, 10)); | |
| 121 | return false; | |
| 122 | } | |
| 123 | ||
| 124 | lastLocation = rock[0].getPosition(); | |
| 125 | return Timing.waitCondition(new Condition() {
| |
| 126 | @Override | |
| 127 | public boolean active() {
| |
| 128 | return Player.getAnimation() != -1; | |
| 129 | } | |
| 130 | }, 3000); | |
| 131 | } | |
| 132 | ||
| 133 | /** | |
| 134 | * Gets the rock under the specified point, by checking the tile polygon of each rock in a radius of 15 | |
| 135 | * @param point the point that may be hovering the rock | |
| 136 | * @return {@link org.tribot.api2007.types.RSObject} that has the name 'Rocks' and contains the specified point
| |
| 137 | */ | |
| 138 | private RSObject getRockUnderPoint(Point point) {
| |
| 139 | RSObject[] rocks = Objects.find(15, "Rocks"); | |
| 140 | for (RSObject rock : rocks) {
| |
| 141 | if (Projection.getTileBoundsPoly(rock.getPosition(), 0).contains(point)) | |
| 142 | return rock; | |
| 143 | } | |
| 144 | return null; | |
| 145 | } | |
| 146 | ||
| 147 | @Override | |
| 148 | public void onPaint(Graphics g) {
| |
| 149 | g.setColor(Color.green); | |
| 150 | for (RSTile tile : rocks.keySet()) {
| |
| 151 | g.drawPolygon(Projection.getTileBoundsPoly(tile, 0)); | |
| 152 | } | |
| 153 | ||
| 154 | if (rocks.size() == 0) {
| |
| 155 | g.drawString("Click the rocks you want to mine...", 10, 40);
| |
| 156 | } | |
| 157 | ||
| 158 | g.setColor(MENU_COLOR); | |
| 159 | g.fillRect(5, 25, 200, 140); | |
| 160 | g.setColor(Color.WHITE); | |
| 161 | g.drawRect(5, 25, 200, 140); | |
| 162 | g.drawRect(15, 30, 180, 22); | |
| 163 | int expGained = Skills.getXP(Skills.SKILLS.MINING) - startExp; | |
| 164 | g.drawString("PowerMiner - By AlphaDog", 25, 45);
| |
| 165 | g.drawString("Runtime: " + Timing.msToString(System.currentTimeMillis() - startTime), 25, 70);
| |
| 166 | g.drawString("Mined: " + amountMined.get(), 25, 90);
| |
| 167 | g.drawString("Mined/Hour: " + getPerHour(amountMined.get()), 25, 110);
| |
| 168 | g.drawString("Exp gained: " + expGained, 25, 130);
| |
| 169 | g.drawString("Exp/Hour: " + getPerHour(expGained), 25, 150);
| |
| 170 | } | |
| 171 | ||
| 172 | private int getPerHour(final int value) {
| |
| 173 | return (int) (value * 3600000D / (System.currentTimeMillis() - startTime)); | |
| 174 | } | |
| 175 | ||
| 176 | /** | |
| 177 | * Overides the mouse event, to make sure that you can enable/disable any rock by clicking on it, | |
| 178 | * without actually interacting with the rock. | |
| 179 | */ | |
| 180 | @Override | |
| 181 | public OVERRIDE_RETURN overrideMouseEvent(final MouseEvent mouseEvent) {
| |
| 182 | if (mouseEvent.getButton() == MouseEvent.BUTTON1) {
| |
| 183 | RSObject rock = getRockUnderPoint(mouseEvent.getPoint()); | |
| 184 | if (rock != null) {
| |
| 185 | if (!rocks.containsKey(rock.getPosition())) {
| |
| 186 | rocks.put(rock.getPosition(), rock.getModel().getVertexCount()); | |
| 187 | } else {
| |
| 188 | rocks.remove(rock.getPosition()); | |
| 189 | } | |
| 190 | return OVERRIDE_RETURN.DISMISS; | |
| 191 | } | |
| 192 | } | |
| 193 | ||
| 194 | return OVERRIDE_RETURN.SEND; | |
| 195 | } | |
| 196 | ||
| 197 | @Override | |
| 198 | public OVERRIDE_RETURN overrideKeyEvent(KeyEvent keyEvent) {
| |
| 199 | return OVERRIDE_RETURN.SEND; | |
| 200 | } | |
| 201 | ||
| 202 | @Override | |
| 203 | public void serverMessageReceived(String s) {
| |
| 204 | if (s.contains("mine some"))
| |
| 205 | amountMined.getAndIncrement(); | |
| 206 | } | |
| 207 | ||
| 208 | //I wish we had an adapter for this :/ | |
| 209 | @Override | |
| 210 | public void clanMessageReceived(String s, String s2) {
| |
| 211 | ||
| 212 | } | |
| 213 | ||
| 214 | @Override | |
| 215 | public void duelRequestReceived(String s, String s2) {
| |
| 216 | ||
| 217 | } | |
| 218 | ||
| 219 | @Override | |
| 220 | public void playerMessageReceived(String s, String s2) {
| |
| 221 | ||
| 222 | } | |
| 223 | ||
| 224 | @Override | |
| 225 | public void personalMessageReceived(String s, String s2) {
| |
| 226 | ||
| 227 | } | |
| 228 | ||
| 229 | @Override | |
| 230 | public void tradeRequestReceived(String s) {
| |
| 231 | ||
| 232 | } | |
| 233 | } |