-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAA_PotionMixer.java
More file actions
296 lines (241 loc) · 8.29 KB
/
AA_PotionMixer.java
File metadata and controls
296 lines (241 loc) · 8.29 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
import java.util.EnumSet;
import java.util.Iterator;
/**
* Mixes potions.
* <p>
* Requirements:
* Start at a bank or Shantay Pass with sleeping bag in inventory.
* The script will try to mix all potions if no potion parameter is provided.
* <p>
* Optional Parameter:
* <attack_potion|restore_prayer_potion|...>
* <p>
* Potions:
* attack_potion
* cure_poison_potion
* strength_potion
* stat_restoration_potion
* restore_prayer_potion
* super_attack_potion
* poison_antidote
* fishing_potion
* super_strength_potion
* weapon_poision
* super_defense_potion
* ranging_potion
* potion_of_zamorak
* <p>
*
* @Author Chomp
*/
public class AA_PotionMixer extends AA_Script {
private static final Coordinate COORDINATE_SHANTAY_BANK_CHEST = new Coordinate(58, 731);
private static final long MIX_DELAY = 1210L; // +- based on latency
private static final int WITHDRAW_COUNT = 14;
private static final int MAXIMUM_FATIGUE = 99;
private Potion potion;
private Iterator<Potion> iterator;
private long startTime;
private double initialHerblawXp;
private long openTimeout;
private long depositTimeout;
private long withdrawUnfTimeout;
private long withdrawSecondaryTimeout;
private long mixTimeout;
private int potionsMixed;
private int materialsRemaining;
private int inventoryCount;
private boolean shantayBanking;
private boolean idle;
public AA_PotionMixer(final Extension extension) {
super(extension);
}
@Override
public void init(final String parameters) {
if (!parameters.isEmpty()) potion = Potion.valueOf(parameters.toUpperCase());
if (!hasInventoryItem(ITEM_ID_SLEEPING_BAG)) {
throw new IllegalStateException("Sleeping bag missing from inventory.");
}
if (potion == null) {
iterator = EnumSet.allOf(Potion.class).iterator();
potion = iterator.next();
}
if (getLevel(Skill.HERBLAW.getIndex()) < potion.level) {
throw new IllegalStateException(String.format("Lvl %d Herblaw required to mix %s.",
potion.level, getItemNameId(potion.id)));
}
shantayBanking = distanceTo(COORDINATE_SHANTAY_BANK_CHEST.getX(), COORDINATE_SHANTAY_BANK_CHEST.getY()) < 10;
initialHerblawXp = getAccurateXpForLevel(Skill.HERBLAW.getIndex());
startTime = System.currentTimeMillis();
}
@Override
public int main() {
if (idle) {
return idle();
}
if (getFatigue() >= MAXIMUM_FATIGUE) {
return sleep();
}
if (System.currentTimeMillis() <= mixTimeout) {
return 0;
}
inventoryCount = getInventoryCount();
final int secondaryIndex = getInventoryIndex(potion.secondaryId);
if (inventoryCount == 1 ||
getInventoryId(1) != potion.unfinishedPotionId ||
secondaryIndex == -1) {
return bank();
}
bot.displayMessage("@gre@Mixing ...");
useItemWithItem(1, secondaryIndex);
mixTimeout = System.currentTimeMillis() + TIMEOUT_TWO_SECONDS;
return 0;
}
@Override
public void onServerMessage(final String message) {
if (message.endsWith("potion")) {
potionsMixed++;
if (materialsRemaining > 0) {
materialsRemaining--;
}
mixTimeout = System.currentTimeMillis() + MIX_DELAY;
} else if (message.endsWith("men.") || message.endsWith("you.")) {
openTimeout = System.currentTimeMillis() + TIMEOUT_FIVE_SECONDS;
} else if (message.endsWith("area")) {
if (!shantayBanking) {
return;
}
idle = true;
} else {
super.onServerMessage(message);
}
}
private int idle() {
if (getX() == COORDINATE_SHANTAY_BANK_CHEST.getX() + 2 &&
getY() == COORDINATE_SHANTAY_BANK_CHEST.getY()) {
idle = false;
return 0;
}
walkTo(COORDINATE_SHANTAY_BANK_CHEST.getX() + 2, COORDINATE_SHANTAY_BANK_CHEST.getY());
return SLEEP_ONE_TICK;
}
private int bank() {
if (!isBanking()) {
if (shantayBanking) {
if (System.currentTimeMillis() <= openTimeout) {
return 0;
}
atObject(COORDINATE_SHANTAY_BANK_CHEST.getX(), COORDINATE_SHANTAY_BANK_CHEST.getY());
openTimeout = System.currentTimeMillis() + TIMEOUT_TWO_SECONDS;
return 0;
}
return openBank();
}
if (inventoryCount > 1 &&
getInventoryId(1) == potion.unfinishedPotionId &&
inventoryCount < MAX_INV_SIZE) {
if (System.currentTimeMillis() <= withdrawSecondaryTimeout) {
return 0;
}
final int secondariesRemaining = bankCount(potion.secondaryId);
if (secondariesRemaining == 0) {
if (iterator == null || !iterator.hasNext()) {
return exit(String.format("Out of %s.", getItemNameId(potion.secondaryId)));
}
potion = iterator.next();
potionsMixed = 0;
initialHerblawXp = getAccurateXpForLevel(Skill.HERBLAW.getIndex());
startTime = System.currentTimeMillis();
if (getLevel(Skill.HERBLAW.getIndex()) < potion.level) {
return exit(String.format("Lvl %d Herblaw required to mix %s.",
potion.level, getItemNameId(potion.id)));
}
return 0;
}
final int unfsRemaining = bankCount(potion.unfinishedPotionId);
materialsRemaining = Math.min(secondariesRemaining, unfsRemaining);
withdraw(potion.secondaryId, WITHDRAW_COUNT);
withdrawSecondaryTimeout = System.currentTimeMillis() + TIMEOUT_TWO_SECONDS;
return 0;
}
if (System.currentTimeMillis() <= withdrawUnfTimeout) {
return 0;
}
if (inventoryCount == 1) {
if (!hasBankItem(potion.unfinishedPotionId)) {
if (iterator == null || !iterator.hasNext()) {
return exit(String.format("Out of %s.", getItemNameId(potion.unfinishedPotionId)));
}
potion = iterator.next();
potionsMixed = 0;
initialHerblawXp = getAccurateXpForLevel(Skill.HERBLAW.getIndex());
startTime = System.currentTimeMillis();
if (getLevel(Skill.HERBLAW.getIndex()) < potion.level) {
return exit(String.format("Lvl %d Herblaw required to mix %s.",
potion.level, getItemNameId(potion.id)));
}
return 0;
}
withdraw(potion.unfinishedPotionId, WITHDRAW_COUNT);
withdrawUnfTimeout = System.currentTimeMillis() + TIMEOUT_TWO_SECONDS;
return 0;
}
if (System.currentTimeMillis() <= depositTimeout) {
return 0;
}
final int itemId = getInventoryId(1);
deposit(itemId, MAX_INV_SIZE);
depositTimeout = System.currentTimeMillis() + TIMEOUT_TWO_SECONDS;
return 0;
}
@Override
public void paint() {
int y = PAINT_OFFSET_Y;
drawString("@yel@Potion Mixer", PAINT_OFFSET_X, y, 1, 0);
drawString(String.format("@yel@Runtime: @whi@%s", toDuration(startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
final double xpGained = getAccurateXpForLevel(Skill.HERBLAW.getIndex()) - initialHerblawXp;
drawString(String.format("@yel@Xp: @whi@%s @cya@(@whi@%s xp@cya@/@whi@hr@cya@)",
DECIMAL_FORMAT.format(xpGained), toUnitsPerHour((int) xpGained, startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT * 2, 1, 0);
drawString(String.format("@yel@%s: @whi@%d @cya@(@whi@%s pots@cya@/@whi@hr@cya@)",
potion, potionsMixed, toUnitsPerHour(potionsMixed, startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
drawString(String.format("@yel@Remaining: @whi@%d", materialsRemaining),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT * 2, 1, 0);
drawString(String.format("@yel@Time remaining: @whi@%s",
toTimeToCompletion(potionsMixed, materialsRemaining, startTime)),
PAINT_OFFSET_X, y + PAINT_OFFSET_Y_INCREMENT, 1, 0);
}
private enum Potion {
ATTACK_POTION(3, 474, 454, 270, "Attack"),
CURE_POISON_POTION(5, 566, 455, 473, "Cure Poison"),
STRENGTH_POTION(12, 222, 456, 220, "Strength"),
STAT_RESTORATION_POTION(22, 477, 457, 219, "Stat Res."),
RESTORE_PRAYER_POTION(38, 483, 458, 469, "Prayer"),
SUPER_ATTACK_POTION(45, 486, 459, 270, "Super Atk"),
POISON_ANTIDOTE(48, 569, 459, 473, "Antidote"),
FISHING_POTION(50, 489, 460, 469, "Fishing"),
SUPER_STRENGTH_POTION(55, 492, 461, 220, "Super Str"),
WEAPON_POISION(60, 572, 461, 472, "Weapon Poison"),
SUPER_DEFENSE_POTION(66, 495, 462, 471, "Super Def"),
RANGING_POTION(72, 498, 463, 501, "Ranging"),
POTION_OF_ZAMORAK(78, 963, 935, 936, "Zamorak");
private final int level;
private final int id;
private final int unfinishedPotionId;
private final int secondaryId;
private final String name;
Potion(final int level, final int id, final int unfinishedPotionId, final int secondaryId, final String name) {
this.level = level;
this.id = id;
this.unfinishedPotionId = unfinishedPotionId;
this.secondaryId = secondaryId;
this.name = name;
}
@Override
public String toString() {
return name;
}
}
}