Add POH incense burner timers
This commit is contained in:
@@ -182,4 +182,7 @@ public final class AnimationID
|
|||||||
public static final int ROCKSLUG_DEATH = 1568;
|
public static final int ROCKSLUG_DEATH = 1568;
|
||||||
public static final int ZYGOMITE_DEATH = 3327;
|
public static final int ZYGOMITE_DEATH = 3327;
|
||||||
public static final int IMP_DEATH = 172;
|
public static final int IMP_DEATH = 172;
|
||||||
|
|
||||||
|
// POH Animations
|
||||||
|
public static final int INCENSE_BURNER = 3687;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,29 +27,25 @@ package net.runelite.client.plugins.poh;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Polygon;
|
import java.time.Duration;
|
||||||
|
import java.time.Instant;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.Perspective;
|
import net.runelite.api.Perspective;
|
||||||
import net.runelite.api.Point;
|
import net.runelite.api.Point;
|
||||||
import net.runelite.api.TileObject;
|
|
||||||
import static net.runelite.client.plugins.poh.PohPlugin.BURNER_LIT;
|
|
||||||
import static net.runelite.client.plugins.poh.PohPlugin.BURNER_UNLIT;
|
|
||||||
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;
|
||||||
import net.runelite.client.ui.overlay.OverlayUtil;
|
import net.runelite.client.ui.overlay.components.ProgressPieComponent;
|
||||||
import net.runelite.client.ui.overlay.components.TextComponent;
|
|
||||||
|
|
||||||
public class BurnerOverlay extends Overlay
|
class BurnerOverlay extends Overlay
|
||||||
{
|
{
|
||||||
private final Client client;
|
private final Client client;
|
||||||
private final PohConfig config;
|
private final PohConfig config;
|
||||||
private final PohPlugin plugin;
|
private final PohPlugin plugin;
|
||||||
private final TextComponent textComponent = new TextComponent();
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public BurnerOverlay(Client client, PohConfig config, PohPlugin plugin)
|
private BurnerOverlay(Client client, PohConfig config, PohPlugin plugin)
|
||||||
{
|
{
|
||||||
setPosition(OverlayPosition.DYNAMIC);
|
setPosition(OverlayPosition.DYNAMIC);
|
||||||
setLayer(OverlayLayer.ABOVE_SCENE);
|
setLayer(OverlayLayer.ABOVE_SCENE);
|
||||||
@@ -66,42 +62,61 @@ public class BurnerOverlay extends Overlay
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.getPohObjects().forEach((object, tile) ->
|
plugin.getIncenseBurners().forEach((tile, burner) ->
|
||||||
{
|
{
|
||||||
if (tile.getPlane() == client.getPlane())
|
if (tile.getPlane() != client.getPlane())
|
||||||
{
|
{
|
||||||
if (BURNER_UNLIT.contains(object.getId()))
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!PohPlugin.BURNER_LIT.contains(burner.getId()))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Instant now = Instant.now();
|
||||||
|
final long startCountdown = Duration.between(burner.getStart(), now).getSeconds();
|
||||||
|
final double certainSec = burner.getCountdownTimer() - startCountdown;
|
||||||
|
|
||||||
|
long endCountdown = 0;
|
||||||
|
|
||||||
|
if (certainSec <= 0)
|
||||||
|
{
|
||||||
|
if (burner.getEnd() == null)
|
||||||
{
|
{
|
||||||
drawBurner(graphics, "Unlit", object, Color.RED);
|
burner.setEnd(Instant.now());
|
||||||
}
|
|
||||||
else if (BURNER_LIT.contains(object.getId()))
|
|
||||||
{
|
|
||||||
drawBurner(graphics, "Lit", object, Color.GREEN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
endCountdown = Duration.between(burner.getEnd(), now).getSeconds();
|
||||||
|
}
|
||||||
|
|
||||||
|
final double randomSec = burner.getRandomTimer() - endCountdown;
|
||||||
|
final ProgressPieComponent pieComponent = new ProgressPieComponent();
|
||||||
|
final Point loc = Perspective.localToCanvas(client, tile.getLocalLocation(), tile.getPlane());
|
||||||
|
|
||||||
|
if (loc == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pieComponent.setPosition(loc);
|
||||||
|
|
||||||
|
if (certainSec > 0)
|
||||||
|
{
|
||||||
|
pieComponent.setProgress(certainSec / burner.getCountdownTimer());
|
||||||
|
pieComponent.setFill(Color.GREEN);
|
||||||
|
pieComponent.setBorderColor(Color.GREEN);
|
||||||
|
pieComponent.render(graphics);
|
||||||
|
}
|
||||||
|
else if (randomSec > 0)
|
||||||
|
{
|
||||||
|
pieComponent.setProgress(randomSec / burner.getRandomTimer());
|
||||||
|
pieComponent.setFill(Color.ORANGE);
|
||||||
|
pieComponent.setBorderColor(Color.ORANGE);
|
||||||
|
pieComponent.render(graphics);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawBurner(Graphics2D graphics, String text, TileObject tileObject, Color color)
|
|
||||||
{
|
|
||||||
Point canvasText = Perspective.getCanvasTextLocation(client, graphics, tileObject.getLocalLocation(), text, 200);
|
|
||||||
|
|
||||||
if (canvasText == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
textComponent.setText(text);
|
|
||||||
textComponent.setPosition(new java.awt.Point(canvasText.getX(), canvasText.getY()));
|
|
||||||
textComponent.setColor(color);
|
|
||||||
textComponent.render(graphics);
|
|
||||||
|
|
||||||
//render tile
|
|
||||||
Polygon poly = tileObject.getCanvasTilePoly();
|
|
||||||
if (poly != null)
|
|
||||||
{
|
|
||||||
OverlayUtil.renderPolygon(graphics, poly, color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018, Tomas Slusny <slusnucky@gmail.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.poh;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
class IncenseBurner
|
||||||
|
{
|
||||||
|
private final Instant start = Instant.now();
|
||||||
|
private final int id;
|
||||||
|
private double countdownTimer;
|
||||||
|
private double randomTimer;
|
||||||
|
private Instant end;
|
||||||
|
}
|
||||||
@@ -93,12 +93,12 @@ public interface PohConfig extends Config
|
|||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
keyName = "showBurner",
|
keyName = "showBurner",
|
||||||
name = "Show Unlit/Lit burner",
|
name = "Show Incense Burner timers",
|
||||||
description = "Configures whether or not unlit/lit burners are displayed"
|
description = "Configures whether or not unlit/lit burners are displayed"
|
||||||
)
|
)
|
||||||
default boolean showBurner()
|
default boolean showBurner()
|
||||||
{
|
{
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfigItem(
|
@ConfigItem(
|
||||||
|
|||||||
@@ -27,23 +27,28 @@ package net.runelite.client.plugins.poh;
|
|||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.runelite.api.Actor;
|
||||||
|
import net.runelite.api.AnimationID;
|
||||||
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.DecorativeObject;
|
import net.runelite.api.DecorativeObject;
|
||||||
import net.runelite.api.GameObject;
|
import net.runelite.api.GameObject;
|
||||||
import net.runelite.api.GameState;
|
import net.runelite.api.GameState;
|
||||||
import static net.runelite.api.ObjectID.INCENSE_BURNER;
|
import net.runelite.api.ObjectID;
|
||||||
import static net.runelite.api.ObjectID.INCENSE_BURNER_13209;
|
import net.runelite.api.Player;
|
||||||
import static net.runelite.api.ObjectID.INCENSE_BURNER_13210;
|
|
||||||
import static net.runelite.api.ObjectID.INCENSE_BURNER_13211;
|
|
||||||
import static net.runelite.api.ObjectID.INCENSE_BURNER_13212;
|
|
||||||
import static net.runelite.api.ObjectID.INCENSE_BURNER_13213;
|
|
||||||
import net.runelite.api.Tile;
|
import net.runelite.api.Tile;
|
||||||
import net.runelite.api.TileObject;
|
import net.runelite.api.TileObject;
|
||||||
|
import net.runelite.api.coords.LocalPoint;
|
||||||
|
import net.runelite.api.events.AnimationChanged;
|
||||||
import net.runelite.api.events.ConfigChanged;
|
import net.runelite.api.events.ConfigChanged;
|
||||||
import net.runelite.api.events.DecorativeObjectDespawned;
|
import net.runelite.api.events.DecorativeObjectDespawned;
|
||||||
import net.runelite.api.events.DecorativeObjectSpawned;
|
import net.runelite.api.events.DecorativeObjectSpawned;
|
||||||
@@ -51,29 +56,47 @@ import net.runelite.api.events.GameObjectDespawned;
|
|||||||
import net.runelite.api.events.GameObjectSpawned;
|
import net.runelite.api.events.GameObjectSpawned;
|
||||||
import net.runelite.api.events.GameStateChanged;
|
import net.runelite.api.events.GameStateChanged;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
|
import net.runelite.client.game.HiscoreManager;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
import net.runelite.client.ui.overlay.OverlayManager;
|
import net.runelite.client.ui.overlay.OverlayManager;
|
||||||
|
import net.runelite.http.api.hiscore.HiscoreEndpoint;
|
||||||
|
import net.runelite.http.api.hiscore.HiscoreResult;
|
||||||
|
import net.runelite.http.api.hiscore.Skill;
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Player-owned House",
|
name = "Player-owned House",
|
||||||
description = "Show minimap icons and mark unlit/lit burners",
|
description = "Show minimap icons and mark unlit/lit burners",
|
||||||
tags = {"construction", "poh", "minimap", "overlay"}
|
tags = {"construction", "poh", "minimap", "overlay"}
|
||||||
)
|
)
|
||||||
|
@Slf4j
|
||||||
public class PohPlugin extends Plugin
|
public class PohPlugin extends Plugin
|
||||||
{
|
{
|
||||||
static final Set<Integer> BURNER_UNLIT = Sets.newHashSet(INCENSE_BURNER, INCENSE_BURNER_13210, INCENSE_BURNER_13212);
|
static final Set<Integer> BURNER_UNLIT = Sets.newHashSet(ObjectID.INCENSE_BURNER, ObjectID.INCENSE_BURNER_13210, ObjectID.INCENSE_BURNER_13212);
|
||||||
static final Set<Integer> BURNER_LIT = Sets.newHashSet(INCENSE_BURNER_13209, INCENSE_BURNER_13211, INCENSE_BURNER_13213);
|
static final Set<Integer> BURNER_LIT = Sets.newHashSet(ObjectID.INCENSE_BURNER_13209, ObjectID.INCENSE_BURNER_13211, ObjectID.INCENSE_BURNER_13213);
|
||||||
|
private static final double ESTIMATED_TICK_LENGTH = 0.6;
|
||||||
|
|
||||||
@Getter(AccessLevel.PACKAGE)
|
@Getter(AccessLevel.PACKAGE)
|
||||||
private final Map<TileObject, Tile> pohObjects = new HashMap<>();
|
private final Map<TileObject, Tile> pohObjects = new HashMap<>();
|
||||||
|
|
||||||
|
@Getter(AccessLevel.PACKAGE)
|
||||||
|
private final Map<Tile, IncenseBurner> incenseBurners = new HashMap<>();
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private OverlayManager overlayManager;
|
private OverlayManager overlayManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private PohOverlay overlay;
|
private PohOverlay overlay;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Client client;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ScheduledExecutorService executor;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private HiscoreManager hiscoreManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private BurnerOverlay burnerOverlay;
|
private BurnerOverlay burnerOverlay;
|
||||||
|
|
||||||
@@ -97,6 +120,7 @@ public class PohPlugin extends Plugin
|
|||||||
overlayManager.remove(overlay);
|
overlayManager.remove(overlay);
|
||||||
overlayManager.remove(burnerOverlay);
|
overlayManager.remove(burnerOverlay);
|
||||||
pohObjects.clear();
|
pohObjects.clear();
|
||||||
|
incenseBurners.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@@ -108,11 +132,21 @@ public class PohPlugin extends Plugin
|
|||||||
@Subscribe
|
@Subscribe
|
||||||
public void onGameObjectSpawned(GameObjectSpawned event)
|
public void onGameObjectSpawned(GameObjectSpawned event)
|
||||||
{
|
{
|
||||||
GameObject gameObject = event.getGameObject();
|
final GameObject gameObject = event.getGameObject();
|
||||||
if (BURNER_LIT.contains(gameObject.getId()) || BURNER_UNLIT.contains(gameObject.getId()) || PohIcons.getIcon(gameObject.getId()) != null)
|
|
||||||
|
if (!BURNER_LIT.contains(gameObject.getId()) && !BURNER_UNLIT.contains(gameObject.getId()))
|
||||||
{
|
{
|
||||||
pohObjects.put(gameObject, event.getTile());
|
if (PohIcons.getIcon(gameObject.getId()) != null)
|
||||||
|
{
|
||||||
|
pohObjects.put(gameObject, event.getTile());
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final double countdownTimer = 130.0; // Minimum amount of seconds a burner will light
|
||||||
|
final double randomTimer = 30.0; // Minimum amount of seconds a burner will light
|
||||||
|
incenseBurners.put(event.getTile(), new IncenseBurner(gameObject.getId(), countdownTimer, randomTimer, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@@ -145,6 +179,71 @@ public class PohPlugin extends Plugin
|
|||||||
if (event.getGameState() == GameState.LOADING)
|
if (event.getGameState() == GameState.LOADING)
|
||||||
{
|
{
|
||||||
pohObjects.clear();
|
pohObjects.clear();
|
||||||
|
incenseBurners.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Subscribe
|
||||||
|
public void onAnimationChanged(AnimationChanged event)
|
||||||
|
{
|
||||||
|
final Actor actor = event.getActor();
|
||||||
|
final String actorName = actor.getName();
|
||||||
|
|
||||||
|
if (!(actor instanceof Player) || actor.getAnimation() != AnimationID.INCENSE_BURNER)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final LocalPoint loc = actor.getLocalLocation();
|
||||||
|
|
||||||
|
// Find burner closest to player
|
||||||
|
incenseBurners.keySet()
|
||||||
|
.stream()
|
||||||
|
.min(Comparator.comparingInt(a -> loc.distanceTo(a.getLocalLocation())))
|
||||||
|
.ifPresent(tile ->
|
||||||
|
{
|
||||||
|
final IncenseBurner incenseBurner = incenseBurners.get(tile);
|
||||||
|
|
||||||
|
if (actor == client.getLocalPlayer())
|
||||||
|
{
|
||||||
|
int level = client.getRealSkillLevel(net.runelite.api.Skill.FIREMAKING);
|
||||||
|
updateBurner(incenseBurner, level);
|
||||||
|
}
|
||||||
|
else if (actorName != null)
|
||||||
|
{
|
||||||
|
lookupPlayer(actorName, incenseBurner);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void lookupPlayer(String playerName, IncenseBurner incenseBurner)
|
||||||
|
{
|
||||||
|
executor.execute(() ->
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final HiscoreResult playerStats = hiscoreManager.lookup(playerName, HiscoreEndpoint.NORMAL);
|
||||||
|
|
||||||
|
if (playerStats == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Skill fm = playerStats.getFiremaking();
|
||||||
|
final int level = fm.getLevel();
|
||||||
|
updateBurner(incenseBurner, Math.max(level, 1));
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
log.warn("Error fetching Hiscore data " + e.getMessage());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void updateBurner(IncenseBurner incenseBurner, int fmLevel)
|
||||||
|
{
|
||||||
|
incenseBurner.setCountdownTimer((200 + fmLevel) * ESTIMATED_TICK_LENGTH);
|
||||||
|
incenseBurner.setRandomTimer(fmLevel * ESTIMATED_TICK_LENGTH);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user