Jump to content

Skill Monitor


Cory
 Share

Recommended Posts

onStart;

SkillMonitor.resetSkills();

onLoop or onPaint;

SkillMonitor.updateSkills(client.getSkills());

use as;

SkillMonitor.xpGained(Skill.MINING)

Class;


import org.osbot.script.rs2.skill.Skill;
import org.osbot.script.rs2.skill.Skills;

import java.util.Collection;
import java.util.HashMap;

/**
 * User: Cory
 * Date: 26/06/13
 * Time: 06:41
 */
public class SkillMonitor {

	private static HashMap<Skill, Monitor> monitors = new HashMap<Skill, Monitor>();

	public static Monitor get(Skill skill) {
		Monitor mon = monitors.get(skill);
		if(mon == null) {
			mon = new Monitor();
			mon.skill = skill;
			monitors.put(skill, mon);
		}
		return mon;
	}

	public static void updateSkills(Skills skills){
		for(Monitor mon : values()) {
			int currentXp = skills.getExperience(mon.skill);
			if(mon.currentXp > 0)
				mon.lastGainedXp = currentXp-mon.currentXp;
			if(mon.currentXp != currentXp && mon.startXp <= 0 && mon.currentXp >= 0) {
				mon.startXp = mon.currentXp;
				mon.startLevel = mon.currentLevel;
				mon.startedTraining = System.currentTimeMillis();
			}
			mon.currentXp = currentXp;
			mon.currentLevel = skills.getCurrentLevel(mon.skill);
			mon.actualLevel = skills.getLevel(mon.skill);
			mon.xpToLvl = xPForLevel(mon.currentLevel+1)-mon.currentXp;
		}
	}

	public static int xpGained(Skill skill) {
		if(startXp(skill) <= 0)
			return 0;
		return currentXp(skill)-startXp(skill);
	}

	public static int lvlGained(Skill skill) {
		if(startXp(skill) <= 0)
			return 0;
		return currentLvl(skill)-startLvl(skill);
	}

	public static int xpToLvl(Skill skill) {
		return get(skill).xpToLvl;
	}

	public static int startXp(Skill skill) {
		return get(skill).startXp;
	}

	public static int startLvl(Skill skill) {
		return get(skill).startLevel;
	}

	public static int currentXp(Skill skill) {
		return get(skill).currentXp;
	}

	public static int currentLvl(Skill skill) {
		return get(skill).currentLevel;
	}

	public static int xPForLevel(int level) {
		int points = 0;
		int output = 0;
		for (int lvl = 1; lvl <= level; lvl++) {
			points += Math.floor((double)lvl + 300.0 * Math.pow(2.0, (double)lvl / 7.0));
			if (lvl >= level)
				return output;
			output = (int)Math.floor(points / 4);
		}
		return 0;
	}

	public static void resetSkills() {
		monitors.clear();
	}

	public static Collection<Monitor> values() {
		return monitors.values();
	}

	public static class Monitor {
		public int startXp = -1, startLevel = 0, lastGainedXp;
		public int currentXp = -1, currentLevel = -1, actualLevel = -1;
		public long startedTraining = -1;
		public Skill skill = null;
		public int xpToLvl = 0;
	}
}

Edited by Cory
  • Like 2
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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