Use XpTrackerService to determine goals in Agility plugin

- Merge laps until next level and laps until next goal together
- Switch to XpTrackerService for determining goal experience

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2019-10-13 11:13:48 +02:00
parent 66fac018eb
commit 030a052ea1
4 changed files with 25 additions and 48 deletions

View File

@@ -69,8 +69,8 @@ public interface AgilityConfig extends Config
@ConfigItem( @ConfigItem(
keyName = "lapsToLevel", keyName = "lapsToLevel",
name = "Show Laps Until Level", name = "Show Laps Until Goal",
description = "Show number of laps remaining until next level is reached.", description = "Show number of laps remaining until next goal is reached.",
position = 3 position = 3
) )
default boolean lapsToLevel() default boolean lapsToLevel()
@@ -78,22 +78,11 @@ public interface AgilityConfig extends Config
return true; return true;
} }
@ConfigItem(
keyName = "lapsToGoal",
name = "Show Laps Until Goal",
description = "Show number of laps remaining until experience tracker goal is reached",
position = 4
)
default boolean lapsToGoal()
{
return false;
}
@ConfigItem( @ConfigItem(
keyName = "overlayColor", keyName = "overlayColor",
name = "Overlay Color", name = "Overlay Color",
description = "Color of Agility overlay", description = "Color of Agility overlay",
position = 5 position = 4
) )
default Color getOverlayColor() default Color getOverlayColor()
{ {
@@ -104,7 +93,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 = 6 position = 5
) )
default boolean highlightMarks() default boolean highlightMarks()
{ {
@@ -115,7 +104,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 = 7 position = 6
) )
default Color getMarkColor() default Color getMarkColor()
{ {
@@ -126,7 +115,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 = 8 position = 7
) )
default boolean highlightShortcuts() default boolean highlightShortcuts()
{ {
@@ -137,7 +126,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 = 9 position = 8
) )
default boolean showTrapOverlay() default boolean showTrapOverlay()
{ {
@@ -148,7 +137,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 = 10 position = 9
) )
default Color getTrapColor() default Color getTrapColor()
{ {
@@ -159,7 +148,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 = 11 position = 10
) )
default boolean notifyAgilityArena() default boolean notifyAgilityArena()
{ {
@@ -170,7 +159,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 = 12 position = 11
) )
default boolean showAgilityArenaTimer() default boolean showAgilityArenaTimer()
{ {

View File

@@ -67,7 +67,10 @@ import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.game.AgilityShortcut; import net.runelite.client.game.AgilityShortcut;
import net.runelite.client.game.ItemManager; import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDependency;
import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.plugins.xptracker.XpTrackerPlugin;
import net.runelite.client.plugins.xptracker.XpTrackerService;
import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.ui.overlay.infobox.InfoBoxManager; import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
@@ -76,6 +79,7 @@ import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
description = "Show helpful information about agility courses and obstacles", description = "Show helpful information about agility courses and obstacles",
tags = {"grace", "marks", "overlay", "shortcuts", "skilling", "traps"} tags = {"grace", "marks", "overlay", "shortcuts", "skilling", "traps"}
) )
@PluginDependency(XpTrackerPlugin.class)
@Slf4j @Slf4j
public class AgilityPlugin extends Plugin public class AgilityPlugin extends Plugin
{ {
@@ -111,6 +115,9 @@ public class AgilityPlugin extends Plugin
@Inject @Inject
private ItemManager itemManager; private ItemManager itemManager;
@Inject
private XpTrackerService xpTrackerService;
@Getter @Getter
private AgilitySession session; private AgilitySession session;
@@ -211,14 +218,14 @@ public class AgilityPlugin extends Plugin
if (session != null && session.getCourse() == course) if (session != null && session.getCourse() == course)
{ {
session.incrementLapCount(client); session.incrementLapCount(client, xpTrackerService);
} }
else else
{ {
session = new AgilitySession(course); session = new AgilitySession(course);
// New course found, reset lap count and set new course // New course found, reset lap count and set new course
session.resetLapCount(); session.resetLapCount();
session.incrementLapCount(client); session.incrementLapCount(client, xpTrackerService);
} }
} }

View File

@@ -28,9 +28,8 @@ import java.time.Instant;
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.Experience;
import net.runelite.api.Skill; import net.runelite.api.Skill;
import net.runelite.api.VarPlayer; import net.runelite.client.plugins.xptracker.XpTrackerService;
@Getter @Getter
@Setter @Setter
@@ -39,7 +38,6 @@ class AgilitySession
private final Courses course; private final Courses course;
private Instant lastLapCompleted; private Instant lastLapCompleted;
private int totalLaps; private int totalLaps;
private int lapsTillLevel;
private int lapsTillGoal; private int lapsTillGoal;
AgilitySession(Courses course) AgilitySession(Courses course)
@@ -47,30 +45,21 @@ class AgilitySession
this.course = course; this.course = course;
} }
void incrementLapCount(Client client) void incrementLapCount(Client client, XpTrackerService xpTrackerService)
{ {
lastLapCompleted = Instant.now(); lastLapCompleted = Instant.now();
++totalLaps; ++totalLaps;
int currentExp = client.getSkillExperience(Skill.AGILITY); final int currentExp = client.getSkillExperience(Skill.AGILITY);
int nextLevel = client.getRealSkillLevel(Skill.AGILITY) + 1; final int goalXp = xpTrackerService.getEndGoalXp(Skill.AGILITY);
final int goalRemainingXp = goalXp - currentExp;
int remainingXp;
do
{
remainingXp = nextLevel <= Experience.MAX_VIRT_LEVEL ? Experience.getXpForLevel(nextLevel) - currentExp : 0;
nextLevel++;
} while (remainingXp < 0);
lapsTillLevel = remainingXp > 0 ? (int) Math.ceil(remainingXp / course.getTotalXp()) : 0;
int goalRemainingXp = client.getVar(VarPlayer.AGILITY_GOAL_END) - currentExp;
lapsTillGoal = goalRemainingXp > 0 ? (int) Math.ceil(goalRemainingXp / course.getTotalXp()) : 0; lapsTillGoal = goalRemainingXp > 0 ? (int) Math.ceil(goalRemainingXp / course.getTotalXp()) : 0;
} }
void resetLapCount() void resetLapCount()
{ {
totalLaps = 0; totalLaps = 0;
lapsTillLevel = 0;
lapsTillGoal = 0; lapsTillGoal = 0;
} }
} }

View File

@@ -85,15 +85,7 @@ class LapCounterOverlay extends Overlay
.right(Integer.toString(session.getTotalLaps())) .right(Integer.toString(session.getTotalLaps()))
.build()); .build());
if (config.lapsToLevel() && session.getLapsTillLevel() > 0) if (config.lapsToLevel() && session.getLapsTillGoal() > 0)
{
panelComponent.getChildren().add(LineComponent.builder()
.left("Laps until level:")
.right(Integer.toString(session.getLapsTillLevel()))
.build());
}
if (config.lapsToGoal() && session.getLapsTillGoal() > 0)
{ {
panelComponent.getChildren().add(LineComponent.builder() panelComponent.getChildren().add(LineComponent.builder()
.left("Laps until goal:") .left("Laps until goal:")