// Offensive metrics derived from the same composed equipment records used by // the forge table. Keep formulas here so future metrics share one data model. #import "../../chapters/craft/forge-data.typ": equipments #import "report_config.typ": weapon-settings #let weapon-nature-labels = ( Light: "Léger", Medium: "Moyen", Heavy: "Lourd", SuperHeavy: "Super-lourd", ) // The first success deals base damage. Each later success adds `p-damage`. #let damage-at-successes(base-damage, p-damage, successes) = if successes <= 0 { 0 } else { base-damage + (successes - 1) * p-damage } // Guard the core rule against regressions as the metric model grows. #assert.eq(damage-at-successes(8, 2, 5), 16) // A precision modifier is applied to the natural precision of 7. Each point // changes the success probability of one die by 10 percentage points. #let natural-precision = weapon-settings.natural_precision #let precision-die-sides = weapon-settings.die_sides #let success-probability(precision) = ( calc.max(0, calc.min(precision-die-sides, natural-precision + precision)) / precision-die-sides ) #let binomial-probability(dice, successes, probability) = ( calc.binom(dice, successes) * (if successes == 0 { 1 } else { calc.pow(probability, successes) }) * ( if dice == successes { 1 } else { calc.pow(1 - probability, dice - successes) } ) ) // Expected damage of one attack. Successes beyond R.Max still occur, but do // not increase damage and are therefore folded into the capped damage value. #let expected-attack-damage(base-damage, p-damage, rmax, dice, probability) = { range(0, dice + 1) .map(successes => ( binomial-probability(dice, successes, probability) * damage-at-successes(base-damage, p-damage, calc.min(successes, rmax)) )) .sum() } #assert.eq(expected-attack-damage(8, 2, 5, 1, 1), 8) #assert.eq(expected-attack-damage(8, 2, 5, 5, 1), 16) #let commitment-pools = weapon-settings.damage_scenarios.map(item => ( key: item.key, label: item.label, dice: item.dice, )) #let commitment-analysis( base-damage, p-damage, rmax, actions, dice, probability, ) = { let single = expected-attack-damage( base-damage, p-damage, rmax, dice, probability, ) let candidates = if actions == 1 and dice >= 2 { range(1, calc.floor(dice / 2) + 1).map(first => ( first: first, second: dice - first, damage: expected-attack-damage( base-damage, p-damage, rmax, first, probability, ) + expected-attack-damage( base-damage, p-damage, rmax, dice - first, probability, ), )) } else { () } let best-split = if candidates.len() == 0 { none } else { candidates.sorted(key: candidate => -candidate.damage).first() } let use-split = best-split != none and best-split.damage > single ( dice: dice, single: single, split: best-split, best: if use-split { best-split.damage } else { single }, strategy: if use-split { str(best-split.first) + "+" + str(best-split.second) } else { str(dice) }, attacks: if use-split { 2 } else { 1 }, ) } // Common entry point for generated equipment and heuristically extracted // attacks. `allow-chain` is false for channelled techniques. #let analyze-weapon-profile( name, base-damage, p-damage, rmax, precision: 0, actions: 1, allow-chain: true, armor-break: 0, armor-pierce: 0, armor-multiplier: 0, damage-multiplier: 1, source: none, ) = { let probability = success-probability(precision) let commitments = (:) for commitment in commitment-pools { let result = commitment-analysis( base-damage, p-damage, rmax, if allow-chain { actions } else { calc.max(2, actions) }, commitment.dice, probability, ) result.single *= damage-multiplier result.best *= damage-multiplier if result.split != none { result.split.damage *= damage-multiplier } commitments.insert(commitment.key, result) } ( name: name, base-damage: base-damage, p-damage: p-damage, precision: precision, effective-precision: natural-precision + precision, success-probability: probability, rmax: rmax, armor-break: armor-break, armor-pierce: armor-pierce, armor-multiplier: armor-multiplier, actions: actions, allow-chain: allow-chain, damage-multiplier: damage-multiplier, max-damage: damage-at-successes(base-damage, p-damage, rmax) * damage-multiplier, commitments: commitments, source: source, ) } #let analyze-weapon(item) = { let actions = calc.max(1, item.action_cost) let capped-damage = damage-at-successes(item.damage, item.p_damage, item.rmax) let normalized = analyze-weapon-profile( item.shape_name, item.damage, item.p_damage, item.rmax, precision: item.precision, actions: actions, armor-break: item.armor_break, armor-pierce: item.armor_pierce, source: item, ) ( name: item.shape_name + " · " + weapon-nature-labels.at(item.nature_category), shape: item.shape_name, nature: weapon-nature-labels.at(item.nature_category), nature-key: item.nature_category, base-damage: item.damage, p-damage: item.p_damage, precision: item.precision, effective-precision: natural-precision + item.precision, success-probability: normalized.success-probability, rmax: item.rmax, armor-break: item.armor_break, armor-pierce: item.armor_pierce, actions: actions, max-damage: capped-damage, damage-per-action: capped-damage / actions, commitments: normalized.commitments, damage-curve: range(1, item.rmax + 1).map(successes => ( successes: successes, damage: damage-at-successes(item.damage, item.p_damage, successes), )), source: item, ) } #let all-weapon-metrics = ( equipments .filter(item => ( item.apply_category == "Weapons" )) .map(analyze-weapon) ) #let weapon-shapes = all-weapon-metrics.map(item => item.shape).dedup() #let weapon-natures = ("Light", "Medium", "Heavy", "SuperHeavy") #let weapon-average(key, weapons: all-weapon-metrics) = { if weapons.len() == 0 { none } else { weapons.map(item => item.at(key)).sum() / weapons.len() } } #let ranked-weapons(key, weapons: all-weapon-metrics) = weapons.sorted( key: item => -item.at(key), )