Merge pull request #262 from SomeoneWithAnInternetConnection/XPOrb-tooltip-exception-fix

Fix IllegalArgumentExceptions from XPGlobes' tooltips for level 1 stats
This commit is contained in:
Adam
2017-12-16 16:25:09 -05:00
committed by GitHub
2 changed files with 24 additions and 9 deletions

View File

@@ -39,29 +39,29 @@ public class Experience
for (int level = 1; level <= MAX_VIRT_LEVEL; ++level)
{
XP_FOR_LEVEL[level - 1] = xp / 4;
int difference = (int) ((double) level + 300.0 * Math.pow(2.0, (double) level / 7.0));
xp += difference;
XP_FOR_LEVEL[level - 1] = xp / 4;
}
}
public static int getXpForLevel(int level)
{
if (level < 2 || level > MAX_VIRT_LEVEL)
if (level < 1 || level > MAX_VIRT_LEVEL)
{
throw new IllegalArgumentException();
throw new IllegalArgumentException(level + " is not a valid level");
}
// XP_FOR_LEVEL[0] is XP for level 2
return XP_FOR_LEVEL[level - 2];
// XP_FOR_LEVEL[0] is XP for level 1
return XP_FOR_LEVEL[level - 1];
}
public static int getLevelForXp(int xp)
{
if (xp < 0)
{
throw new IllegalArgumentException();
throw new IllegalArgumentException("XP must not be negative");
}
int low = 0;
@@ -82,11 +82,11 @@ public class Experience
}
else
{
break;
return mid + 1;
}
}
return high + 2;
return high + 1;
}
public static double getCombatLevelPrecise(int attackLevel, int strengthLevel,

View File

@@ -36,6 +36,21 @@ public class ExperienceTest
{
int xp = Experience.getXpForLevel(99);
Assert.assertEquals(XP_FOR_99, xp);
xp = Experience.getXpForLevel(1);
Assert.assertEquals(0, xp);
}
@Test(expected = IllegalArgumentException.class)
public void testGetXpForHighLevel()
{
int xp = Experience.getXpForLevel(Integer.MAX_VALUE);
}
@Test(expected = IllegalArgumentException.class)
public void testGetXpForLowLevel()
{
int xp = Experience.getXpForLevel(0);
}
@Test