Class DefaultExperienceCalculator
- All Implemented Interfaces:
ExperienceCalculator
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoublegetExpByLevel(Pet pet, int level) Calculates the cumulative experience required to reach the given level.Returns a unique identifier for this calculator (e.g.longReturns a version number representing the current revision of this calculator's formula.booleanisUsable()Indicates whether this calculator is ready to produce results.
-
Constructor Details
-
DefaultExperienceCalculator
public DefaultExperienceCalculator()Creates the curve MyPet ships with.
-
-
Method Details
-
getExpByLevel
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 tolevel - 1, where each increment is7 + floor((currentLevel - 1) * 3.5).- Specified by:
getExpByLevelin interfaceExperienceCalculator- 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
ExperienceCachecan detect staleness and recalculate. Returns1-- the formula has never changed.- Specified by:
getVersionin interfaceExperienceCalculator- 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:
isUsablein interfaceExperienceCalculator- Returns:
trueifExperienceCalculator.getExpByLevel(de.Keyle.MyPet.api.entity.Pet, int)can be called safely
-
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:
getIdentifierin interfaceExperienceCalculator- Returns:
- this calculator's unique identifier
-