mwg API
    Preparing search index...

    Function assignTraits

    • Draws count distinct traits at random from pool and applies their modifiers to stats permanently - no clock, no trigger, nothing removes them automatically. Each trait gets its own source symbol so a game that genuinely needs to strip one later still can, via StatBlock.removeModifiersFrom, even though nothing here ever calls that itself.

      Parameters

      • stats: StatBlock
      • pool: readonly TraitDef[]
      • count: number

        clamped to pool.length - asking for more traits than exist in the pool assigns every one of them rather than throwing

      Returns AssignedTrait[]

      import { assignTraits, StatBlock, type TraitDef } from '@datamoc/mw_games/actors';

      const stats = new StatBlock({ base: { strength: 10, speed: 10 } });
      const pool: TraitDef[] = [
      { name: 'strong', modifiers: [{ stat: 'strength', op: 'add', value: 3 }] },
      { name: 'fast', modifiers: [{ stat: 'speed', op: 'add', value: 3 }] },
      ];

      const assigned = assignTraits(stats, pool, 1); // one random trait, applied permanently
      console.log(assigned[0].trait.name);