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. 
This commit is contained in:
@@ -54,11 +54,6 @@ class XpStateSingle
|
|||||||
return toHourly(xpGained);
|
return toHourly(xpGained);
|
||||||
}
|
}
|
||||||
|
|
||||||
int getXpSec()
|
|
||||||
{
|
|
||||||
return getXpHr() / 3600;
|
|
||||||
}
|
|
||||||
|
|
||||||
int getActionsHr()
|
int getActionsHr()
|
||||||
{
|
{
|
||||||
return toHourly(actions);
|
return toHourly(actions);
|
||||||
@@ -71,12 +66,21 @@ class XpStateSingle
|
|||||||
return 0;
|
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.
|
// 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)
|
// To prevent that, pretend the skill has been active for a minute (60 seconds)
|
||||||
// This will create a lower estimate for the first minute,
|
// This will create a lower estimate for the first minute,
|
||||||
// but it isn't ridiculous like saying 2 billion XP per hour.
|
// but it isn't ridiculous like saying 2 billion XP per hour.
|
||||||
long timeElapsedInSeconds = Math.max(60, Duration.between(skillTimeStart, Instant.now()).getSeconds());
|
return Math.max(60, Duration.between(skillTimeStart, Instant.now()).getSeconds());
|
||||||
return (int) ((1.0 / (timeElapsedInSeconds / 3600.0)) * value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int getXpRemaining()
|
int getXpRemaining()
|
||||||
@@ -120,10 +124,14 @@ class XpStateSingle
|
|||||||
|
|
||||||
String getTimeTillLevel()
|
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";
|
return "\u221e";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user