-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVRangeGuild.java
More file actions
526 lines (432 loc) · 15.3 KB
/
VRangeGuild.java
File metadata and controls
526 lines (432 loc) · 15.3 KB
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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
import java.applet.Applet;
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.util.regex.Pattern;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import org.hexbot.api.event.MessageEvent;
import org.hexbot.api.event.RenderEvent;
import org.hexbot.api.methods.core.MethodContext;
import org.hexbot.api.methods.input.Camera;
import org.hexbot.api.methods.input.Keyboard;
import org.hexbot.api.methods.input.Mouse;
import org.hexbot.api.methods.interactive.GameObjects;
import org.hexbot.api.methods.interactive.Npcs;
import org.hexbot.api.methods.interactive.Players;
import org.hexbot.api.methods.interactive.Widgets;
import org.hexbot.api.methods.interfaces.Inventory;
import org.hexbot.api.methods.interfaces.Skills;
import org.hexbot.api.methods.movement.Walking;
import org.hexbot.api.methods.util.Settings;
import org.hexbot.api.util.Random;
import org.hexbot.api.util.Time;
import org.hexbot.api.wrapper.Area;
import org.hexbot.api.wrapper.GameObject;
import org.hexbot.api.wrapper.InventoryItem;
import org.hexbot.api.wrapper.Npc;
import org.hexbot.api.wrapper.Tile;
import org.hexbot.api.wrapper.WidgetComponent;
import org.hexbot.script.Category;
import org.hexbot.script.Employer;
import org.hexbot.script.ScriptManifest;
import org.hexbot.script.Worker;
import util.ExchangeItem;
import util.ExchangeParser;
@ScriptManifest(author = "countvidal", description = "Bots Ranging Competition at Range Guild", name = "Vidals Guild Ranger", category = Category.RANGED)
public class VRangeGuild extends Employer implements RenderEvent, MessageEvent,
MouseMotionListener {
// Paint
private static final String PAINT_IMAGE_URL = "http://i.imgur.com/aEDg8dX.png";
int once = 0;
String process = "Null";
private BufferedImage paintImage = null;
// paint related variables
private long startTime;
private long timeRunning;
private int startExp;
private int gainedExp;
private boolean closePaint = false;
private boolean startScript = false;
private int price;
private int starttickets;
public VRangeGuild(MethodContext context) {
super(context);
}
/**
* Substitutes 000000 for M
*
* @return String Number with M
*/
private static String millValue(final int value) {
if (value >= 1000000) {
return Integer.toString(value / 1000000) + "M";
} else {
return Integer.toString(value / 1000) + "K";
}
}
@Override
public void onStart() {
submit(new StartGame(context), new PlayGame(context, new EquipArrows(context),
new ShootTarget(context), new CloseTarget(context),
new GetPrize(context)), new ReturnToSpot(context));
loadImage();
if (context.inventory.contains(1464)) {
starttickets = context.inventory.getItem(1464).getStackSize();
} else {
starttickets = 0;
}
if (!context.inventory.contains(995)) {
System.out.println("No coins in inventory stopping.");
stop();
}
ExchangeItem item = ExchangeParser.lookup("Rune arrows", true);
price = (int) item.getAverage();
System.out.println(Integer.toString(price));
context.mouse.setSpeed(Mouse.Speed.FAST);
startTime = System.currentTimeMillis();
startExp = context.skills.getCurrentExp(context.skills.RANGE);
}
@Override
public void mouseDragged(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseMoved(MouseEvent arg0) {
// TODO Auto-generated method stub
}
private void updateStats() {
timeRunning = System.currentTimeMillis() - startTime;
gainedExp = context.skills.getCurrentExp(context.skills.RANGE)
- startExp;
}
private void loadImage() {
try {
URL painImageUrl = new URL(PAINT_IMAGE_URL);
paintImage = ImageIO.read(painImageUrl);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
System.out.println("Could not get paintImage");
}
}
@Override
public void onRender(Graphics g) {
Graphics2D g2d = (Graphics2D) g.create();
// drawing mouse
drawMouse(g);
if (context.mouse.getX() >= 483 && context.mouse.getX() <= 507
&& context.mouse.getY() >= 344 && context.mouse.getY() <= 368) {
if (closePaint && once == 0) {
closePaint = false;
once = 1;
} else if (once == 0) {
closePaint = true;
once = 1;
}
} else {
once = 0;
}
// drawing paint
if (paintImage != null && !closePaint) {
drawPaint(g2d);
}
g2d.dispose();
}
public void drawMouse(Graphics g) {
Graphics2D g2d = (Graphics2D) g.create();
g2d.setColor(Color.CYAN);
int x = context.mouse.getX();
int y = context.mouse.getY();
g2d.drawLine(x - 5, y - 5, x + 5, y + 5);
g2d.drawLine(x - 5, y + 5, x + 5, y - 5);
g2d.drawString("(" + context.mouse.getX() + "," + context.mouse.getY()
+ ")", x + 10, y + 10);
g2d.dispose();
}
private void drawPaint(Graphics2D g2d) {
updateStats();
// paint the image
g2d.drawImage(paintImage, 3, 330, null);
// paint expGained
g2d.drawString(
String.format("%,d", gainedExp)
+ " | "
+ String.format(
"%,d",
(Skills.getExperienceAt(context.skills
.getCurrentLevel(context.skills.RANGE) + 1) - context.skills
.getCurrentExp(context.skills.RANGE)))
+ " XP to LvL", 342, 398);
// paint time running
int seconds = (int) (timeRunning / 1000) % 60;
int minutes = (int) (timeRunning / 60000) % 60;
int hours = (int) timeRunning / 1000 / 60 / 60;
String timeRunningString = String.format("%02dh:%02dm:%02ds", hours,
minutes, seconds);
g2d.drawString(timeRunningString, 325, 438);
// paint exp per hour
int expPerSecond = 0;
if (timeRunning > 0) {
if (seconds < 5 && minutes <= 0 && hours <= 0) {
expPerSecond = 5;
} else {
expPerSecond = gainedExp / (int) (timeRunning / 1000);
}
}
double expPerHour = expPerSecond * 60 * 60;
// System.out.println(Integer.toString(expPerHour));
double expLeft = (double) Skills.getExperienceAt(context.skills
.getCurrentLevel(context.skills.RANGE) + 1)
- context.skills.getCurrentExp(context.skills.RANGE);
DecimalFormat df = new DecimalFormat("#.##");
double timeToLvl = 0.00;
if (expPerHour > 0) {
timeToLvl = expLeft / expPerHour;
g2d.drawString(
String.format("%,.2f", expPerHour) + " | "
+ df.format(timeToLvl) + " Hrs to lvl.", 335, 420);
}
g2d.drawString(process, 99, 435);
g2d.drawString(Integer.toString(getCurrentScore()) + " | "
+ getTargetColor(), 110, 397);
int tickets = context.inventory.getItem(1464).getStackSize()
- starttickets;
int arrows = tickets / 40;
g2d.drawString(millValue(price * arrows), 83, 418);
}
@Override
public void onMessageReceived(int i, String s, String s2) {
}
public boolean isInGame() {
return getArrowNum() > 0;
}
public int getArrowNum() {
return context.settings.getAt(156);
}
public int getCurrentScore() {
return context.settings.getAt(157);
}
public String getTargetColor() {
int c = context.settings.getAt(158);
if (c == 9 || c == 10) {
return "Black";
} else if (c == 5 || c == 7 || c == 8) {
return "Blue";
} else if (c == 1) {
return "Yellow";
} else if (c == 2 || c == 3 || c == 4) {
return "Red";
} else if (c == 0) {
return "Bulls Eye";
} else if (c == 1) {
return "Missed";
}
return "";
}
public abstract class WorkerGroup extends Worker {
private Worker[] workers;
public WorkerGroup(MethodContext context, Worker... workers) {
super(context);
this.workers = workers;
}
public abstract boolean activate();
public void work() {
for (Worker worker : workers) {
if (worker.validate()) {
worker.work();
}
}
}
public boolean validate() {
return activate();
}
}
private class ReturnToSpot extends Worker {
Area arena = new Area(new Tile(2667, 3417), new Tile(2672, 3421),
new Tile(2675, 3418), new Tile(2672, 3413));
public ReturnToSpot(MethodContext context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
public void work() {
if (context.walking.walk(arena.getCentralTile())) {
Time.sleep(1000, 1200);
}
}
@Override
public boolean validate() {
// TODO Auto-generated method stub
return isInGame() && !arena.contains(context.players.getLocal());
}
}
private class StartGame extends Worker {
public StartGame(MethodContext context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
public void work() {
process = "Starting Game";
final int PARENT_JUDGE = 242;
WidgetComponent judge = context.widgets.getChild(PARENT_JUDGE, 1);
if (judge != null && judge.isVisible()) {
WidgetComponent toClick = context.widgets.getChild(
PARENT_JUDGE, 4);
if (toClick != null && toClick.isVisible()) {
toClick.click();
Time.sleep(800, 900);
}
}
final int SURE = 230;
WidgetComponent sure = context.widgets.getChild(SURE, 1);
if (sure != null && sure.isVisible()) {
sure.click();
Time.sleep(800, 900);
}
final int CONTINUE2 = 64;
WidgetComponent continues2 = context.widgets.getChild(CONTINUE2, 3);
if (continues2 != null && continues2.isVisible()) {
continues2.click();
Time.sleep(800, 900);
}
final int CONTINUE = 241;
WidgetComponent continues = context.widgets.getChild(CONTINUE, 3);
if (continues != null && continues.isVisible()) {
continues.click();
Time.sleep(800, 900);
}
if (!continues2.isVisible() && !continues.isVisible() && !sure.isVisible()
&& !judge.isVisible()) {
Npc judges = context.npcs.getNearest("Competition Judge");
judges.click();
}
return;
}
@Override
public boolean validate() {
return !isInGame();
}
}
private class PlayGame extends WorkerGroup {
Area arena = new Area(new Tile(2667, 3417), new Tile(2672, 3421),
new Tile(2675, 3418), new Tile(2672, 3413));
public PlayGame(MethodContext ctx, Worker... workers) {
super(ctx, workers);
}
@Override
public boolean activate() {
return isInGame() && arena.contains(context.players.getLocal());
}
}
private class EquipArrows extends Worker {
public EquipArrows(MethodContext context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
public void work() {
process = "Equipping Arrows";
context.inventory.getItem(882).click();
Time.sleep(1000, 1200);
}
@Override
public boolean validate() {
return context.inventory.contains(882);
}
}
private class ShootTarget extends Worker {
public ShootTarget(MethodContext context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
public void work() {
process = "Shooting Target";
GameObject target = context.gameObjects.getNearest("Target");
if (target == null) {
return;
}
if (target.isVisible()) {
target.click();
Time.sleep(200, 500);
} else {
context.camera.turnTo(target);
context.camera.setPitch(false);
}
}
@Override
public boolean validate() {
return getArrowNum() > 0 && getArrowNum() < 11
&& !context.widgets.getChild(325, 89).isVisible();
}
}
private class CloseTarget extends Worker {
public CloseTarget(MethodContext context) {
super(context);
}
@Override
public void work() {
process = "Closing Target";
context.widgets.getChild(325, 88).click();
Time.sleep(500, 800);
}
@Override
public boolean validate() {
return getArrowNum() > 0
&& context.widgets.getChild(325, 88).isVisible();
}
}
private class GetPrize extends Worker {
public GetPrize(MethodContext context) {
super(context);
}
@Override
public void work() {
process = "Getting Prize";
Npc judge = context.npcs.getNearest("Competition Judge");
if (judge == null) {
return;
}
if (judge.isVisible()) {
judge.click();
} else {
context.camera.turnTo(judge);
}
Time.sleep(500, 800);
}
@Override
public boolean validate() {
return getArrowNum() == 11
&& !context.widgets.getChild(325, 89).isVisible();
}
}
}