Skip to content

Commit

Permalink
Merge pull request runelite#566 from sethtroll/addcannonspots
Browse files Browse the repository at this point in the history
Add common cannon spots
  • Loading branch information
Adam- authored Mar 18, 2018
2 parents ddb0282 + 8729cd2 commit d6e61aa
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,14 @@ default Color highlightDoubleHitColor()
{
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
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;
Expand All @@ -51,6 +56,7 @@
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;

Expand All @@ -76,6 +82,9 @@ public class CannonPlugin extends Plugin
@Getter
private GameObject cannon;

@Getter
private List<WorldPoint> spotPoints = new ArrayList<>();

@Inject
private ItemManager itemManager;

Expand All @@ -88,6 +97,9 @@ public class CannonPlugin extends Plugin
@Inject
private CannonOverlay cannonOverlay;

@Inject
private CannonSpotOverlay cannonSpotOverlay;

@Inject
private CannonConfig config;

Expand All @@ -101,9 +113,9 @@ CannonConfig provideConfig(ConfigManager configManager)
}

@Override
public Overlay getOverlay()
public Collection<Overlay> getOverlays()
{
return cannonOverlay;
return Arrays.asList(cannonOverlay, cannonSpotOverlay);
}

@Override
Expand Down Expand Up @@ -135,6 +147,29 @@ public void onConfigChanged(ConfigChanged event)

}

@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)
{
Expand Down Expand Up @@ -197,7 +232,7 @@ public void onChatMessage(ChatMessage event)
if (m.find())
{
int amt = Integer.valueOf(m.group());

// make sure cballs doesn't go above MAX_CBALLS
if (amt + cballsLeft > MAX_CBALLS)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright (c) 2018, Seth <https://github.com/sethtroll>
* 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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2018, Seth <https://github.com/sethtroll>
* 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<WorldPoint> 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;
}
}

0 comments on commit d6e61aa

Please sign in to comment.