mwg API
    Preparing search index...

    Class AttackPreview

    The numbers an attack dialog shows and animates: the attacker and defender's hp over the course of a blow, plus the totals the labels print.

    It deliberately computes no damage of its own - this framework supplies no damage formula, so a game hands in the per-strike damage exactly as its own rules worked it out. What the preview adds is the part a dialog needs and a formula does not: the timeline (one frame per strike, sampleAt the animation's own clock) and the two totals (the maximum, damage * strikes, and the expected value once chanceToHit is weighed). Which strikes actually land is hits, so a preview can show the maximum by default or a known outcome a replay already rolled.

    import { AttackPreview } from '@datamoc/mw_games/battle';

    const preview = new AttackPreview({
    attacker: { hp: 20 },
    defender: { hp: 12 },
    damage: 4,
    strikes: 3,
    chanceToHit: 0.6,
    strikeDuration: 0.2,
    });
    console.log(preview.totalDamage); // 12
    console.log(preview.sampleAt(0.25).defenderHp); // 8, after the second strike
    Index
    chanceToHit: number
    expectedDamage: number
    frames: readonly AttackFrame[]
    totalDamage: number
    • get defenderKilled(): boolean

      whether the defender would be at 0 hp once every landing strike has been shown

      Returns boolean