Index

XPCalculator

MMO\rpg\xp · 1 symbol · generated 5 Oct 2026

class

XPCalculator

XPCalculator.php:12

Ties an objective's configuration (curve type + params, level cap, tiers) to the design doc's formulas: level cost, cumulative XP, starting level from a 0-1 skill score, and per-action XP with streak / diminishing- returns handling.

class MMO\rpg\xp\XPCalculator
Namespace
MMO\rpg\xp
See
docs/XP system.md

Index

config
actionXp($params)XP_action = xpBase * quantity * difficulty * streakMultiplier * diminishingFactor streakMultiplier = min(1 + 0.05 * streakDays, 2.0) diminishingFactor = 1 / (1 + 0.5 * sameDayRepeats)
applyInactivityDecay($totalXp, $inactiveDays, $graceDays, $halfLifeDays, $floorXp)Inactivity decay — the practical counterpart to the Regression curve.
cumulativeXp($n)
defaultTiers() static
levelFromTotalXp($totalXp, $lMax)Resolve a total XP total into current level / progress into the next level.
levelTable($lMax)Full level-by-level table from 1 to $lMax, with tier labels.
startingLevel($skillScore, $lMax)L_start = round(S * L_max), S in [0,1].
tierForLevel($level, $lMax)
xpForLevel($n)
__construct($config)

Properties1

config

protected array $config
Type
array

Methods10

actionXp($params)

XPCalculator.php:110

XP_action = xpBase * quantity * difficulty * streakMultiplier * diminishingFactor streakMultiplier = min(1 + 0.05 * streakDays, 2.0) diminishingFactor = 1 / (1 + 0.5 * sameDayRepeats)

function actionXp(array $params): float
$paramsarray
returnsfloat

applyInactivityDecay($totalXp, $inactiveDays, $graceDays, $halfLifeDays, $floorXp)

XPCalculator.php:141

Inactivity decay — the practical counterpart to the Regression curve.

function applyInactivityDecay( float $totalXp, int $inactiveDays, int $graceDays, float $halfLifeDays, float $floorXp = 0.0 ): floatModels real backsliding: skill/streak progress erodes the longer an objective goes untouched, following the Ebbinghaus forgetting-curve shape (a half-life decay), not a cliff-edge reset. xpAfter = floor + (xpBefore - floor) * 0.5 ^ (effectiveInactiveDays / halfLifeDays) effectiveInactiveDays = max(0, inactiveDays - graceDays) graceDays: no decay at all within this many inactive days (a short break shouldn't cost you anything). halfLifeDays: after the grace period, how many days of continued inactivity it takes to lose half the XP above the floor. Smaller = more punishing regression; larger = more forgiving. floorXp: XP never decays below this (e.g. the cumulative XP of level 1, so a lapse can knock you down levels but never all the way to zero).
$totalXpfloat
$inactiveDaysint
$graceDaysint
$halfLifeDaysfloat
$floorXp = 0.0float
returnsfloat

levelFromTotalXp($totalXp, $lMax)

XPCalculator.php:77

Resolve a total XP total into current level / progress into the next level.

function levelFromTotalXp(float $totalXp, int $lMax): array
$totalXpfloat
$lMaxint
returnsarray

levelTable($lMax)

XPCalculator.php:33

Full level-by-level table from 1 to $lMax, with tier labels.

function levelTable(int $lMax): array
$lMaxint
returnsarray

startingLevel($skillScore, $lMax)

XPCalculator.php:71

L_start = round(S * L_max), S in [0,1].

function startingLevel(float $skillScore, int $lMax): int
$skillScorefloat
$lMaxint
returnsint