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(
keyName = "lapsToLevel",
name = "Show Laps Until Level",
description = "Show number of laps remaining until next level is reached.",
name = "Show Laps Until Goal",
description = "Show number of laps remaining until next goal is reached.",
position = 3
)
default boolean lapsToLevel()
@@ -78,22 +78,11 @@ public interface AgilityConfig extends Config
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(
keyName = "overlayColor",
name = "Overlay Color",
description = "Color of Agility overlay",
position = 5
position = 4
)
default Color getOverlayColor()
{
@@ -104,7 +93,7 @@ public interface AgilityConfig extends Config
keyName = "highlightMarks",
name = "Highlight Marks of Grace",
description = "Enable/disable the highlighting of retrievable Marks of Grace",
position = 6
position = 5
)
default boolean highlightMarks()
{
@@ -115,7 +104,7 @@ public interface AgilityConfig extends Config
keyName = "markHighlight",
name = "Mark Highlight Color",
description = "Color of highlighted Marks of Grace",
position = 7
position = 6
)
default Color getMarkColor()
{
@@ -126,7 +115,7 @@ public interface AgilityConfig extends Config
keyName = "highlightShortcuts",
name = "Highlight Agility Shortcuts",
description = "Enable/disable the highlighting of Agility shortcuts",
position = 8
position = 7
)
default boolean highlightShortcuts()
{
@@ -137,7 +126,7 @@ public interface AgilityConfig extends Config
keyName = "trapOverlay",
name = "Show Trap Overlay",
description = "Enable/disable the highlighting of traps on Agility courses",
position = 9
position = 8
)
default boolean showTrapOverlay()
{
@@ -148,7 +137,7 @@ public interface AgilityConfig extends Config
keyName = "trapHighlight",
name = "Trap Overlay Color",
description = "Color of Agility trap overlay",
position = 10
position = 9
)
default Color getTrapColor()
{
@@ -159,7 +148,7 @@ public interface AgilityConfig extends Config
keyName = "agilityArenaNotifier",
name = "Agility Arena notifier",
description = "Notify on ticket location change in Agility Arena",
position = 11
position = 10
)
default boolean notifyAgilityArena()
{
@@ -170,7 +159,7 @@ public interface AgilityConfig extends Config
keyName = "agilityArenaTimer",
name = "Agility Arena timer",
description = "Configures whether Agility Arena timer is displayed",
position = 12
position = 11
)
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.ItemManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDependency;
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.infobox.InfoBoxManager;
@@ -76,6 +79,7 @@ import net.runelite.client.ui.overlay.infobox.InfoBoxManager;
description = "Show helpful information about agility courses and obstacles",
tags = {"grace", "marks", "overlay", "shortcuts", "skilling", "traps"}
)
@PluginDependency(XpTrackerPlugin.class)
@Slf4j
public class AgilityPlugin extends Plugin
{
@@ -111,6 +115,9 @@ public class AgilityPlugin extends Plugin
@Inject
private ItemManager itemManager;
@Inject
private XpTrackerService xpTrackerService;
@Getter
private AgilitySession session;
@@ -211,14 +218,14 @@ public class AgilityPlugin extends Plugin
if (session != null && session.getCourse() == course)
{
session.incrementLapCount(client);
session.incrementLapCount(client, xpTrackerService);
}
else
{
session = new AgilitySession(course);
// New course found, reset lap count and set new course
session.resetLapCount();
session.incrementLapCount(client);
session.incrementLapCount(client, xpTrackerService);
}
}

View File

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

View File

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