/** * formulaEval.ts — evaluate an RPG Maker MV damage formula without running it. * * A damage formula is a JavaScript expression the engine evaluates with `a` * (the user), `b` (the target) and `v` (game variables) in scope. Anything that * wants to reason about balance has to turn that string into a number. * * The tempting shortcut is to substitute the stat names for numbers and hand * the rest to a real evaluator. That is a remote code execution hole: the * formula comes from the project's Skills.json, which the person running this * tool did not necessarily write, and substituting six known tokens sanitises * nothing — everything else in the string still reaches the evaluator. * * So this is a real parser: tokenise, shunting-yard to RPN, evaluate. It knows * arithmetic, parentheses, and the Math functions formulas actually use. * Anything it does not recognise makes it return a reason rather than a number. * That distinction matters for statistics: a formula scored as 0 because it * failed to parse drags an average down and hides the outlier you were looking * for, so callers must be able to tell "no damage" from "could not tell". */ /** The stats a formula is evaluated against. */ export interface FormulaContext { /** The user of the skill. */ a: Record; /** The target. */ b: Record; /** Game variables, by id. Unknown ids read as 0, as they do in a fresh game. */ v?: Record; } /** Reference combatants, so two formulas are compared on the same footing. */ export declare const REFERENCE_CONTEXT: FormulaContext; export type EvalResult = { ok: true; value: number; } | { ok: false; reason: string; }; /** * Evaluate a damage formula against a set of stats. Returns `ok: false` with a * reason for anything it cannot read statically — never a number it guessed. */ export declare function evaluateFormula(formula: string, ctx?: FormulaContext): EvalResult;