mwg API
    Preparing search index...

    Interface ResourceCost

    One spendable cost: amount of the stat pool, the way a spell costs mana.

    Costs operate on the stat's base value - the stored pool - not its modified total: a buff that raises maximum mana changes the ceiling, not what is left to spend. Restoring the pool is just stats.setBase; only spending needed a primitive of its own.

    import { canAfford, spend, refund, convertToCharges, StatBlock, Charges } from '@datamoc/mw_games/actors';

    const stats = new StatBlock({ base: { mana: 30 } });
    const cost = { stat: 'mana', amount: 10 };

    if (canAfford(stats, cost)) spend(stats, cost);
    refund(stats, cost, 0.5); // half the cost back, e.g. on a missed cast

    const battery = new Charges({ max: 5, regenRate: 10 });
    convertToCharges(stats, { stat: 'mana', amount: 20 }, battery, 5); // 20 mana -> 4 charges
    interface ResourceCost {
        amount: number;
        stat: string;
    }
    Index
    amount: number
    stat: string