-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAA_HighLevelAlchemy.java
More file actions
216 lines (164 loc) · 5.96 KB
/
AA_HighLevelAlchemy.java
File metadata and controls
216 lines (164 loc) · 5.96 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
/**
* Casts high level alchemy on an item.
* <p>
* Requirements:
* Start at a bank or Shantay Pass with sleeping bag, staff of fire, nature runes, and coins in inventory.
* <p>
* Required Parameter:
* <itemId>
* <p>
*
* @Author Chomp
*/
public class AA_HighLevelAlchemy extends AA_Script {
private static final Coordinate COORDINATE_SHANTAY_BANK_CHEST = new Coordinate(58, 731);
private static final long CAST_DELAY = 1280L; // +- based on latency
private static final int[] ITEM_IDS_STAFF_OF_FIRE = new int[]{197, 615, 682};
private static final int SPELL_ID_HIGH_ALCHEMY = 28;
private static final int ITEM_ID_NATURE_RUNE = 40;
private static final int ITEM_ID_COINS = 10;
private static final int MAXIMUM_FATIGUE = 99;
private static final int INITIAL_INVENTORY_SIZE = 4;
private long startTime;
private double initialMagicXp;
private long openTimeout;
private long withdrawTimeout;
private long alchTimeout;
private int initialCoinCount;
private int coinsIndex;
private int natureRunesIndex;
private int alchCount;
private int alchsRemaining;
private boolean shantayBanking;
private boolean idle;
private int itemId;
public AA_HighLevelAlchemy(final Extension extension) {
super(extension);
}
@Override
public void init(final String parameters) {
if (parameters.isEmpty()) printInstructions();
itemId = Integer.parseInt(parameters);
if (getInventoryIndex(ITEM_ID_SLEEPING_BAG) != 0) {
throw new IllegalStateException("Sleeping bag missing from 1st inv slot.");
}
final int staffOfFireIndex = getInventoryIndex(ITEM_IDS_STAFF_OF_FIRE);
if (staffOfFireIndex != 1 || !isItemEquipped(staffOfFireIndex)) {
throw new IllegalStateException("Staff of fire unequipped/missing from 2nd inv slot.");
}
natureRunesIndex = getInventoryIndex(ITEM_ID_NATURE_RUNE);
if (natureRunesIndex != 2) {
throw new IllegalStateException("Nature runes missing from 3rd inv slot.");
}
coinsIndex = getInventoryIndex(ITEM_ID_COINS);
if (coinsIndex != 3) {
throw new IllegalStateException("Coin missing from 4th inv slot.");
}
initialCoinCount = getInventoryStack(coinsIndex);
shantayBanking = distanceTo(COORDINATE_SHANTAY_BANK_CHEST.getX(), COORDINATE_SHANTAY_BANK_CHEST.getY()) < 10;
initialMagicXp = getAccurateXpForLevel(Skill.MAGIC.getIndex());
startTime = System.currentTimeMillis();
}
@Override
public int main() {
if (idle) {
return idle();
}
if (getFatigue() >= MAXIMUM_FATIGUE) {
return sleep();
}
if (System.currentTimeMillis() <= alchTimeout) {
return 0;
}
if (getInventoryId(natureRunesIndex) != ITEM_ID_NATURE_RUNE) {
return exit("Out of nature runes.");
}
if (getInventoryCount() == INITIAL_INVENTORY_SIZE ||
getInventoryId(INITIAL_INVENTORY_SIZE) != itemId) {
return bank();
}
bot.displayMessage("@gre@Casting ...");
castOnItem(SPELL_ID_HIGH_ALCHEMY, INITIAL_INVENTORY_SIZE);
alchTimeout = System.currentTimeMillis() + TIMEOUT_TWO_SECONDS;
return 0;
}
@Override
public void onServerMessage(final String message) {
if (message.startsWith("Alchemy")) {
alchCount++;
if (alchsRemaining > 0) {
alchsRemaining--;
}
alchTimeout = System.currentTimeMillis() + CAST_DELAY;
} else if (message.endsWith("spell")) {
alchTimeout = 0L;
} 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 (System.currentTimeMillis() <= withdrawTimeout) {
return 0;
}
final int itemsRemaining = bankCount(itemId);
if (itemsRemaining == 0) {
return exit(String.format("Out of %ss.", getItemNameId(itemId)));
}
final int natureRunesRemaining = getInventoryStack(natureRunesIndex);
alchsRemaining = Math.min(natureRunesRemaining, itemsRemaining);
withdraw(itemId, MAX_INV_SIZE - INITIAL_INVENTORY_SIZE);
withdrawTimeout = System.currentTimeMillis() + TIMEOUT_TWO_SECONDS;
return 0;
}
@Override
public void paint() {
int y = PAINT_OFFSET_Y;
drawString("@yel@High Level Alchemy", 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.MAGIC.getIndex()) - initialMagicXp;
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@Alchs: @whi@%s @cya@(@whi@%s casts@cya@/@whi@hr@cya@)",
alchCount, toUnitsPerHour(alchCount, startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
final int coins = getInventoryStack(coinsIndex) - initialCoinCount;
drawString(String.format("@yel@Gold: @whi@%s @cya@(@whi@%s coins@cya@/@whi@hr@cya@)",
coins, toUnitsPerHour(coins, startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
drawString(String.format("@yel@Remaining: @whi@%d", alchsRemaining),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT * 2, 1, 0);
drawString(String.format("@yel@Time remaining: @whi@%s",
toTimeToCompletion(alchCount, alchsRemaining, startTime)),
PAINT_OFFSET_X, y + PAINT_OFFSET_Y_INCREMENT, 1, 0);
}
}