This repository was archived by the owner on Dec 30, 2025. It is now read-only.
forked from crazyeyes-pb/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoTanner.java
More file actions
311 lines (271 loc) · 10.4 KB
/
AutoTanner.java
File metadata and controls
311 lines (271 loc) · 10.4 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
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.util.HashMap;
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.Methods;
import org.rsbot.script.util.Timer;
import org.rsbot.script.wrappers.RSArea;
import org.rsbot.script.wrappers.RSInterface;
import org.rsbot.script.wrappers.RSNPC;
import org.rsbot.script.wrappers.RSTile;
import org.rsbot.script.wrappers.RSTilePath;
@ScriptManifest(authors = { "LastCoder" }, keywords = { "Crafting" }, name = "ArbiTannerLite", version = 2.0, description = "Start, all options are in GUI.", requiresVersion = 244)
public class AutoTanner extends Script implements MessageListener,
PaintListener {
class Gui extends javax.swing.JFrame {
/**
* GUI
*/
private static final long serialVersionUID = 1L;
public HashMap<String, Hide> hideOptMap = new HashMap<String, Hide>();
public String[] hideOpt = new String[AutoTanner.HIDE_ARRAY.length];
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel3;
// End of variables declaration
/**
* 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
gui_on = true;
for (int i = 0; i < AutoTanner.HIDE_ARRAY.length; i++) {
hideOpt[i] = AutoTanner.HIDE_ARRAY[i].name;
hideOptMap.put(hideOpt[i], AutoTanner.HIDE_ARRAY[i]);
}
jLabel1 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jComboBox1 = new javax.swing.JComboBox();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
jLabel1.setText("AutoTanner");
jLabel3.setText("Which Hide:");
jButton1.setText("START");
jButton1.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(final java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(hideOpt));
final 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(103, 103, 103).addComponent(jLabel1)).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 275, Short.MAX_VALUE)).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel3).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))).addContainerGap()));
layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel1).addGap(27, 27, 27).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel3).addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)).addGap(37, 37, 37).addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
pack();
}// </editor-fold>
private void jButton1ActionPerformed(
final java.awt.event.ActionEvent evt) {
setVisible(false);
hide = hideOptMap.get(jComboBox1.getSelectedItem().toString());
gui_on = false;
}
}
static class Hide {
public String name;
public int ind_id;
public int tanned_id;
public int component_id;
public Hide(final String name, final int ind_id, final int tanned_id,
final int component_id) {
this.name = name;
this.ind_id = ind_id;
this.component_id = component_id;
this.tanned_id = tanned_id;
}
}
public enum state {
BANK, WALK_TO, TRADE_TANNER, INTERFACE, WALK_FROM, REST, TURN_ON_RUN
}
private static final Hide[] HIDE_ARRAY = new Hide[] {
new Hide("Cow Hide", 1739, 1741, 2),
new Hide("Green Dragon Hide", 1753, 1745, 5),
new Hide("Red Dragon Hide", 1749, 2507, 7),
new Hide("Blue Dragon Hide", 1751, 2505, 6),
new Hide("Black Dragon Hide", 1747, 2509, 8) };
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 int TANNER = 2824;
private static final RSTile[] OLD_PATH = new RSTile[] {
new RSTile(3269, 3166), new RSTile(3270, 3166),
new RSTile(3271, 3166), new RSTile(3272, 3166),
new RSTile(3273, 3166), new RSTile(3274, 3167),
new RSTile(3274, 3167), new RSTile(3274, 3168),
new RSTile(3274, 3170), new RSTile(3274, 3170),
new RSTile(3275, 3171), new RSTile(3275, 3171),
new RSTile(3275, 3172), new RSTile(3275, 3173),
new RSTile(3275, 3173), new RSTile(3277, 3179),
new RSTile(3278, 3180), new RSTile(3278, 3180),
new RSTile(3279, 3181), new RSTile(3279, 3181),
new RSTile(3280, 3182), new RSTile(3281, 3183),
new RSTile(3281, 3183), new RSTile(3281, 3184),
new RSTile(3281, 3185), new RSTile(3281, 3186),
new RSTile(3281, 3186), new RSTile(3281, 3187),
new RSTile(3281, 3190), new RSTile(3280, 3191),
new RSTile(3278, 3191), new RSTile(3276, 3192) };
private RSTilePath current_path;
private RSTilePath path_back;
private Hide hide;
private boolean gui_on = false;
private int profit;
private int profitMade;
private int made;
private long startTime;
public boolean atBank() {
final RSArea a = new RSArea(new RSTile(3264, 3159), new RSTile(3274, 3174));
return a.contains(getMyPlayer().getLocation());
}
public boolean atTanner() {
final RSArea a = new RSArea(new RSTile(3270, 3189), new RSTile(3277, 3195));
return a.contains(getMyPlayer().getLocation());
}
public state getState() {
final RSInterface inter = interfaces.get(324);
if (inter.isValid()) {
return state.INTERFACE;
} else if (walking.getEnergy() > Methods.random(80, 100)
&& !walking.isRunEnabled()) {
return state.TURN_ON_RUN;
} else if (atBank()) {
if (inventory.contains(hide.ind_id)) {
return state.WALK_TO;
} else {
return state.BANK;
}
} else if (atTanner()) {
if (inventory.contains(hide.ind_id)) {
return state.TRADE_TANNER;
} else {
return state.WALK_FROM;
}
} else {
if (inventory.contains(hide.ind_id)) {
return state.WALK_TO;
} else {
return state.WALK_FROM;
}
}
}
@Override
public int loop() {
switch (getState()) {
case TURN_ON_RUN:
walking.setRun(true);
for (int i = 0; i < 10 && !walking.isRunEnabled(); i++) {
Methods.sleep(100, 200);
}
Methods.sleep(Methods.random(1200, 1500));
break;
case REST:
walking.rest();
Methods.sleep(Methods.random(1200, 1500));
break;
case WALK_TO:
current_path.traverse();
break;
case WALK_FROM:
path_back.traverse();
break;
case TRADE_TANNER:
final RSNPC tanner_npc = npcs.getNearest(AutoTanner.TANNER);
if (tanner_npc != null && getMyPlayer().getAnimation() == -1) {
tanner_npc.doAction("Trade");
Methods.sleep(Methods.random(1200, 1500));
}
break;
case BANK:
if (!bank.isOpen()) {
if (getMyPlayer().getAnimation() != -1) {
Methods.sleep(Methods.random(1200, 1500));
} else {
bank.open();
}
} else {
if (!inventory.contains(hide.ind_id)) {
if (inventory.contains(hide.tanned_id)) {
bank.deposit(hide.tanned_id, 0);
Methods.sleep(Methods.random(1200, 1500));
}
if (bank.getItem(hide.ind_id) != null) {
bank.withdraw(hide.ind_id, 0);
Methods.sleep(Methods.random(1200, 1500));
} else {
log("Out of Hides.");
break;
}
}
}
break;
case INTERFACE:
final RSInterface tan_inter = interfaces.get(324);
if (tan_inter.isValid()) {
tan_inter.getComponent(hide.component_id).doAction("Tan All");
for (int i = 0; i < 100 && inventory.contains(hide.tanned_id); i++) {
Methods.sleep(20);
}
made = made + inventory.getCount(hide.tanned_id);
profitMade = profit * made;
}
break;
}
return Methods.random(800, 1200);
}
@Override
public void messageReceived(final MessageEvent e) {
}
@Override
public void onRepaint(final Graphics g1) {
final Graphics2D g = (Graphics2D) g1;
final long millis = System.currentTimeMillis() - startTime;
final String time = Timer.format(millis);
final int profitHour = (int) (3600 * profitMade / millis);
g.setColor(AutoTanner.COLOR_1);
g.fillRect(14, 350, 474, 99);
g.setColor(AutoTanner.COLOR_2);
g.setStroke(AutoTanner.STROKE);
g.drawRect(14, 350, 474, 99);
g.setFont(AutoTanner.FONT_1);
g.setColor(AutoTanner.COLOR_3);
g.drawString("AutoTanner", 209, 374);
g.setFont(AutoTanner.FONT_2);
g.drawString("Profit: " + profitMade, 18, 390);
g.drawString("Profit Hour: " + profitHour, 18, 400);
g.drawString("Time Ran: " + time, 182, 390);
g.drawString("Status: " + getState().toString(), 182, 400);
}
@Override
public boolean onStart() {
new Gui().setVisible(true);
while (gui_on) {
Methods.sleep(20);
}
current_path = walking.newTilePath(AutoTanner.OLD_PATH);
path_back = walking.newTilePath(AutoTanner.OLD_PATH).reverse();
profit = grandExchange.lookup(hide.tanned_id).getGuidePrice()
- grandExchange.lookup(hide.ind_id).getGuidePrice();
startTime = System.currentTimeMillis();
return game.isLoggedIn();
}
}