mwg API
    Preparing search index...

    Class BossPhases

    A phased boss fight: HP-fraction thresholds that fire enter-once hooks, plus a cooldown rotation for the boss's abilities.

    The shape every multi-stage boss shares, whether it teleports at half health, enrages at a third, or summons adds at each bracket: the fight is a ladder of phases entered top-down, and each turn the boss ticks its abilities and uses whatever is ready. mwg tracks the ladder and the timers; what a phase does (relocate, spawn, change the arena) and what an ability is stay the game's own code, fired from the hooks and picks this returns.

    import { BossPhases, AbilityCycle } from '@datamoc/mw_games/roguelike';

    const phases = new BossPhases([0.66, 0.33]); // three stages
    const entered = phases.check(0.3); // [1, 2] if a massive hit skipped straight past phase 1

    const abilities = new AbilityCycle({ slam: 3, roar: 5 });
    abilities.advance(1); // one turn of cooldowns ticking down
    if (abilities.ready().includes('slam')) abilities.use('slam');
    Index
    • Parameters

      • thresholds: readonly number[] = []

        HP fractions that open a new phase, highest first (e.g. [0.66, 0.33] for a three-stage fight) - descending order is required, since a lower bracket must never open before a higher one

      Returns BossPhases

    • get phase(): number

      which phase the fight is in: the count of thresholds at or above hpFraction

      Returns number

    • Moves the fight to whatever phase hpFraction belongs in.

      Parameters

      • hpFraction: number

      Returns number[]

      the newly entered phase indices, in order - empty when nothing changed, so a game fires each phase's enter-hook exactly once; a single massive hit can enter several at once, and all of them are reported

    • restarts the fight at phase 0, for a rematch or a reused boss object

      Returns void