Accurate Projectile Overlay
This commit is contained in:
@@ -9,14 +9,13 @@
|
|||||||
package net.runelite.client.plugins.gauntlet;
|
package net.runelite.client.plugins.gauntlet;
|
||||||
|
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.api.GameObject;
|
||||||
import net.runelite.api.NPC;
|
import net.runelite.api.NPC;
|
||||||
import net.runelite.api.Perspective;
|
import net.runelite.api.Perspective;
|
||||||
import net.runelite.api.Point;
|
import net.runelite.api.Point;
|
||||||
import net.runelite.api.Projectile;
|
import net.runelite.api.Projectile;
|
||||||
import net.runelite.api.Tile;
|
import net.runelite.api.Tile;
|
||||||
import net.runelite.api.TileObject;
|
|
||||||
import net.runelite.api.coords.LocalPoint;
|
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.Overlay;
|
||||||
import net.runelite.client.ui.overlay.OverlayLayer;
|
import net.runelite.client.ui.overlay.OverlayLayer;
|
||||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||||
@@ -58,27 +57,45 @@ public class GauntletOverlay extends Overlay {
|
|||||||
int id = projectile.getId();
|
int id = projectile.getId();
|
||||||
|
|
||||||
BufferedImage icon = null;
|
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;
|
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;
|
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;
|
icon = plugin.imageAttackPrayer;
|
||||||
|
color = Color.MAGENTA;
|
||||||
|
}
|
||||||
|
|
||||||
if (icon == null)
|
if (icon == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
int x = (int) projectile.getX();
|
Polygon polygon = GauntletUtils.boundProjectile(client, projectile);
|
||||||
int y = (int) projectile.getY();
|
if (polygon == null) {
|
||||||
|
int x = (int) projectile.getX();
|
||||||
|
int y = (int) projectile.getY();
|
||||||
|
|
||||||
LocalPoint point = new LocalPoint(x, y);
|
LocalPoint point = new LocalPoint(x, y);
|
||||||
Point loc = Perspective.getCanvasImageLocation(client, point, icon, 0);
|
Point loc = Perspective.getCanvasImageLocation(client, point, icon, -(int) projectile.getZ());
|
||||||
|
|
||||||
if (loc == null)
|
if (loc == null)
|
||||||
continue;
|
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()) {
|
for (NPC npc : this.client.getNpcs()) {
|
||||||
@@ -143,7 +160,6 @@ public class GauntletOverlay extends Overlay {
|
|||||||
attackIcon = plugin.imageAttackRange;
|
attackIcon = plugin.imageAttackRange;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
attackIcon = null;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,7 +174,7 @@ public class GauntletOverlay extends Overlay {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This section handles any text overlays.
|
// This section handles any text overlays.
|
||||||
String textOverlay = new String();
|
String textOverlay = "";
|
||||||
|
|
||||||
// Handles the counter for the boss.
|
// Handles the counter for the boss.
|
||||||
if (config.countBossAttacks()) {
|
if (config.countBossAttacks()) {
|
||||||
@@ -197,12 +213,12 @@ public class GauntletOverlay extends Overlay {
|
|||||||
// This section overlays all resources.
|
// This section overlays all resources.
|
||||||
LocalPoint playerLocation = client.getLocalPlayer().getLocalLocation();
|
LocalPoint playerLocation = client.getLocalPlayer().getLocalLocation();
|
||||||
|
|
||||||
for (TileObject object : plugin.resources.keySet()) {
|
for (GameObject object : plugin.resources.keySet()) {
|
||||||
Tile tile = plugin.resources.get(object);
|
Tile tile = plugin.resources.get(object);
|
||||||
if (tile.getPlane() == client.getPlane()
|
if (tile.getPlane() == client.getPlane()
|
||||||
&& object.getLocalLocation().distanceTo(playerLocation) < MAX_DISTANCE) {
|
&& 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();
|
Polygon polygon = object.getCanvasTilePoly();
|
||||||
|
|
||||||
if (polygon != null) {
|
if (polygon != null) {
|
||||||
|
@@ -208,7 +208,7 @@ class GauntletTimer extends Overlay {
|
|||||||
|
|
||||||
panelComponent.getChildren().add(TitleComponent.builder().text("Gauntlet Timer").color(Color.WHITE).build());
|
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());
|
panelComponent.getChildren().add(LineComponent.builder().left("Inactive").right("0:00").build());
|
||||||
} else {
|
} else {
|
||||||
String elapsedPrepTime, elapsedBossTime, elapsedTotalTime;
|
String elapsedPrepTime, elapsedBossTime, elapsedTotalTime;
|
||||||
|
@@ -1,8 +1,18 @@
|
|||||||
package net.runelite.client.plugins.gauntlet;
|
package net.runelite.client.plugins.gauntlet;
|
||||||
|
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.api.Model;
|
||||||
import net.runelite.api.NPC;
|
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 {
|
public class GauntletUtils {
|
||||||
|
|
||||||
@@ -159,4 +169,34 @@ public class GauntletUtils {
|
|||||||
return false;
|
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