Repository navigation
Expand file tree
/
Copy pathGauntletOverlay.java
More file actions
266 lines (213 loc) · 11.5 KB
/
Copy pathGauntletOverlay.java
File metadata and controls
266 lines (213 loc) · 11.5 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
/*
* 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 net.runelite.api.Client;
import net.runelite.api.GameObject;
import net.runelite.api.NPC;
import net.runelite.api.Perspective;
import net.runelite.api.Point;
import net.runelite.api.Projectile;
import net.runelite.api.Tile;
import net.runelite.api.coords.LocalPoint;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayPriority;
import net.runelite.client.ui.overlay.OverlayUtil;
import javax.inject.Inject;
import java.awt.*;
import java.awt.image.BufferedImage;
public class GauntletOverlay extends Overlay {
private final Client client;
private final GauntletPlugin plugin;
private final GauntletConfig config;
private static final int MAX_DISTANCE = 2350;
@Inject
private GauntletOverlay(Client client, GauntletPlugin plugin, GauntletConfig config) {
this.client = client;
this.plugin = plugin;
this.config = config;
setPosition(OverlayPosition.DYNAMIC);
setPriority(OverlayPriority.HIGH);
setLayer(OverlayLayer.ABOVE_SCENE);
}
@Override
public Dimension render(Graphics2D graphics) {
// Save resources. There's nothing to render if the user is not in a raid.
if (!GauntletUtils.inRaid(client))
return null;
if (GauntletUtils.inBoss(client)) { // This section handles the visuals when the player is in the boss room.
// This section handles the projectile overlays.
for (Projectile projectile : this.client.getProjectiles()) {
int id = projectile.getId();
BufferedImage icon = null;
Color color = null;
if (GauntletUtils.arrayContainsInteger(GauntletUtils.PROJECTILE_MAGIC, id) && config.uniqueAttackVisual()) {
icon = plugin.imageAttackMage;
color = Color.CYAN;
} else if (GauntletUtils.arrayContainsInteger(GauntletUtils.PROJECTILE_RANGE, id) && config.uniqueAttackVisual()) {
icon = plugin.imageAttackRange;
color = Color.GREEN;
} else if (GauntletUtils.arrayContainsInteger(GauntletUtils.PROJECTILE_PRAYER, id) && config.uniquePrayerVisual()) {
icon = plugin.imageAttackPrayer;
color = Color.MAGENTA;
}
if (icon == null)
continue;
Polygon polygon = GauntletUtils.boundProjectile(client, projectile);
if (polygon == null) {
int x = (int) projectile.getX();
int y = (int) projectile.getY();
LocalPoint point = new LocalPoint(x, y);
Point loc = Perspective.getCanvasImageLocation(client, point, icon, -(int) projectile.getZ());
if (loc == null)
continue;
graphics.drawImage(icon, loc.getX(), loc.getY(), null);
} else {
graphics.setColor(color);
graphics.draw(polygon);
graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 50));
graphics.fill(polygon);
Rectangle bounds = polygon.getBounds();
int x = (int) bounds.getCenterX() - (icon.getWidth() / 2);
int y = (int) bounds.getCenterY() - (icon.getHeight() / 2);
graphics.drawImage(icon, x, y, null);
}
}
for (NPC npc : this.client.getNpcs()) {
// Draws graphics on tornadoes.
if (config.overlayTornadoes() && plugin.tornadoesActive && GauntletUtils.isTornado(npc)) {
String textOverlay = Integer.toString(plugin.tornadoTicks);
Point textLoc = Perspective.getCanvasTextLocation(client, graphics, npc.getLocalLocation(), textOverlay, 0);
if (textLoc == null)
continue;
Font oldFont = graphics.getFont();
graphics.setFont(new Font("Arial", Font.BOLD, 20));
Point pointShadow = new Point(textLoc.getX() + 1, textLoc.getY() + 1);
OverlayUtil.renderTextLocation(graphics, pointShadow, textOverlay, Color.BLACK);
OverlayUtil.renderTextLocation(graphics, textLoc, textOverlay, Color.YELLOW);
graphics.setFont(oldFont);
}
// Draws the graphics on the boss.
if (GauntletUtils.isBoss(npc)) {
final LocalPoint point = npc.getLocalLocation();
// Overlay the boss with a color on it's convex hull.
if (config.overlayBoss()) {
Polygon polygon = npc.getConvexHull();
if (polygon != null) {
Color color;
switch (plugin.currentPhase) {
case MAGIC:
color = Color.CYAN;
break;
case RANGE:
color = Color.GREEN;
break;
default:
color = Color.WHITE;
break;
}
graphics.draw(polygon);
graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 50));
graphics.fill(polygon);
}
}
// Overlay of the boss with an icon denoting it's current attack style.
if (config.overlayBossPrayer()) {
BufferedImage attackIcon = null;
switch (plugin.currentPhase) {
case MAGIC:
attackIcon = plugin.imageAttackMage;
break;
case RANGE:
attackIcon = plugin.imageAttackRange;
break;
default:
break;
}
if (attackIcon != null) {
Point imageLoc = Perspective.getCanvasImageLocation(client, point, attackIcon, npc.getLogicalHeight() / 2);
if (imageLoc == null)
continue;
graphics.drawImage(attackIcon, imageLoc.getX(), imageLoc.getY(), null);
}
}
// This section handles any text overlays.
String textOverlay = "";
// Handles the counter for the boss.
if (config.countBossAttacks()) {
textOverlay = Integer.toString(plugin.bossCounter);
}
// Handles the counter for the player.
if (config.countPlayerAttacks()) {
if (textOverlay.length() > 0)
textOverlay += " | ";
textOverlay += Integer.toString(plugin.playerCounter);
}
// Handles drawing the text onto the boss.
if (textOverlay.length() > 0) {
Point textLoc = Perspective.getCanvasTextLocation(client, graphics, point, textOverlay, npc.getLogicalHeight() / 2);
if (textLoc == null)
continue;
textLoc = new Point(textLoc.getX(), textLoc.getY() + 35);
Font oldFont = graphics.getFont();
graphics.setFont(new Font("Arial", Font.BOLD, 20));
Point pointShadow = new Point(textLoc.getX() + 1, textLoc.getY() + 1);
OverlayUtil.renderTextLocation(graphics, pointShadow, textOverlay, Color.BLACK);
OverlayUtil.renderTextLocation(graphics, textLoc, textOverlay, Color.CYAN);
graphics.setFont(oldFont);
}
}
}
} else {
// This section overlays all resources.
LocalPoint playerLocation = client.getLocalPlayer().getLocalLocation();
for (GameObject object : plugin.resources.keySet()) {
Tile tile = plugin.resources.get(object);
if (tile.getPlane() == client.getPlane()
&& object.getLocalLocation().distanceTo(playerLocation) < MAX_DISTANCE) {
// Don't use Convex Hull click box. As the room start to fill up, your FPS will dip.
Polygon polygon = object.getCanvasTilePoly();
if (polygon != null) {
// This section will highlight the resource with color.
if (config.highlightResourcesColor()) {
Color color = SystemColor.YELLOW;
graphics.setColor(color);
graphics.draw(polygon);
graphics.setColor(new Color(color.getRed(), color.getGreen(), color.getBlue(), 50));
graphics.fill(polygon);
}
// This section will overlay the resource with an icon.
if (config.highlightResourcesIcons()) {
int id = object.getId();
BufferedImage icon = null;
if (GauntletUtils.arrayContainsInteger(GauntletUtils.CRYSTAL_DEPOSIT, id)) {
icon = plugin.imageCrystalDeposit;
} else if (GauntletUtils.arrayContainsInteger(GauntletUtils.PHREN_ROOTS, id)) {
icon = plugin.imagePhrenRoots;
} else if (GauntletUtils.arrayContainsInteger(GauntletUtils.FISHING_SPOTS, id)) {
icon = plugin.imageFishingSpot;
} else if (GauntletUtils.arrayContainsInteger(GauntletUtils.GRYM_ROOTS, id)) {
icon = plugin.imageGrymRoot;
} else if (GauntletUtils.arrayContainsInteger(GauntletUtils.LINUM_TIRINUM, id)) {
icon = plugin.imageLinumTirinum;
}
if (icon != null) {
Rectangle bounds = polygon.getBounds();
int startX = (int) bounds.getCenterX() - (icon.getWidth() / 2);
int startY = (int) bounds.getCenterY() - (icon.getHeight() / 2);
graphics.drawImage(icon, startX, startY, null);
}
}
}
}
}
}
return null;
}
}