Accurate Projectile Overlay
This commit is contained in:
@@ -9,14 +9,13 @@
|
||||
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.TileObject;
|
||||
import net.runelite.api.coords.LocalPoint;
|
||||
import net.runelite.api.coords.WorldPoint;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayLayer;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
@@ -58,27 +57,45 @@ public class GauntletOverlay extends Overlay {
|
||||
int id = projectile.getId();
|
||||
|
||||
BufferedImage icon = null;
|
||||
Color color = null;
|
||||
|
||||
if (GauntletUtils.arrayContainsInteger(GauntletUtils.PROJECTILE_MAGIC, id) && config.uniqueAttackVisual())
|
||||
if (GauntletUtils.arrayContainsInteger(GauntletUtils.PROJECTILE_MAGIC, id) && config.uniqueAttackVisual()) {
|
||||
icon = plugin.imageAttackMage;
|
||||
else if (GauntletUtils.arrayContainsInteger(GauntletUtils.PROJECTILE_RANGE, id) && config.uniqueAttackVisual())
|
||||
color = Color.CYAN;
|
||||
} else if (GauntletUtils.arrayContainsInteger(GauntletUtils.PROJECTILE_RANGE, id) && config.uniqueAttackVisual()) {
|
||||
icon = plugin.imageAttackRange;
|
||||
else if (GauntletUtils.arrayContainsInteger(GauntletUtils.PROJECTILE_PRAYER, id) && config.uniquePrayerVisual())
|
||||
color = Color.GREEN;
|
||||
} else if (GauntletUtils.arrayContainsInteger(GauntletUtils.PROJECTILE_PRAYER, id) && config.uniquePrayerVisual()) {
|
||||
icon = plugin.imageAttackPrayer;
|
||||
color = Color.MAGENTA;
|
||||
}
|
||||
|
||||
if (icon == null)
|
||||
continue;
|
||||
|
||||
int x = (int) projectile.getX();
|
||||
int y = (int) projectile.getY();
|
||||
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, 0);
|
||||
LocalPoint point = new LocalPoint(x, y);
|
||||
Point loc = Perspective.getCanvasImageLocation(client, point, icon, -(int) projectile.getZ());
|
||||
|
||||
if (loc == null)
|
||||
continue;
|
||||
if (loc == null)
|
||||
continue;
|
||||
|
||||
graphics.drawImage(icon, loc.getX(), loc.getY(), null);
|
||||
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()) {
|
||||
@@ -143,7 +160,6 @@ public class GauntletOverlay extends Overlay {
|
||||
attackIcon = plugin.imageAttackRange;
|
||||
break;
|
||||
default:
|
||||
attackIcon = null;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -158,7 +174,7 @@ public class GauntletOverlay extends Overlay {
|
||||
}
|
||||
|
||||
// This section handles any text overlays.
|
||||
String textOverlay = new String();
|
||||
String textOverlay = "";
|
||||
|
||||
// Handles the counter for the boss.
|
||||
if (config.countBossAttacks()) {
|
||||
@@ -197,12 +213,12 @@ public class GauntletOverlay extends Overlay {
|
||||
// This section overlays all resources.
|
||||
LocalPoint playerLocation = client.getLocalPlayer().getLocalLocation();
|
||||
|
||||
for (TileObject object : plugin.resources.keySet()) {
|
||||
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 Clickbox. As the room start to fill up, your FPS will dip.
|
||||
// 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) {
|
||||
|
@@ -208,7 +208,7 @@ class GauntletTimer extends Overlay {
|
||||
|
||||
panelComponent.getChildren().add(TitleComponent.builder().text("Gauntlet Timer").color(Color.WHITE).build());
|
||||
|
||||
if(timeRaidStart == -1L) { // User restarted the plugin mid raid. Timer is inaccurate.
|
||||
if (timeRaidStart == -1L) { // User restarted the plugin mid raid. Timer is inaccurate.
|
||||
panelComponent.getChildren().add(LineComponent.builder().left("Inactive").right("0:00").build());
|
||||
} else {
|
||||
String elapsedPrepTime, elapsedBossTime, elapsedTotalTime;
|
||||
|
@@ -1,8 +1,18 @@
|
||||
package net.runelite.client.plugins.gauntlet;
|
||||
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Model;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.Varbits;
|
||||
import net.runelite.api.Perspective;
|
||||
import net.runelite.api.Point;
|
||||
import net.runelite.api.Projectile;
|
||||
import net.runelite.api.coords.LocalPoint;
|
||||
import net.runelite.api.model.Jarvis;
|
||||
import net.runelite.api.model.Vertex;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GauntletUtils {
|
||||
|
||||
@@ -159,4 +169,34 @@ public class GauntletUtils {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static Polygon boundProjectile(Client client, Projectile p) {
|
||||
if (p == null || p.getModel() == null)
|
||||
return null;
|
||||
|
||||
Model model = p.getModel();
|
||||
LocalPoint point = new LocalPoint((int) p.getX(), (int) p.getY());
|
||||
int tileHeight = Perspective.getTileHeight(client, point, client.getPlane());
|
||||
|
||||
List<Vertex> vertices = model.getVertices();
|
||||
List<Point> list = new ArrayList<>();
|
||||
|
||||
for (final Vertex vertex : vertices) {
|
||||
final Point localToCanvas = Perspective.localToCanvas(client, point.getX() - vertex.getX(), point.getY() - vertex.getZ(), tileHeight + vertex.getY() + (int) p.getZ());
|
||||
if (localToCanvas != null) {
|
||||
list.add(localToCanvas);
|
||||
}
|
||||
}
|
||||
|
||||
final List<Point> convexHull = Jarvis.convexHull(list);
|
||||
if (convexHull == null)
|
||||
return null;
|
||||
|
||||
final Polygon polygon = new Polygon();
|
||||
for (final Point hullPoint : convexHull) {
|
||||
polygon.addPoint(hullPoint.getX(), hullPoint.getY());
|
||||
}
|
||||
|
||||
return polygon;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user