Skip to content

Commit

Permalink
Clarify clock advance odds (#481)
Browse files Browse the repository at this point in the history
If a clocks's advance odds are set to "Certain", i.e. 100%, rolling dice
is skipped now and the clock is instantly advanced, the same way as if
it was set to "no roll". Clarify that there's no advance roll happening
in the prompt as well.

Fixes #478
  • Loading branch information
sgreg authored Mar 2, 2025
1 parent 941f148 commit b9440b5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/clocks/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,35 @@ export async function advanceClock(

const defaultOdds = clockInfo.raw["default-odds"];
let wrapClockUpdates: (nodes: Node[]) => Node[];
let rollOdds = 100;
let oddsName = "no roll";

if (defaultOdds !== "no roll") {
const oddsIndex = namedOddsSchema.options.findIndex(
(val) => defaultOdds === val,
);
const roll = await CustomSuggestModal.select(
plugin.app,
namedOddsSchema.options,
(odds) => `${capitalize(odds)} (${STANDARD_ODDS[odds]}%)`,
(odds) =>
`${capitalize(odds)} (${STANDARD_ODDS[odds]}%)${STANDARD_ODDS[odds] == 100 ? " -> advance without roll" : ""}`,
undefined,
"Choose the odds to advance",
oddsIndex > -1 ? oddsIndex : undefined,
);
const rollOdds = STANDARD_ODDS[roll];
rollOdds = STANDARD_ODDS[roll];
oddsName = roll;
}

if (rollOdds < 100) {
const result = await campaignContext
.diceRollerFor("move")
.rollAsync(DiceGroup.of(Dice.fromDiceString("1d100", DieKind.Oracle)));
const shouldAdvance = result[0].value <= rollOdds;

wrapClockUpdates = (nodes) => {
const props: { name: string; roll: number; result: string } = {
name: `Will [[${clockPath}|${stripMarkdown(plugin, clockInfo.name)}]] advance? (${capitalize(roll)})`,
name: `Will [[${clockPath}|${stripMarkdown(plugin, clockInfo.name)}]] advance? (${capitalize(oddsName)})`,
roll: result[0].value,
result: shouldAdvance ? "Yes" : "No",
};
Expand Down

0 comments on commit b9440b5

Please sign in to comment.