From 36765360a7380bcde95051a18b3ae7caef806fa1 Mon Sep 17 00:00:00 2001 From: Seth Date: Sat, 10 Feb 2018 19:36:17 -0600 Subject: [PATCH] cannon plugin: add common cannon spots --- .../client/plugins/cannon/CannonConfig.java | 10 ++ .../client/plugins/cannon/CannonPlugin.java | 41 ++++++- .../plugins/cannon/CannonSpotOverlay.java | 109 ++++++++++++++++++ .../client/plugins/cannon/CannonSpots.java | 74 ++++++++++++ 4 files changed, 231 insertions(+), 3 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonSpotOverlay.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonSpots.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonConfig.java index 2d2e459c82..0af2a463da 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonConfig.java @@ -75,4 +75,14 @@ public interface CannonConfig extends Config { return Color.RED; } + + @ConfigItem( + keyName = "showCannonSpots", + name = "Show common cannon spots", + description = "Configures whether to show common cannon spots or not" + ) + default boolean showCannonSpots() + { + return true; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonPlugin.java index f5daf0b223..eb2446b82d 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonPlugin.java @@ -27,6 +27,11 @@ package net.runelite.client.plugins.cannon; import com.google.common.eventbus.Subscribe; import com.google.inject.Provides; import java.awt.Color; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.inject.Inject; @@ -51,6 +56,7 @@ import net.runelite.client.config.ConfigManager; import net.runelite.client.game.ItemManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; +import net.runelite.client.task.Schedule; import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.infobox.InfoBoxManager; @@ -76,6 +82,9 @@ public class CannonPlugin extends Plugin @Getter private GameObject cannon; + @Getter + private List spotPoints = new ArrayList<>(); + @Inject private ItemManager itemManager; @@ -88,6 +97,9 @@ public class CannonPlugin extends Plugin @Inject private CannonOverlay cannonOverlay; + @Inject + private CannonSpotOverlay cannonSpotOverlay; + @Inject private CannonConfig config; @@ -101,9 +113,9 @@ public class CannonPlugin extends Plugin } @Override - public Overlay getOverlay() + public Collection getOverlays() { - return cannonOverlay; + return Arrays.asList(cannonOverlay, cannonSpotOverlay); } @Override @@ -135,6 +147,29 @@ public class CannonPlugin extends Plugin } + @Schedule( + period = 1, + unit = ChronoUnit.SECONDS + ) + public void checkSpots() + { + if (!config.showCannonSpots()) + { + return; + } + + spotPoints.clear(); + for (WorldPoint spot : CannonSpots.getCannonSpots()) + { + if (spot.getPlane() != client.getPlane() || !spot.isInScene(client)) + { + continue; + } + + spotPoints.add(spot); + } + } + @Subscribe public void onGameObjectSpawned(GameObjectSpawned event) { @@ -197,7 +232,7 @@ public class CannonPlugin extends Plugin if (m.find()) { int amt = Integer.valueOf(m.group()); - + // make sure cballs doesn't go above MAX_CBALLS if (amt + cballsLeft > MAX_CBALLS) { diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonSpotOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonSpotOverlay.java new file mode 100644 index 0000000000..d23e013320 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonSpotOverlay.java @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2018, Seth + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.cannon; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.awt.Polygon; +import java.awt.image.BufferedImage; +import javax.inject.Inject; +import net.runelite.api.Client; +import static net.runelite.api.ItemID.CANNONBALL; +import net.runelite.api.Perspective; +import net.runelite.api.Point; +import net.runelite.api.coords.LocalPoint; +import net.runelite.api.coords.WorldPoint; +import net.runelite.client.game.ItemManager; +import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.OverlayUtil; + +public class CannonSpotOverlay extends Overlay +{ + private static final int MAX_DISTANCE = 2350; + + private final Client client; + private final CannonPlugin plugin; + private final CannonConfig config; + + @Inject + private ItemManager itemManager; + + @Inject + CannonSpotOverlay(Client client, CannonPlugin plugin, CannonConfig config) + { + setPosition(OverlayPosition.DYNAMIC); + this.client = client; + this.plugin = plugin; + this.config = config; + } + + @Override + public Dimension render(Graphics2D graphics, java.awt.Point parent) + { + if (!config.showCannonSpots() || plugin.isCannonPlaced()) + { + return null; + } + + for (WorldPoint spot : plugin.getSpotPoints()) + { + if (spot.getPlane() != client.getPlane()) + { + continue; + } + + LocalPoint spotPoint = LocalPoint.fromWorld(client, spot); + LocalPoint localLocation = client.getLocalPlayer().getLocalLocation(); + + if (spotPoint != null && localLocation.distanceTo(spotPoint) <= MAX_DISTANCE) + { + renderCannonSpot(graphics, client, spotPoint, itemManager.getImage(CANNONBALL), Color.RED); + } + } + + return null; + } + + private void renderCannonSpot(Graphics2D graphics, Client client, LocalPoint point, BufferedImage image, Color color) + { + //Render tile + Polygon poly = Perspective.getCanvasTilePoly(client, point); + + if (poly != null) + { + OverlayUtil.renderPolygon(graphics, poly, color); + } + + //Render icon + Point imageLoc = Perspective.getCanvasImageLocation(client, graphics, point, image, 0); + + if (imageLoc != null) + { + OverlayUtil.renderImageLocation(graphics, imageLoc, image); + } + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonSpots.java b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonSpots.java new file mode 100644 index 0000000000..12554f1648 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/cannon/CannonSpots.java @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2018, Seth + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.cannon; + +import java.util.ArrayList; +import java.util.List; +import lombok.Getter; +import net.runelite.api.coords.WorldPoint; + +public enum CannonSpots +{ + + BLOODVELDS(new WorldPoint(2439, 9821, 0), new WorldPoint(2448, 9821, 0), new WorldPoint(2472, 9833, 0), new WorldPoint(2453, 9817, 0)), + FIRE_GIANTS(new WorldPoint(2393, 9782, 0), new WorldPoint(2412, 9776, 0), new WorldPoint(2401, 9780, 0)), + ABBERANT_SPECTRES(new WorldPoint(2456, 9791, 0)), + HELLHOUNDS(new WorldPoint(2431, 9776, 0), new WorldPoint(2413, 9786, 0), new WorldPoint(2783, 9686, 0)), + BLACK_DEMONS(new WorldPoint(2859, 9778, 0), new WorldPoint(2841, 9791, 0)), + ELVES(new WorldPoint(2044, 4635, 0)), + SUQAHS(new WorldPoint(2114, 3943, 0)), + TROLLS(new WorldPoint(2405, 3857, 0)), + GREATER_DEMONS(new WorldPoint(1438, 10089, 2)), + BRINE_RAT(new WorldPoint(2707, 10132, 0)), + DAGGANOTH(new WorldPoint(2524, 10020, 0)), + DARK_BEAST(new WorldPoint(1992, 4655, 0)), + DUST_DEVIL(new WorldPoint(3218, 9366, 0)), + KALPHITE(new WorldPoint(3307, 9528, 0)), + LESSER_DEMON(new WorldPoint(2838, 9559, 0)), + LIZARDMEN(new WorldPoint(1500, 3703, 1)), + MINIONS_OF_SCARABAS(new WorldPoint(3297, 9252, 0)), + SMOKE_DEVIL(new WorldPoint(2398, 9444, 0)); + + @Getter + private static final List cannonSpots = new ArrayList<>(); + + static + { + for (CannonSpots cannonSpot : values()) + { + for (WorldPoint spot : cannonSpot.spots) + { + cannonSpots.add(spot); + } + } + } + + private final WorldPoint[] spots; + + CannonSpots(WorldPoint... spots) + { + this.spots = spots; + } +}