-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathGuildRanger.java
489 lines (399 loc) · 10.8 KB
/
GuildRanger.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
import org.rsbot.event.listeners.PaintListener;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.methods.Skills;
import org.rsbot.script.util.Timer;
import org.rsbot.script.wrappers.*;
import java.awt.*;
import java.util.HashSet;
import java.util.Set;
@ScriptManifest(name = "Guild Ranger", authors = {"Vastico"}, description = "Trains range at the ranging guild on the targets.", version = 1.7, keywords = {
"Combat", "Ranged"})
public class GuildRanger extends Script implements PaintListener {
private interface GameConstants {
RSArea SHOOTING_AREA = new RSArea(2669, 3417, 2673, 3420);
RSArea SAFE_AREA = new RSArea(2646, 3440, 2643, 3444);
RSTile GUILD_DOOR_TILE = new RSTile(2659, 3437);
RSTile SAFE_DOOR_TILE = new RSTile(2656, 3440);
int TARGET = 2513;
int BRONZE_ARROW = 882;
int COMPETITION_JUDGE = 693;
int GUILD_DOOR = 2514;
int PAYMENT_INTERFACE = 236;
int TARGET_INTERFACE = 325;
Color BACKGROUND_COLOR = new Color(0, 0, 0, 100);
Color TEXT_COLOR = new Color(255, 255, 255, 255);
RenderingHints ANTI_ALIASING = new RenderingHints(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
}
private abstract class Action {
public abstract void execute();
public abstract void complete();
public abstract boolean isValid();
public abstract String getDescription();
public void paint(Graphics render) {
}
}
private abstract class ObjectAction extends Action {
private final int id;
private final String action;
private Point location;
private int attempts = 0;
public ObjectAction(int id, String action) {
this.id = id;
this.action = action;
}
@Override
public void execute() {
if (location != null) {
mouse.move(location, 1, 1);
if (isTargetInterfaceOpen()) {
mouse.click(location, 1, 1, true);
}
if (menu.doAction(action)) {
sleep(20);
attempts = 0;
} else if (attempts > 8) {
failsafe = true;
} else {
attempts++;
}
} else {
RSObject obj = objects.getNearest(id);
if (obj != null) {
if (obj.isOnScreen()) {
location = obj.getModel().getPoint();
} else {
camera.turnTo(obj, 10);
}
}
}
}
@Override
public void complete() {
attempts = 0;
location = null;
}
@Override
public String getDescription() {
return "Object Action [" + action + "]";
}
}
private abstract class NPCAction extends Action {
private final int id;
private final String action;
public NPCAction(int id, String action) {
this.id = id;
this.action = action;
}
@Override
public void execute() {
if (judge == null) {
judge = npcs.getNearest(id);
}
if (judge != null) {
if (!judge.isOnScreen()) {
camera.turnTo(judge, 10);
} else if (judge.doAction(action)) {
if (!getMyPlayer().isIdle()) {
sleep(500);
}
sleep(1500);
}
}
}
@Override
public void complete() {
}
@Override
public String getDescription() {
return "NPC Action [" + action + "]";
}
}
private abstract class UniversalAction extends Action {
@Override
public void execute() {
}
@Override
public void complete() {
}
@Override
public boolean isValid() {
return false;
}
@Override
public String getDescription() {
return "";
}
}
private abstract class WalkToArea extends Action {
private final RSArea destination;
private final String description;
private RSTile location;
public WalkToArea(RSArea destination, String description) {
this.destination = destination;
this.description = description;
}
public abstract boolean isTargetValid();
@Override
public void execute() {
if (!walking.isRunEnabled() && walking.getEnergy() > random(20, 50)) {
walking.setRun(true);
sleep(500);
}
RSTile tile = destination.getCentralTile();
if (location == null
|| getMyPlayer().isIdle()
|| (calc.distanceTo(location) < 10 && !destination
.contains(location))) {
if (calc.tileOnScreen(tile) && random(0, 10) > 7) {
walking.walkTileOnScreen(calc.getTileOnScreen(tile));
} else {
walking.walkTo(tile);
}
location = walking.getDestination();
sleep(random(1000, 1800));
}
}
@Override
public void complete() {
location = null;
}
@Override
public boolean isValid() {
return isTargetValid()
&& !destination.contains(getMyPlayer().getLocation());
}
@Override
public String getDescription() {
return "Walk To Area [" + description + "]";
}
}
private Set<Action> actions;
private long startTime = 0L;
private int startXp = 0;
private int startLvl = 0;
private RSNPC judge;
private Action action;
private boolean failsafe = false;
@Override
public boolean onStart() {
actions = new HashSet<Action>();
actions.add(new UniversalAction() {
@Override
public void execute() {
RSComponent closeInterface = interfaces.getComponent(
GameConstants.TARGET_INTERFACE, 40);
if (closeInterface != null && closeInterface.isValid()) {
closeInterface.doClick();
sleep(500);
}
failsafe = false;
}
@Override
public boolean isValid() {
return failsafe && isTargetInterfaceOpen();
}
@Override
public String getDescription() {
return "Closing Failsafe Interface";
}
});
actions.add(new UniversalAction() {
@Override
public void execute() {
RSComponent paymentInterface = interfaces.getComponent(
GameConstants.PAYMENT_INTERFACE, 1);
if (paymentInterface != null && paymentInterface.isValid()) {
paymentInterface.doClick();
sleep(500);
}
}
@Override
public boolean isValid() {
return isPaymentInterfaceOpen();
}
@Override
public String getDescription() {
return "Paying Competition Judge";
}
});
actions.add(new UniversalAction() {
@Override
public void execute() {
RSItem bronzeArrow = inventory
.getItem(GameConstants.BRONZE_ARROW);
if (bronzeArrow != null) {
bronzeArrow.doAction("Wield");
sleep(1200);
}
}
@Override
public boolean isValid() {
return hasArrowsInInventory();
}
@Override
public String getDescription() {
return "Wielding Arrows";
}
});
actions.add(new WalkToArea(GameConstants.SAFE_AREA, "safe area") {
@Override
public void execute() {
RSObject obj = objects.getNearest(GameConstants.GUILD_DOOR);
if (obj != null
&& calc.distanceBetween(obj.getLocation(),
GameConstants.GUILD_DOOR_TILE) < 2) {
if (obj.isOnScreen()) {
if (obj.doAction("Open")) {
sleep(random(1000, 2000));
}
} else if (!GameConstants.GUILD_DOOR_TILE.equals(walking
.getDestination())) {
walking.walkTo(GameConstants.GUILD_DOOR_TILE);
}
} else {
super.execute();
}
}
@Override
public boolean isTargetValid() {
return isAttackingRanger();
}
});
actions.add(new WalkToArea(GameConstants.SHOOTING_AREA, "shooting area") {
@Override
public void execute() {
RSObject obj = objects.getNearest(GameConstants.GUILD_DOOR);
if (obj != null
&& calc.distanceBetween(obj.getLocation(),
GameConstants.SAFE_DOOR_TILE) < 2) {
if (obj.isOnScreen()) {
if (obj.doAction("Open")) {
sleep(random(1000, 2000));
}
} else if (!GameConstants.SAFE_DOOR_TILE.equals(walking
.getDestination())) {
walking.walkTo(GameConstants.SAFE_DOOR_TILE);
}
} else {
super.execute();
}
}
@Override
public boolean isTargetValid() {
return !inShootingArea() && !isAttackingRanger();
}
});
actions.add(new ObjectAction(GameConstants.TARGET, "Fire-at") {
@Override
public void execute() {
super.execute();
}
@Override
public boolean isValid() {
return !canCompete() && inShootingArea()
&& !hasArrowsInInventory() && !failsafe;
}
});
actions.add(new NPCAction(GameConstants.COMPETITION_JUDGE, "Compete") {
@Override
public boolean isValid() {
return canCompete() && !isPaymentInterfaceOpen()
&& !hasArrowsInInventory();
}
});
return true;
}
@Override
public int loop() {
mouse.setSpeed(random(6, 8));
if (camera.getPitch() > 1) {
camera.setPitch(false);
}
if (action != null) {
if (action.isValid()) {
action.execute();
} else {
action.complete();
action = null;
}
} else {
for (Action a : actions) {
if (a.isValid()) {
action = a;
break;
}
}
}
return random(50, 100);
}
@Override
public void onFinish() {
}
private boolean inShootingArea() {
return GameConstants.SHOOTING_AREA
.contains(getMyPlayer().getLocation());
}
private boolean isAttackingRanger() {
return getMyPlayer().getInteracting() != null
&& getMyPlayer().getInteracting().getName() != null
&& getMyPlayer().getInteracting().getName().equals("Guard");
}
private boolean canCompete() {
return settings.getSetting(156) == 0 || interfaces.get(243).isValid();
}
private boolean hasArrowsInInventory() {
return inventory.getCount(GameConstants.BRONZE_ARROW) > 0;
}
private boolean isTargetInterfaceOpen() {
return interfaces.get(GameConstants.TARGET_INTERFACE).isValid();
}
private boolean isPaymentInterfaceOpen() {
return interfaces.get(GameConstants.PAYMENT_INTERFACE).isValid();
}
@Override
public void onRepaint(Graphics render) {
if (game.isLoggedIn() && skills.getRealLevel(Skills.RANGE) >= 40) {
Graphics2D g = (Graphics2D) render;
g.setRenderingHints(GameConstants.ANTI_ALIASING);
if (startTime == 0) {
startTime = System.currentTimeMillis();
}
if (startXp == 0) {
startXp = skills.getCurrentExp(Skills.RANGE);
}
if (startLvl == 0) {
startLvl = skills.getRealLevel(Skills.RANGE);
}
if (action != null) {
action.paint(g);
}
g.setColor(GameConstants.BACKGROUND_COLOR);
g.fillRect(10, 35, 205, 195);
g.setColor(GameConstants.TEXT_COLOR);
g.drawRect(10, 35, 205, 195);
g.drawString("GuildRanger by Vastico", 20, 55);
g.drawString(Timer.format(System.currentTimeMillis() - startTime),
20, 75);
g.drawString(action != null ? action.getDescription()
: "Calculating...", 20, 95);
g.drawString("XP Gained: "
+ (skills.getCurrentExp(Skills.RANGE) - startXp), 20, 115);
g.drawString("XP Per Hour: " + calculateXpPerHour(), 20, 135);
g.drawString("Current Level: " + skills.getRealLevel(Skills.RANGE),
20, 155);
g.drawString("Levels Gained: "
+ (skills.getRealLevel(Skills.RANGE) - startLvl), 20, 175);
g.drawString("Current Score: " + settings.getSetting(157), 20, 195);
int hit = settings.getSetting(156);
hit = hit >= 1 ? hit - 1 : 0;
g.drawString("Arrows Fired(10): " + hit, 20, 215);
}
}
private int calculateXpPerHour() {
int gainedXp = (skills.getCurrentExp(Skills.RANGE) - startXp);
return (int) ((3600000.0 / (System.currentTimeMillis() - startTime)) * gainedXp);
}
}