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; 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( @ConfigItem(
keyName = "overlayColor", keyName = "overlayColor",
name = "Overlay Color", name = "Overlay Color",
description = "Color of Agility overlay", description = "Color of Agility overlay",
position = 4 position = 5
) )
default Color getOverlayColor() default Color getOverlayColor()
{ {
@@ -93,7 +104,7 @@ public interface AgilityConfig extends Config
keyName = "highlightMarks", keyName = "highlightMarks",
name = "Highlight Marks of Grace", name = "Highlight Marks of Grace",
description = "Enable/disable the highlighting of retrievable Marks of Grace", description = "Enable/disable the highlighting of retrievable Marks of Grace",
position = 5 position = 6
) )
default boolean highlightMarks() default boolean highlightMarks()
{ {
@@ -104,7 +115,7 @@ public interface AgilityConfig extends Config
keyName = "markHighlight", keyName = "markHighlight",
name = "Mark Highlight Color", name = "Mark Highlight Color",
description = "Color of highlighted Marks of Grace", description = "Color of highlighted Marks of Grace",
position = 6 position = 7
) )
default Color getMarkColor() default Color getMarkColor()
{ {
@@ -115,7 +126,7 @@ public interface AgilityConfig extends Config
keyName = "highlightShortcuts", keyName = "highlightShortcuts",
name = "Highlight Agility Shortcuts", name = "Highlight Agility Shortcuts",
description = "Enable/disable the highlighting of Agility shortcuts", description = "Enable/disable the highlighting of Agility shortcuts",
position = 7 position = 8
) )
default boolean highlightShortcuts() default boolean highlightShortcuts()
{ {
@@ -126,7 +137,7 @@ public interface AgilityConfig extends Config
keyName = "trapOverlay", keyName = "trapOverlay",
name = "Show Trap Overlay", name = "Show Trap Overlay",
description = "Enable/disable the highlighting of traps on Agility courses", description = "Enable/disable the highlighting of traps on Agility courses",
position = 8 position = 9
) )
default boolean showTrapOverlay() default boolean showTrapOverlay()
{ {
@@ -137,7 +148,7 @@ public interface AgilityConfig extends Config
keyName = "trapHighlight", keyName = "trapHighlight",
name = "Trap Overlay Color", name = "Trap Overlay Color",
description = "Color of Agility trap overlay", description = "Color of Agility trap overlay",
position = 9 position = 10
) )
default Color getTrapColor() default Color getTrapColor()
{ {
@@ -148,7 +159,7 @@ public interface AgilityConfig extends Config
keyName = "agilityArenaNotifier", keyName = "agilityArenaNotifier",
name = "Agility Arena notifier", name = "Agility Arena notifier",
description = "Notify on ticket location change in Agility Arena", description = "Notify on ticket location change in Agility Arena",
position = 10 position = 11
) )
default boolean notifyAgilityArena() default boolean notifyAgilityArena()
{ {
@@ -159,7 +170,7 @@ public interface AgilityConfig extends Config
keyName = "agilityArenaTimer", keyName = "agilityArenaTimer",
name = "Agility Arena timer", name = "Agility Arena timer",
description = "Configures whether Agility Arena timer is displayed", description = "Configures whether Agility Arena timer is displayed",
position = 11 position = 12
) )
default boolean showAgilityArenaTimer() default boolean showAgilityArenaTimer()
{ {
@@ -170,7 +181,7 @@ public interface AgilityConfig extends Config
keyName = "highlightStick", keyName = "highlightStick",
name = "Highlight Stick", name = "Highlight Stick",
description = "Highlight the retrievable stick in the Werewolf Agility Course", description = "Highlight the retrievable stick in the Werewolf Agility Course",
position = 12 position = 13
) )
default boolean highlightStick() default boolean highlightStick()
{ {
@@ -181,7 +192,7 @@ public interface AgilityConfig extends Config
keyName = "stickHighlightColor", keyName = "stickHighlightColor",
name = "Stick Highlight Color", name = "Stick Highlight Color",
description = "Color of highlighted stick", description = "Color of highlighted stick",
position = 13 position = 14
) )
default Color stickHighlightColor() default Color stickHighlightColor()
{ {

View File

@@ -24,12 +24,14 @@
*/ */
package net.runelite.client.plugins.agility; package net.runelite.client.plugins.agility;
import java.time.Instant; import com.google.common.collect.EvictingQueue;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.Skill; import net.runelite.api.Skill;
import net.runelite.client.plugins.xptracker.XpTrackerService; import net.runelite.client.plugins.xptracker.XpTrackerService;
import java.time.Duration;
import java.time.Instant;
@Getter @Getter
@Setter @Setter
@@ -39,6 +41,8 @@ class AgilitySession
private Instant lastLapCompleted; private Instant lastLapCompleted;
private int totalLaps; private int totalLaps;
private int lapsTillGoal; private int lapsTillGoal;
private final EvictingQueue<Duration> lastLapTimes = EvictingQueue.create(10);
private int lapsPerHour;
AgilitySession(Courses course) AgilitySession(Courses course)
{ {
@@ -47,7 +51,8 @@ class AgilitySession
void incrementLapCount(Client client, XpTrackerService xpTrackerService) void incrementLapCount(Client client, XpTrackerService xpTrackerService)
{ {
lastLapCompleted = Instant.now(); calculateLapsPerHour();
++totalLaps; ++totalLaps;
final int currentExp = client.getSkillExperience(Skill.AGILITY); final int currentExp = client.getSkillExperience(Skill.AGILITY);
@@ -64,9 +69,37 @@ class AgilitySession
lapsTillGoal = goalRemainingXp > 0 ? (int) Math.ceil(goalRemainingXp / courseTotalExp) : 0; 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() void resetLapCount()
{ {
totalLaps = 0; totalLaps = 0;
lapsTillGoal = 0; lapsTillGoal = 0;
lastLapTimes.clear();
lapsPerHour = 0;
} }
} }

View File

@@ -89,6 +89,14 @@ class LapCounterOverlay extends OverlayPanel
.build()); .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); return super.render(graphics);
} }
} }