From 993716e11aeeee9eb9bf1e3c554281bc300b4976 Mon Sep 17 00:00:00 2001 From: Quasindro Date: Wed, 17 Jul 2019 01:04:27 +0200 Subject: [PATCH] nmz: Add total and per hour points to NMZ overlay --- .../nightmarezone/NightmareZoneOverlay.java | 14 +++++- .../nightmarezone/NightmareZonePlugin.java | 48 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZoneOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZoneOverlay.java index 71ae196d3e..d732d14d3b 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZoneOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZoneOverlay.java @@ -30,6 +30,7 @@ import javax.inject.Inject; import net.runelite.api.Client; import net.runelite.api.ItemID; import static net.runelite.api.MenuAction.RUNELITE_OVERLAY_CONFIG; +import net.runelite.api.VarPlayer; import net.runelite.api.Varbits; import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.WidgetInfo; @@ -101,10 +102,21 @@ class NightmareZoneOverlay extends Overlay renderAbsorptionCounter(); + final int currentPoints = client.getVar(Varbits.NMZ_POINTS); + final int totalPoints = currentPoints + client.getVar(VarPlayer.NMZ_REWARD_POINTS); + panelComponent.getChildren().clear(); panelComponent.getChildren().add(LineComponent.builder() .left("Points: ") - .right(StackFormatter.formatNumber(client.getVar(Varbits.NMZ_POINTS))) + .right(StackFormatter.formatNumber(currentPoints)) + .build()); + panelComponent.getChildren().add(LineComponent.builder() + .left("Points/Hour: ") + .right(StackFormatter.formatNumber(plugin.getPointsPerHour())) + .build()); + panelComponent.getChildren().add(LineComponent.builder() + .left("Total: ") + .right(StackFormatter.formatNumber(totalPoints)) .build()); return panelComponent.render(graphics); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZonePlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZonePlugin.java index d5b91a94cd..2f75094c7c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZonePlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/nightmarezone/NightmareZonePlugin.java @@ -25,8 +25,11 @@ package net.runelite.client.plugins.nightmarezone; import com.google.inject.Provides; +import java.time.Duration; +import java.time.Instant; import java.util.Arrays; import javax.inject.Inject; +import lombok.Getter; import net.runelite.api.ChatMessageType; import net.runelite.api.Client; import net.runelite.api.Varbits; @@ -51,6 +54,7 @@ import net.runelite.client.util.Text; public class NightmareZonePlugin extends Plugin { private static final int[] NMZ_MAP_REGION = {9033}; + private static final Duration HOUR = Duration.ofHours(1); @Inject private Notifier notifier; @@ -67,6 +71,11 @@ public class NightmareZonePlugin extends Plugin @Inject private NightmareZoneOverlay overlay; + @Getter + private int pointsPerHour; + + private Instant nmzSessionStartTime; + // This starts as true since you need to get // above the threshold before sending notifications private boolean absorptionNotificationSend = true; @@ -90,6 +99,8 @@ public class NightmareZonePlugin extends Plugin { nmzWidget.setHidden(false); } + + resetPointsPerHour(); } @Subscribe @@ -114,12 +125,23 @@ public class NightmareZonePlugin extends Plugin absorptionNotificationSend = true; } + if (nmzSessionStartTime != null) + { + resetPointsPerHour(); + } + return; } + if (config.absorptionNotification()) { checkAbsorption(); } + + if (config.moveOverlay()) + { + pointsPerHour = calculatePointsPerHour(); + } } @Subscribe @@ -193,6 +215,32 @@ public class NightmareZonePlugin extends Plugin } } + private int calculatePointsPerHour() + { + Instant now = Instant.now(); + final int currentPoints = client.getVar(Varbits.NMZ_POINTS); + + if (nmzSessionStartTime == null) + { + nmzSessionStartTime = now; + } + + Duration timeSinceStart = Duration.between(nmzSessionStartTime, now); + + if (!timeSinceStart.isZero()) + { + return (int) ((double) currentPoints * (double) HOUR.toMillis() / (double) timeSinceStart.toMillis()); + } + + return 0; + } + + private void resetPointsPerHour() + { + nmzSessionStartTime = null; + pointsPerHour = 0; + } + public boolean isInNightmareZone() { return Arrays.equals(client.getMapRegions(), NMZ_MAP_REGION);