Jump to content

NovumNation Skill tracker


Wizard

Recommended Posts

So, as there is no more team NovumNation anymore, I decided to release this skill tracker that i made for the team' API back then.

 

Features:

-Neat

-Tracks all the skills 

-You can specify which skills to fade and which not

 

Im not going to explain how to add it, its quite simple for you to figure how to add it if you have a basic understanding of Java.

 

The code was written to work with a different framework, so I rewrote it fast, thus you may find some errors.

 

SkillWrapper.Java

public class SkillWrapper {

    private int startXp;
    private int currentXp;
    private int startLevel;
    private int prevGainedXp;
    private long lastGainedXP;
    public boolean keep = false;

    public SkillWrapper(int startXp, int currentXp, int startLevel) {
        this.startXp = startXp;
        this.currentXp = currentXp;
        this.startLevel = startLevel;
    }

    public int getSecTNL(int xpTNL) {
        final int gains = getHourlyGains();
        return (gains == 0) ? 0 : (int) ((3600L * xpTNL) / (long) gains);
    }

    public int getHourlyGains() {
        long time = getRuntime(NNScript.startTime);
        return (time == 0L) ? 0 : (int) ((3600000D * (currentXp - startXp)) / time);
    }

    public int getGainedXp() {
        return currentXp - startXp;
    }

    public long getRuntime(long startTime) {
        return (System.currentTimeMillis() - startTime);
    }

    public void setCurrentXp(int currentXp) {
        this.currentXp = currentXp;
        if (currentXp != startXp && getGainedXp() > prevGainedXp) {
            lastGainedXP = System.currentTimeMillis();
            prevGainedXp = getGainedXp();
        }
    }

    public int getStartXp() {
        return startXp;
    }

    public int getCurrentXp() {
        return currentXp;
    }

    public int getStartLevel() {
        return startLevel;
    }

    public long getLastGainedXP() {
        return lastGainedXP;
    }

    public void reset() {
        this.startXp = 0;
        this.currentXp = 0;
    }

    public static String SecToHMS(int sec) {
        int min = sec / 60;
        sec %= 60;
        int hour = min / 60;
        min %= 60;
        return "" + hour + ":" + min + ":" + sec;
    }

}

SkillTracker.java

public class SkillTracker {

    private Script s;
    private Map<Skill, SkillWrapper> skills;

    public SkillTracker(Script s, Skill... skills) {
        this.s = s;
        this.skills = new HashMap<Skill, SkillWrapper>();
        for (Skill s1 : Skill.values()) {
            add(s1);
        }
        for(Skill s1 : skills) {
            if(this.skills.containsKey(s1)) {
                getWrapper(s1).keep = true;
            }
        }
    }

    public void updateAll() {
        for (Map.Entry<Skill, SkillWrapper> m : skills.entrySet()) {
            update(m.getKey());
        }
    }

    public void update(Skill skill) {
        if (skills.containsKey(skill)) {
            getWrapper(skill).setCurrentXp(s.client.getSkills().getExperience(skill));
        }
    }

    public void add(Skill skill) {
        if (!skills.containsKey(skill)) {
            skills.put(skill, new SkillWrapper(s.client.getSkills().getExperience(skill), 0, s.client.getSkills().getLevel(skill)));
            update(skill);
        }

    }

    public void remove(Skill skill) {
        if (skills.containsKey(skill)) {
            getWrapper(skill).reset();
            skills.remove(skill);
        }
    }

    public SkillWrapper getWrapper(Skill skill) {
        return skills.get(skill);
    }

    public Map<Skill, SkillWrapper> getSkills() {
        return skills;
    }
}

SkillTrackerPaint.java

public class SkillTrackerPaint  {

    private Script s;
    private SkillTracker tracker;

    public static final int[] XP_TABLE = {0, 0, 83, 174, 276, 388, 512, 650,
            801, 969, 1154, 1358, 1584, 1833, 2107, 2411, 2746, 3115, 3523,
            3973, 4470, 5018, 5624, 6291, 7028, 7842, 8740, 9730, 10824, 12031,
            13363, 14833, 16456, 18247, 20224, 22406, 24815, 27473, 30408,
            33648, 37224, 41171, 45529, 50339, 55649, 61512, 67983, 75127,
            83014, 91721, 101333, 111945, 123660, 136594, 150872, 166636,
            184040, 203254, 224466, 247886, 273742, 302288, 333804, 368599,
            407015, 449428, 496254, 547953, 605032, 668051, 737627, 814445,
            899257, 992895, 1096278, 1210421, 1336443, 1475581, 1629200,
            1798808, 1986068, 2192818, 2421087, 2673114, 2951373, 3258594,
            3597792, 3972294, 4385776, 4842295, 5346332, 5902831, 6517253,
            7195629, 7944614, 8771558, 9684577, 10692629, 11805606, 13034431
    };

