-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathGauntletPlugin.java
More file actions
442 lines (372 loc) · 15 KB
/
GauntletPlugin.java
File metadata and controls
442 lines (372 loc) · 15 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
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
/*
* THIS SOFTWARE WRITTEN BY A KEYBOARD-WIELDING MONKEY BOI
* No rights reserved. Use, redistribute, and modify at your own discretion,
* and in accordance with Yagex and RuneLite guidelines.
* However, aforementioned monkey would prefer if you don't sell this plugin for profit.
* Good luck on your raids!
*/
package net.runelite.client.plugins.gauntlet;
import com.google.inject.Provides;
import lombok.AccessLevel;
import lombok.Getter;
import net.runelite.api.Actor;
import net.runelite.api.Client;
import net.runelite.api.GameObject;
import net.runelite.api.GameState;
import net.runelite.api.HeadIcon;
import net.runelite.api.NPC;
import net.runelite.api.NPCComposition;
import net.runelite.api.Player;
import net.runelite.api.Projectile;
import net.runelite.api.Skill;
import net.runelite.api.SoundEffectID;
import net.runelite.api.Tile;
import net.runelite.api.events.AnimationChanged;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameObjectChanged;
import net.runelite.api.events.GameObjectDespawned;
import net.runelite.api.events.GameObjectSpawned;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.NpcDespawned;
import net.runelite.api.events.NpcSpawned;
import net.runelite.api.events.VarbitChanged;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.SkillIconManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.util.ImageUtil;
import javax.inject.Inject;
import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
@PluginDescriptor(
name = "Gauntlet",
description = "All-in-one plugin for the Gauntlet.",
tags = {"Gauntlet"},
enabledByDefault = false
)
public class GauntletPlugin extends Plugin {
public BufferedImage imageCrystalDeposit;
public BufferedImage imagePhrenRoots;
public BufferedImage imageFishingSpot;
public BufferedImage imageGrymRoot;
public BufferedImage imageLinumTirinum;
public BufferedImage imageAttackRange;
public BufferedImage imageAttackMage;
public BufferedImage imageAttackPrayer;
public final Map<GameObject, Tile> resources = new HashMap<>();
public Set<Projectile> projectiles = new HashSet<>();
public int bossCounter = 0; // Attacks until the boss changes attack styles.
public BossAttackPhase currentPhase = BossAttackPhase.UNKNOWN;
public int playerCounter = 6; // Attacks until the boss changes prayer.
public enum BossAttackPhase {
MAGIC, RANGE, UNKNOWN;
}
public enum BossAttack {
MAGIC, RANGE, PRAYER, LIGHTNING;
}
@Inject
private Client client;
@Inject
private ClientThread clientThread;
@Getter(AccessLevel.PUBLIC)
@Inject
private OverlayManager overlayManager;
@Inject
private GauntletOverlay overlay;
@Inject
private SkillIconManager iconManager;
@Inject
private GauntletConfig config;
@Provides
GauntletConfig getConfig(ConfigManager configManager) {
return configManager.getConfig(GauntletConfig.class);
}
@Inject
private GauntletTimer timer;
private boolean timerVisible = true;
public boolean tornadoesActive = false;
public int tornadoTicks = GauntletUtils.TORNADO_TICKS;
public boolean completeStartup = false;
@Override
protected void startUp() {
loadImages(config.iconSize());
resetCounters();
timerVisible = config.displayTimerWidget();
timer.resetStates();
if (timerVisible) {
overlayManager.add(timer);
}
overlayManager.add(overlay);
// This section checks if the user is trying to start the timer while mid-raid.
// Varbits can only be checked on the client thread. Perform init check if nessessary.
if (client.getGameState() != GameState.STARTING && client.getGameState() != GameState.UNKNOWN) {
completeStartup = false;
clientThread.invoke(new Runnable() {
public void run() {
timer.initStates();
completeStartup = true;
}
});
} else
completeStartup = true;
}
@Override
protected void shutDown() {
resetCounters();
timer.resetStates();
if (timerVisible) {
overlayManager.remove(timer);
timerVisible = false;
}
overlayManager.remove(overlay);
}
/**
* Called when images need to be resized.
*/
private void loadImages(int imageSize) {
imageCrystalDeposit = ImageUtil.resizeImage(iconManager.getSkillImage(Skill.MINING, true), imageSize, imageSize);
imagePhrenRoots = ImageUtil.resizeImage(iconManager.getSkillImage(Skill.WOODCUTTING, true), imageSize, imageSize);
imageFishingSpot = ImageUtil.resizeImage(iconManager.getSkillImage(Skill.FISHING, true), imageSize, imageSize);
imageGrymRoot = ImageUtil.resizeImage(iconManager.getSkillImage(Skill.HERBLORE, true), imageSize, imageSize);
imageLinumTirinum = ImageUtil.resizeImage(iconManager.getSkillImage(Skill.FARMING, true), imageSize, imageSize);
imageAttackMage = ImageUtil.resizeImage(iconManager.getSkillImage(Skill.MAGIC, true), imageSize, imageSize);
imageAttackRange = ImageUtil.resizeImage(iconManager.getSkillImage(Skill.RANGED, true), imageSize, imageSize);
imageAttackPrayer = ImageUtil.resizeImage(iconManager.getSkillImage(Skill.PRAYER, true), imageSize, imageSize);
}
@Subscribe
public void onConfigChanged(ConfigChanged event) {
if (event.getGroup() == null || event.getKey() == null || !event.getGroup().equals("Gauntlet"))
return;
if (event.getKey().equals("displayTimerWidget")) {
if (config.displayTimerWidget() && !timerVisible) {
overlayManager.add(timer);
timerVisible = true;
} else if (!config.displayTimerWidget() && timerVisible) {
overlayManager.remove(timer);
timerVisible = false;
}
} else if (event.getKey().equals("iconSize")) {
loadImages(config.iconSize());
}
}
@Subscribe
public void onVarbitChanged(VarbitChanged event) {
// This handles the timer based on varp states.
if (this.completeStartup)
timer.checkStates(true);
}
@Subscribe
public void onNpcSpawned(NpcSpawned event) {
NPC npc = event.getNpc();
if (GauntletUtils.isBoss(npc))
resetCounters();
}
@Subscribe
public void onNpcDespawned(NpcDespawned event) {
NPC npc = event.getNpc();
if (GauntletUtils.isBoss(npc))
resetCounters();
}
/**
* Reset all boss and player related counter resources.
*/
private void resetCounters() {
bossCounter = 0;
currentPhase = BossAttackPhase.UNKNOWN;
playerCounter = 6;
tornadoesActive = false;
tornadoTicks = GauntletUtils.TORNADO_TICKS;
projectiles.clear();
}
/**
* Method is called when an attack is performed by the boss.
*
* @param style BossAttack ; the attack performed by the boss
*/
public void doAttack(BossAttack style) {
// Prayer attacks are magic related. We only care if it's prayer to play the unique sound.
// This section will change all PRAYER attacks to MAGIC.
if (style == BossAttack.PRAYER) {
if (config.uniquePrayerAudio()) {
client.playSoundEffect(SoundEffectID.MAGIC_SPLASH_BOING);
}
style = BossAttack.MAGIC;
}
// This section will decrement the boss attack counter by 1.
if (style == BossAttack.LIGHTNING) {
bossCounter--;
} else if (style == BossAttack.RANGE) {
if (currentPhase != BossAttackPhase.RANGE) {
currentPhase = BossAttackPhase.RANGE;
bossCounter = 3;
} else {
bossCounter--;
}
} else if (style == BossAttack.MAGIC) {
if (currentPhase != BossAttackPhase.MAGIC) {
currentPhase = BossAttackPhase.MAGIC;
bossCounter = 3;
} else {
bossCounter--;
}
}
// This section will reset the boss attack counter if necessary.
if (bossCounter <= 0) {
BossAttackPhase nextPhase;
switch (currentPhase) {
case MAGIC:
bossCounter = 4;
nextPhase = BossAttackPhase.RANGE;
break;
case RANGE:
bossCounter = 4;
nextPhase = BossAttackPhase.MAGIC;
break;
default:
bossCounter = 0;
nextPhase = BossAttackPhase.UNKNOWN;
break;
}
currentPhase = nextPhase;
}
}
@Subscribe
public void onAnimationChanged(AnimationChanged event) {
Actor actor = event.getActor();
// This section handles the player counter.
if (actor instanceof Player && GauntletUtils.inBoss(client)) {
Player p = (Player) actor;
if (p.getName().equals(client.getLocalPlayer().getName())) {
int id = p.getAnimation();
if (id != -1) {
// Detect the overhead prayer that the boss is using and determine the list of animations that the boss is currently immune to.
int[] wrong_style = new int[]{};
for (NPC npc : this.client.getNpcs()) {
if (GauntletUtils.isBoss(npc)) {
NPCComposition comp = npc.getComposition();
if (comp != null) {
HeadIcon prayer = comp.getOverheadIcon();
if (prayer != null) {
switch (prayer) {
case MELEE:
wrong_style = GauntletUtils.MELEE_ANIMATIONS;
break;
case RANGED:
wrong_style = GauntletUtils.RANGE_ANIMATIONS;
break;
case MAGIC:
wrong_style = GauntletUtils.MAGE_ANIMATIONS;
break;
default:
wrong_style = new int[]{};
break;
}
break;
}
}
}
}
// Check that the player performed an attack animation that the boss isn't immune to.
if (GauntletUtils.arrayContainsInteger(GauntletUtils.PLAYER_ANIMATIONS, id) && !GauntletUtils.arrayContainsInteger(wrong_style, id)) {
// Attack is valid. Decrement the player attack counter and reset it if necessary.
playerCounter--;
if (playerCounter <= 0) {
playerCounter = 6;
}
}
}
}
}
// This section handles the boss attack counter if they perform a lightning attack.
if (actor instanceof NPC) {
NPC npc = (NPC) actor;
if (GauntletUtils.isBoss(npc)) {
int id = npc.getAnimation();
if (id == GauntletUtils.BOSS_ANIMATION_LIGHTNING) {
this.doAttack(BossAttack.LIGHTNING);
}
}
}
}
@Subscribe
public void onGameTick(GameTick event) {
// This handles the timer based on player health.
if (this.completeStartup)
timer.checkStates(false);
// This section handles the boss attack counter if they perform a projectile attack.
Set<Projectile> newProjectiles = new HashSet<>();
for (Projectile projectile : client.getProjectiles()) {
newProjectiles.add(projectile);
if (!projectiles.contains(projectile)) {
int id = projectile.getId();
if (GauntletUtils.arrayContainsInteger(GauntletUtils.PROJECTILE_MAGIC, id)) {
this.doAttack(BossAttack.MAGIC);
} else if (GauntletUtils.arrayContainsInteger(GauntletUtils.PROJECTILE_PRAYER, id)) {
this.doAttack(BossAttack.PRAYER);
} else if (GauntletUtils.arrayContainsInteger(GauntletUtils.PROJECTILE_RANGE, id)) {
this.doAttack(BossAttack.RANGE);
}
}
}
projectiles.clear();
projectiles = newProjectiles;
// This section handles lightning decay.
if (!this.tornadoesActive) {
for (NPC npc : client.getNpcs()) {
if (GauntletUtils.isTornado(npc)) {
tornadoesActive = true;
tornadoTicks = GauntletUtils.TORNADO_TICKS;
break;
}
}
} else {
tornadoTicks--;
if (tornadoTicks <= 0) {
tornadoesActive = false;
tornadoTicks = GauntletUtils.TORNADO_TICKS;
}
}
}
@Subscribe
public void onGameObjectSpawned(GameObjectSpawned event) {
onGameObject(event.getTile(), null, event.getGameObject());
}
@Subscribe
public void onGameObjectChanged(GameObjectChanged event) {
onGameObject(event.getTile(), event.getPrevious(), event.getGameObject());
}
@Subscribe
public void onGameObjectDespawned(GameObjectDespawned event) {
onGameObject(event.getTile(), event.getGameObject(), null);
}
@Subscribe
public void onGameStateChanged(GameStateChanged event) {
if (event.getGameState() == GameState.LOADING) {
resources.clear();
}
}
/**
* Called when a GameObject spawns, changes, or despawns.
*
* @param tile Tile
* @param oldObject TileObject
* @param newObject TileObject
*/
private void onGameObject(Tile tile, GameObject oldObject, GameObject newObject) {
resources.remove(oldObject);
if (newObject == null) {
return;
}
int id = newObject.getId();
if (GauntletUtils.arrayContainsInteger(GauntletUtils.RESOURCE_IDS, id)) {
resources.put(newObject, tile);
}
}
}