Read current exp, instead of stored exp.

This means that exp used in enchanting is subtracted from total exp.
This commit is contained in:
KHobbits 2011-12-14 03:41:24 +00:00
parent 79861b1f10
commit 2202448cee
2 changed files with 23 additions and 6 deletions

View File

@ -81,7 +81,7 @@ public class Trade
}
if (exp != null && exp > 0
&& user.getTotalExperience() < exp) {
&& SetExpFix.getTotalExperience(user) < exp) {
throw new ChargeException(_("notEnoughExperience"));
}
}
@ -116,7 +116,7 @@ public class Trade
}
if (getExperience() != null)
{
SetExpFix.setTotalExperience(user, user.getTotalExperience() + getExperience());
SetExpFix.setTotalExperience(user, SetExpFix.getTotalExperience(user) + getExperience());
}
return success;
}
@ -155,7 +155,7 @@ public class Trade
}
if (getExperience() != null)
{
final int experience = user.getTotalExperience();
final int experience = SetExpFix.getTotalExperience(user);
if (experience < getExperience() && getExperience() > 0)
{
throw new ChargeException(_("notEnoughExperience"));

View File

@ -17,7 +17,7 @@ public class SetExpFix
int amount = exp;
while (amount > 0)
{
final int expToLevel = getExpTolevel(player);
final int expToLevel = getExpToLevel(player);
amount -= expToLevel;
if (amount >= 0)
{
@ -34,8 +34,25 @@ public class SetExpFix
}
}
private static int getExpTolevel(final Player player)
private static int getExpToLevel(final Player player)
{
return getExpToLevel(player.getLevel());
}
private static int getExpToLevel(final int level)
{
return 7 + (level * 7 >> 1);
}
public static int getTotalExperience(final Player player)
{
return 7 + (player.getLevel() * 7 >> 1);
int exp = (int) (getExpToLevel(player) * player.getExp());
int currentLevel = player.getLevel();
while (currentLevel > 0) {
currentLevel--;
exp += getExpToLevel(currentLevel);
}
return exp;
}
}