Jump to content

Skill tracker


Joseph

Recommended Posts

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;
		}
	}
}

Edited by josedpay
  • Like 1
Link to comment
Share on other sites

 

 

SkillTracker.java

	
	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 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;
	}

it always did my friend.

Link to comment
Share on other sites

  • 1 year later...

 

i'm calling it correctly but still not showing up.

 

g.drawString("Experience p/HR: " + skillTracker.getGainedXPPerHour(Skill.PRAYER), 5, 160);
g.drawString("Next Level up in: " + skillTracker.getTimeToLevel(Skill.PRAYER), 5, 175);

Fixed* by reverting back to the api code i did before using this released version; thanks for posting anyways.

Edited by booleans yay
Link to comment
Share on other sites

  • 1 year later...

Great code!

there is a minor mistake in getGainedSkills()

public List<Skill> getGainedSkills() {
        Iterator<Skill> skill = mapTracker.keySet().iterator();
        List<Skill> list = new ArrayList<>();

        while (skill.hasNext()) {
            Skill s = skill.next();
            if (hasGainedXP(s)) {
                list.add(s);
            }
        }
        return list;
    }
Edited by Pegasus
  • Like 1
Link to comment
Share on other sites

20 hours ago, Pegasus said:

Great code!

there is a minor mistake in getGainedSkills()


public List<Skill> getGainedSkills() {
        Iterator<Skill> skill = mapTracker.keySet().iterator();
        List<Skill> list = new ArrayList<>();

        while (skill.hasNext()) {
            Skill s = skill.next();
            if (hasGainedXP(s)) {
                list.add(s);
            }
        }
        return list;
    }

bruh the thread was made in 2015, OP is banned AND the last post was well over 1.5 years ago.

Edited by Slut
fuq
  • Like 1
Link to comment
Share on other sites

2 hours ago, Slut said:

I don't considering there's an Experience Tracker in the API.

This.

OP's class doesn't really offer anything that the existing OSBot ExperienceTracker and Skills class doesn't.

getGainedSkills() is redundant because you should know which skills you are gaining XP in, because you started the experience tracker for them :doge:
 

Edited by Explv
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...