-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathAutoSmith.java
480 lines (443 loc) · 15 KB
/
AutoSmith.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
import org.rsbot.event.events.MessageEvent;
import org.rsbot.event.listeners.MessageListener;
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.HashMap;
@ScriptManifest(authors = {"LastCoder"}, keywords = "Smith, Auto", name = "ArbiSmitherLite", version = 2.0, description = "Start, all options are in GUI.")
public class AutoSmith extends Script implements MessageListener,
PaintListener {
private static final SMLoc[] LOCATIONS = new SMLoc[]{
new SMLoc("AL_KHARID", 11666, new RSArea(new RSTile(3275, 3175),
new RSTile(3264, 3160)), new RSTile[]{
new RSTile(3271, 3166), new RSTile(3273, 3166),
new RSTile(3274, 3167), new RSTile(3274, 3169),
new RSTile(3275, 3172), new RSTile(3276, 3174),
new RSTile(3276, 3177), new RSTile(3277, 3178),
new RSTile(3278, 3180), new RSTile(3280, 3182),
new RSTile(3281, 3183), new RSTile(3281, 3185),
new RSTile(3280, 3185), new RSTile(3278, 3185),
new RSTile(3277, 3186), new RSTile(3276, 3186)})};
private static final Color COLOR_1 = new Color(0, 0, 0, 155);
private static final Color COLOR_2 = new Color(0, 0, 0);
private static final Color COLOR_3 = new Color(255, 255, 255);
private static final BasicStroke STROKE = new BasicStroke(1);
private static final Font FONT_1 = new Font("Arial", 0, 17);
private static final Font FONT_2 = new Font("Arial", 0, 9);
private static final Materials[] Materials = new Materials[]{
new Materials("Bronze Bars", 1, 436, 438, 14, 14),
new Materials("Iron Bars", 15, 440, -1, 28, -1),
new Materials("Silver Bars", 20, 442, -1, 28, -1),
new Materials("Steel Bars", 30, 440, 453, 9, 18),
new Materials("Gold Bars", 40, 444, -1, 28, -1),
new Materials("Mithril Bars", 50, 447, 453, 12, 14),
new Materials("Adamant Bars", 70, 449, 453, 4, 24),
new Materials("Rune Bars", 85, 451, 453, 3, 24)};
private static SMLoc location;
private static Materials MATERIAL;
private long activity_time;
private static boolean gui_on = false;
private RSTilePath path;
private RSTilePath path_back;
private long startExp;
private long startTime;
private long expGained;
private int expHour;
private enum state {
BANK, WALK, SMITH, INTERFACE, SLEEP
}
private int barsCrafted;
public boolean onStart() {
new Gui().setVisible(true);
while (gui_on) {
sleep(20);
}
if (location.equals(LOCATIONS[0])) {
log("We are smithing in Al-Kharid.");
} else if (location.equals(LOCATIONS[1])) {
log("We are smithing in Varrock.");
}
path = walking.newTilePath(location.walk_path);
path_back = walking.newTilePath(location.walk_path).reverse();
startExp = (long) skills.getCurrentExp(Skills.SMITHING);
startTime = System.currentTimeMillis();
return game.isLoggedIn();
}
private boolean inArea(RSArea area) {
return area.contains(getMyPlayer().getLocation());
}
private int distanceTo(int ID) {
RSObject obj = objects.getNearest(ID);
if (obj != null) {
return calc.distanceTo(obj);
}
return -1;
}
private boolean busy() {
return System.currentTimeMillis() - activity_time < 8000;
}
private state getState() {
if (interfaces.get(905).isValid()) {
log("Interface is valid.");
return state.INTERFACE;
} else if (inArea(location.bank_area)) {
if (inventory.contains(MATERIAL.inv_id)) {
if (MATERIAL.inv_second_id != -1) {
if (inventory.contains(MATERIAL.inv_second_id)) {
log("Inventory contains 1st and 2nd");
return state.WALK;
} else {
return state.BANK;
}
} else {
return state.WALK;
}
} else {
return state.BANK;
}
} else if (distanceTo(location.furnace_id) < 5) {
if (!busy()) {
if (inventory.contains(MATERIAL.inv_id)) {
return state.SMITH;
} else {
return state.WALK;
}
} else {
return state.SLEEP;
}
}
return state.WALK;
}
@Override
public int loop() {
switch (getState()) {
case BANK:
if (!bank.isOpen()) {
bank.open();
for (int i = 0; i < 100 && !bank.isOpen(); i++)
sleep(20);
} else {
if (MATERIAL.inv_second_id != -1) {
if (!inventory.contains(MATERIAL.inv_id)) {
if (inventory.getCount() > 1) {
bank.depositAll();
}
bank.withdraw(MATERIAL.inv_id, MATERIAL.primary);
for (int i = 0; i < 100
&& !inventory.contains(MATERIAL.inv_id); i++)
sleep(20);
}
if (!inventory.contains(MATERIAL.inv_second_id)) {
bank.withdraw(MATERIAL.inv_second_id,
MATERIAL.secondary);
for (int i = 0; i < 100
&& !inventory.contains(MATERIAL.inv_second_id); i++)
sleep(20);
}
} else {
if (!inventory.contains(MATERIAL.inv_id)) {
if (inventory.getCount() > 1) {
bank.depositAll();
}
bank.withdraw(MATERIAL.inv_id, MATERIAL.primary);
for (int i = 0; i < 100
&& !inventory.contains(MATERIAL.inv_id); i++)
sleep(20);
}
}
}
break;
case WALK:
if (MATERIAL.inv_second_id != -1) {
if (inventory.contains(MATERIAL.inv_id)
&& inventory.contains(MATERIAL.inv_second_id)) {
path.traverse();
sleep(20);
} else {
path_back.traverse();
sleep(20);
}
} else {
if (inventory.contains(MATERIAL.inv_id)) {
path.traverse();
} else {
path_back.traverse();
}
}
break;
case SMITH:
RSObject furnace = objects.getNearest(location.furnace_id);
if (furnace != null) {
if (!furnace.isOnScreen()) {
camera.turnTo(furnace);
for (int i = 0; i < 100 && !furnace.isOnScreen(); i++)
sleep(20);
} else {
if (!inventory.isItemSelected()) {
RSItem ore = inventory.getItem(MATERIAL.inv_id);
if (ore != null) {
ore.doAction("Use");
}
for (int i = 0; i < 100 && !inventory.isItemSelected(); i++)
sleep(20);
} else {
furnace.doAction("Furnace");
sleep(200);
}
}
}
break;
case INTERFACE:
interfaces.get(905).getComponent(14).doAction("All");
break;
case SLEEP:
sleep(20);
break;
}
return random(600, 1200);
}
public void messageReceived(MessageEvent e) {
String message = e.getMessage();
if (message.contains("You smelt") || message.contains("You")) {
activity_time = System.currentTimeMillis();
barsCrafted++;
}
}
public void onRepaint(Graphics g1) {
Graphics2D g = (Graphics2D) g1;
long millis = System.currentTimeMillis() - startTime;
String time = Timer.format(millis);
if ((skills.getCurrentExp(Skills.SMITHING) - startExp) > 0
&& startExp > 0) {
expGained = skills.getCurrentExp(Skills.SMITHING) - startExp;
}
if (expGained > 0 && millis > 0) {
expHour = (int) (3600 * expGained / millis);
}
g.setColor(COLOR_1);
g.fillRect(14, 350, 474, 99);
g.setColor(COLOR_2);
g.setStroke(STROKE);
g.drawRect(14, 350, 474, 99);
g.setFont(FONT_1);
g.setColor(COLOR_3);
g.drawString("AutoSmither", 209, 374);
g.setFont(FONT_2);
g.drawString("EXP/Hr: " + expHour, 18, 390);
g.drawString("EXP Gained: " + expGained, 18, 400);
g.drawString("Time Ran: " + time, 182, 390);
g.drawString("Status: " + getState().toString(), 182, 400);
g.drawString("Bars Crafted: " + barsCrafted, 395, 390);
}
static class Gui extends javax.swing.JFrame {
/**
* GUI
*/
private static final long serialVersionUID = 1L;
private final String[] bars = new String[Materials.length];
private final String[] locations = new String[LOCATIONS.length];
private HashMap<String, SMLoc> locMap = new HashMap<String, SMLoc>();
private HashMap<String, Materials> matMap = new HashMap<String, Materials>();
/**
* Creates new form Gui
*/
public Gui() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the
* form. WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
gui_on = true;
for (int i = 0; i < Materials.length; i++) {
bars[i] = Materials[i].name;
matMap.put(bars[i], Materials[i]);
}
for (int i = 0; i < LOCATIONS.length; i++) {
locations[i] = LOCATIONS[i].name;
locMap.put(locations[i], LOCATIONS[i]);
}
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jComboBox1 = new javax.swing.JComboBox();
jLabel3 = new javax.swing.JLabel();
jComboBox2 = new javax.swing.JComboBox();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
jLabel1.setText("AutoSmither");
jLabel2.setText("Where:");
jComboBox1
.setModel(new javax.swing.DefaultComboBoxModel(locations));
jLabel3.setText("Type:");
jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(bars));
jButton1.setText("START");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
getContentPane());
getContentPane().setLayout(layout);
layout
.setHorizontalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addGap(
147,
147,
147)
.addComponent(
jLabel1))
.addGroup(
layout
.createSequentialGroup()
.addGap(
37,
37,
37)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING,
false)
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jLabel3)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(
jComboBox2,
0,
javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
.addGroup(
layout
.createSequentialGroup()
.addComponent(
jLabel2)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(
jComboBox1,
javax.swing.GroupLayout.PREFERRED_SIZE,
86,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addComponent(
jButton1,
javax.swing.GroupLayout.DEFAULT_SIZE,
352,
Short.MAX_VALUE)))
.addContainerGap()));
layout
.setVerticalGroup(layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(
layout
.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jLabel2)
.addComponent(
jComboBox1,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(
javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(
layout
.createParallelGroup(
javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(
jLabel3)
.addComponent(
jComboBox2,
javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(26, 26, 26)
.addComponent(
jButton1,
javax.swing.GroupLayout.DEFAULT_SIZE,
43, Short.MAX_VALUE)
.addContainerGap()));
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
location = locMap.get(jComboBox1.getSelectedItem().toString());
MATERIAL = matMap.get(jComboBox2.getSelectedItem().toString());
gui_on = false;
setVisible(false);
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JComboBox jComboBox2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
// End of variables declaration
}
static class SMLoc {
public String name;
public int furnace_id;
public RSArea bank_area;
public RSTile[] walk_path;
public SMLoc(String name, int FURNACE_ID, RSArea bankZones,
RSTile[] WALK_PATH) {
this.name = name;
this.furnace_id = FURNACE_ID;
this.bank_area = bankZones;
this.walk_path = WALK_PATH;
}
}
static class Materials {
public String name;
public int req_lvl;
public int inv_id;
public int inv_second_id;
public int primary;
public int secondary;
public Materials(String name, int REQ_LVL, int INV_ID,
int INV_SECOND_ID, int PRIMARY, int SECONDARY) {
this.name = name;
this.req_lvl = REQ_LVL;
this.inv_id = INV_ID;
this.primary = PRIMARY;
this.secondary = SECONDARY;
this.inv_second_id = INV_SECOND_ID;
}
}
}