Skip to content

Commit

Permalink
Merge pull request runelite#2271 from LeviSchuck/xp-negative
Browse files Browse the repository at this point in the history
Fix negative total XP calculation when skill starts
  • Loading branch information
Adam- authored May 3, 2018
2 parents 57e5010 + 274e045 commit c4b71f3
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ private int toHourly(int value)
return 0;
}

long timeElapsedInSeconds = Duration.between(skillTimeStart, Instant.now()).getSeconds();
// If the skill started just now, we can divide by near zero, this results in odd behavior.
// To prevent that, pretend the skill has been active for a minute (60 seconds)
// This will create a lower estimate for the first minute,
// but it isn't ridiculous like saying 2 billion XP per hour.
long timeElapsedInSeconds = Math.max(60, Duration.between(skillTimeStart, Instant.now()).getSeconds());
return (int) ((1.0 / (timeElapsedInSeconds / 3600.0)) * value);
}

Expand Down

0 comments on commit c4b71f3

Please sign in to comment.