Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @ScriptManifest(name = "PowerMiner", authors = "AlphaDog", category = "Mining")
- public class PowerMiner extends Script implements Painting, EventBlockingOverride, MessageListening07 {
- private static final Color MENU_COLOR = new Color(0, 0, 0, 95);
- private static final Filter<RSItem> ORE_FILTER = Filters.Items.nameContains("ore", "Clay");
- private static final Filter<RSItem> PICKAXE_FILTER = Filters.Items.nameContains("pickaxe");
- private Filter<RSObject> rockFilter = new Filter<RSObject>() {
- @Override
- public boolean accept(RSObject rsObject) {
- for (RSTile tile : rocks.keySet()) {
- if (rsObject.getPosition().equals(tile)) {
- RSObjectDefinition def = rsObject.getDefinition();
- if (def == null) return false;
- short[] colors = def.getModifiedColors();
- return colors != null && colors.length > 1 && colors[0] != colors[1] && !smokingRockFilter.accept(rsObject);
- }
- }
- return false;
- }
- };
- private final Filter<RSObject> smokingRockFilter = new Filter<RSObject>() {
- @Override
- public boolean accept(RSObject rsObject) {
- RSModel model = rsObject.getModel();
- return model != null && Math.abs(rocks.get(rsObject.getPosition()) - model.getVertexCount()) > 20;
- }
- };
- private final ConcurrentHashMap<RSTile, Integer> rocks = new ConcurrentHashMap<>();
- private AtomicInteger amountMined = new AtomicInteger();
- private RSTile lastLocation;
- private long startTime;
- private int startExp;
- @Override
- public void run() {
- MessageListener.addListener(this);
- Mouse.setSpeed(800);
- while (rocks.size() == 0)
- sleep(100);
- startExp = Skills.getXP(Skills.SKILLS.MINING);
- startTime = System.currentTimeMillis();
- while (true) {
- if (Inventory.find(PICKAXE_FILTER).length == 0 && !Equipment.isEquipped(PICKAXE_FILTER)) {
- System.out.println("No pickaxe, logging out");
- Login.logout();
- return;
- }
- if (Game.getItemSelectionState() == 1) {
- Interfaces.get(548, 50).click(); //deselect item
- sleep(200);
- continue;
- }
- if (Player.getAnimation() != -1) {
- if (!checkSmokingRock()) {
- sleep(100, 200);
- continue;
- }
- System.out.println("Smoking rock detected!");
- }
- if (Inventory.isFull())
- Inventory.drop(Inventory.find(ORE_FILTER));
- else if (ChooseOption.isOpen())
- ChooseOption.select(ChooseOption.getOptions()[1]);
- else if (clickRock())
- openDropMenu();
- else sleep(100);
- }
- }
- /**
- * Checks the last clicked rock is smoking by using the smoking rock filter
- * @return <tt>true</tt> if the rock is smoking
- */
- private boolean checkSmokingRock() {
- if (lastLocation == null) return false;
- RSObject[] rock = Objects.getAt(lastLocation);
- return rock.length > 0 && smokingRockFilter.accept(rock[0]);
- }
- /**
- * Opens the option menu for any ore in your inventory
- * @return <tt>true</tt> if the option menu is successfully opened
- */
- private boolean openDropMenu() {
- RSItem[] ores = Inventory.find(ORE_FILTER);
- if (ores.length == 0 || !ores[0].hover())
- return false;
- Mouse.click(MouseEvent.BUTTON3);
- sleep(200);
- return ChooseOption.isOpen();
- }
- /**
- * Clicks with the nearest rock
- * @return <tt>true</tt> if the rock has successfully been clicked
- */
- private boolean clickRock() {
- RSObject[] rock = Objects.findNearest(10, rockFilter);
- if (rock.length == 0 || !rock[0].click())
- return false;
- if (!Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return Game.getCrosshairState() == 2;
- }
- }, 300)) {
- Mouse.move(Mouse.getPos().x + General.random(-10, 10), Mouse.getPos().y + General.random(-10, 10));
- return false;
- }
- lastLocation = rock[0].getPosition();
- return Timing.waitCondition(new Condition() {
- @Override
- public boolean active() {
- return Player.getAnimation() != -1;
- }
- }, 3000);
- }
- /**
- * Gets the rock under the specified point, by checking the tile polygon of each rock in a radius of 15
- * @param point the point that may be hovering the rock
- * @return {@link org.tribot.api2007.types.RSObject} that has the name 'Rocks' and contains the specified point
- */
- private RSObject getRockUnderPoint(Point point) {
- RSObject[] rocks = Objects.find(15, "Rocks");
- for (RSObject rock : rocks) {
- if (Projection.getTileBoundsPoly(rock.getPosition(), 0).contains(point))
- return rock;
- }
- return null;
- }
- @Override
- public void onPaint(Graphics g) {
- g.setColor(Color.green);
- for (RSTile tile : rocks.keySet()) {
- g.drawPolygon(Projection.getTileBoundsPoly(tile, 0));
- }
- if (rocks.size() == 0) {
- g.drawString("Click the rocks you want to mine...", 10, 40);
- }
- g.setColor(MENU_COLOR);
- g.fillRect(5, 25, 200, 140);
- g.setColor(Color.WHITE);
- g.drawRect(5, 25, 200, 140);
- g.drawRect(15, 30, 180, 22);
- int expGained = Skills.getXP(Skills.SKILLS.MINING) - startExp;
- g.drawString("PowerMiner - By AlphaDog", 25, 45);
- g.drawString("Runtime: " + Timing.msToString(System.currentTimeMillis() - startTime), 25, 70);
- g.drawString("Mined: " + amountMined.get(), 25, 90);
- g.drawString("Mined/Hour: " + getPerHour(amountMined.get()), 25, 110);
- g.drawString("Exp gained: " + expGained, 25, 130);
- g.drawString("Exp/Hour: " + getPerHour(expGained), 25, 150);
- }
- private int getPerHour(final int value) {
- return (int) (value * 3600000D / (System.currentTimeMillis() - startTime));
- }
- /**
- * Overides the mouse event, to make sure that you can enable/disable any rock by clicking on it,
- * without actually interacting with the rock.
- */
- @Override
- public OVERRIDE_RETURN overrideMouseEvent(final MouseEvent mouseEvent) {
- if (mouseEvent.getButton() == MouseEvent.BUTTON1) {
- RSObject rock = getRockUnderPoint(mouseEvent.getPoint());
- if (rock != null) {
- if (!rocks.containsKey(rock.getPosition())) {
- rocks.put(rock.getPosition(), rock.getModel().getVertexCount());
- } else {
- rocks.remove(rock.getPosition());
- }
- return OVERRIDE_RETURN.DISMISS;
- }
- }
- return OVERRIDE_RETURN.SEND;
- }
- @Override
- public OVERRIDE_RETURN overrideKeyEvent(KeyEvent keyEvent) {
- return OVERRIDE_RETURN.SEND;
- }
- @Override
- public void serverMessageReceived(String s) {
- if (s.contains("mine some"))
- amountMined.getAndIncrement();
- }
- //I wish we had an adapter for this :/
- @Override
- public void clanMessageReceived(String s, String s2) {
- }
- @Override
- public void duelRequestReceived(String s, String s2) {
- }
- @Override
- public void playerMessageReceived(String s, String s2) {
- }
- @Override
- public void personalMessageReceived(String s, String s2) {
- }
- @Override
- public void tradeRequestReceived(String s) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement