[PR #8495] [MERGED] Roll plain dice through one shared roller and grammar (part 1 of #8489) #8634

Closed
opened 2026-11-07 16:46:07 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8495
Author: @kolacheee
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @kolacheee

Base: staging ← Head: claude/project-thread-mhcusi


📝 Commits (5)

  • a242e59 Let dice callers pass their own roller
  • 40ae448 Roll every plain die with the secure roller
  • 2f37c76 Read the roll macro and narration dice with the shared grammar
  • d8bcad2 Keep the macros doc's table layout as it was
  • 35332e7 Keep near-limit roll macros literal and pin the secure die in tests

📊 Changes

11 files changed (+215 additions, -67 deletions)

View changed files

📝 docs/prompts/macros.md (+1 -1)
📝 packages/client/src/components/game/game-narration-format.ts (+16 -13)
📝 packages/server/src/services/game/dice-rng.ts (+8 -23)
📝 packages/server/src/services/game/skill-check.service.ts (+3 -4)
📝 packages/shared/src/utils/dice-notation.ts (+47 -9)
📝 packages/shared/src/utils/macro-engine.ts (+15 -8)
📝 scripts/regressions/combat-conditions.regression.ts (+12 -0)
📝 scripts/regressions/dice-notation.regression.ts (+59 -9)
📝 scripts/regressions/game-tool-controls.regression.ts (+11 -0)
📝 scripts/regressions/prompt.regression.ts (+31 -0)
📝 scripts/regressions/roleplay-commands.regression.ts (+12 -0)

📄 Description

Linked issue

Part of #8489 (steps 1 to 3 of the plan in this comment). Extension dice formats and ruleset combat follow in later PRs.

Why this change

Dice were rolled by several separate generators and read by several separate parsers, so the same notation could roll differently depending on where it was typed. This gives every roller one shape, lets the code that reads a roll take its dice from whoever calls it, puts the plain rolls on the same fair die, and puts the roll macro on the same grammar. Ruleset fights keep their seeded stream, because the shared code now takes a roller passed in by the caller.

What changed

  • /roll, composer dice, the roll_dice tool, multiplayer /roll, legacy combat, encounters and the skill-check d20 now roll with the same secure die as the dice pool and one-request dice (Web Crypto, in both the browser and the server), not Math.random(). Results look the same to players.
  • {{roll:}} accepts the same notation as /roll, so {{roll:d20}} and {{roll:1d8+3}} now roll; before, they stayed as literal text. Its randomness is unchanged: a chat with a message seed still rolls the same faces it always did, an unseeded one still uses Math.random(), and its own looser count and face limits (and {{roll:0d6}} → "0") stay as they were.
  • The [dice: ...] badge in Game Mode narration reads its notation with the shared grammar (it matches exactly the same text as before).
  • For developers: DieRoller lives in @marinara-engine/shared, rollParsedDice(parsed, roll?) takes a roller, and the server's dice-rng.ts re-exports the shared rollDieSecurely.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Regressions run locally and passing: dice-notation (new roller and secure-die cases), prompt (new seeded {{roll:}} face check, the new notation forms and the exact-total edge), dice-display, game-dice-commands, game-mode-dice-tool, game-text-dice, gm-skill-check-resolution, one-request-dice-gate/branch/pool/placeholders, game-ruleset-dice-pool, assembler-macro-budget, capability-gm-verbs, combat-conditions, roleplay-commands, game-tool-controls. Server, shared and client lint and type checks pass.

Manual verification notes

  • Manually verify /roll 2d6+3 and /roll in a chat still post a roll card with sensible faces.
  • Manually verify {{roll:d20}} and {{roll:1d8+3}} in a message resolve to numbers in range.
  • Manually verify a Game Mode [dice: 1d20 = 14] record still shows the dice badge.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

docs/prompts/macros.md gains one sentence about the {{roll:}} forms; it is added to the docs-i18n catch-up issue #7512.

UI evidence (if applicable)

No visual change.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/8495 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `claude/project-thread-mhcusi` --- ### 📝 Commits (5) - [`a242e59`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a242e5900e066f1d4f7afd4526e194524b1980f0) Let dice callers pass their own roller - [`40ae448`](https://github.com/Pasta-Devs/Marinara-Engine/commit/40ae448499d74a6f581cbc436baf2d0fa3e583b2) Roll every plain die with the secure roller - [`2f37c76`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2f37c76badfb7d55e0e81ce611593a6f480d56c5) Read the roll macro and narration dice with the shared grammar - [`d8bcad2`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d8bcad2d13dde3614e7501e39c2caf1d4c34c103) Keep the macros doc's table layout as it was - [`35332e7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/35332e71b63ebcc8c1789c5570a766dccbb9ef91) Keep near-limit roll macros literal and pin the secure die in tests ### 📊 Changes **11 files changed** (+215 additions, -67 deletions) <details> <summary>View changed files</summary> 📝 `docs/prompts/macros.md` (+1 -1) 📝 `packages/client/src/components/game/game-narration-format.ts` (+16 -13) 📝 `packages/server/src/services/game/dice-rng.ts` (+8 -23) 📝 `packages/server/src/services/game/skill-check.service.ts` (+3 -4) 📝 `packages/shared/src/utils/dice-notation.ts` (+47 -9) 📝 `packages/shared/src/utils/macro-engine.ts` (+15 -8) 📝 `scripts/regressions/combat-conditions.regression.ts` (+12 -0) 📝 `scripts/regressions/dice-notation.regression.ts` (+59 -9) 📝 `scripts/regressions/game-tool-controls.regression.ts` (+11 -0) 📝 `scripts/regressions/prompt.regression.ts` (+31 -0) 📝 `scripts/regressions/roleplay-commands.regression.ts` (+12 -0) </details> ### 📄 Description ## Linked issue Part of #8489 (steps 1 to 3 of the plan in [this comment](https://github.com/Pasta-Devs/Marinara-Engine/issues/8489#issuecomment-6518263129)). Extension dice formats and ruleset combat follow in later PRs. ## Why this change Dice were rolled by several separate generators and read by several separate parsers, so the same notation could roll differently depending on where it was typed. This gives every roller one shape, lets the code that reads a roll take its dice from whoever calls it, puts the plain rolls on the same fair die, and puts the roll macro on the same grammar. Ruleset fights keep their seeded stream, because the shared code now takes a roller passed in by the caller. ## What changed - `/roll`, composer dice, the `roll_dice` tool, multiplayer `/roll`, legacy combat, encounters and the skill-check d20 now roll with the same secure die as the dice pool and one-request dice (Web Crypto, in both the browser and the server), not `Math.random()`. Results look the same to players. - `{{roll:}}` accepts the same notation as `/roll`, so `{{roll:d20}}` and `{{roll:1d8+3}}` now roll; before, they stayed as literal text. Its randomness is unchanged: a chat with a message seed still rolls the same faces it always did, an unseeded one still uses `Math.random()`, and its own looser count and face limits (and `{{roll:0d6}}` → "0") stay as they were. - The `[dice: ...]` badge in Game Mode narration reads its notation with the shared grammar (it matches exactly the same text as before). - For developers: `DieRoller` lives in `@marinara-engine/shared`, `rollParsedDice(parsed, roll?)` takes a roller, and the server's `dice-rng.ts` re-exports the shared `rollDieSecurely`. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` Regressions run locally and passing: dice-notation (new roller and secure-die cases), prompt (new seeded `{{roll:}}` face check, the new notation forms and the exact-total edge), dice-display, game-dice-commands, game-mode-dice-tool, game-text-dice, gm-skill-check-resolution, one-request-dice-gate/branch/pool/placeholders, game-ruleset-dice-pool, assembler-macro-budget, capability-gm-verbs, combat-conditions, roleplay-commands, game-tool-controls. Server, shared and client lint and type checks pass. ### Manual verification notes - Manually verify `/roll 2d6+3` and `/roll` in a chat still post a roll card with sensible faces. - Manually verify `{{roll:d20}}` and `{{roll:1d8+3}}` in a message resolve to numbers in range. - Manually verify a Game Mode `[dice: 1d20 = 14]` record still shows the dice badge. ## Docs and release impact - [ ] No docs changes needed - [x] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) `docs/prompts/macros.md` gains one sentence about the `{{roll:}}` forms; it is added to the docs-i18n catch-up issue #7512. ## UI evidence (if applicable) No visual change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:46:07 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#8634
No description provided.