Fix til next level time for low xp amounts

Cause:
Time til next level relied on xp per hour being divided by 3600
(seconds in an hour). For XP rates under 3600 per hour, this would
result in a divide by zero.

Solution:
Use floats and rely on an xp per second implementation that works on
seconds instead of hours.

It appears to work as expected.
![image](https://user-images.githubusercontent.com/245911/40274136-f8f61314-5b94-11e8-8d22-03b40b6108ff.png)
This commit is contained in:
Levi Schuck
2018-05-19 18:51:27 -05:00
parent 95d55608c1
commit d2440f9c66

View File

@@ -54,11 +54,6 @@ class XpStateSingle
return toHourly(xpGained);
}
int getXpSec()
{
return getXpHr() / 3600;
}
int getActionsHr()
{
return toHourly(actions);
@@ -71,12 +66,21 @@ class XpStateSingle
return 0;
}
return (int) ((1.0 / (getTimeElapsedInSeconds() / 3600.0)) * value);
}
private long getTimeElapsedInSeconds()
{
if (skillTimeStart == null)
{
return 0;
}
// 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);
return Math.max(60, Duration.between(skillTimeStart, Instant.now()).getSeconds());
}
int getXpRemaining()
@@ -120,10 +124,14 @@ class XpStateSingle
String getTimeTillLevel()
{
if (getXpSec() > 0)
float xpPerSecond = (float)xpGained / (float)getTimeElapsedInSeconds();
if (xpPerSecond > 0)
{
return LocalTime.MIN.plusSeconds( getXpRemaining() / getXpSec() ).toString();
float remainingSeconds = getXpRemaining() / xpPerSecond;
return LocalTime.MIN.plusSeconds((long)remainingSeconds).toString();
}
return "\u221e";
}