Jump to content

having issues calculating EXP per hour


Recommended Posts

Posted (edited)

Currently using this equation with my logic being that 60 minutes / time elapsed * experienced gained will equate to the correct experience per hour and in my script i use this equation to represent that

    public void onStart() {
        startingStrengthEXP = getSkills().getExperience(Skill.STRENGTH);
        startTime = System.currentTimeMillis();
        }

int currentStrengthEXP = getSkills().getExperience(Skill.STRENGTH);
final long runTime = System.currentTimeMillis() - startTime;
(3600000 / runTime) * (currentStrengthEXP-startingStrengthEXP)

and this works up until about the first 15 minutes and i notice the math starts to go under and it becomes very obvious at 20 minutes were i was able to do the math in my head and know that it was 50% what the correct amount of experience per hour should be. Is there an issue with how I'm calculating the run time or is there a better way to calculate experience per hour? thanks :) the calculation code is in my onpaint() if that makes any difference. another thing after about 30 minutes it seems to just equal a 1:1 ratio where exp per hour is = to strength gained

Edited by vladbuff
Posted (edited)

I've realized the error is with how java divides ints normally in that it throws away the quotient and rounds.

after changing my code to do the division without throwing away the quotient and it rounds the final number so the exp per hour doesn't have a decimal seems to be working for now.

    public void onStart() {
        startingStrengthEXP = getSkills().getExperience(Skill.STRENGTH);
        startTime = System.currentTimeMillis();
        }

int currentStrengthEXP = getSkills().getExperience(Skill.STRENGTH);
final long runTime = System.currentTimeMillis() - startTime;
double actualQuotient = (double)3600000 / runTime;
Math.round(actualQuotient) * (currentStrengthEXP-startingStrengthEXP)

 

Edited by vladbuff
Posted
2 hours ago, vladbuff said:

I've realized the error is with how java divides ints normally in that it throws away the quotient and rounds.

after changing my code to do the division without throwing away the quotient and it rounds the final number so the exp per hour doesn't have a decimal seems to be working for now.

    public void onStart() {
        startingStrengthEXP = getSkills().getExperience(Skill.STRENGTH);
        startTime = System.currentTimeMillis();
        }

int currentStrengthEXP = getSkills().getExperience(Skill.STRENGTH);
final long runTime = System.currentTimeMillis() - startTime;
double actualQuotient = (double)3600000 / runTime;
Math.round(actualQuotient) * (currentStrengthEXP-startingStrengthEXP)

 

This is the method I have on my Timer class

    public int getPerHour(int value) {
        return (int) (value * 3600000d / (System.currentTimeMillis() - start));
    }

About the same as you have, except for the fact I multiply first instead of diving so there are no rounding errors :)

  • Like 1
Posted
11 hours ago, Khaleesi said:

This is the method I have on my Timer class

    public int getPerHour(int value) {
        return (int) (value * 3600000d / (System.currentTimeMillis() - start));
    }

About the same as you have, except for the fact I multiply first instead of diving so there are no rounding errors :)

Really appreciate this as i was still getting rounding errors at 1hour+ with my new method currently testing yours right now !

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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