Jump to content

AccuXP - [API]


Reid

Recommended Posts

Meant for new scripters. If you're going to hate go away.

 

Enjoy.

package org.purplekush.api;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

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

/**
 * 
 * @author Reid (PurpleKush)
 * @version 0.1
 */

public class AccuXP {
	
	public  static String status;	
	private Script s;
	private static long startTime;
	private static int skillToTrackXP;
	private static Skill skillTracking;

	public AccuXP(Script s) {
		this.s = s;
	}

	/**
	 * Starts Timer
	 */
	public void startTimer() {
		startTime = System.currentTimeMillis();
	}

	/**
	 * What skill you would like to track
	 * @param skill
	 */
	public void trackXPForSkill(Skill skill) {
		skillToTrackXP = s.client.getSkills().getExperience(skill);
		skillTracking = skill;
	}

	/**
	 * Paint data to canvas
	 * @param g
	 */
	public void calculatePaint(Graphics g) {
		int totalXP = s.client.getSkills().getExperience(skillTracking) - skillToTrackXP;
		long millis = System.currentTimeMillis() - startTime;
		int xpPH = (int) (totalXP * 3600000.0D / millis);
		g.setColor(Color.WHITE);
		g.setFont(new Font("Myriad Pro", Font.PLAIN, 16));
		g.drawString("Time Running : "+ getFormattedTime(System.currentTimeMillis()- startTime), 7, 275);
		g.drawString("Status : " + status, 7, 295);
		g.drawString("XP P/H : " + xpPH, 7, 315);
		g.drawString("XP Gained : " + totalXP, 7, 335);
	}

	private String getFormattedTime(final long timeMilliseconds) {
		final StringBuilder b = new StringBuilder();
		final long runtime = timeMilliseconds;
		final long totalSecs = runtime / 1000;
		final long totalMins = totalSecs / 60;
		final long totalHours = totalMins / 60;
		final int seconds = (int) totalSecs % 60;
		final int minutes = (int) totalMins % 60;
		final int hours = (int) totalHours % 60;
		if (hours < 10) {
			b.append("0");
		}
		b.append(hours);
		b.append(":");
		if (minutes < 10) {
			b.append("0");
		}
		b.append(minutes);
		b.append(":");
		if (seconds < 10) {
			b.append("0");
		}
		b.append(seconds);
		return b.toString();
	}
}

Usage:

	AccuXP xp = new AccuXP(this);

        public void onStart(){
		xp.startTimer();
		xp.trackXPForSkill(Skill.COOKING);
	}

        public void onPaint(Graphics g){
		xp.calculatePaint(g);
	}

Edited by PurpleKush
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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