Merge pull request #449 from Lucwousin/lol_my_pp_feels_strange

Fix pp plugin (lol pp)
This commit is contained in:
Ganom
2019-05-30 15:06:15 -04:00
committed by GitHub
4 changed files with 92 additions and 80 deletions

View File

@@ -330,7 +330,7 @@ public enum Varbits
* Pyramid plunder * Pyramid plunder
*/ */
PYRAMID_PLUNDER_TIMER(2375), PYRAMID_PLUNDER_TIMER(2375),
PYRAMID_PLUNDER_ROOM(2377), PYRAMID_PLUNDER_ROOM(2374),
/** /**
* Barrows * Barrows

View File

@@ -1,40 +0,0 @@
/*
* Copyright (c) 2018, Steffen Hauge <steffen.oerum.hauge@hotmail.com>
* 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<Integer> WALL_OBSTACLE_IDS = ImmutableSet.of(
26618, 26619, 26620, 26621
);
static final Set<Integer> TRAP_OBSTACLE_IDS = ImmutableSet.of(
SPEARTRAP_21280
);
}

View File

@@ -28,14 +28,17 @@ import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.awt.geom.Area; import java.awt.geom.Area;
import java.util.Map;
import javax.inject.Inject; import javax.inject.Inject;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.ObjectComposition; 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.Point;
import net.runelite.api.Tile;
import net.runelite.api.TileObject;
import net.runelite.api.coords.LocalPoint; 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.Overlay;
import net.runelite.client.ui.overlay.OverlayLayer; import net.runelite.client.ui.overlay.OverlayLayer;
import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayPosition;
@@ -48,14 +51,12 @@ public class PyramidPlunderOverlay extends Overlay
private final Client client; private final Client client;
private final PyramidPlunderPlugin plugin; private final PyramidPlunderPlugin plugin;
private final PyramidPlunderConfig config;
@Inject @Inject
private PyramidPlunderOverlay(Client client, PyramidPlunderPlugin plugin, PyramidPlunderConfig config) private PyramidPlunderOverlay(Client client, PyramidPlunderPlugin plugin)
{ {
this.client = client; this.client = client;
this.plugin = plugin; this.plugin = plugin;
this.config = config;
setPosition(OverlayPosition.DYNAMIC); setPosition(OverlayPosition.DYNAMIC);
setLayer(OverlayLayer.ABOVE_SCENE); setLayer(OverlayLayer.ABOVE_SCENE);
} }
@@ -71,19 +72,16 @@ public class PyramidPlunderOverlay extends Overlay
LocalPoint playerLocation = client.getLocalPlayer().getLocalLocation(); LocalPoint playerLocation = client.getLocalPlayer().getLocalLocation();
Point mousePosition = client.getMouseCanvasPosition(); Point mousePosition = client.getMouseCanvasPosition();
plugin.getObstacles().forEach((object, tile) -> for (Map.Entry<TileObject, Tile> entry : plugin.getHighlighted().entrySet())
{ {
if (Obstacles.WALL_OBSTACLE_IDS.contains(object.getId()) && !config.highlightDoors() || TileObject object = entry.getKey();
Obstacles.TRAP_OBSTACLE_IDS.contains(object.getId()) && !config.highlightSpearTrap()) Tile tile = entry.getValue();
{
return;
}
if (tile.getPlane() == client.getPlane() && if (tile.getPlane() == client.getPlane() &&
object.getLocalLocation().distanceTo(playerLocation) < MAX_DISTANCE) object.getLocalLocation().distanceTo(playerLocation) < MAX_DISTANCE)
{ {
int objectID = object.getId(); int objectID = object.getId();
if (Obstacles.WALL_OBSTACLE_IDS.contains(object.getId())) if (object.getId() == CLOSED_DOOR || object.getId() == OPENED_DOOR)
{ {
//Impostor //Impostor
ObjectComposition comp = client.getObjectDefinition(objectID); ObjectComposition comp = client.getObjectDefinition(objectID);
@@ -91,7 +89,7 @@ public class PyramidPlunderOverlay extends Overlay
if (impostor == null) if (impostor == null)
{ {
return; continue;
} }
objectID = impostor.getId(); objectID = impostor.getId();
} }
@@ -102,11 +100,11 @@ public class PyramidPlunderOverlay extends Overlay
Color configColor = Color.GREEN; Color configColor = Color.GREEN;
switch (objectID) switch (objectID)
{ {
case SPEARTRAP_21280: case TRAP:
configColor = COLOR_SPEAR_TRAP; configColor = COLOR_SPEAR_TRAP;
break; break;
case TOMB_DOOR_20948: case OPENED_DOOR: // Does this need a overlay?
case TOMB_DOOR_20949: case CLOSED_DOOR:
configColor = COLOR_DOOR; configColor = COLOR_DOOR;
break; break;
} }
@@ -125,7 +123,7 @@ public class PyramidPlunderOverlay extends Overlay
graphics.fill(objectClickbox); graphics.fill(objectClickbox);
} }
} }
}); }
return null; return null;
} }

View File

@@ -1,5 +1,6 @@
/* /*
* Copyright (c) 2018, Steffen Hauge <steffen.oerum.hauge@hotmail.com> * Copyright (c) 2018, Steffen Hauge <steffen.oerum.hauge@hotmail.com>
* Copyright (c) 2019, Lucas <https://github.com/Lucwousin>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -24,15 +25,30 @@
*/ */
package net.runelite.client.plugins.pyramidplunder; package net.runelite.client.plugins.pyramidplunder;
import com.google.common.eventbus.Subscribe; import com.google.common.collect.ImmutableSet;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set;
import javax.inject.Inject; import javax.inject.Inject;
import lombok.Getter; import lombok.Getter;
import net.runelite.api.Client; 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.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.Player;
import net.runelite.api.Tile; import net.runelite.api.Tile;
import net.runelite.api.TileObject; 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.WallObjectDespawned;
import net.runelite.api.events.WallObjectSpawned; import net.runelite.api.events.WallObjectSpawned;
import net.runelite.client.config.ConfigManager; import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.ItemManager; import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginDescriptor;
@@ -65,12 +82,33 @@ import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
public class PyramidPlunderPlugin extends Plugin public class PyramidPlunderPlugin extends Plugin
{ {
private static final int PYRAMIND_PLUNDER_REGION_ID = 7749; private static final int PYRAMID_PLUNDER_REGION_ID = 7749;
private static final int PYRAMIND_PLUNDER_TIMER_MAX = 500; private static final int PYRAMID_PLUNDER_TIMER_MAX = 500;
private static final double GAMETICK_SECOND = 0.6; 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<Integer> LOOTABLE = ImmutableSet.of(
GRAND_GOLD_CHEST,
SARCOPHAGUS_21255,
URN_21261,
URN_21262,
URN_21263
);
private static final Set<Integer> LOOTED = ImmutableSet.of(
OPENED_GOLD_CHEST,
SARCOPHAGUS_21256,
URN_21265,
URN_21266,
URN_21267
);
private static final Set<Integer> DOOR_WALL_IDS = ImmutableSet.of(
26618, 26619, 26620, 26621
);
@Getter @Getter
private final Map<TileObject, Tile> obstacles = new HashMap<>(); private final Map<TileObject, Tile> highlighted = new HashMap<>();
@Inject @Inject
private Client client; private Client client;
@@ -93,7 +131,7 @@ public class PyramidPlunderPlugin extends Plugin
@Getter @Getter
private boolean isInGame; private boolean isInGame;
private int pyramidTimer = 0; private int pyramidTimer;
@Provides @Provides
PyramidPlunderConfig getConfig(ConfigManager configManager) PyramidPlunderConfig getConfig(ConfigManager configManager)
@@ -104,20 +142,24 @@ public class PyramidPlunderPlugin extends Plugin
@Override @Override
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
overlayManager.add(pyramidPlunderOverlay);
} }
@Override @Override
protected void shutDown() throws Exception protected void shutDown() throws Exception
{ {
overlayManager.remove(pyramidPlunderOverlay); overlayManager.remove(pyramidPlunderOverlay);
obstacles.clear(); highlighted.clear();
reset(); reset();
} }
@Subscribe @Subscribe
public void onConfigChanged(ConfigChanged event) public void onConfigChanged(ConfigChanged event)
{ {
if (!"pyramidplunder".equals(event.getGroup()))
{
return;
}
if (!config.showTimer()) if (!config.showTimer())
{ {
removeTimer(); removeTimer();
@@ -125,12 +167,11 @@ public class PyramidPlunderPlugin extends Plugin
if (config.showTimer() && isInGame) if (config.showTimer() && isInGame)
{ {
int remainingTime = PYRAMIND_PLUNDER_TIMER_MAX - pyramidTimer; int remainingTime = GAME_TICK_LENGTH * (PYRAMID_PLUNDER_TIMER_MAX - pyramidTimer);
if (remainingTime >= 2) if (remainingTime >= 2)
{ {
double timeInSeconds = remainingTime * GAMETICK_SECOND; showTimer(remainingTime, ChronoUnit.MILLIS);
showTimer((int) timeInSeconds, ChronoUnit.SECONDS);
} }
} }
} }
@@ -148,11 +189,19 @@ public class PyramidPlunderPlugin extends Plugin
private void showTimer(int period, ChronoUnit chronoUnit) private void showTimer(int period, ChronoUnit chronoUnit)
{ {
removeTimer(); removeTimer();
infoBoxManager.addInfoBox(new PyramidPlunderTimer(this, itemManager.getImage(PHARAOHS_SCEPTRE), period, chronoUnit));
infoBoxManager.addInfoBox(
new PyramidPlunderTimer(
this,
itemManager.getImage(PHARAOHS_SCEPTRE),
period,
chronoUnit
)
);
} }
@Subscribe @Subscribe
public void onGameStateChange(GameStateChanged event) public void onGameStateChanged(GameStateChanged event)
{ {
switch (event.getGameState()) switch (event.getGameState())
{ {
@@ -161,7 +210,7 @@ public class PyramidPlunderPlugin extends Plugin
reset(); reset();
break; break;
case LOADING: case LOADING:
obstacles.clear(); highlighted.clear();
break; break;
case LOGGED_IN: case LOGGED_IN:
if (!isInRegion()) if (!isInRegion())
@@ -181,7 +230,7 @@ public class PyramidPlunderPlugin extends Plugin
} }
WorldPoint location = local.getWorldLocation(); 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) if (pyramidTimer == 0)
{ {
reset(); reset();
return;
} }
if (pyramidTimer == 1) if (pyramidTimer == 1)
{ {
overlayManager.add(pyramidPlunderOverlay);
isInGame = true; isInGame = true;
if (config.showTimer()) if (config.showTimer())
{ {
@@ -213,6 +265,7 @@ public class PyramidPlunderPlugin extends Plugin
private void reset() private void reset()
{ {
isInGame = false; isInGame = false;
overlayManager.remove(pyramidPlunderOverlay);
removeTimer(); removeTimer();
} }
@@ -229,7 +282,7 @@ public class PyramidPlunderPlugin extends Plugin
} }
@Subscribe @Subscribe
public void onGameObjectDeSpawned(GameObjectDespawned event) public void onGameObjectDespawned(GameObjectDespawned event)
{ {
onTileObject(event.getTile(), event.getGameObject(), null); onTileObject(event.getTile(), event.getGameObject(), null);
} }
@@ -247,24 +300,25 @@ public class PyramidPlunderPlugin extends Plugin
} }
@Subscribe @Subscribe
public void onWallObjectDeSpawned(WallObjectDespawned event) public void onWallObjectDespawned(WallObjectDespawned event)
{ {
onTileObject(event.getTile(), event.getWallObject(), null); onTileObject(event.getTile(), event.getWallObject(), null);
} }
private void onTileObject(Tile tile, TileObject oldObject, TileObject newObject) private void onTileObject(Tile tile, TileObject oldObject, TileObject newObject)
{ {
obstacles.remove(oldObject); highlighted.remove(oldObject);
if (newObject == null) if (newObject == null)
{ {
return; return;
} }
if (Obstacles.WALL_OBSTACLE_IDS.contains(newObject.getId()) || int id = newObject.getId();
Obstacles.TRAP_OBSTACLE_IDS.contains(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);
} }
} }
} }