From 411a25fceaeb3503b8eea06c9dd18b17057b7302 Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Thu, 2 May 2024 21:37:02 -0700 Subject: [PATCH] Add methods for calculating XP difference between two levels --- src/games/stendhal/common/Level.java | 35 +++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/games/stendhal/common/Level.java b/src/games/stendhal/common/Level.java index e7e770f86ef..9a079fc8b41 100644 --- a/src/games/stendhal/common/Level.java +++ b/src/games/stendhal/common/Level.java @@ -1,6 +1,6 @@ /* $Id$ */ /*************************************************************************** - * (C) Copyright 2003 - Marauroa * + * (C) Copyright 2003-2024 - Marauroa * *************************************************************************** *************************************************************************** * * @@ -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.