Add Pyramid Plunder plugin

Co-authored-by: Adam <Adam@sigterm.info>
This commit is contained in:
Mitchell Kovacs
2020-05-26 23:57:34 -04:00
committed by Adam
parent e60d603a07
commit c5a698f852
5 changed files with 620 additions and 0 deletions

View File

@@ -356,7 +356,9 @@ public enum Varbits
/**
* Pyramid plunder
*/
PYRAMID_PLUNDER_ROOM_LOCATION(2365),
PYRAMID_PLUNDER_TIMER(2375),
PYRAMID_PLUNDER_THIEVING_LEVEL(2376),
PYRAMID_PLUNDER_ROOM(2377),
/**

View File

@@ -0,0 +1,154 @@
/*
* Copyright (c) 2020 Mitchell <https://github.com/Mitchell-Kovacs>
* 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.pyramidplunder;
import java.awt.Color;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
@ConfigGroup("pyramidplunder")
public interface PyramidPlunderConfig extends Config
{
@ConfigItem(
position = 0,
keyName = "hideTimer",
name = "Hide default timer",
description = "Hides the default pyramid plunder timer"
)
default boolean hideTimer()
{
return true;
}
@ConfigItem(
position = 1,
keyName = "showExactTimer",
name = "Show exact timer",
description = "Displays the amount of time remaining as an infobox"
)
default boolean showExactTimer()
{
return true;
}
@ConfigItem(
position = 2,
keyName = "timerLowWarning",
name = "Timer low warning",
description = "Determines the time when the timers color will change"
)
default int timerLowWarning()
{
return 30;
}
@ConfigItem(
position = 3,
keyName = "highlightDoorsColor",
name = "Highlight doors color",
description = "Selects the color for highlighting tomb doors"
)
default Color highlightDoorsColor()
{
return Color.green;
}
@ConfigItem(
position = 4,
keyName = "highlightDoors",
name = "Highlight doors",
description = "Highlights the four tomb doors in each room"
)
default boolean highlightDoors()
{
return true;
}
@ConfigItem(
position = 5,
keyName = "highlightSpeartrapColor",
name = "Highlight speartrap color",
description = "Selects the color for highlighting speartraps"
)
default Color highlightSpeartrapsColor()
{
return Color.orange;
}
@ConfigItem(
position = 6,
keyName = "highlightSpeartraps",
name = "Highlight speartraps",
description = "Highlight the spear traps at the entrance of each room"
)
default boolean highlightSpeartraps()
{
return true;
}
@ConfigItem(
position = 7,
keyName = "highlightContainersColor",
name = "Highlight containers color",
description = "Selects the color for highlighting urns, chests and sarcophagus"
)
default Color highlightContainersColor()
{
return Color.yellow;
}
@ConfigItem(
position = 8,
keyName = "highlightUrnsFloor",
name = "Highlight urns floor",
description = "Highlight the urns starting at selected floor and up"
)
default int highlightUrnsFloor()
{
return 9;
}
@ConfigItem(
position = 9,
keyName = "highlightedChestFloor",
name = "Highlight chest floor",
description = "Highlight the Grand Gold Chest starting at selected floor and up"
)
default int highlightChestFloor()
{
return 9;
}
@ConfigItem(
position = 10,
keyName = "highlightedSarcophagusFloor",
name = "Highlight sarcophagus floor",
description = "Highlight the sarcophagus starting at selected floor and up"
)
default int highlightSarcophagusFloor()
{
return 9;
}
}

View File

@@ -0,0 +1,168 @@
/*
* Copyright (c) 2020 Mitchell <https://github.com/Mitchell-Kovacs>
* 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.pyramidplunder;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.Shape;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.GameObject;
import net.runelite.api.ObjectComposition;
import net.runelite.api.Point;
import net.runelite.api.Varbits;
import net.runelite.api.coords.LocalPoint;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import static net.runelite.client.plugins.pyramidplunder.PyramidPlunderPlugin.GRAND_GOLD_CHEST_CLOSED_ID;
import static net.runelite.client.plugins.pyramidplunder.PyramidPlunderPlugin.GRAND_GOLD_CHEST_ID;
import static net.runelite.client.plugins.pyramidplunder.PyramidPlunderPlugin.SARCOPHAGUS_CLOSED_ID;
import static net.runelite.client.plugins.pyramidplunder.PyramidPlunderPlugin.SARCOPHAGUS_ID;
import static net.runelite.client.plugins.pyramidplunder.PyramidPlunderPlugin.SPEARTRAP_ID;
import static net.runelite.client.plugins.pyramidplunder.PyramidPlunderPlugin.TOMB_DOOR_CLOSED_ID;
import static net.runelite.client.plugins.pyramidplunder.PyramidPlunderPlugin.TOMB_DOOR_WALL_IDS;
import static net.runelite.client.plugins.pyramidplunder.PyramidPlunderPlugin.URN_CLOSED_IDS;
import static net.runelite.client.plugins.pyramidplunder.PyramidPlunderPlugin.URN_IDS;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil;
class PyramidPlunderOverlay extends Overlay
{
private static final int MAX_DISTANCE = 2350;
private final Client client;
private final PyramidPlunderPlugin plugin;
private final PyramidPlunderConfig config;
@Inject
private PyramidPlunderOverlay(Client client, PyramidPlunderPlugin plugin, PyramidPlunderConfig config)
{
super(plugin);
setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_SCENE);
this.client = client;
this.plugin = plugin;
this.config = config;
}
@Override
public Dimension render(Graphics2D graphics)
{
Widget ppWidget = client.getWidget(WidgetInfo.PYRAMID_PLUNDER_DATA);
if (ppWidget == null)
{
return null;
}
ppWidget.setHidden(config.hideTimer());
LocalPoint playerLocation = client.getLocalPlayer().getLocalLocation();
// Highlight convex hulls of urns, chests, and sarcophagus
int currentFloor = client.getVar(Varbits.PYRAMID_PLUNDER_ROOM);
for (GameObject object : plugin.getObjectsToHighlight())
{
if (config.highlightUrnsFloor() > currentFloor && URN_IDS.contains(object.getId())
|| config.highlightChestFloor() > currentFloor && GRAND_GOLD_CHEST_ID == object.getId()
|| config.highlightSarcophagusFloor() > currentFloor && SARCOPHAGUS_ID == object.getId()
|| object.getLocalLocation().distanceTo(playerLocation) >= MAX_DISTANCE)
{
continue;
}
ObjectComposition imposter = client.getObjectDefinition(object.getId()).getImpostor();
if (URN_CLOSED_IDS.contains(imposter.getId())
|| GRAND_GOLD_CHEST_CLOSED_ID == imposter.getId()
|| SARCOPHAGUS_CLOSED_ID == imposter.getId())
{
Shape shape = object.getConvexHull();
if (shape != null)
{
OverlayUtil.renderPolygon(graphics, shape, config.highlightContainersColor());
}
}
}
Point mousePosition = client.getMouseCanvasPosition();
// Highlight clickboxes of speartraps and tomb doors
plugin.getTilesToHighlight().forEach((object, tile) ->
{
if (!config.highlightDoors() && TOMB_DOOR_WALL_IDS.contains(object.getId())
|| !config.highlightSpeartraps() && SPEARTRAP_ID == object.getId()
|| tile.getPlane() != client.getPlane()
|| object.getLocalLocation().distanceTo(playerLocation) >= MAX_DISTANCE)
{
return;
}
Color highlightColor;
if (SPEARTRAP_ID == object.getId())
{
// this varbit is set to 1 when you enter a room and 0 once you get passed the spike traps
if (client.getVar(Varbits.PYRAMID_PLUNDER_ROOM_LOCATION) != 1)
{
return;
}
highlightColor = config.highlightSpeartrapsColor();
}
else
{
ObjectComposition imposter = client.getObjectDefinition(object.getId()).getImpostor();
if (imposter.getId() != TOMB_DOOR_CLOSED_ID)
{
return;
}
highlightColor = config.highlightDoorsColor();
}
Shape objectClickbox = object.getClickbox();
if (objectClickbox != null)
{
if (objectClickbox.contains(mousePosition.getX(), mousePosition.getY()))
{
graphics.setColor(highlightColor.darker());
}
else
{
graphics.setColor(highlightColor);
}
graphics.draw(objectClickbox);
graphics.setColor(new Color(highlightColor.getRed(), highlightColor.getGreen(),
highlightColor.getBlue(), 50));
graphics.fill(objectClickbox);
}
});
return null;
}
}

View File

@@ -0,0 +1,222 @@
/*
* Copyright (c) 2020 Mitchell <https://github.com/Mitchell-Kovacs>
* 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.pyramidplunder;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Provides;
import java.time.Duration;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.inject.Inject;
import lombok.Getter;
import net.runelite.api.Client;
import net.runelite.api.GameObject;
import net.runelite.api.GameState;
import static net.runelite.api.ItemID.PHARAOHS_SCEPTRE;
import static net.runelite.api.NullObjectID.*;
import static net.runelite.api.ObjectID.GRAND_GOLD_CHEST;
import static net.runelite.api.ObjectID.SARCOPHAGUS_21255;
import static net.runelite.api.ObjectID.SPEARTRAP_21280;
import static net.runelite.api.ObjectID.TOMB_DOOR_20948;
import static net.runelite.api.ObjectID.URN_21261;
import static net.runelite.api.ObjectID.URN_21262;
import static net.runelite.api.ObjectID.URN_21263;
import net.runelite.api.Tile;
import net.runelite.api.TileObject;
import net.runelite.api.Varbits;
import net.runelite.api.WallObject;
import net.runelite.api.events.GameObjectSpawned;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.GameTick;
import net.runelite.api.events.WallObjectSpawned;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
import net.runelite.client.util.RSTimeUnit;
@PluginDescriptor(
name = "Pyramid Plunder",
description = "Show custom overlay for Pyramid Plunder",
tags = {"minigame", "thieving", "pp"},
enabledByDefault = false
)
public class PyramidPlunderPlugin extends Plugin
{
// Total time of a pyramid plunder game (5 minutes)
private static final Duration PYRAMID_PLUNDER_DURATION = Duration.of(501, RSTimeUnit.GAME_TICKS);
private static final int PYRAMID_PLUNDER_REGION = 7749;
static final Set<Integer> TOMB_DOOR_WALL_IDS = ImmutableSet.of(NULL_26618, NULL_26619, NULL_26620, NULL_26621);
static final int TOMB_DOOR_CLOSED_ID = TOMB_DOOR_20948;
static final int SPEARTRAP_ID = SPEARTRAP_21280;
static final Set<Integer> URN_IDS = ImmutableSet.of(NULL_26580, NULL_26600, NULL_26601, NULL_26602,
NULL_26603, NULL_26604, NULL_26605, NULL_26606, NULL_26607, NULL_26608, NULL_26609, NULL_26610, NULL_26611,
NULL_26612, NULL_26613);
static final Set<Integer> URN_CLOSED_IDS = ImmutableSet.of(URN_21261, URN_21262, URN_21263);
static final int GRAND_GOLD_CHEST_ID = NULL_26616;
static final int GRAND_GOLD_CHEST_CLOSED_ID = GRAND_GOLD_CHEST;
static final int SARCOPHAGUS_ID = NULL_26626;
static final int SARCOPHAGUS_CLOSED_ID = SARCOPHAGUS_21255;
@Inject
private Client client;
@Inject
private PyramidPlunderConfig config;
@Inject
private OverlayManager overlayManager;
@Inject
private PyramidPlunderOverlay overlay;
@Inject
private InfoBoxManager infoBoxManager;
@Inject
private ItemManager itemManager;
@Inject
private ClientThread clientThread;
@Getter
private final Map<TileObject, Tile> tilesToHighlight = new HashMap<>();
@Getter
private final List<GameObject> objectsToHighlight = new ArrayList<>();
private PyramidPlunderTimer timer;
@Provides
PyramidPlunderConfig getConfig(ConfigManager configManager)
{
return configManager.getConfig(PyramidPlunderConfig.class);
}
@Override
protected void startUp() throws Exception
{
overlayManager.add(overlay);
}
@Override
protected void shutDown() throws Exception
{
tilesToHighlight.clear();
objectsToHighlight.clear();
overlayManager.remove(overlay);
timer = null;
infoBoxManager.removeIf(PyramidPlunderTimer.class::isInstance);
clientThread.invoke(() ->
{
Widget ppWidget = client.getWidget(WidgetInfo.PYRAMID_PLUNDER_DATA);
if (ppWidget != null)
{
ppWidget.setHidden(false);
}
});
}
@Subscribe
public void onGameStateChanged(GameStateChanged event)
{
if (event.getGameState() == GameState.LOADING)
{
tilesToHighlight.clear();
objectsToHighlight.clear();
}
}
@Subscribe
public void onGameTick(GameTick tick)
{
if (isInPyramidPlunder())
{
if (timer == null)
{
int ppTimer = client.getVar(Varbits.PYRAMID_PLUNDER_TIMER);
Duration remaining = PYRAMID_PLUNDER_DURATION.minus(ppTimer, RSTimeUnit.GAME_TICKS);
timer = new PyramidPlunderTimer(remaining, itemManager.getImage(PHARAOHS_SCEPTRE), this,
config, client);
infoBoxManager.addInfoBox(timer);
}
}
else if (timer != null)
{
infoBoxManager.removeInfoBox(timer);
timer = null;
}
}
@Subscribe
public void onWallObjectSpawned(WallObjectSpawned event)
{
WallObject object = event.getWallObject();
if (TOMB_DOOR_WALL_IDS.contains(object.getId()))
{
tilesToHighlight.put(object, event.getTile());
}
}
@Subscribe
public void onGameObjectSpawned(GameObjectSpawned event)
{
GameObject object = event.getGameObject();
if (SPEARTRAP_ID == object.getId())
{
tilesToHighlight.put(object, event.getTile());
}
else if (URN_IDS.contains(object.getId())
|| GRAND_GOLD_CHEST_ID == object.getId()
|| SARCOPHAGUS_ID == object.getId())
{
objectsToHighlight.add(object);
}
}
public boolean isInPyramidPlunder()
{
return client.getLocalPlayer() != null
&& PYRAMID_PLUNDER_REGION == client.getLocalPlayer().getWorldLocation().getRegionID()
&& client.getVar(Varbits.PYRAMID_PLUNDER_TIMER) > 0;
}
}

View File

@@ -0,0 +1,74 @@
/*
* Copyright (c) 2020 Mitchell <https://github.com/Mitchell-Kovacs>
* 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.pyramidplunder;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.time.Duration;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import net.runelite.api.Client;
import net.runelite.api.Varbits;
import net.runelite.client.ui.overlay.infobox.Timer;
class PyramidPlunderTimer extends Timer
{
private final PyramidPlunderConfig config;
private final Client client;
public PyramidPlunderTimer(
Duration duration,
BufferedImage image,
PyramidPlunderPlugin plugin,
PyramidPlunderConfig config,
Client client
)
{
super(duration.toMillis(), ChronoUnit.MILLIS, image, plugin);
this.config = config;
this.client = client;
}
@Override
public Color getTextColor()
{
long secondsLeft = Duration.between(Instant.now(), getEndTime()).getSeconds();
return secondsLeft < config.timerLowWarning() ? Color.RED.brighter() : Color.white;
}
@Override
public String getTooltip()
{
int floor = client.getVar(Varbits.PYRAMID_PLUNDER_ROOM);
int thievingLevel = client.getVar(Varbits.PYRAMID_PLUNDER_THIEVING_LEVEL);
return String.format("Time remaining. Floor: %d. Thieving level: %d", floor, thievingLevel);
}
@Override
public boolean render()
{
return config.showExactTimer();
}
}