    private Color MAIN_BOX;
    private Color MAIN_REFLECTION;

    private Color HOVER_RECT;

    private final Font ARIAL_9 = new Font("Arial", 0, 9);
    private final Font ARIAL_12 = new Font("Arial", 0, 12);

    private Color MAIN_COLOR = null;
    private Color MAIN_TRIM = null;
    private Color FONT_COLOR;

    private Rectangle hover;

    public SkillTrackerPaint(Script s, Skill... skills) {
        this.s = s;
        tracker = new SkillTracker(this.s, skills);
    }

    public void paint(Graphics g) {
        if (!tracker.getSkills().isEmpty()) {
            tracker.updateAll();
            int y = 3;
            for (Map.Entry<Skill, SkillWrapper> entry : tracker.getSkills().entrySet()) {
                long lastGainedXP = entry.getValue().getLastGainedXP();
                int alpha = 255;
                if (System.currentTimeMillis() - lastGainedXP < 30000 || entry.getValue().keep) {
                    if (System.currentTimeMillis() - lastGainedXP >= 29000 && !entry.getValue().keep) {
                        long timeLeft = 30000 - (System.currentTimeMillis() - lastGainedXP); //0-5000
                        alpha = (int) (255D * (timeLeft / 1000D));
                    }
                    drawBar(g, y, entry.getKey(), alpha);
                    hover = new Rectangle(345, y, 166, 20);
                    if (NNScript.mousePosition != null)
                        if (hover.contains(NNScript.mousePosition))
                            drawHover(g, y, entry.getKey());
                    y += 21;
                }
            }
        }
    }

    private void drawBar(Graphics g1, int y, Skill s, int alpha) {
        Graphics2D g = (Graphics2D) g1;
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        Color mCol = new Color(Colors.forSkill(s).getColor());
        MAIN_COLOR = new Color(mCol.getRed(), mCol.getGreen(), mCol.getBlue(), alpha);

        Color tCol = new Color(Colors.forSkill(s).getTrim());
        MAIN_TRIM = new Color(tCol.getRed(), tCol.getGreen(), tCol.getBlue(), alpha);

        MAIN_BOX = new Color(0, 0, 0, alpha - 55 > 0 ? alpha - 55 : 0);
        MAIN_REFLECTION = new Color(255, 255, 255, alpha - 205 > 0 ? alpha - 205 : 0);
        HOVER_RECT = new Color(0, 0, 0, alpha - 104 > 0 ? alpha - 104 : 0);
        FONT_COLOR = new Color(255, 255, 255, alpha);

        g.setColor(MAIN_BOX);
        g.fillRect(4 + 346, y, 166, 20);
        g.setColor(MAIN_COLOR);
        g.fillRect(4 + 429, y + 2, 80, 15);
        g.setColor(MAIN_TRIM);
        g.setStroke(new BasicStroke(2));
        g.drawRect(4 + 429, y + 2, 80, 15);
        g.fillRect(4 + 429, y + 2, (int) (getPercentToNextLevel(s) * 0.81), 14);
        g.drawRect(4 + 429, y + 2, (int) (getPercentToNextLevel(s) * 0.81), 14);
        g.setColor(MAIN_REFLECTION);
        g.fillRect(4 + 429, y + 2, 80, 9);
        g.setFont(ARIAL_12);
        g.setColor(FONT_COLOR);
        g.drawString(s.toString(), 4 + 348, y + 14);
        g.setFont(ARIAL_9);
        g.drawString(getPercentToNextLevel(s) + "% to level", 4 + 442, y + 13);
    }

    private void drawHover(Graphics g1, int y, Skill s) {
        Graphics2D g = (Graphics2D) g1;
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        g.setStroke(new BasicStroke(2));
        g.setColor(MAIN_TRIM);
        g.drawPolygon(new Polygon(new int[]{335 + 185, 335 + 180, 335 + 185}, new int[]{y + 2, y + 10, y + 20}, 3));
        g.setColor(HOVER_RECT);
        g.fill(new Polygon(new int[]{335 + 185, 335 + 180, 335 + 185}, new int[]{y + 2, y + 10, y + 20}, 3));
        if (y >= (505 - 90))
            y = 505 - 90;
        g.setColor(MAIN_TRIM);
        g.drawRect(335 + 185, y, 131, 85);
        g.setColor(MAIN_COLOR);
        g.fillRect(335 + 185, y, 131, 85);
        g.setColor(FONT_COLOR);
        g.setFont(ARIAL_9);
        g.drawString("Current level: " + this.s.client.getSkills().getLevel(s), 335 + 189, y + 14);
        g.drawString("Gained levels: " + (this.s.client.getSkills().getLevel(s) - tracker.getWrapper(s).getStartLevel()), 335 + 189, y + 25);
        g.drawString("Current xp: " + this.s.client.getSkills().getExperience(s), 335 + 189, y + 36);
        g.drawString("Gained xp: " + tracker.getWrapper(s).getGainedXp(), 335 + 189, y + 47);
        g.drawString("XP TNL: " + getExpToNextLevel(s), 335 + 189, y + 58);
        g.drawString("XP/Hour: " + tracker.getWrapper(s).getHourlyGains(), 335 + 189, y + 69);
        g.drawString("Time TNL: " + SkillWrapper.SecToHMS(tracker.getWrapper(s).getSecTNL(getExpToNextLevel(s))), 335 + 189, y + 80);
    }

