so im releasing my skill tracker on account of a request. Plus i personally dont like osbot experience tracker. IM pretty sure they have most of these methods in there, probably hidden. @Alek feel free to use if you decide to update the experience class.
updated: to support EnumMap
Add this into the on start of the script. (The class that extends Script)
Skilltracker skillTracker = new SkillTracker(this);
SkillTracker.java
package com.divine.tracker;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.Iterator;
import java.util.List;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
public class SkillTracker {
private final EnumMap<Skill, Tracker> mapTracker;
private Script ctx;
public SkillTracker(Script ctx) {
this.ctx = ctx;
this.mapTracker = new EnumMap<Skill, Tracker>(Skill.class);
}
public EnumMap<Skill, Tracker> getTrackerMap() {
return this.mapTracker;
}
public long getTotalXpGained() {
long amount = 0;
for (Skill skill: getGainedSkills()) {
amount += getGainedXP(skill);
}
return amount;
}
public List<Skill> getGainedSkills() {
Iterator<Skill> skill = mapTracker.keySet().iterator();
List<Skill> list = new ArrayList<>();
while (skill.hasNext()) {
if (hasGainedXP(skill.next())) {
list.add(skill.next());
}
}
return list;
}
private boolean hasGainedXP(Skill skill) {
return getGainedXP(skill) > 0;
}
public void track(Skill...skills) {
for (Skill skill: (skills.length == 0) ? Skill.values(): skills) {
mapTracker.put(skill, new Tracker(skill));
}
}
public Tracker get(Skill skill) {
Tracker tracker = mapTracker.get(skill);
if (tracker == null)
throw new UnsupportedOperationException("You're not tracking this skill!");
return tracker;
}
public long getElapsed(Skill skill) {
return System.currentTimeMillis() - get(skill).startedTrackingAt;
}
public int getGainedLevels(Skill skill) {
return ctx.skills.getStatic(skill) - get(skill).getStartLevel();
}
public int getGainedXP(Skill skill) {
return ctx.skills.getExperience(skill) - get(skill).getStartExp();
}
public int getGainedXPPerHour(Skill skill) {
return (int) actionsPerHour(getGainedXP(skill), get(skill).getStartedTrackingAt());
}
public int percentToLevel(Skill skill) {
int currentLevel = ctx.skills.getStatic(skill);
int expBetween = expBetween(currentLevel, currentLevel+1);
int expIntoLevel = ctx.skills.getExperience(skill) - getExpForLevel(currentLevel);
return (int) (((double) expIntoLevel / (double) expBetween) * 100D);
}
public long getTimeToLevel(Skill skill) {
if (getGainedXP(skill) <= 0)
return 0;
return (long) ((expToLevel(skill) * 3600000.0D) / (double) getGainedXPPerHour(skill));
}
public long getTimeToLevel(Skill skill, int target) {
if (getGainedXP(skill) <= 0)
return 0;
return (long) ((expToLevel(skill, target) * 3600000.0D) / (double) getGainedXPPerHour(skill));
}
/*
* Private methods
*/
private int expToLevel(Skill skill) {
return ctx.skills.experienceToLevel(skill);
}
private int expToLevel(Skill skill, int target) {
return getExpForLevel(target) - ctx.skills.getExperience(skill);
}
private int expBetween(int value1, int value2) {
return getExpForLevel(Math.max(value1, value2))
- getExpForLevel(Math.min(value1, value2));
}
private double actionsPerHour(long actions, long startTime) {
return (3600000D / (System.currentTimeMillis() - startTime) * actions);
}
private int getExpForLevel(int level) {
return ctx.skills.getExperienceForLevel(level);
}
private class Tracker {
private final int startExp, startLevel;
private final long startedTrackingAt;
private Tracker(final Skill track) {
this.startExp = ctx.skills.getExperience(track);
this.startLevel = ctx.skills.getStatic(track);
this.startedTrackingAt = System.currentTimeMillis();
}
public int getStartExp() {
return startExp;
}
public int getStartLevel() {
return startLevel;
}
public long getStartedTrackingAt() {
return startedTrackingAt;
}
}
}