Skip to content

Commit

Permalink
fix: calculate XP points properly than use getTotalExperience
Browse files Browse the repository at this point in the history
  • Loading branch information
Thatsmusic99 committed Jun 14, 2023
1 parent 52dcabc commit 7437cd2
Showing 1 changed file with 17 additions and 12 deletions.
Expand Up @@ -34,7 +34,11 @@ public void addLevels(LevelsPayment levels) {

@Override
public double getPlayerAmount(Player player) {
return player.getTotalExperience();

// Get the XP that the player is on according to their level
int xpLevels = getEXPBetweenLevels(player.getLevel());
int totalXPinLevel = expInLevel(player.getLevel());
return xpLevels + totalXPinLevel - player.getExpToLevel();
}

@Override
Expand All @@ -48,7 +52,7 @@ public boolean canPay(Player player) {
int expPoints = getEXPBetweenLevels(player.getLevel());
requiredPoints += expPoints;
}
if (player.getTotalExperience() >= requiredPoints) {
if (getPlayerAmount(player) >= requiredPoints) {
return true;
} else {
CustomMessages.sendMessage(player, "Error.notEnoughEXPPoints", "{points}", String.valueOf(requiredPoints));
Expand Down Expand Up @@ -82,17 +86,18 @@ protected int getEXPBetweenLevels(int startingLevel) {
// Next, we need to calculate the amount of EXP points to deduct.
// Let's remove 1 off the current level each time.
for (int i = 0; i < levels.getPaymentAmount(); i++) {
// Get the resulting level.
int level = startingLevel - i - 1;
// If the level is 0-15:
if (level < 16) {
expPoints += 2 * level + 7;
} else if (level < 31) {
expPoints += 5 * level - 38;
} else {
expPoints += 9 * level - 158;
}
expPoints += expInLevel(startingLevel - i - 1);
}
return expPoints;
}

protected int expInLevel(int currentLevel) {
if (currentLevel < 16) {
return 2 * currentLevel + 7;
} else if (currentLevel < 31) {
return 5 * currentLevel - 38;
} else {
return 9 * currentLevel - 158;
}
}
}

0 comments on commit 7437cd2

Please sign in to comment.