Skip to content

Commit

Permalink
Fix off-by-one level bug in ExperienceHolderData.
Browse files Browse the repository at this point in the history
  • Loading branch information
JBYoshi committed Aug 5, 2017
1 parent 747ac2c commit b8cc78a
Showing 1 changed file with 7 additions and 5 deletions.
Expand Up @@ -136,14 +136,16 @@ public int getTotalExp() {
public void setTotalExp(int totalExp) {
this.totalExp = totalExp;
int level = 0;
for (int i = totalExp; i > 0; i -= ExperienceHolderUtils.getExpBetweenLevels(level)) {
level ++;
if (i - ExperienceHolderUtils.getExpBetweenLevels(level) <= 0) {
this.expSinceLevel = i;
this.expBetweenLevels = ExperienceHolderUtils.getExpBetweenLevels(level);
while (true) {
int expToNextLevel = ExperienceHolderUtils.getExpBetweenLevels(level);
if (totalExp < expToNextLevel) {
this.expSinceLevel = totalExp;
this.expBetweenLevels = expToNextLevel;
this.level = level;
break;
}
totalExp -= expToNextLevel;
level++;
}
}

Expand Down

0 comments on commit b8cc78a

Please sign in to comment.