mwg API
    Preparing search index...

    Class SkillPoints

    The seam StatBlock and Progression never had: a levelling curve already tells a game how many levels it just gained, and a stat block already holds any named stat a game invents - lockpicking exactly as well as strength - but nothing turns "gained a level" into "has a point to spend", or spends one with the usual rules a skill spend wants (a cap, a cost that rises the more of a stat is already bought).

    Deliberately not a wrapper around Progression itself: a game grants points from levelling (grant(levelsGained) after Progression.addExperience returns a positive number), from a quest reward, from a trainer NPC, or all three - this only tracks the ledger and the spend rule, the same way skillCheck is a dice roll and nothing about who is rolling it.

    import { SkillPoints, StatBlock } from '@datamoc/mw_games/actors';

    const stats = new StatBlock({ base: { lockpicking: 0 } });
    const points = new SkillPoints(stats, { cap: () => 10, cost: (_stat, rank) => rank });

    points.grant(3); // e.g. after Progression.addExperience returned levelsGained
    if (points.canSpend('lockpicking')) points.spend('lockpicking');

    console.log(stats.base('lockpicking'), points.points);
    Index
    • whether stat could be raised one more rank right now - affordable, and under its cap

      Parameters

      • stat: string

      Returns boolean

    • adds points to the ledger - typically levels gained times however many a level grants

      Parameters

      • points: number

      Returns void

    • Raises stat's base value by one rank, spending whatever that rank costs.

      Parameters

      • stat: string

      Returns boolean

      false, spending nothing, if the rank is capped or not affordable

    • The unspent ledger, and only that.

      Spent points are already saved: spend raises a stat's base value on the StatBlock, so restoring that block restores every rank ever bought. Recording them a second time here would be state kept in two places, which is exactly the kind of pair that drifts the first time one path forgets to update the other.

      Returns { points: number }