From 8d6eecd2fec6386d44c653572059bf1046d50168 Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 30 May 2019 20:57:21 +0200 Subject: [PATCH] Fix pp plugin (lol pp) --- .../main/java/net/runelite/api/Varbits.java | 2 +- .../plugins/pyramidplunder/Obstacles.java | 40 -------- .../pyramidplunder/PyramidPlunderOverlay.java | 34 ++++--- .../pyramidplunder/PyramidPlunderPlugin.java | 96 +++++++++++++++---- 4 files changed, 92 insertions(+), 80 deletions(-) delete mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/pyramidplunder/Obstacles.java diff --git a/runelite-api/src/main/java/net/runelite/api/Varbits.java b/runelite-api/src/main/java/net/runelite/api/Varbits.java index c952e83609..ec3d36114b 100644 --- a/runelite-api/src/main/java/net/runelite/api/Varbits.java +++ b/runelite-api/src/main/java/net/runelite/api/Varbits.java @@ -330,7 +330,7 @@ public enum Varbits * Pyramid plunder */ PYRAMID_PLUNDER_TIMER(2375), - PYRAMID_PLUNDER_ROOM(2377), + PYRAMID_PLUNDER_ROOM(2374), /** * Barrows diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/pyramidplunder/Obstacles.java b/runelite-client/src/main/java/net/runelite/client/plugins/pyramidplunder/Obstacles.java deleted file mode 100644 index fff21802f0..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/plugins/pyramidplunder/Obstacles.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2018, Steffen Hauge - * 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 java.util.Set; -import static net.runelite.api.ObjectID.SPEARTRAP_21280; - -public class Obstacles -{ - static final Set WALL_OBSTACLE_IDS = ImmutableSet.of( - 26618, 26619, 26620, 26621 - ); - - static final Set TRAP_OBSTACLE_IDS = ImmutableSet.of( - SPEARTRAP_21280 - ); -} \ No newline at end of file diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/pyramidplunder/PyramidPlunderOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/pyramidplunder/PyramidPlunderOverlay.java index 7607a8022f..4881d47f96 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/pyramidplunder/PyramidPlunderOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/pyramidplunder/PyramidPlunderOverlay.java @@ -28,14 +28,17 @@ import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.geom.Area; +import java.util.Map; import javax.inject.Inject; import net.runelite.api.Client; import net.runelite.api.ObjectComposition; -import static net.runelite.api.ObjectID.SPEARTRAP_21280; -import static net.runelite.api.ObjectID.TOMB_DOOR_20948; -import static net.runelite.api.ObjectID.TOMB_DOOR_20949; import net.runelite.api.Point; +import net.runelite.api.Tile; +import net.runelite.api.TileObject; import net.runelite.api.coords.LocalPoint; +import static net.runelite.client.plugins.pyramidplunder.PyramidPlunderPlugin.CLOSED_DOOR; +import static net.runelite.client.plugins.pyramidplunder.PyramidPlunderPlugin.OPENED_DOOR; +import static net.runelite.client.plugins.pyramidplunder.PyramidPlunderPlugin.TRAP; import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.OverlayLayer; import net.runelite.client.ui.overlay.OverlayPosition; @@ -48,14 +51,12 @@ public class PyramidPlunderOverlay extends Overlay private final Client client; private final PyramidPlunderPlugin plugin; - private final PyramidPlunderConfig config; @Inject - private PyramidPlunderOverlay(Client client, PyramidPlunderPlugin plugin, PyramidPlunderConfig config) + private PyramidPlunderOverlay(Client client, PyramidPlunderPlugin plugin) { this.client = client; this.plugin = plugin; - this.config = config; setPosition(OverlayPosition.DYNAMIC); setLayer(OverlayLayer.ABOVE_SCENE); } @@ -71,19 +72,16 @@ public class PyramidPlunderOverlay extends Overlay LocalPoint playerLocation = client.getLocalPlayer().getLocalLocation(); Point mousePosition = client.getMouseCanvasPosition(); - plugin.getObstacles().forEach((object, tile) -> + for (Map.Entry entry : plugin.getHighlighted().entrySet()) { - if (Obstacles.WALL_OBSTACLE_IDS.contains(object.getId()) && !config.highlightDoors() || - Obstacles.TRAP_OBSTACLE_IDS.contains(object.getId()) && !config.highlightSpearTrap()) - { - return; - } + TileObject object = entry.getKey(); + Tile tile = entry.getValue(); if (tile.getPlane() == client.getPlane() && object.getLocalLocation().distanceTo(playerLocation) < MAX_DISTANCE) { int objectID = object.getId(); - if (Obstacles.WALL_OBSTACLE_IDS.contains(object.getId())) + if (object.getId() == CLOSED_DOOR || object.getId() == OPENED_DOOR) { //Impostor ObjectComposition comp = client.getObjectDefinition(objectID); @@ -91,7 +89,7 @@ public class PyramidPlunderOverlay extends Overlay if (impostor == null) { - return; + continue; } objectID = impostor.getId(); } @@ -102,11 +100,11 @@ public class PyramidPlunderOverlay extends Overlay Color configColor = Color.GREEN; switch (objectID) { - case SPEARTRAP_21280: + case TRAP: configColor = COLOR_SPEAR_TRAP; break; - case TOMB_DOOR_20948: - case TOMB_DOOR_20949: + case OPENED_DOOR: // Does this need a overlay? + case CLOSED_DOOR: configColor = COLOR_DOOR; break; } @@ -125,7 +123,7 @@ public class PyramidPlunderOverlay extends Overlay graphics.fill(objectClickbox); } } - }); + } return null; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/pyramidplunder/PyramidPlunderPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/pyramidplunder/PyramidPlunderPlugin.java index afd2464204..129d8c926a 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/pyramidplunder/PyramidPlunderPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/pyramidplunder/PyramidPlunderPlugin.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018, Steffen Hauge + * Copyright (c) 2019, Lucas * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -24,15 +25,30 @@ */ package net.runelite.client.plugins.pyramidplunder; -import com.google.common.eventbus.Subscribe; +import com.google.common.collect.ImmutableSet; import com.google.inject.Provides; import java.time.temporal.ChronoUnit; import java.util.HashMap; import java.util.Map; +import java.util.Set; import javax.inject.Inject; import lombok.Getter; import net.runelite.api.Client; +import static net.runelite.api.Constants.GAME_TICK_LENGTH; import static net.runelite.api.ItemID.PHARAOHS_SCEPTRE; +import static net.runelite.api.ObjectID.GRAND_GOLD_CHEST; +import static net.runelite.api.ObjectID.OPENED_GOLD_CHEST; +import static net.runelite.api.ObjectID.SARCOPHAGUS_21255; +import static net.runelite.api.ObjectID.SARCOPHAGUS_21256; +import static net.runelite.api.ObjectID.SPEARTRAP_21280; +import static net.runelite.api.ObjectID.TOMB_DOOR_20948; +import static net.runelite.api.ObjectID.TOMB_DOOR_20949; +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 static net.runelite.api.ObjectID.URN_21265; +import static net.runelite.api.ObjectID.URN_21266; +import static net.runelite.api.ObjectID.URN_21267; import net.runelite.api.Player; import net.runelite.api.Tile; import net.runelite.api.TileObject; @@ -48,6 +64,7 @@ import net.runelite.api.events.WallObjectChanged; import net.runelite.api.events.WallObjectDespawned; import net.runelite.api.events.WallObjectSpawned; 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; @@ -65,12 +82,33 @@ import net.runelite.client.ui.overlay.infobox.InfoBoxManager; public class PyramidPlunderPlugin extends Plugin { - private static final int PYRAMIND_PLUNDER_REGION_ID = 7749; - private static final int PYRAMIND_PLUNDER_TIMER_MAX = 500; - private static final double GAMETICK_SECOND = 0.6; + private static final int PYRAMID_PLUNDER_REGION_ID = 7749; + private static final int PYRAMID_PLUNDER_TIMER_MAX = 500; + static final int TRAP = SPEARTRAP_21280; + static final int CLOSED_DOOR = TOMB_DOOR_20948; + static final int OPENED_DOOR = TOMB_DOOR_20949; + + // Next 2 are in here for anyone who wants to spend more time on this + private static final Set LOOTABLE = ImmutableSet.of( + GRAND_GOLD_CHEST, + SARCOPHAGUS_21255, + URN_21261, + URN_21262, + URN_21263 + ); + private static final Set LOOTED = ImmutableSet.of( + OPENED_GOLD_CHEST, + SARCOPHAGUS_21256, + URN_21265, + URN_21266, + URN_21267 + ); + private static final Set DOOR_WALL_IDS = ImmutableSet.of( + 26618, 26619, 26620, 26621 + ); @Getter - private final Map obstacles = new HashMap<>(); + private final Map highlighted = new HashMap<>(); @Inject private Client client; @@ -93,7 +131,7 @@ public class PyramidPlunderPlugin extends Plugin @Getter private boolean isInGame; - private int pyramidTimer = 0; + private int pyramidTimer; @Provides PyramidPlunderConfig getConfig(ConfigManager configManager) @@ -104,20 +142,24 @@ public class PyramidPlunderPlugin extends Plugin @Override protected void startUp() throws Exception { - overlayManager.add(pyramidPlunderOverlay); } @Override protected void shutDown() throws Exception { overlayManager.remove(pyramidPlunderOverlay); - obstacles.clear(); + highlighted.clear(); reset(); } @Subscribe public void onConfigChanged(ConfigChanged event) { + if (!"pyramidplunder".equals(event.getGroup())) + { + return; + } + if (!config.showTimer()) { removeTimer(); @@ -125,12 +167,11 @@ public class PyramidPlunderPlugin extends Plugin if (config.showTimer() && isInGame) { - int remainingTime = PYRAMIND_PLUNDER_TIMER_MAX - pyramidTimer; + int remainingTime = GAME_TICK_LENGTH * (PYRAMID_PLUNDER_TIMER_MAX - pyramidTimer); if (remainingTime >= 2) { - double timeInSeconds = remainingTime * GAMETICK_SECOND; - showTimer((int) timeInSeconds, ChronoUnit.SECONDS); + showTimer(remainingTime, ChronoUnit.MILLIS); } } } @@ -148,11 +189,19 @@ public class PyramidPlunderPlugin extends Plugin private void showTimer(int period, ChronoUnit chronoUnit) { removeTimer(); - infoBoxManager.addInfoBox(new PyramidPlunderTimer(this, itemManager.getImage(PHARAOHS_SCEPTRE), period, chronoUnit)); + + infoBoxManager.addInfoBox( + new PyramidPlunderTimer( + this, + itemManager.getImage(PHARAOHS_SCEPTRE), + period, + chronoUnit + ) + ); } @Subscribe - public void onGameStateChange(GameStateChanged event) + public void onGameStateChanged(GameStateChanged event) { switch (event.getGameState()) { @@ -161,7 +210,7 @@ public class PyramidPlunderPlugin extends Plugin reset(); break; case LOADING: - obstacles.clear(); + highlighted.clear(); break; case LOGGED_IN: if (!isInRegion()) @@ -181,7 +230,7 @@ public class PyramidPlunderPlugin extends Plugin } WorldPoint location = local.getWorldLocation(); - return location.getRegionID() == PYRAMIND_PLUNDER_REGION_ID; + return location.getRegionID() == PYRAMID_PLUNDER_REGION_ID; } @@ -199,9 +248,12 @@ public class PyramidPlunderPlugin extends Plugin if (pyramidTimer == 0) { reset(); + return; } + if (pyramidTimer == 1) { + overlayManager.add(pyramidPlunderOverlay); isInGame = true; if (config.showTimer()) { @@ -213,6 +265,7 @@ public class PyramidPlunderPlugin extends Plugin private void reset() { isInGame = false; + overlayManager.remove(pyramidPlunderOverlay); removeTimer(); } @@ -229,7 +282,7 @@ public class PyramidPlunderPlugin extends Plugin } @Subscribe - public void onGameObjectDeSpawned(GameObjectDespawned event) + public void onGameObjectDespawned(GameObjectDespawned event) { onTileObject(event.getTile(), event.getGameObject(), null); } @@ -247,24 +300,25 @@ public class PyramidPlunderPlugin extends Plugin } @Subscribe - public void onWallObjectDeSpawned(WallObjectDespawned event) + public void onWallObjectDespawned(WallObjectDespawned event) { onTileObject(event.getTile(), event.getWallObject(), null); } private void onTileObject(Tile tile, TileObject oldObject, TileObject newObject) { - obstacles.remove(oldObject); + highlighted.remove(oldObject); if (newObject == null) { return; } - if (Obstacles.WALL_OBSTACLE_IDS.contains(newObject.getId()) || - Obstacles.TRAP_OBSTACLE_IDS.contains(newObject.getId())) + int id = newObject.getId(); + if (id == TRAP && config.highlightSpearTrap() || + (DOOR_WALL_IDS.contains(id) || id == OPENED_DOOR || id == CLOSED_DOOR) && config.highlightDoors()) { - obstacles.put(newObject, tile); + highlighted.put(newObject, tile); } } }