Merge pull request #9388 from adwitkow/nmz-points-overlay

nmz: Add total and per hour points to NMZ overlay
This commit is contained in:
Adam
2019-07-30 17:20:20 -04:00
committed by GitHub
2 changed files with 61 additions and 1 deletions

View File

@@ -30,6 +30,7 @@ import javax.inject.Inject;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.ItemID; import net.runelite.api.ItemID;
import static net.runelite.api.MenuAction.RUNELITE_OVERLAY_CONFIG; import static net.runelite.api.MenuAction.RUNELITE_OVERLAY_CONFIG;
import net.runelite.api.VarPlayer;
import net.runelite.api.Varbits; import net.runelite.api.Varbits;
import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo; import net.runelite.api.widgets.WidgetInfo;
@@ -101,10 +102,21 @@ class NightmareZoneOverlay extends Overlay
renderAbsorptionCounter(); renderAbsorptionCounter();
final int currentPoints = client.getVar(Varbits.NMZ_POINTS);
final int totalPoints = currentPoints + client.getVar(VarPlayer.NMZ_REWARD_POINTS);
panelComponent.getChildren().clear(); panelComponent.getChildren().clear();
panelComponent.getChildren().add(LineComponent.builder() panelComponent.getChildren().add(LineComponent.builder()
.left("Points: ") .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()); .build());
return panelComponent.render(graphics); return panelComponent.render(graphics);

View File

@@ -25,8 +25,11 @@
package net.runelite.client.plugins.nightmarezone; package net.runelite.client.plugins.nightmarezone;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.time.Duration;
import java.time.Instant;
import java.util.Arrays; import java.util.Arrays;
import javax.inject.Inject; import javax.inject.Inject;
import lombok.Getter;
import net.runelite.api.ChatMessageType; import net.runelite.api.ChatMessageType;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.Varbits; import net.runelite.api.Varbits;
@@ -51,6 +54,7 @@ import net.runelite.client.util.Text;
public class NightmareZonePlugin extends Plugin public class NightmareZonePlugin extends Plugin
{ {
private static final int[] NMZ_MAP_REGION = {9033}; private static final int[] NMZ_MAP_REGION = {9033};
private static final Duration HOUR = Duration.ofHours(1);
@Inject @Inject
private Notifier notifier; private Notifier notifier;
@@ -67,6 +71,11 @@ public class NightmareZonePlugin extends Plugin
@Inject @Inject
private NightmareZoneOverlay overlay; private NightmareZoneOverlay overlay;
@Getter
private int pointsPerHour;
private Instant nmzSessionStartTime;
// This starts as true since you need to get // This starts as true since you need to get
// above the threshold before sending notifications // above the threshold before sending notifications
private boolean absorptionNotificationSend = true; private boolean absorptionNotificationSend = true;
@@ -90,6 +99,8 @@ public class NightmareZonePlugin extends Plugin
{ {
nmzWidget.setHidden(false); nmzWidget.setHidden(false);
} }
resetPointsPerHour();
} }
@Subscribe @Subscribe
@@ -114,12 +125,23 @@ public class NightmareZonePlugin extends Plugin
absorptionNotificationSend = true; absorptionNotificationSend = true;
} }
if (nmzSessionStartTime != null)
{
resetPointsPerHour();
}
return; return;
} }
if (config.absorptionNotification()) if (config.absorptionNotification())
{ {
checkAbsorption(); checkAbsorption();
} }
if (config.moveOverlay())
{
pointsPerHour = calculatePointsPerHour();
}
} }
@Subscribe @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() public boolean isInNightmareZone()
{ {
return Arrays.equals(client.getMapRegions(), NMZ_MAP_REGION); return Arrays.equals(client.getMapRegions(), NMZ_MAP_REGION);