agility plugin: add laps per hour to lap counter overlay

Co-authored-by: Adam <Adam@sigterm.info>
This commit is contained in:
Petter Sæther Moen
2020-04-22 12:20:47 -04:00
committed by Adam
parent 7d25ed8b42
commit a626e97176
3 changed files with 64 additions and 12 deletions

View File

@@ -78,11 +78,22 @@ public interface AgilityConfig extends Config
return true;
}
@ConfigItem(
keyName = "lapsPerHour",
name = "Show Laps Per Hour",
description = "Shows how many laps you can expect to complete per hour.",
position = 4
)
default boolean lapsPerHour()
{
return true;
}
@ConfigItem(
keyName = "overlayColor",
name = "Overlay Color",
description = "Color of Agility overlay",
position = 4
position = 5
)
default Color getOverlayColor()
{
@@ -93,7 +104,7 @@ public interface AgilityConfig extends Config
keyName = "highlightMarks",
name = "Highlight Marks of Grace",
description = "Enable/disable the highlighting of retrievable Marks of Grace",
position = 5
position = 6
)
default boolean highlightMarks()
{
@@ -104,7 +115,7 @@ public interface AgilityConfig extends Config
keyName = "markHighlight",
name = "Mark Highlight Color",
description = "Color of highlighted Marks of Grace",
position = 6
position = 7
)
default Color getMarkColor()
{
@@ -115,7 +126,7 @@ public interface AgilityConfig extends Config
keyName = "highlightShortcuts",
name = "Highlight Agility Shortcuts",
description = "Enable/disable the highlighting of Agility shortcuts",
position = 7
position = 8
)
default boolean highlightShortcuts()
{
@@ -126,7 +137,7 @@ public interface AgilityConfig extends Config
keyName = "trapOverlay",
name = "Show Trap Overlay",
description = "Enable/disable the highlighting of traps on Agility courses",
position = 8
position = 9
)
default boolean showTrapOverlay()
{
@@ -137,7 +148,7 @@ public interface AgilityConfig extends Config
keyName = "trapHighlight",
name = "Trap Overlay Color",
description = "Color of Agility trap overlay",
position = 9
position = 10
)
default Color getTrapColor()
{
@@ -148,7 +159,7 @@ public interface AgilityConfig extends Config
keyName = "agilityArenaNotifier",
name = "Agility Arena notifier",
description = "Notify on ticket location change in Agility Arena",
position = 10
position = 11
)
default boolean notifyAgilityArena()
{
@@ -159,7 +170,7 @@ public interface AgilityConfig extends Config
keyName = "agilityArenaTimer",
name = "Agility Arena timer",
description = "Configures whether Agility Arena timer is displayed",
position = 11
position = 12
)
default boolean showAgilityArenaTimer()
{
@@ -170,7 +181,7 @@ public interface AgilityConfig extends Config
keyName = "highlightStick",
name = "Highlight Stick",
description = "Highlight the retrievable stick in the Werewolf Agility Course",
position = 12
position = 13
)
default boolean highlightStick()
{
@@ -181,7 +192,7 @@ public interface AgilityConfig extends Config
keyName = "stickHighlightColor",
name = "Stick Highlight Color",
description = "Color of highlighted stick",
position = 13
position = 14
)
default Color stickHighlightColor()
{

View File

@@ -24,12 +24,14 @@
*/
package net.runelite.client.plugins.agility;
import java.time.Instant;
import com.google.common.collect.EvictingQueue;
import lombok.Getter;
import lombok.Setter;
import net.runelite.api.Client;
import net.runelite.api.Skill;
import net.runelite.client.plugins.xptracker.XpTrackerService;
import java.time.Duration;
import java.time.Instant;
@Getter
@Setter
@@ -39,6 +41,8 @@ class AgilitySession
private Instant lastLapCompleted;
private int totalLaps;
private int lapsTillGoal;
private final EvictingQueue<Duration> lastLapTimes = EvictingQueue.create(10);
private int lapsPerHour;
AgilitySession(Courses course)
{
@@ -47,7 +51,8 @@ class AgilitySession
void incrementLapCount(Client client, XpTrackerService xpTrackerService)
{
lastLapCompleted = Instant.now();
calculateLapsPerHour();
++totalLaps;
final int currentExp = client.getSkillExperience(Skill.AGILITY);
@@ -64,9 +69,37 @@ class AgilitySession
lapsTillGoal = goalRemainingXp > 0 ? (int) Math.ceil(goalRemainingXp / courseTotalExp) : 0;
}
void calculateLapsPerHour()
{
Instant now = Instant.now();
if (lastLapCompleted != null)
{
Duration timeSinceLastLap = Duration.between(lastLapCompleted, now);
if (!timeSinceLastLap.isNegative())
{
lastLapTimes.add(timeSinceLastLap);
Duration sum = Duration.ZERO;
for (Duration lapTime : lastLapTimes)
{
sum = sum.plus(lapTime);
}
Duration averageLapTime = sum.dividedBy(lastLapTimes.size());
lapsPerHour = (int) (Duration.ofHours(1).toMillis() / averageLapTime.toMillis());
}
}
lastLapCompleted = now;
}
void resetLapCount()
{
totalLaps = 0;
lapsTillGoal = 0;
lastLapTimes.clear();
lapsPerHour = 0;
}
}

View File

@@ -89,6 +89,14 @@ class LapCounterOverlay extends OverlayPanel
.build());
}
if (config.lapsPerHour() && session.getLapsPerHour() > 0)
{
panelComponent.getChildren().add(LineComponent.builder()
.left("Laps per hour:")
.right(Integer.toString(session.getLapsPerHour()))
.build());
}
return super.render(graphics);
}
}