The client is offline due to RuneScape update. You may see instance errors but this is due to the update and not actual instance errors. This should be resolved soon. Join our Discord for more information.

SkillTracker API



  • SkillTracker:

    /**
     * @author Jacob Rhiel - Intelli created Feb, 2019
     */
    public class SkillTracker {
    
        /**
         * List of currently tracked skills.
         */
        private static final Map<Integer, PersonaSkill> trackedSkills = new HashMap<>();
    
        /**
         * Starts tracking a specified skill.
         * @param persona The {@link PersonaSkill} we are trying to track.
         * @return Whether or not it is being tracked.
         */
        public static boolean startTracking(PersonaSkill persona) {
            if(isTracking(persona)) return false;
            persona.setTracked(true);
            persona.setTrackingStartTime(System.currentTimeMillis());
            trackedSkills.putIfAbsent(persona.getSkill().getIndex(), persona);
            return trackedSkills.containsKey(persona.getSkill().getIndex());
        }
    
        /**
         * Stops tracking a specified skill.
         * @param persona The {@link PersonaSkill} we are trying to stop tracking.
         * @return Whether or not it was successfully un-tracked.
         */
        public static boolean stopTracking(PersonaSkill persona) {
            if(!isTracking(persona)) return false;
            persona.setTracked(false);
            persona.setTrackingStartTime(0);
            return trackedSkills.remove(persona.getSkill().getIndex(), persona);
        }
    
        /**
         * Checks if we are tracking the specified skill.
         * @param persona The {@link PersonaSkill} to check.
         * @return Whether or not we are tracking this skill.
         */
        public static boolean isTracking(PersonaSkill persona) {
            return trackedSkills.containsKey(persona.getSkill().getIndex());
        }
    
        /**
         * Checks if we are tracking the specified skill.
         * @param index The index of the skill to check.
         * @return Whether or not we are tracking this skill.
         */
        public static boolean isTracking(int index) {
            return trackedSkills.containsKey(index);
        }
    
        /**
         * Updates the tracked skill.
         * @param event The {@link SkillEvent} that is produced on a skill update.
         * @return Whether we handled the skill update or not.
         */
        public static boolean updateSkill(SkillEvent event) {
            if(!isTracking(event.getSource().getIndex())) return false;
            return PersonaSkill.handleSkillChange(event);
        }
    
    }
    

    PersonaSkill:

    /**
     * @author Jacob Rhiel - Intelli created Feb, 2019
     */
    @RequiredArgsConstructor
    @Getter
    public enum PersonaSkill implements SkillSet {
    
        AGILITY(Skill.AGILITY),
    
        THIEVING(Skill.THIEVING),
    
        ;
    
        private final Skill skill;
    
        @Getter
        @Setter
        private long trackingStartTime;
    
        @Getter
        @Setter
        private boolean tracked;
    
        @Getter
        @Setter
        private int startingLevel;
    
        @Getter
        @Setter
        private int currentLevel;
    
        @Getter
        @Setter
        private int startingExperience;
    
        @Getter
        @Setter
        private int currentExperience;
    
        @Getter
        @Setter
        private int currentDisplayLevel;
    
        /**
         * Gets the duration of time that the skill has been tracked
         * @return The time the skill has been being tracked.
         */
        public long getTrackingTime() {
            return System.currentTimeMillis() - this.trackingStartTime;
        }
    
        /**
         * Handles the type of skill update that has been applied
         * @param event The {@link SkillEvent} that triggered the update
         * @return Whether or not the type was updated.
         */
        public static boolean handleSkillChange(SkillEvent event) {
            PersonaSkill persona = PersonaSkill.getPersonaSkill(event.getSource());
            SkillUpdateType updateType = SkillUpdateType.getUpdateType(event.getType());
            switch(updateType) {
                case TYPE_EXPERIENCE:
                    handleExperienceChanged(persona, event);
                    return true;
                case TYPE_LEVEL:
                case TYPE_TEMPORARY_LEVEL:
                    handleLevelChanged(persona, event, updateType);
                    return true;
            }
            return false;
        }
    
        /**
         * Updates on experience change
         * @param persona The {@link PersonaSkill} we are changing experience for
         * @param event The {@link SkillEvent} that triggered the event
         */
        public static void handleExperienceChanged(PersonaSkill persona, SkillEvent event) {
            int difference = event.getCurrent() - event.getPrevious();
            persona.addToExperience(difference);
        }
    
        /**
         * Updates levels changed
         * @param persona The {@link PersonaSkill} we are changing levels for
         * @param event The {@link SkillEvent} that triggered the event
         * @param type The {@link SkillUpdateType} of the triggered skill
         */
        public static void handleLevelChanged(PersonaSkill persona, SkillEvent event, SkillUpdateType type) {
            boolean displayLevel = type.equals(SkillUpdateType.TYPE_TEMPORARY_LEVEL);
            int difference = event.getCurrent() - event.getPrevious();
            if(displayLevel) {
                persona.setCurrentDisplayLevel(event.getCurrent());
            } else {
                persona.addToLevels(difference);
            }
        }
    
        /**
         * Returns the experience gained per {@link TimeUnit} based on duration.
         * @param skill The {@link PersonaSkill} we are tracking
         * @param timeUnit The {@link TimeUnit} that we want to return
         * @param timeRunning The time running in MS that the skill has been tracked
         * @return The experience per {@link TimeUnit}
         */
        public double getExperiencePerTime(PersonaSkill skill, TimeUnit timeUnit, long timeRunning) {
            int gainedExperience = skill.gainedExperience();
            long duration = timeUnit.convert(timeRunning, timeUnit);
            return gainedExperience / duration;
        }
    
        /**
         * Adds experience to this {@link PersonaSkill}
         * @param amount The amount of experience to add
         */
        public void addToExperience(int amount) {
            setCurrentExperience(getCurrentExperience() + amount);
        }
    
        /**
         * Adds levels to this {@link PersonaSkill}
         * @param amount The amount of levels to add
         */
        public void addToLevels(int amount) {
            setCurrentLevel(getCurrentLevel() + amount);
        }
    
        /**
         * Gets the {@link PersonaSkill} based on {@link Skill} argument
         * @param skill The {@link Skill} that represents our {@link PersonaSkill}
         * @return The matching {@link PersonaSkill}.
         */
        public static PersonaSkill getPersonaSkill(Skill skill) {
            for(PersonaSkill personaSkill : PersonaSkill.values()) {
                if(personaSkill.getSkill().equals(skill)) {
                    return personaSkill;
                }
            }
            return null;
        }
    
        @Override
        public int gainedLevels() {
            return this.currentLevel - this.startingLevel;
        }
    
        @Override
        public int gainedExperience() {
            return this.currentExperience - this.startingExperience;
        }
    
    }
    

    SkillUpdateType:

    /**
     * @author Jacob Rhiel - Intelli created Feb, 2019
     */
    public enum SkillUpdateType {
    
        TYPE_EXPERIENCE,
    
        TYPE_LEVEL,
    
        TYPE_TEMPORARY_LEVEL,
    
        ;
    
        public static SkillUpdateType getUpdateType(int opcode) {
            return SkillUpdateType.values()[opcode];
        }
    
    }
    
    


  • It is better to use StopWatch() for time tracking.


  • Contributor Script Writer

    Lombok isn't supported on the SDN for people that are willing to use this



  • @burak

     <plugin>
                    <groupId>org.projectlombok</groupId>
                    <artifactId>lombok-maven-plugin</artifactId>
                    <version>1.18.4.0</version>
                    <executions>
                        <execution>
                            <phase>generate-sources</phase>
                            <goals>
                                <goal>delombok</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>
    

 

55
Online

15.4k
Users

1.3k
Topics

18.6k
Posts