mwg API
    Preparing search index...

    Function battleOrder

    • Turn order by speed, with move priority overriding it - one round's worth of ordering, not a persistent queue. mwg/roguelike's Scheduler already covers continuous energy-cost time for a dungeon; a battle round picks everyone's action first and then needs only this, a single stable sort.

      Type Parameters

      • A extends { priority?: number; speed: number }

      Parameters

      • actions: readonly A[]

      Returns A[]

      import { battleOrder, type BattleAction } from '@datamoc/mw_games/battle';

      const actions: BattleAction<string>[] = [
      { actor: 'hero', speed: 12 },
      { actor: 'wolf', speed: 18 },
      { actor: 'hero-item', speed: 12, priority: 1 }, // items go first regardless of speed
      ];

      const order = battleOrder(actions).map((a) => a.actor); // ['hero-item', 'wolf', 'hero']