Skip to content

Commit

Permalink
Add methods for calculating XP difference between two levels
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed May 16, 2024
1 parent c7a4b5b commit 411a25f
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/games/stendhal/common/Level.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* $Id$ */
/***************************************************************************
* (C) Copyright 2003 - Marauroa *
* (C) Copyright 2003-2024 - Marauroa *
***************************************************************************
***************************************************************************
* *
Expand Down Expand Up @@ -132,6 +132,39 @@ public static int getXP(final int level) {
return -1;
}

/**
* Calculates the XP difference between two levels.
*
* @param start
* Starting level.
* @param target
* Target level.
* @return
* Amount of XP needed from {@code first} to {@code second}.
*/
public static int getXPDiff(final int start, final int target) {
if (target > start) {
final int xpStart = Level.getXP(start);
final int xpTarget = Level.getXP(target);
if (xpStart > -1 && xpTarget > xpStart) {
return xpTarget - xpStart;
}
}
return 0;
}

/**
* Calculates the XP difference from one level to the next.
*
* @param level
* Starting level.
* @return
* Amount of XP needed from {@code level} to the next.
*/
public static int getXPDiff(final int level) {
return Level.getXPDiff(level, level+1);
}

/**
* Calculates how many levels to add when a certain amount of experience is
* added.
Expand Down

0 comments on commit 411a25f

Please sign in to comment.