-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAA_SpellCaster.java
More file actions
185 lines (150 loc) · 4.41 KB
/
AA_SpellCaster.java
File metadata and controls
185 lines (150 loc) · 4.41 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
/**
* A script for Maging npcs.
* Start script near the npc to be maged.
* <p>
* Required Parameter:
* -s,--spell <WIND_STRIKE|WATER_STRIKE|...|FIRE_WAVE>
* -i,--id <npcId>
* <p>
*
* @Author Chomp
*/
public class AA_SpellCaster extends AA_Script {
private static final long CAST_DELAY = 1200L; // +- based on latency
private static final int MAXIMUM_FATIGUE = 100;
private double initialMagicXp;
private long startTime;
private long castTimeout;
private Spell spell;
private int npcId;
private int startX;
private int startY;
private boolean idle;
public AA_SpellCaster(final Extension ex) {
super(ex);
}
@Override
public void init(final String parameters) {
if (parameters.isEmpty()) printInstructions();
final String[] args = parameters.split(" ");
for (int i = 0; i < args.length; i++) {
switch (args[i].toLowerCase()) {
case "-s":
case "--spell":
spell = Spell.valueOf(args[++i].toUpperCase());
break;
case "-i":
case "--id":
npcId = Integer.parseInt(args[++i]);
break;
default:
throw new IllegalArgumentException("Error: malformed parameters. Try again ...");
}
}
if (!hasInventoryItem(ITEM_ID_SLEEPING_BAG)) {
throw new IllegalStateException("Sleeping bag missing from inventory.");
}
startX = getPlayerX();
startY = getPlayerY();
initialMagicXp = getSkillExperience(Skill.MAGIC.getIndex());
startTime = System.currentTimeMillis();
}
@Override
public int main() {
if (idle) {
if (getPlayerX() == startX && getPlayerY() == startY) {
final Coordinate coordinate = getWalkableCoordinate();
if (coordinate != null) {
walkTo(coordinate.getX(), coordinate.getY());
return SLEEP_ONE_TICK;
}
}
idle = false;
}
if (getPlayerX() != startX || getPlayerY() != startY) {
walkTo(startX, startY);
return SLEEP_ONE_TICK;
}
if (getFatiguePercent() >= MAXIMUM_FATIGUE) {
return sleep();
}
if (System.currentTimeMillis() <= castTimeout) {
return 0;
}
final Object npc = getNearestNpc(npcId, false, false);
if (npc == null) {
return 0;
}
bot.displayMessage("@cya@Casting ...");
castOnNpc(spell.getId(), npc);
castTimeout = System.currentTimeMillis() + SLEEP_TWO_SECONDS;
return 0;
}
@Override
public void onServerMessage(final String message) {
if (message.endsWith("successfully")) {
castTimeout = System.currentTimeMillis() + CAST_DELAY;
} else if (message.startsWith("reagents", 23)) {
exit("Out of runes.");
} else if (message.endsWith("spell")) {
castTimeout = 0L;
} else if (message.endsWith("seconds")) {
castTimeout = System.currentTimeMillis() + TIMEOUT_TEN_SECONDS * 2;
} else if (message.endsWith("area")) {
idle = true;
} else {
super.onServerMessage(message);
}
}
@Override
public void paint() {
int y = PAINT_OFFSET_Y;
bot.drawString("@yel@Spell Caster", PAINT_OFFSET_X, y, 1, 0);
bot.drawString(String.format("@yel@Runtime: @whi@%s", toDuration(startTime)),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT, 1, 0);
final double xpGained = getSkillExperience(Skill.MAGIC.getIndex()) - initialMagicXp;
bot.drawString(String.format("@red@Spell: @whi@%s", spell),
PAINT_OFFSET_X, y += PAINT_OFFSET_Y_INCREMENT * 2, 1, 0);
bot.drawString(String.format("@cya@Magic 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, 1, 0);
}
public enum Spell {
WIND_STRIKE("Wind Strike", 0),
WATER_STRIKE("Water Strike", 2),
EARTH_STRIKE("Earth Strike", 4),
FIRE_STRIKE("Fire Strike", 6),
WIND_BOLT("Wind Bolt", 8),
WATER_BOLT("Water Bolt", 11),
EARTH_BOLT("Earth Bolt", 14),
FIRE_BOLT("Fire Bolt", 17),
CRUMBLE_UNDEAD("Crumble Undead", 19),
WIND_BLAST("Wind Blast", 20),
WATER_BLAST("Water Blast", 23),
EARTH_BLAST("Earth Blast", 27),
FIRE_BLAST("Fire Blast", 32),
CLAWS_OF_GUTHIX("Claws of Guthix", 33),
SARADOMIN_STRIKE("Saradomin Strike", 34),
FLAMES_OF_ZAMORAK("Flames of Zamorak", 35),
WIND_WAVE("Wind Wave", 37),
WATER_WAVE("Water Wave", 39),
EARTH_WAVE("Earth Wave", 43),
FIRE_WAVE("Fire Wave", 45);
private final String name;
private final int id;
Spell(final String name, final int id) {
this.name = name;
this.id = id;
}
@Override
public String toString() {
return name;
}
public String getName() {
return name;
}
public int getId() {
return id;
}
}
}