[PR #6348] [MERGED] feat(game): lend the ruleset sheet to battles and write the outcome back (rulesets combat bridge) #7146

Closed
opened 2026-10-23 04:16:57 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/6348
Author: @kolacheee
Created: 9/19/2026
Status: ✅ Merged
Merged: 9/19/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/rulesets-combat-bridge


📝 Commits (10+)

  • 6e6a575 feat(game): the ruleset battle block and the combat bridge helpers (Capability API 1.22)
  • f725560 feat(game): lend the ruleset sheet to battles and write the outcome back
  • dce6a4e fix(game): say in the catalog picker when battles do use an entry's numbers
  • 088acab fix(game): carry health into a bridged battle as a share of the maximum
  • e9a003f fix(game): seed a bridged battle in the same tick, and hold alwaysWhen to the column's type
  • fc76d4a fix(game): refuse a health pool that starts empty, and say which mechanics fields a battle reads
  • 063671a fix(game): hold the combat-starting gate while a bridged battle waits for its catalogs
  • 342d470 fix(game): an area heal from the sheet never targets all enemies, and only the owning battle lowers the start gate
  • ee01f36 refactor(game): one equals check for hideWhen and alwaysWhen, and memoize the picker's battle catalogs
  • a74b31d fix(game): address the first CodeRabbit review of the combat bridge

📊 Changes

25 files changed (+2219 additions, -53 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/development/game-rulesets-and-sheets-implementation.md (+21 -5)
📝 docs/development/optional-agent-packages.md (+26 -0)
📝 docs/development/ruleset-5e-2014.example.json (+24 -0)
📝 docs/examples/rulesets/ember-roads.json (+15 -3)
📝 docs/extending/ruleset.schema.json (+119 -0)
📝 docs/extending/writing-rulesets.md (+85 -2)
📝 docs/game/combat.md (+4 -0)
📝 packages/client/src/components/game/GameCombatUI.tsx (+5 -0)
📝 packages/client/src/components/game/GameSurface.tsx (+192 -5)
📝 packages/client/src/components/rulesets/RulesetCatalogPicker.tsx (+11 -1)
📝 packages/client/src/hooks/use-capability-packages.ts (+16 -8)
➕ packages/client/src/lib/ruleset-combat-bridge.ts (+180 -0)
📝 packages/client/src/localization/locales/en.json (+3 -0)
📝 packages/server/src/services/capability-packages/package-manager.service.ts (+12 -4)
➕ packages/shared/src/features/rulesets/combat-bridge.ts (+391 -0)
📝 packages/shared/src/features/tactical-combat/engine.ts (+5 -0)
📝 packages/shared/src/index.ts (+1 -0)
📝 packages/shared/src/schemas/capability-package.schema.ts (+6 -1)
📝 packages/shared/src/schemas/ruleset.schema.ts (+130 -14)

...and 5 more files

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Part of #6314 (the combat bridge; it does not close the issue). Builds on #6345 (catalogs, merged).

Why this change

  • A game on a ruleset keeps each character's hit points, spell slots and other resources on a sheet, but a battle ignored all of it: everyone started fresh on Marinara's own numbers, with skills the model invented, and nothing the fight cost ever reached the sheet. A wizard who had spent every slot walked into the next fight with slots to spare.
  • This is an interim bridge, not ruleset combat. Battles still run on Marinara's combat model. Sign-off wanted: docs/development/game-combat-rulesets-implementation.md reserves a real 5e combat adapter as its own later slice. This PR stays off that ground on purpose (no attack rolls, saves or concentration), the plan doc now says the bridge is superseded for a ruleset the day a real adapter for it exists, and I would like the maintainer's yes or no on that arrangement before or at merge.

What changed

  • Opt-in battle block in ruleset.json: the live pool that is health, an optional energy pool, the spell slot pools with their levels, and the sheet lists that supply skills (onlyWhen a boolean column, alwaysWhen a column equals a value, which is how 5e says "prepared spells, and cantrips always"). Cross-checked like the rest of the file. A ruleset without the block changes nothing, and coverage.combat keeps meaning "this ruleset brings its own combat rules".
  • Seeding. Right before the party is set, in the one place all three combat presentations share, each party member with a readable sheet starts on the sheet's state. Health is carried as a share of the maximum: the combatant keeps Marinara's own maximum and starts at the sheet's share of it (5 of 9 on the sheet is 33 of 60 in the fight). The first version carried raw numbers and a browser pass showed why that cannot work: Marinara's fighters have about 60 health and take 11 to 15 a hit, so a 9-point pool died to one blow. Energy and spell slots are small counts and stay absolute.
  • Skills. Rows picked from a catalog become CombatSkills through the entry's mechanics: kind to type, range and burst area from the catalog's distance unit to grid cells, the amount's average to power on the Engine's existing scale (divisor 7, clamped 0.5 to 3, so nothing hits harder than a skill the Engine could generate itself), a slot cost to slotLevel, an energy cost to mpCost. Utility and reaction entries, hand-typed rows, and costs the Engine cannot spend are left out. An area attack or debuff targets all enemies in Classic; an area heal or buff stays single-target, because the Engine has no "all allies" scope. Attack rolls, saves, concentration and upcasting are not used.
  • Write-back when the battle ends, before the recap is sent: the final share of health is converted back to the sheet's scale and the spent energy and slots are applied through the same applyRulesetSheetOp the Game Master's sheet commands use, in one game-state patch. A member whose health did not change gets no health change, so rounding can never move a sheet; a living member is never written below 1. The recap tells the Game Master the sheets were already updated. An abandoned battle writes nothing back.
  • Timing. The battle catalogs are fetched when the game opens, so a battle seeds its party in the same tick as today. If a battle starts before they arrive, the existing combat-starting gate holds the narration and the input until the party is in place, and the slow path marks its battle so a late answer cannot land on one that ended or was replaced.
  • Honesty. A toast at the start of a bridged battle says health and resources come from the sheet, health is carried as a share, and damage is Marinara's combat math. The catalog picker's note now says when battles do use an entry's numbers. Docs say the same.
  • Summaries. Classic and Tactical summaries carry energy and spell slots like the director's already did.
  • Capability API 1.22 gates the battle block for packages, with a readable install refusal on an older declaration.
  • Docs: authoring guide (Battles section), docs/game/combat.md, docs/development/optional-agent-packages.md, the plan (what the bridge settled, the relationship to the combat handoff). The Ember Roads example gains a battle block (Grit as health, Luck as energy) to prove the non-5e case; the 5e example gains one too, with Pact slots left out because a fixed level list cannot express them.
  • Regressions: game-ruleset-combat-bridge (schema refusals, seeding on both examples, skills, the share in both directions, write-back), ruleset-combat-bridge-client (the pure client composition: lookup by normalized name with the persona tie-break, merge of several members, the reload path).

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

Manual verification notes

Commands run locally by the agent: pnpm check (exit 0), pnpm localization:check, the full node regression lane (pnpm regression:node, 317 of 317), and the two new regressions. Six complete local CodeRabbit sweeps were run before opening. Their findings were fixed (the party is seeded in the same tick from preloaded catalogs, with the combat-starting gate held on the slow path; an area heal or buff from the sheet no longer borrows the "all enemies" scope; a health pool that starts empty is refused; alwaysWhen.equals is typed like hideWhen; wording), and the last complete one returned no findings. One suggestion was declined: falling back to the reload path when the game state was not ready at battle start. Those fighters started at full, so measuring the end of the fight against the sheet's share would write health changes that never happened; the bridge stands aside for that fight instead. The e2e suite was checked by reading it: no spec sets a game ruleset or mocks the ruleset routes, so every combat spec takes the unchanged synchronous path; the combatSkillsFromSheet and generatedPartyMemberToCombatant exports core-flows imports are untouched. Playwright was not run locally.

The agent drove a scratch server on port 7820 with a fresh data folder and no model connected, using a scripted game on the Ember Roads example and the legacy [combat:] tag to start a battle: a party member whose sheet read 5 of 9 Grit and 2 of 3 Luck started at 33 of 60 health and 2 of 3 energy, the toast appeared, the player without a sheet was untouched at 60 of 60, the auto-controlled member used a catalog skill ("Tessa Vane uses Coldfire Toss on Rust Hound for 11 damage"), she was hit down to 16 of 60, Flee ended the battle, and the sheet's live state then read 2 Grit and 2 Luck. The recap carried the line saying the sheets were already updated. The first pass, with raw numbers, is what showed the scale problem described above.

Still to verify by hand:

  • Manually play a bridged battle with a real model on the 5e ruleset once the package ships its battle block (a follow-up release in Marinara-Agents): slots spent in the fight are gone on the sheet afterwards, and a prepared catalog spell appears as a skill.
  • Manually check Tactical and the Game Master directed presentation; only Classic was exercised by hand.
  • Manually reload in the middle of a bridged battle, finish it, and confirm the write-back.
  • Manually start a battle right after opening a game on a slow connection, so the catalogs have not arrived yet: the combat-starting state should hold until the party appears. This path was not exercised by hand.
  • Manually confirm a game with no ruleset, and one whose ruleset has no battle block, fight exactly as before.
  • Manually verify light mode and a phone-width viewport for the toast.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) 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 touched: CHANGELOG.md, docs/game/combat.md, docs/extending/writing-rulesets.md, docs/development/optional-agent-packages.md, the plan, both example rulesets and the generated schema. The [docs-i18n] follow-up is batched for the ruleset slices.

UI evidence (if applicable)

To be added by a human: the toast at the start of a bridged battle and the combat HUD of a seeded member.

Summary by CodeRabbit

  • New Features

    • Rulesets can optionally connect character sheets to battles, including health, energy, spell slots, and selected abilities.
    • Health carries proportionally into combat, while final health and spent resources can be written back to sheets.
    • Combat summaries now include energy and spell-slot status.
    • Rulesets without battle configuration retain existing combat behavior.
  • Documentation

    • Added guidance and examples for configuring battle-enabled rulesets.
  • Compatibility

    • Battle-enabled rulesets require Capability API 1.22 or newer.

🔄 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/6348 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/19/2026 **Status:** ✅ Merged **Merged:** 9/19/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/rulesets-combat-bridge` --- ### 📝 Commits (10+) - [`6e6a575`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6e6a57598ab5c2d5103a31d535176b39ab1f0105) feat(game): the ruleset battle block and the combat bridge helpers (Capability API 1.22) - [`f725560`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f7255608773b0add1b33b8cc56c26b998ce74e3b) feat(game): lend the ruleset sheet to battles and write the outcome back - [`dce6a4e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/dce6a4ea7a9467d6bc797245ab61dc226de88cb2) fix(game): say in the catalog picker when battles do use an entry's numbers - [`088acab`](https://github.com/Pasta-Devs/Marinara-Engine/commit/088acab8a8d01aac833f2d182a92411b4c0db95d) fix(game): carry health into a bridged battle as a share of the maximum - [`e9a003f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e9a003fd36cfd6a756cd49d96ae76c073508d83c) fix(game): seed a bridged battle in the same tick, and hold alwaysWhen to the column's type - [`fc76d4a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fc76d4a389048020a8464a910758adcb4e25b788) fix(game): refuse a health pool that starts empty, and say which mechanics fields a battle reads - [`063671a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/063671ad3ddc16f0a44651673130fca0817ed07d) fix(game): hold the combat-starting gate while a bridged battle waits for its catalogs - [`342d470`](https://github.com/Pasta-Devs/Marinara-Engine/commit/342d470e93c1bbf6d2a554335d49134ace31e773) fix(game): an area heal from the sheet never targets all enemies, and only the owning battle lowers the start gate - [`ee01f36`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ee01f3670adeb5907cc552d991000a390cc9d844) refactor(game): one equals check for hideWhen and alwaysWhen, and memoize the picker's battle catalogs - [`a74b31d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a74b31d2b7f79e3f68a2813441d9361d18b8c626) fix(game): address the first CodeRabbit review of the combat bridge ### 📊 Changes **25 files changed** (+2219 additions, -53 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/development/game-rulesets-and-sheets-implementation.md` (+21 -5) 📝 `docs/development/optional-agent-packages.md` (+26 -0) 📝 `docs/development/ruleset-5e-2014.example.json` (+24 -0) 📝 `docs/examples/rulesets/ember-roads.json` (+15 -3) 📝 `docs/extending/ruleset.schema.json` (+119 -0) 📝 `docs/extending/writing-rulesets.md` (+85 -2) 📝 `docs/game/combat.md` (+4 -0) 📝 `packages/client/src/components/game/GameCombatUI.tsx` (+5 -0) 📝 `packages/client/src/components/game/GameSurface.tsx` (+192 -5) 📝 `packages/client/src/components/rulesets/RulesetCatalogPicker.tsx` (+11 -1) 📝 `packages/client/src/hooks/use-capability-packages.ts` (+16 -8) ➕ `packages/client/src/lib/ruleset-combat-bridge.ts` (+180 -0) 📝 `packages/client/src/localization/locales/en.json` (+3 -0) 📝 `packages/server/src/services/capability-packages/package-manager.service.ts` (+12 -4) ➕ `packages/shared/src/features/rulesets/combat-bridge.ts` (+391 -0) 📝 `packages/shared/src/features/tactical-combat/engine.ts` (+5 -0) 📝 `packages/shared/src/index.ts` (+1 -0) 📝 `packages/shared/src/schemas/capability-package.schema.ts` (+6 -1) 📝 `packages/shared/src/schemas/ruleset.schema.ts` (+130 -14) _...and 5 more files_ </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Part of #6314 (the combat bridge; it does not close the issue). Builds on #6345 (catalogs, merged). ## Why this change - A game on a ruleset keeps each character's hit points, spell slots and other resources on a sheet, but a battle ignored all of it: everyone started fresh on Marinara's own numbers, with skills the model invented, and nothing the fight cost ever reached the sheet. A wizard who had spent every slot walked into the next fight with slots to spare. - This is an interim bridge, not ruleset combat. Battles still run on Marinara's combat model. **Sign-off wanted:** `docs/development/game-combat-rulesets-implementation.md` reserves a real 5e combat adapter as its own later slice. This PR stays off that ground on purpose (no attack rolls, saves or concentration), the plan doc now says the bridge is superseded for a ruleset the day a real adapter for it exists, and I would like the maintainer's yes or no on that arrangement before or at merge. ## What changed - **Opt-in `battle` block** in `ruleset.json`: the live pool that is health, an optional energy pool, the spell slot pools with their levels, and the sheet lists that supply skills (`onlyWhen` a boolean column, `alwaysWhen` a column equals a value, which is how 5e says "prepared spells, and cantrips always"). Cross-checked like the rest of the file. A ruleset without the block changes nothing, and `coverage.combat` keeps meaning "this ruleset brings its own combat rules". - **Seeding.** Right before the party is set, in the one place all three combat presentations share, each party member with a readable sheet starts on the sheet's state. **Health is carried as a share of the maximum**: the combatant keeps Marinara's own maximum and starts at the sheet's share of it (5 of 9 on the sheet is 33 of 60 in the fight). The first version carried raw numbers and a browser pass showed why that cannot work: Marinara's fighters have about 60 health and take 11 to 15 a hit, so a 9-point pool died to one blow. Energy and spell slots are small counts and stay absolute. - **Skills.** Rows picked from a catalog become `CombatSkill`s through the entry's `mechanics`: kind to type, range and burst area from the catalog's distance unit to grid cells, the amount's average to `power` on the Engine's existing scale (divisor 7, clamped 0.5 to 3, so nothing hits harder than a skill the Engine could generate itself), a slot cost to `slotLevel`, an energy cost to `mpCost`. Utility and reaction entries, hand-typed rows, and costs the Engine cannot spend are left out. An area attack or debuff targets all enemies in Classic; an area heal or buff stays single-target, because the Engine has no "all allies" scope. Attack rolls, saves, concentration and upcasting are not used. - **Write-back** when the battle ends, before the recap is sent: the final share of health is converted back to the sheet's scale and the spent energy and slots are applied through the same `applyRulesetSheetOp` the Game Master's sheet commands use, in one game-state patch. A member whose health did not change gets no health change, so rounding can never move a sheet; a living member is never written below 1. The recap tells the Game Master the sheets were already updated. An abandoned battle writes nothing back. - **Timing.** The battle catalogs are fetched when the game opens, so a battle seeds its party in the same tick as today. If a battle starts before they arrive, the existing combat-starting gate holds the narration and the input until the party is in place, and the slow path marks its battle so a late answer cannot land on one that ended or was replaced. - **Honesty.** A toast at the start of a bridged battle says health and resources come from the sheet, health is carried as a share, and damage is Marinara's combat math. The catalog picker's note now says when battles do use an entry's numbers. Docs say the same. - **Summaries.** Classic and Tactical summaries carry energy and spell slots like the director's already did. - **Capability API 1.22** gates the `battle` block for packages, with a readable install refusal on an older declaration. - Docs: authoring guide (Battles section), `docs/game/combat.md`, `docs/development/optional-agent-packages.md`, the plan (what the bridge settled, the relationship to the combat handoff). The Ember Roads example gains a `battle` block (Grit as health, Luck as energy) to prove the non-5e case; the 5e example gains one too, with Pact slots left out because a fixed level list cannot express them. - Regressions: `game-ruleset-combat-bridge` (schema refusals, seeding on both examples, skills, the share in both directions, write-back), `ruleset-combat-bridge-client` (the pure client composition: lookup by normalized name with the persona tie-break, merge of several members, the reload path). ## 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` ### Manual verification notes Commands run locally by the agent: `pnpm check` (exit 0), `pnpm localization:check`, the full node regression lane (`pnpm regression:node`, 317 of 317), and the two new regressions. Six complete local CodeRabbit sweeps were run before opening. Their findings were fixed (the party is seeded in the same tick from preloaded catalogs, with the combat-starting gate held on the slow path; an area heal or buff from the sheet no longer borrows the "all enemies" scope; a health pool that starts empty is refused; `alwaysWhen.equals` is typed like `hideWhen`; wording), and the last complete one returned no findings. One suggestion was declined: falling back to the reload path when the game state was not ready at battle start. Those fighters started at full, so measuring the end of the fight against the sheet's share would write health changes that never happened; the bridge stands aside for that fight instead. The e2e suite was checked by reading it: no spec sets a game ruleset or mocks the ruleset routes, so every combat spec takes the unchanged synchronous path; the `combatSkillsFromSheet` and `generatedPartyMemberToCombatant` exports `core-flows` imports are untouched. Playwright was not run locally. The agent drove a scratch server on port 7820 with a fresh data folder and no model connected, using a scripted game on the Ember Roads example and the legacy `[combat:]` tag to start a battle: a party member whose sheet read 5 of 9 Grit and 2 of 3 Luck started at 33 of 60 health and 2 of 3 energy, the toast appeared, the player without a sheet was untouched at 60 of 60, the auto-controlled member used a catalog skill ("Tessa Vane uses Coldfire Toss on Rust Hound for 11 damage"), she was hit down to 16 of 60, **Flee** ended the battle, and the sheet's live state then read 2 Grit and 2 Luck. The recap carried the line saying the sheets were already updated. The first pass, with raw numbers, is what showed the scale problem described above. Still to verify by hand: - Manually play a bridged battle with a real model on the 5e ruleset once the package ships its `battle` block (a follow-up release in Marinara-Agents): slots spent in the fight are gone on the sheet afterwards, and a prepared catalog spell appears as a skill. - Manually check Tactical and the Game Master directed presentation; only Classic was exercised by hand. - Manually reload in the middle of a bridged battle, finish it, and confirm the write-back. - Manually start a battle right after opening a game on a slow connection, so the catalogs have not arrived yet: the combat-starting state should hold until the party appears. This path was not exercised by hand. - Manually confirm a game with no ruleset, and one whose ruleset has no `battle` block, fight exactly as before. - Manually verify light mode and a phone-width viewport for the toast. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) 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 touched: `CHANGELOG.md`, `docs/game/combat.md`, `docs/extending/writing-rulesets.md`, `docs/development/optional-agent-packages.md`, the plan, both example rulesets and the generated schema. The `[docs-i18n]` follow-up is batched for the ruleset slices. ## UI evidence (if applicable) To be added by a human: the toast at the start of a bridged battle and the combat HUD of a seeded member. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Rulesets can optionally connect character sheets to battles, including health, energy, spell slots, and selected abilities. - Health carries proportionally into combat, while final health and spent resources can be written back to sheets. - Combat summaries now include energy and spell-slot status. - Rulesets without battle configuration retain existing combat behavior. - **Documentation** - Added guidance and examples for configuring battle-enabled rulesets. - **Compatibility** - Battle-enabled rulesets require Capability API 1.22 or newer. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:16:57 +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#7146
No description provided.