From 19851cd111ffa27b9a110cc3bb2de0f17fe47db8 Mon Sep 17 00:00:00 2001 From: Chris Wegrzyn Date: Tue, 14 May 2024 22:47:34 -0400 Subject: [PATCH] Add burn node when burning momentum on move --- src/moves/action.ts | 70 ++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/src/moves/action.ts b/src/moves/action.ts index 83ff49e6..b705f205 100644 --- a/src/moves/action.ts +++ b/src/moves/action.ts @@ -127,35 +127,53 @@ export function validAdds(baseStat: number): number[] { } function generateMechanicsNode(move: MoveDescription): Document { - let roll: Node; - let addDesc: Node[] = []; + const children: Node[] = []; if (moveIsAction(move)) { const adds = (move.adds ?? []).reduce((acc, { amount }) => acc + amount, 0); - roll = node("roll", { - values: [move.stat], - properties: { - action: move.action, - stat: move.statVal, - adds, - vs1: move.challenge1, - vs2: move.challenge2, - }, - }); - addDesc = (move.adds ?? []) - .filter(({ amount }) => amount != 0) - .map(({ amount, desc }) => - node("add", { values: [amount, ...(desc ? [desc] : [])] }), + + // Add "add" nodes for each non-zero add + children.push( + ...(move.adds ?? []) + .filter(({ amount }) => amount != 0) + .map(({ amount, desc }) => + node("add", { values: [amount, ...(desc ? [desc] : [])] }), + ), + ); + + // Main roll node + children.push( + node("roll", { + values: [move.stat], + properties: { + action: move.action, + stat: move.statVal, + adds, + vs1: move.challenge1, + vs2: move.challenge2, + }, + }), + ); + + // Momentum burn + if (move.burn) { + children.push( + node("burn", { + properties: { from: move.burn.orig, to: move.burn.reset }, + }), ); + } } else if (moveIsProgress(move)) { - roll = node("progress-roll", { - properties: { - // TODO: what about progress track id? - // TODO: use a ticks prop instead... or at least use a helper to get this - score: Math.floor(move.progressTicks / 4), - vs1: move.challenge1, - vs2: move.challenge2, - }, - }); + children.push( + node("progress-roll", { + properties: { + // TODO: what about progress track id? + // TODO: use a ticks prop instead... or at least use a helper to get this + score: Math.floor(move.progressTicks / 4), + vs1: move.challenge1, + vs2: move.challenge2, + }, + }), + ); } else { throw new Error("what kind of move is this?"); } @@ -164,7 +182,7 @@ function generateMechanicsNode(move: MoveDescription): Document { const doc: Document = [ node("move", { values: [move.name], - children: [...addDesc, roll], + children, }), ]; return doc;