ExperienceManager (was ExperienceUtils) - make giving/taking exp a bit more intuitive

Discussion in 'Resources' started by desht, Jan 13, 2012.

Thread Status:
Not open for further replies.
  1. Offline


    I've just pushed an update to this which changes the way some of the calculations are done; it should resolve the problem reported by KodekPL a few months back (sorry it took so long!).

    I've done some testing using ScrollingMenuSign (with the $x,<n> command cost) and all seems to be behaving well at various experience levels.
  2. Offline


    Awesome, I'll have to update my version.
  3. Offline


    If I manipulate the lookup table, would it change how many exp points are needed to reach a level or would it just mess with the calculations?
    I basicly want to make sure that there is wayyyy more exp needed to reach the next level (like a day of work = 1 level) for a more RPGy exp system
  4. Offline


    You should handle the PlayerExpChangeEvent, and scale down the amount of experience awarded (like a flat 50% decrease). That would effectively increase the amount of experience needed to level up by 100%. You can even use a different scaling depending on the current level, and replicate the old 1.2.5 experience system.

    As for ExperienceManager, changing the lookup table and formula should work. Although, it might be simpler to just scale down the amount of experience awarded here as well, especially if you rarely reward a large sum of experience.

    EDIT: 200% is 3 times as much, not double.
  5. Offline


    scaling down at PlayerExpChangeEvent is int, therefor it would probably scale down to zero if I apply *0.1 (10%).

    I will take a look, thanks ;)
  6. Offline


    That would be a problem, yes. One approach might be to store a (floating-point) buffer of pending experience in your listener - the fractional amount that is "owed" to the player. The listener would look like this (untested code):
    private final Map<String,FloatpendingExp = new HashMap<String,Float>();
    public void onExpChange(PlayerExpChangeEvent event) {
    String name event.getPlayer().getName();
    float owed pendingExp.containsKey(name) ? pendingExp.get(name) : 0.0f;
    owed += event.getAmount() / 10.0f;  // adjust divisor to suit here;
    int intPart = (int) owed;
    pendingExp.put(nameowed intPart);
    To illustrate, assume a divisor of 10.0, and player is killing mobs worth 4xp each:
    • kill mob #1 - get 0.4 exp - player gets 0xp, is owed 0.4xp
    • kill mob #2 - get 0.4 exp - player gets 0xp, is owed 0.8xp
    • kill mob #3 - get 0.4 exp - now the player is owed 1.2xp, so give him 1xp, and owe him 0.2xp
    Tracking the XP deficit across server restarts would be a little more work, but given that the running deficit is always less than 1xp, you might get away with ignoring that bit :)
    MTN likes this.
  7. Offline


    True, but you can award fractional experience through ExperienceManager.

    This is how I do it in ExperienceMod (GitHub):
    1. // We can't give fractional values with ordinary experience orbs, but we can approximate it
    2. double exact = event.getAmount() * factor;
    3. int oldXP = event.getAmount();
    4. int newXP = (int) exact;
    6. event.setAmount(newXP);
    8. // Give the last fraction
    9. if (exact > newXP) {
    10. manager.changeExp(exact - newXP); // ExperienceManager
    11. }
    MTN and desht like this.
  8. Offline


    I thought about it and basicly wanted to find a cooler way. But hey, sometimes...
    Thanks guys!
Thread Status:
Not open for further replies.

Share This Page