View difference between Paste ID: jyN2UrVN and cEj6ZCYt
SHOW: | | - or go back to the newest paste.
1-
@ScriptManifest(name = "PowerMiner", authors = "AlphaDog", category = "Mining")
1+
public enum AgilityCourse {
2-
public class PowerMiner extends Script implements Painting, EventBlockingOverride, MessageListening07 {
2+
3-
    private static final Color MENU_COLOR = new Color(0, 0, 0, 95);
3+
    GNOME_COURSE(
4
            new Obstacle(
5-
    private static final Filter<RSItem> ORE_FILTER = Filters.Items.nameContains("ore", "Clay");
5+
                    "Log balance",
6-
    private static final Filter<RSItem> PICKAXE_FILTER = Filters.Items.nameContains("pickaxe");
6+
                    new RSArea(new RSTile[]{
7
                            new RSTile(2468, 3435, 0),
8-
    private Filter<RSObject> rockFilter = new Filter<RSObject>() {
8+
                            new RSTile(2491, 3436, 0),
9-
        @Override
9+
                            new RSTile(2487, 3441, 0),
10-
        public boolean accept(RSObject rsObject) {
10+
                            new RSTile(2472, 3441, 0)
11-
            for (RSTile tile : rocks.keySet()) {
11+
                    })
12-
                if (rsObject.getPosition().equals(tile)) {
12+
            ),
13-
                    RSObjectDefinition def = rsObject.getDefinition();
13+
            new Obstacle(
14-
                    if (def == null) return false;
14+
                    "Obstacle net",
15-
                    short[] colors = def.getModifiedColors();
15+
                    new RSArea(new RSTile[]{
16-
                    return colors != null && colors.length > 1 && colors[0] != colors[1] && !smokingRockFilter.accept(rsObject);
16+
                            new RSTile(2470, 3430, 0),
17-
                }
17+
                            new RSTile(2470, 3425, 0),
18
                            new RSTile(2478, 3425, 0),
19
                            new RSTile(2478, 3430, 0)
20-
            return false;
20+
                    })
21
            ),
22-
    };
22+
            new Obstacle(
23
                    "Tree branch",
24-
    private final Filter<RSObject> smokingRockFilter = new Filter<RSObject>() {
24+
                    new RSArea(new RSTile[]{
25-
        @Override
25+
                            new RSTile(2471, 3425, 1),
26-
        public boolean accept(RSObject rsObject) {
26+
                            new RSTile(2471, 3422, 1),
27-
            RSModel model = rsObject.getModel();
27+
                            new RSTile(2477, 3422, 1),
28-
            return model != null && Math.abs(rocks.get(rsObject.getPosition()) - model.getVertexCount()) > 20;
28+
                            new RSTile(2477, 3425, 1)
29
                    })
30-
    };
30+
            ),
31
            new Obstacle(
32-
    private final ConcurrentHashMap<RSTile, Integer> rocks = new ConcurrentHashMap<>();
32+
                    "Balancing rope",
33
                    new RSArea(new RSTile[]{
34-
    private AtomicInteger amountMined = new AtomicInteger();
34+
                            new RSTile(2472, 3422, 2),
35-
    private RSTile lastLocation;
35+
                            new RSTile(2472, 3418, 2),
36-
    private long startTime;
36+
                            new RSTile(2478, 3418, 2),
37-
    private int startExp;
37+
                            new RSTile(2478, 3422, 2)
38
                    })
39-
    @Override
39+
            ),
40-
    public void run() {
40+
            new Obstacle(
41-
        MessageListener.addListener(this);
41+
                    "Tree branch",
42-
        Mouse.setSpeed(800);
42+
                    new RSArea(new RSTile[]{
43
                            new RSTile(2483, 3418, 2),
44-
        while (rocks.size() == 0)
44+
                            new RSTile(2489, 3418, 2),
45-
            sleep(100);
45+
                            new RSTile(2489, 3422, 2),
46
                            new RSTile(2483, 3422, 2)
47-
        startExp = Skills.getXP(Skills.SKILLS.MINING);
47+
                    })
48-
        startTime = System.currentTimeMillis();
48+
            ),
49
            new Obstacle(
50-
        while (true) {
50+
                    "Obstacle net",
51-
            if (Inventory.find(PICKAXE_FILTER).length == 0 && !Equipment.isEquipped(PICKAXE_FILTER)) {
51+
                    new RSArea(new RSTile[]{
52-
                System.out.println("No pickaxe, logging out");
52+
                            new RSTile(2483, 3416, 0),
53-
                Login.logout();
53+
                            new RSTile(2489, 3416, 0),
54-
                return;
54+
                            new RSTile(2488, 3426, 0),
55
                            new RSTile(2483, 3426, 0)
56
                    })
57-
            if (Game.getItemSelectionState() == 1) {
57+
            ),
58-
                Interfaces.get(548, 50).click(); //deselect item
58+
            new Obstacle(
59-
                sleep(200);
59+
                    "Obstacle pipe",
60-
                continue;
60+
                    new RSArea(new RSTile[]{
61
                            new RSTile(2483, 3427, 0),
62
                            new RSTile(2489, 3427, 0),
63-
            if (Player.getAnimation() != -1) {
63+
                            new RSTile(2489, 3432, 0),
64-
                if (!checkSmokingRock()) {
64+
                            new RSTile(2483, 3432, 0)
65-
                    sleep(100, 200);
65+
                    })
66-
                    continue;
66+
            )
67-
                }
67+
    ),
68-
                System.out.println("Smoking rock detected!");
68+
69
    DRAYNOR_ROOF(
70
            new Obstacle(
71-
            if (Inventory.isFull())
71+
                    "Rough wall",
72-
                Inventory.drop(Inventory.find(ORE_FILTER));
72+
                    new RSArea(new RSTile[] {
73-
            else if (ChooseOption.isOpen())
73+
                            new RSTile(3102, 3259, 0),
74-
                ChooseOption.select(ChooseOption.getOptions()[1]);
74+
                            new RSTile(3105, 3259, 0),
75-
            else if (clickRock())
75+
                            new RSTile(3106, 3282, 0),
76-
                openDropMenu();
76+
                            new RSTile(3103, 3282, 0)
77-
            else sleep(100);
77+
                    })),
78
            new Obstacle(
79
                    "Tightrope",
80
                    new RSArea(new RSTile[] {
81
                            new RSTile(3097, 3277, 3),
82-
     * Checks the last clicked rock is smoking by using the smoking rock filter
82+
                            new RSTile(3103, 3277, 3),
83-
     * @return <tt>true</tt> if the rock is smoking
83+
                            new RSTile(3103, 3282, 3),
84
                            new RSTile(3097, 3282, 3)
85-
    private boolean checkSmokingRock() {
85+
                    })),
86-
        if (lastLocation == null) return false;
86+
            new Obstacle(
87-
        RSObject[] rock = Objects.getAt(lastLocation);
87+
                    "Tightrope",
88-
        return rock.length > 0 && smokingRockFilter.accept(rock[0]);
88+
                    new RSArea(new RSTile[] {
89
                            new RSTile(3093, 3275, 3),
90
                            new RSTile(3090, 3278, 3),
91
                            new RSTile(3087, 3274, 3),
92-
     * Opens the option menu for any ore in your inventory
92+
                            new RSTile(3090, 3270, 3)
93-
     * @return <tt>true</tt> if the option menu is successfully opened
93+
                    })),
94
            new Obstacle(
95-
    private boolean openDropMenu() {
95+
                    "Narrow wall",
96-
        RSItem[] ores = Inventory.find(ORE_FILTER);
96+
                    new RSArea(new RSTile[] {
97-
        if (ores.length == 0 || !ores[0].hover())
97+
                            new RSTile(3089, 3265, 3),
98-
            return false;
98+
                            new RSTile(3096, 3264, 3),
99
                            new RSTile(3096, 3269, 3),
100-
        Mouse.click(MouseEvent.BUTTON3);
100+
                            new RSTile(3089, 3268, 3)
101-
        sleep(200);
101+
                    })),
102-
        return ChooseOption.isOpen();
102+
            new Obstacle(
103
                    "Wall",
104
                    new RSArea(new RSTile[] {
105
                            new RSTile(3089, 3262, 3),
106-
     * Clicks with the nearest rock
106+
                            new RSTile(3089, 3256, 3),
107-
     * @return <tt>true</tt> if the rock has successfully been clicked
107+
                            new RSTile(3087, 3256, 3),
108
                            new RSTile(3087, 3261, 3)
109-
    private boolean clickRock() {
109+
                    })),
110-
        RSObject[] rock = Objects.findNearest(10, rockFilter);
110+
            new Obstacle("Gap",
111-
        if (rock.length == 0 || !rock[0].click())
111+
                    new RSArea(new RSTile[] {
112-
            return false;
112+
                            new RSTile(3087, 3256, 3),
113
                            new RSTile(3095, 3256, 3),
114-
        if (!Timing.waitCondition(new Condition() {
114+
                            new RSTile(3095, 3254, 3),
115-
            @Override
115+
                            new RSTile(3087, 3254, 3)
116-
            public boolean active() {
116+
                    })),
117-
                return Game.getCrosshairState() == 2;
117+
            new Obstacle("Crate",
118
                    new RSArea(new RSTile[] {
119-
        }, 300)) {
119+
                            new RSTile(3096, 3262, 3),
120-
            Mouse.move(Mouse.getPos().x + General.random(-10, 10), Mouse.getPos().y + General.random(-10, 10));
120+
                            new RSTile(3102, 3262, 3),
121-
            return false;
121+
                            new RSTile(3101, 3256, 3),
122
                            new RSTile(3096, 3256, 3)
123
                    }))
124-
        lastLocation = rock[0].getPosition();
124+
    ),
125-
        return Timing.waitCondition(new Condition() {
125+
126-
            @Override
126+
    AL_KHARID_ROOF(
127-
            public boolean active() {
127+
            new Obstacle(
128-
                return Player.getAnimation() != -1;
128+
                    "Rough wall",
129
                    new RSArea(new RSTile[] {
130-
        }, 3000);
130+
                            new RSTile(3301, 3195, 0),
131
                            new RSTile(3298, 3198, 0),
132
                            new RSTile(3270, 3199, 0),
133
                            new RSTile(3270, 3195, 0),
134-
     * Gets the rock under the specified point, by checking the tile polygon of each rock in a radius of 15
134+
                            new RSTile(3296, 3191, 0)
135-
     * @param point the point that may be hovering the rock
135+
                    })),
136-
     * @return {@link org.tribot.api2007.types.RSObject} that has the name 'Rocks' and contains the specified point
136+
            new Obstacle(
137
                    "Tightrope",
138-
    private RSObject getRockUnderPoint(Point point) {
138+
                    new RSArea(new RSTile[] {
139-
        RSObject[] rocks = Objects.find(15, "Rocks");
139+
                            new RSTile(3270, 3196, 3),
140-
        for (RSObject rock : rocks) {
140+
                            new RSTile(3279, 3196, 3),
141-
            if (Projection.getTileBoundsPoly(rock.getPosition(), 0).contains(point))
141+
                            new RSTile(3278, 3179, 3),
142-
                return rock;
142+
                            new RSTile(3270, 3179, 3)
143
                    })),
144
            new Obstacle(
145
                    "Cable",
146
                    new RSArea(new RSTile[] {
147-
    @Override
147+
                            new RSTile(3273, 3174, 3),
148-
    public void onPaint(Graphics g) {
148+
                            new RSTile(3265, 3174, 3),
149-
        g.setColor(Color.green);
149+
                            new RSTile(3265, 3161, 3),
150-
        for (RSTile tile : rocks.keySet()) {
150+
                            new RSTile(3272, 3161, 3)
151-
            g.drawPolygon(Projection.getTileBoundsPoly(tile, 0));
151+
                    })),
152
            new Obstacle(
153
                    "Zip line",
154-
        if (rocks.size() == 0) {
154+
                    new RSArea(new RSTile[] {
155-
            g.drawString("Click the rocks you want to mine...", 10, 40);
155+
                            new RSTile(3303, 3159, 3),
156
                            new RSTile(3303, 3170, 3),
157
                            new RSTile(3289, 3169, 3),
158-
        g.setColor(MENU_COLOR);
158+
                            new RSTile(3288, 3177, 3),
159-
        g.fillRect(5, 25, 200, 140);
159+
                            new RSTile(3283, 3177, 3),
160-
        g.setColor(Color.WHITE);
160+
                            new RSTile(3283, 3160, 3)
161-
        g.drawRect(5, 25, 200, 140);
161+
                    })),
162-
        g.drawRect(15, 30, 180, 22);
162+
            new Obstacle(
163-
        int expGained = Skills.getXP(Skills.SKILLS.MINING) - startExp;
163+
                    "Tropical tree",
164-
        g.drawString("PowerMiner - By AlphaDog", 25, 45);
164+
                    new RSArea(new RSTile[] {
165-
        g.drawString("Runtime: " + Timing.msToString(System.currentTimeMillis() - startTime), 25, 70);
165+
                            new RSTile(3313, 3166, 1),
166-
        g.drawString("Mined: " + amountMined.get(), 25, 90);
166+
                            new RSTile(3313, 3160, 1),
167-
        g.drawString("Mined/Hour: " + getPerHour(amountMined.get()), 25, 110);
167+
                            new RSTile(3319, 3160, 1),
168-
        g.drawString("Exp gained: " + expGained, 25, 130);
168+
                            new RSTile(3319, 3166, 1)
169-
        g.drawString("Exp/Hour: " + getPerHour(expGained), 25, 150);
169+
                    })),
170
            new Obstacle(
171
                    "Roof top beams",
172-
    private int getPerHour(final int value) {
172+
                    new RSArea(new RSTile[] {
173-
        return (int) (value * 3600000D / (System.currentTimeMillis() - startTime));
173+
                            new RSTile(3319, 3171, 2),
174
                            new RSTile(3319, 3180, 2),
175
                            new RSTile(3311, 3180, 2),
176
                            new RSTile(3312, 3172, 2)
177-
     * Overides the mouse event, to make sure that you can enable/disable any rock by clicking on it,
177+
                    })),
178-
     * without actually interacting with the rock.
178+
            new Obstacle(
179
                    "Tightrope",
180-
    @Override
180+
                    new RSArea(new RSTile[] {
181-
    public OVERRIDE_RETURN overrideMouseEvent(final MouseEvent mouseEvent) {
181+
                            new RSTile(3319, 3180, 3),
182-
        if (mouseEvent.getButton() == MouseEvent.BUTTON1) {
182+
                            new RSTile(3319, 3187, 3),
183-
            RSObject rock = getRockUnderPoint(mouseEvent.getPoint());
183+
                            new RSTile(3312, 3187, 3),
184-
            if (rock != null) {
184+
                            new RSTile(3312, 3180, 3)
185-
                if (!rocks.containsKey(rock.getPosition())) {
185+
                    })),
186-
                    rocks.put(rock.getPosition(), rock.getModel().getVertexCount());
186+
            new Obstacle(
187-
                } else {
187+
                    "Gap",
188-
                    rocks.remove(rock.getPosition());
188+
                    new RSArea(new RSTile[] {
189-
                }
189+
                            new RSTile(3306, 3188, 3),
190-
                return OVERRIDE_RETURN.DISMISS;
190+
                            new RSTile(3303, 3185, 3),
191
                            new RSTile(3297, 3191, 3),
192
                            new RSTile(3301, 3194, 3)
193
                    }))
194-
        return OVERRIDE_RETURN.SEND;
194+
    );
195
196
    private final Obstacle[] obstacles;
197-
    @Override
197+
198-
    public OVERRIDE_RETURN overrideKeyEvent(KeyEvent keyEvent) {
198+
    AgilityCourse(Obstacle... obstacles) {
199-
        return OVERRIDE_RETURN.SEND;
199+
        this.obstacles = obstacles;
200
    }
201
202-
    @Override
202+
203-
    public void serverMessageReceived(String s) {
203+
     * Gets the next obstacle by checking if the player is inside the obstacle's area
204-
        if (s.contains("mine some"))
204+
     * @return the next {@link scripts.alpharunner.Obstacle}
205-
            amountMined.getAndIncrement();
205+
206
    public Obstacle getNextObstacle() {
207
        for (Obstacle obstacle : obstacles) {
208-
    //I wish we had an adapter for this :/ 
208+
            if (obstacle.area.contains(Player.getPosition()) && obstacle.area.plane == Game.getPlane()) {
209-
    @Override
209+
                return obstacle;
210-
    public void clanMessageReceived(String s, String s2) {
210+
211
        }
212
        return null;
213
    }
214-
    @Override
214+
215-
    public void duelRequestReceived(String s, String s2) {
215+
216
     * Gets the nearest obstacle based on the center of the obstacle's area
217
     * @return the nearest {@link scripts.alpharunner.Obstacle}
218
     */
219-
    @Override
219+
    public Obstacle getNearestObstacle() {
220-
    public void playerMessageReceived(String s, String s2) {
220+
        Obstacle nearest = null;
221
        int distance = Integer.MAX_VALUE;
222
223
        for (Obstacle obstacle : obstacles) {
224-
    @Override
224+
            if (obstacle.area.plane != Game.getPlane()) continue;
225-
    public void personalMessageReceived(String s, String s2) {
225+
            final int tempDist = Utility.getCenterTile(obstacle.area).distanceTo(Player.getPosition());
226
            if (tempDist < distance) {
227
                distance = tempDist;
228
                nearest = obstacle;
229-
    @Override
229+
230-
    public void tradeRequestReceived(String s) {
230+
231
        return nearest;
232
    }
233
234
    /**
235
     * @return <tt>true</tt> if the course is a rooftop course
236
     */
237
    public boolean isRoof() {
238
        return toString().toLowerCase().contains("roof");
239
    }
240
}