Skip to content

Commit

Permalink
Add burn node when burning momentum on move
Browse files Browse the repository at this point in the history
  • Loading branch information
cwegrzyn committed May 15, 2024
1 parent 8b044e9 commit 19851cd
Showing 1 changed file with 44 additions and 26 deletions.
70 changes: 44 additions & 26 deletions src/moves/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?");
}
Expand All @@ -164,7 +182,7 @@ function generateMechanicsNode(move: MoveDescription): Document {
const doc: Document = [
node("move", {
values: [move.name],
children: [...addDesc, roll],
children,
}),
];
return doc;
Expand Down

0 comments on commit 19851cd

Please sign in to comment.