    public int getPercentToNextLevel(final Skill skill) {
        final int lvl = s.client.getSkills().getLevel(skill);
        if (lvl == 99) {
            return 0;
        }
        final int xpTotal = XP_TABLE[lvl + 1] - XP_TABLE[lvl];
        if (xpTotal == 0) {
            return 0;
        }
        final int xpDone = s.client.getSkills().getExperience(skill) - XP_TABLE[lvl];
        return 100 * xpDone / xpTotal;
    }

    public int getExpToNextLevel(final Skill skill) {
        final int lvl = s.client.getSkills().getLevel(skill);
        if (lvl == 99) {
            return 0;
        }
        return XP_TABLE[lvl + 1] - s.client.getSkills().getExperience(skill);
    }

    enum Colors {
        AGILITY(Skill.AGILITY, 0x1f215b, 0x6b1f1a),
        ATTACK(Skill.ATTACK, 0x6b1f1a, 0x98931b),
        CONSTRUCTION(Skill.CONSTRUCTION, 0x8b816f, 0x945819),
        COOKING(Skill.COOKING, 0x451f44, 0x5c1406),
        CRAFTING(Skill.CRAFTING, 0x6d533c, 0x6d533c),
        DEFENCE(Skill.DEFENCE, 0x6375b0, 0xc1b9b8),
        FARMING(Skill.FARMING, 0x214b23, 0x6c8649),
        FIREMAKING(Skill.FIREMAKING, 0xa24508, 0xb29a06),
        FISHING(Skill.FISHING, 0x687a88, 0xa69718),
        FLETCHING(Skill.FLETCHING, 0x02272f, 0xa46108),
        HERBLORE(Skill.HERBLORE, 0x085a0d, 0x989428),
        HITPOINTS(Skill.HITPOINTS, 0xb2b0a6, 0xa12111),
        HUNTER(Skill.HUNTER, 0x454135, 0x150f0f),
        MAGIC(Skill.MAGIC, 0x6a6964, 0x191f6d),
        MINING(Skill.MINING, 0x322f1e, 0x548faf),
        PRAYER(Skill.PRAYER, 0xbdb3b3, 0xbe8f18),
        RANGED(Skill.RANGED, 0x4d6317, 0x7c4728),
        RUNECRAFTING(Skill.RUNECRAFTING, 0xa2a196, 0xcdb317),
        SLAYER(Skill.SLAYER, 0x1f1c1c, 0x6f170d),
        SMITHING(Skill.SMITHING, 0x494939, 0xcdb317),
        STRENGTH(Skill.STRENGTH, 0x086844, 0xa12111),
        THIEVING(Skill.THIEVING, 0x6a3b5a, 0x383333),
        WOORDCUTTING(Skill.WOODCUTTING, 0x826a3b, 0x2d6541);

        private Colors(Skill skill, int color, int trim) {
            this.skill = skill;
            this.color = color;
            this.trim = trim;
        }

        public static Colors forSkill(Skill skill) {
            for (Colors c : Colors.values()) {
                if (c.getSkill() == skill)
                    return c;
            }
            return null;
        }

        int getTrim() {
            return trim;
        }

        Skill getSkill() {
            return skill;
        }

        int getColor() {
            return color;
        }

        private Skill skill;
        private int color;
        private int trim;
    }

}

How to use:

 

In your main class, add:

    private Skill[] skills = null;
    private SkillTrackerPaint stPaint = null;

    public static long startTime;
    public static Point mousePosition;

onStart method, add:

skills = {Skills.ATTACK.. etc}
//to make it always display the progress of those skills and not fade after 20 secs
 if (skills != null && skills.length > 0)
            stPaint = new SkillTrackerPaint(this, skills);

onPaint method, add:

 if (stPaint != null) {
            stPaint.paint(g);
        }

mouseMoved method, add:

        mousePosition = a.getPoint();

Final results(skills.add(Skills.values())wink.png

Rchi6pd.png

 

Credits:

Gandalf

Cory

Edited by Gandalf
  • Like 1
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...