Merge pull request #2370 from AWarbear/AgilityLapCounterFix

Fix agility laps left counter
This commit is contained in:
Adam
2018-05-05 22:03:16 -04:00
committed by GitHub
3 changed files with 14 additions and 8 deletions

View File

@@ -25,7 +25,6 @@
package net.runelite.client.plugins.agility; package net.runelite.client.plugins.agility;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
import com.google.common.primitives.Ints;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
@@ -142,8 +141,8 @@ public class AgilityPlugin extends Plugin
lastAgilityXp = agilityXp; lastAgilityXp = agilityXp;
// Get course // Get course
Courses course = Courses.getCourse(skillGained); Courses course = Courses.getCourse(client.getLocalPlayer().getWorldLocation().getRegionID());
if (course == null || !Ints.contains(client.getMapRegions(), course.getRegionId())) if (course == null || Math.abs(course.getLastObstacleXp() - skillGained) > 1)
{ {
return; return;
} }

View File

@@ -54,7 +54,13 @@ public class AgilitySession
int currentExp = client.getSkillExperience(Skill.AGILITY); int currentExp = client.getSkillExperience(Skill.AGILITY);
int nextLevel = client.getRealSkillLevel(Skill.AGILITY) + 1; int nextLevel = client.getRealSkillLevel(Skill.AGILITY) + 1;
int remainingXp = nextLevel <= Experience.MAX_VIRT_LEVEL ? Experience.getXpForLevel(nextLevel) - currentExp : 0;
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; lapsTillLevel = remainingXp > 0 ? (int) Math.ceil(remainingXp / course.getTotalXp()) : 0;
} }

View File

@@ -48,11 +48,12 @@ public enum Courses
RELLEKA(780.0, 475, 10553), RELLEKA(780.0, 475, 10553),
ARDOUGNE(793.0, 529, 10547); ARDOUGNE(793.0, 529, 10547);
private final static Map<Integer, Courses> courseXps = new HashMap<>(); private final static Map<Integer, Courses> coursesByRegion = new HashMap<>();
@Getter @Getter
private final double totalXp; private final double totalXp;
@Getter
private final int lastObstacleXp; private final int lastObstacleXp;
@Getter @Getter
@@ -62,12 +63,12 @@ public enum Courses
{ {
for (Courses course : values()) for (Courses course : values())
{ {
courseXps.put(course.lastObstacleXp, course); coursesByRegion.put(course.regionId, course);
} }
} }
public static Courses getCourse(int exp) public static Courses getCourse(int regionId)
{ {
return courseXps.get(exp); return coursesByRegion.get(regionId);
} }
} }