volcanic mine plugin: show optimal paths

Add gas chamber rock timer
This commit is contained in:
l2-
2017-11-25 00:12:12 +01:00
committed by Adam
parent 6f4fb6d8be
commit 6402e16bb5
6 changed files with 229 additions and 43 deletions

View File

@@ -22,7 +22,7 @@
* (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.volcanicminehelper;
package net.runelite.client.plugins.volcanicmine;
import java.time.Duration;

View File

@@ -0,0 +1,117 @@
/*
* Copyright (c) 2017. l2-
*
* 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.volcanicmine;
import com.google.common.collect.ImmutableSet;
import net.runelite.api.Point;
import java.util.Set;
class OptimalPaths
{
private static final int INSTANCE_SIZE = 192;
private static final Set<Point> OPTIMAL_PATH_POINTS = ImmutableSet.of(
new Point(161, 145),
new Point(161, 144),
new Point(161, 143),
new Point(161, 142),
new Point(169, 151),
new Point(169, 148),
new Point(169, 147),
new Point(169, 133),
new Point(175, 146),
new Point(176, 146),
new Point(179, 116),
new Point(179, 117),
new Point(179, 118),
new Point(167, 101),
new Point(167, 100),
new Point(167, 104),
new Point(167, 105),
new Point(166, 76),
new Point(166, 77),
new Point(166, 78),
new Point(166, 79),
new Point(146, 107),
new Point(145, 107),
new Point(144, 107),
new Point(143, 107),
new Point(142, 107),
new Point(141, 107),
new Point(139, 104),
new Point(139, 103),
new Point(139, 102),
new Point(139, 101),
new Point(152, 101),
new Point(152, 100),
new Point(149, 76)
);
public final static Set<Point> BOULDER_RANGE_POINTS = ImmutableSet.of(
new Point(162, 123),
new Point(161, 152),
new Point(160, 151),
new Point(163, 105),
new Point(163, 104),
new Point(163, 103),
new Point(163, 102),
new Point(163, 101),
new Point(164, 92),
new Point(164, 91),
new Point(164, 90),
new Point(164, 83),
new Point(165, 80),
new Point(164, 80),
new Point(155, 80),
new Point(155, 81),
new Point(155, 82),
new Point(155, 83),
new Point(155, 89),
new Point(155, 90),
new Point(155, 91),
new Point(155, 92),
new Point(156, 103),
new Point(156, 104),
new Point(156, 105),
new Point(162, 126),
new Point(162, 125),
new Point(162, 124)
);
//only use global location
public static boolean isOptimalPathTile(Point point)
{
Point instanceLocation = new Point(point.getX() % INSTANCE_SIZE, point.getY() % INSTANCE_SIZE);
return OPTIMAL_PATH_POINTS.contains(instanceLocation);
}
//only use global location
public static boolean isBoulderRangeTile(Point point)
{
Point instanceLocation = new Point(point.getX() % INSTANCE_SIZE, point.getY() % INSTANCE_SIZE);
return BOULDER_RANGE_POINTS.contains(instanceLocation);
}
}

View File

@@ -23,7 +23,7 @@
* (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.volcanicminehelper;
package net.runelite.client.plugins.volcanicmine;
import java.awt.Color;
import net.runelite.client.config.Config;
@@ -94,6 +94,28 @@ public interface VolcanicMineConfig extends Config
@ConfigItem(
position = 5,
keyName = "timerOverlay",
name = "timer overlay",
description = "The overlay showing the timers"
)
default boolean timerOverlay()
{
return true;
}
@ConfigItem(
position = 6,
keyName = "optimalPathOverlay",
name = "show optimal Paths",
description = "The overlay showing the optimal paths"
)
default boolean optimalPaths()
{
return true;
}
@ConfigItem(
position = 7,
keyName = "platformColorLow",
name = "PlatformColor low risk",
description = "Configures the color for the platformOverlay"
@@ -104,7 +126,7 @@ public interface VolcanicMineConfig extends Config
}
@ConfigItem(
position = 6,
position = 8,
keyName = "platformColorMed",
name = "PlatformColor med risk",
description = "Configures the color for the platformOverlay"
@@ -115,7 +137,7 @@ public interface VolcanicMineConfig extends Config
}
@ConfigItem(
position = 7,
position = 9,
keyName = "platformColorHigh",
name = "PlatformColor high risk",
description = "Configures the color for the platformOverlay"
@@ -126,7 +148,7 @@ public interface VolcanicMineConfig extends Config
}
@ConfigItem(
position = 8,
position = 10,
keyName = "platformTimerThreshold",
name = "Platform timer notification threshold",
description = "At what time does the plugin notify (in seconds), set to -1 to disable"
@@ -137,7 +159,7 @@ public interface VolcanicMineConfig extends Config
}
@ConfigItem(
position = 9,
position = 11,
keyName = "timeLeftThreshold",
name = "Time left threshold",
description = "At what time does the plugin notify (in seconds), set to -1 to disable"
@@ -148,7 +170,7 @@ public interface VolcanicMineConfig extends Config
}
@ConfigItem(
position = 9,
position = 12,
keyName = "stabilityThreshold",
name = "Stability threshold",
description = "At what stability does the plugin notify (in percentage), set to -1 to disable"
@@ -159,7 +181,7 @@ public interface VolcanicMineConfig extends Config
}
@ConfigItem(
position = 10,
position = 13,
keyName = "prayer",
name = "Prayer warning",
description = "Protect prayer warning setting"
@@ -170,7 +192,7 @@ public interface VolcanicMineConfig extends Config
}
@ConfigItem(
position = 11,
position = 14,
keyName = "hotTiles",
name = "Hot Tile warning",
description = "Hot tile warning setting"
@@ -181,7 +203,7 @@ public interface VolcanicMineConfig extends Config
}
@ConfigItem(
position = 12,
position = 15,
keyName = "timerWarning",
name = "timer warning",
description = "timer low warning setting"
@@ -192,7 +214,7 @@ public interface VolcanicMineConfig extends Config
}
@ConfigItem(
position = 13,
position = 16,
keyName = "stabilityWarning",
name = "stability warning",
description = "stability low warning setting"

View File

@@ -23,13 +23,14 @@
* (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.volcanicminehelper;
package net.runelite.client.plugins.volcanicmine;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Polygon;
import java.awt.Rectangle;
import java.io.IOException;
import java.io.InputStream;
@@ -41,6 +42,7 @@ import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.GameObject;
import net.runelite.api.GameState;
import net.runelite.api.Perspective;
import net.runelite.api.Point;
import net.runelite.api.Prayer;
import net.runelite.api.Region;
@@ -54,23 +56,24 @@ import org.slf4j.LoggerFactory;
public class VolcanicMineOverlay extends Overlay
{
private static final Logger logger = LoggerFactory.getLogger(VolcanicMineHelperPlugin.class);
private static final Logger logger = LoggerFactory.getLogger(VolcanicMinePlugin.class);
private static final int THRESH_LOW = 45;
private static final int THRESH_MED = 5;
private static final int MAX_DISTANCE = 19; //2400/128 rounded up
private static final int REGION_SIZE = 104;
private static final int Z_OFFSET_TIMER = 25;
private static final String PROTECT_MESSAGE = "Protect!";
private final VolcanicMineHelperPlugin plugin;
private final VolcanicMinePlugin plugin;
private final VolcanicMineConfig config;
private final Client client;
private Image protectFromMissilesImg;
@Inject
VolcanicMineOverlay(@Nullable Client client, VolcanicMineHelperPlugin plugin, VolcanicMineConfig config)
VolcanicMineOverlay(@Nullable Client client, VolcanicMinePlugin plugin, VolcanicMineConfig config)
{
super(OverlayPosition.DYNAMIC);
this.client = client;
@@ -142,12 +145,45 @@ public class VolcanicMineOverlay extends Overlay
{
continue;
}
renderPaths(graphics, tile);
renderGameObjects(graphics, tile);
}
}
}
private void renderPaths(Graphics2D graphics, Tile tile)
{
if (config.optimalPaths() && !plugin.getObjectTimerMap().containsKey(tile))
{
Point worldLoc = tile.getWorldLocation();
if (client.getLocalPlayer().getWorldLocation().distanceTo(worldLoc) > MAX_DISTANCE)
{
return;
}
if (OptimalPaths.isOptimalPathTile(worldLoc))
{
Point localTile = tile.getLocalLocation();
localTile = new Point(localTile.getX() + Perspective.LOCAL_TILE_SIZE / 2, localTile.getY() + Perspective.LOCAL_TILE_SIZE / 2);
Polygon poly = Perspective.getCanvasTilePoly(client, localTile);
if (poly != null)
{
OverlayUtil.renderPolygon(graphics, poly, Color.CYAN);
}
}
else if (OptimalPaths.isBoulderRangeTile(worldLoc))
{
Point localTile = tile.getLocalLocation();
localTile = new Point(localTile.getX() + Perspective.LOCAL_TILE_SIZE / 2, localTile.getY() + Perspective.LOCAL_TILE_SIZE / 2);
Polygon poly = Perspective.getCanvasTilePoly(client, localTile);
if (poly != null)
{
OverlayUtil.renderPolygon(graphics, poly, Color.MAGENTA);
}
}
}
}
private void renderGameObjects(Graphics2D graphics, Tile tile)
{
GameObject[] gameObjects = tile.getGameObjects();
@@ -155,10 +191,9 @@ public class VolcanicMineOverlay extends Overlay
{
return;
}
for (GameObject gameObject : gameObjects)
{
if (gameObject != null && plugin.getObjectTimerMap().containsKey(tile))
if (gameObject != null && plugin.getObjectTimerMap().containsKey(tile) && config.timerOverlay())
{
Duration duration = Duration.between(Instant.now(), plugin.getObjectTimerMap().get(tile));
if (!duration.isNegative())
@@ -169,7 +204,7 @@ public class VolcanicMineOverlay extends Overlay
Color color;
if (seconds > THRESH_LOW)
{
color = config.platformColorLow();;
color = config.platformColorLow();
}
else if (seconds > THRESH_MED)
{

View File

@@ -23,7 +23,7 @@
* (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.volcanicminehelper;
package net.runelite.client.plugins.volcanicmine;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Binder;
@@ -67,13 +67,16 @@ import net.runelite.api.queries.NPCQuery;
@PluginDescriptor(
name = "Volcanic mine helper"
)
public class VolcanicMineHelperPlugin extends Plugin
public class VolcanicMinePlugin extends Plugin
{
private static final Logger logger = LoggerFactory.getLogger(VolcanicMineHelperPlugin.class);
private static final Logger logger = LoggerFactory.getLogger(VolcanicMinePlugin.class);
private static final int REGION_SIZE = 104;
private static final int MAX_DISTANCE = 2400;
private static final int LAVA_ID = 30997;
private static final int LAVA_BEAST_ATTACK_RANGE = 1400;
private static final int GAS_CHAMBER_ROCK_ID = 31045;
private static final int GAS_CHAMBER_NO_ROCK_ID = 31046;
private static final int GAS_CHAMBER_ROCK_RESPAWN_TIMER = 15;
private static final String LAVA_BEAST = "Lava beast";
private static final Pattern coltagPattern = Pattern.compile("((<col=([0-f]){6}>)|(<\\/col>))");
@@ -263,7 +266,7 @@ public class VolcanicMineHelperPlugin extends Plugin
private boolean isInside()
{
Widget widget = client.getWidget(WidgetInfo.VOLCANICMINE_GENERAL_INFOBOX_GROUP);
return widget != null && !widget.isHidden();
return widget != null && !widget.isHidden() && client.getPlane() == 1;
}
private boolean lavaBeastInRange(Player player)
@@ -322,12 +325,12 @@ public class VolcanicMineHelperPlugin extends Plugin
continue;
}
lookForPlatforms(tile, player);
lookForGameObjects(tile, player);
}
}
}
private void lookForPlatforms(Tile tile, Player player)
private void lookForGameObjects(Tile tile, Player player)
{
Point playerLocation = player.getLocalLocation();
GameObject[] gameObjects = tile.getGameObjects();
@@ -342,27 +345,36 @@ public class VolcanicMineHelperPlugin extends Plugin
{
continue;
}
LavaPlatform lavaPlatform = LavaPlatform.fromId(gameObject.getId());
Point objectLocation = gameObject.getLocalLocation();
if (lavaPlatform == null
|| abs(playerLocation.getX() - objectLocation.getX()) > MAX_DISTANCE
|| abs(playerLocation.getY() - objectLocation.getY()) > MAX_DISTANCE)
if (abs(playerLocation.getX() - objectLocation.getX()) < MAX_DISTANCE
&& abs(playerLocation.getY() - objectLocation.getY()) < MAX_DISTANCE)
{
continue;
}
LavaPlatform lavaPlatform = LavaPlatform.fromId(gameObject.getId());
Instant now = Instant.now();
Instant vanishTime;
Instant now = Instant.now();
Instant vanishTime = now.plus(lavaPlatform.getTime());
Instant returnInstant = objectTimerMap.putIfAbsent(tile, vanishTime);
if (returnInstant != null)
{
if (returnInstant.isBefore(now)
|| vanishTime.isBefore(returnInstant))
if (lavaPlatform != null)
{
objectTimerMap.replace(tile, vanishTime);
vanishTime = now.plus(lavaPlatform.getTime());
}
else if (gameObject.getId() == GAS_CHAMBER_NO_ROCK_ID)
{
vanishTime = now.plus(Duration.ofSeconds(GAS_CHAMBER_ROCK_RESPAWN_TIMER));
}
else
{
continue;
}
Instant returnInstant = objectTimerMap.putIfAbsent(tile, vanishTime);
if (returnInstant != null)
{
if (returnInstant.isBefore(now)
|| vanishTime.isBefore(returnInstant))
{
objectTimerMap.replace(tile, vanishTime);
}
}
}
}
@@ -373,7 +385,7 @@ public class VolcanicMineHelperPlugin extends Plugin
//remove the timers which hit 0
objectTimerMap = objectTimerMap.entrySet().stream()
.filter(entry -> Instant.now().isBefore(entry.getValue()))
.filter(v -> v.getKey().getGameObjects() != null && v.getKey().getGameObjects()[0] != null && v.getKey().getGameObjects()[0].getId() != LAVA_ID)
.filter(v -> v.getKey().getGameObjects() != null && v.getKey().getGameObjects()[0] != null && v.getKey().getGameObjects()[0].getId() != LAVA_ID && v.getKey().getGameObjects()[0].getId() != GAS_CHAMBER_ROCK_ID)
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
}

View File

@@ -23,7 +23,7 @@
* (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.volcanicminehelper;
package net.runelite.client.plugins.volcanicmine;
public enum WarningMode
{