Class DefaultExperienceCalculator

java.lang.Object
de.Keyle.MyPet.api.skill.experience.DefaultExperienceCalculator
All Implemented Interfaces:
ExperienceCalculator

public class DefaultExperienceCalculator extends Object implements ExperienceCalculator
The built-in experience calculator that ships with MyPet.

Uses a progressive formula where each level requires 7 + floor((level - 1) * 3.5) more experience than the previous one, producing a smoothly accelerating curve similar to vanilla Minecraft's XP requirements.

This calculator is always usable and serves as the fallback when no custom calculator is configured or when a custom calculator fails to load.

  • Constructor Details

    • DefaultExperienceCalculator

      public DefaultExperienceCalculator()
      Creates the curve MyPet ships with.
  • Method Details

    • getExpByLevel

      public double getExpByLevel(Pet pet, int level)
      Calculates the cumulative experience required to reach the given level.

      For level 1 or below, returns 0. For higher levels, sums the per-level increments from level 1 up to level - 1, where each increment is 7 + floor((currentLevel - 1) * 3.5).

      Specified by:
      getExpByLevel in interface ExperienceCalculator
      Parameters:
      pet - the pet whose level curve is being calculated (allows per-type curves)
      level - the target level (1-based; level 1 typically requires 0 experience)
      Returns:
      the total experience required to reach level
    • getVersion

      public long getVersion()
      Returns a version number representing the current revision of this calculator's formula.

      If the formula changes (for example, an admin edits the JavaScript source), the version must increment so the ExperienceCache can detect staleness and recalculate. Returns 1 -- the formula has never changed.

      Specified by:
      getVersion in interface ExperienceCalculator
      Returns:
      the formula's revision number
    • isUsable

      public boolean isUsable()
      Indicates whether this calculator is ready to produce results.

      A calculator might be unusable if, for example, its backing script failed to compile or a required dependency is missing. Always returns true; the default calculator has no external dependencies.

      Specified by:
      isUsable in interface ExperienceCalculator
      Returns:
      true if ExperienceCalculator.getExpByLevel(de.Keyle.MyPet.api.entity.Pet, int) can be called safely
    • getIdentifier

      public String getIdentifier()
      Returns a unique identifier for this calculator (e.g. "MyPet", "Power").

      Used alongside ExperienceCalculator.getVersion() to key the experience cache. Returns "MyPet", identifying this as the built-in calculator.

      Specified by:
      getIdentifier in interface ExperienceCalculator
      Returns:
      this calculator's unique identifier