[PR #6372] [MERGED] feat(game): a combat block for rulesets and the pure resolver behind it (real ruleset combat, slice 1) #7154

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

📋 Pull Request Information

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

Base: staging ← Head: feat/ruleset-combat-core


📝 Commits (10+)

  • b3b0c8f feat(rulesets): a combat block and the mechanics a fight reads
  • 9626ae7 feat(game): a pure resolver for ruleset combat
  • 9174902 feat(rulesets): a combat block in both example rulesets
  • 2a6d8d7 feat(packages): capability api 1.26 for ruleset combat
  • 188a99d test(game): pin ruleset combat on the 5e example
  • f49ccfb test(game): pin ruleset combat on the 2d6 example too
  • acd8b38 test(packages): pin the 1.26 install gate for ruleset combat
  • 3ea5840 docs(rulesets): record real ruleset combat and its first slice
  • 8ee90b1 test(game): drop an unused helper from the combat regression
  • f7daafa docs(game): measure the 5e example's threat tiers from the SRD creatures

📊 Changes

22 files changed (+5996 additions, -84 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/development/game-combat-rulesets-implementation.md (+40 -28)
📝 docs/development/game-rulesets-and-sheets-implementation.md (+90 -1)
📝 docs/development/optional-agent-packages.md (+27 -0)
📝 docs/development/ruleset-5e-2014.example.json (+212 -0)
📝 docs/examples/rulesets/ember-roads.json (+53 -5)
📝 docs/extending/ruleset.schema.json (+1116 -0)
📝 docs/extending/writing-rulesets.md (+175 -5)
📝 packages/server/src/services/capability-packages/package-manager.service.ts (+24 -0)
➕ packages/shared/src/features/ruleset-combat/encounter.ts (+605 -0)
➕ packages/shared/src/features/ruleset-combat/index.ts (+51 -0)
➕ packages/shared/src/features/ruleset-combat/options.ts (+259 -0)
➕ packages/shared/src/features/ruleset-combat/resolve.ts (+914 -0)
➕ packages/shared/src/features/ruleset-combat/types.ts (+350 -0)
📝 packages/shared/src/index.ts (+1 -0)
📝 packages/shared/src/schemas/capability-package.schema.ts (+9 -1)
📝 packages/shared/src/schemas/ruleset.schema.ts (+480 -28)
📝 scripts/generate-ruleset-schema.mjs (+13 -0)
📝 scripts/regressions/capability-package-lifecycle.regression.ts (+5 -5)
📝 scripts/regressions/game-ruleset-catalogs.regression.ts (+21 -8)

...and 2 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 #6361 (real ruleset combat, slice C1 of 5; it does not close the issue) and of #6314. Builds on #6370 (layers, merged).

Why this change

  • A game on a ruleset keeps a real character sheet, but a battle still runs on Marinara's own numbers: about 60 health, damage as a multiplier, no attack rolls and no saving throws. The combat bridge (#6348) only carries numbers across that seam. People who pick a real system want the fight itself to be that system.
  • The decision recorded on #6361: battles are resolved by data-driven combat kinds. The Engine knows a small closed set of kinds, a ruleset fills one in, and nothing in the Engine is hard-wired to one game. This slice is the format and the pure resolver. Nothing is playable yet: no session, no route and no UI ship here, so no existing battle changes.

What changed

  • An optional combat block in ruleset.json, kind attack-vs-defense: the health pool, a defense value reference, initiative, the attack roll (dice, advantage, what the extreme faces do, how a critical hit grows), the action economy (named budgets that refill on the holder's own turn or each round, and a movement reference), which sheet lists are attacks and which are abilities, the standard actions, the sheet's own conditions mapped onto a closed list of effects, concentration, dying, damage types, and a threat tier table for later slices. Everything is cross-checked against the sheet it names.
  • Catalog mechanics grows, additively: targetCount, autoHit, applies (conditions with a duration and an optional save to end them), temporary, scales (an amount that grows with a sheet value) and budget. An entry that asks for a save in a list whose abilities source declares no save difficulty is refused, because a save against nothing always succeeds.
  • A pure resolver in packages/shared/src/features/ruleset-combat/: createRulesetEncounter, rulesetCombatOptions (the legal menu for whoever's turn it is, with costs checked against the live sheet and a forecast), applyRulesetCombatChoice, advanceRulesetTurn, rulesetEncounterOutcome, rulesetEncounterSummary. It never throws, takes an injected seeded roller, and its state is plain JSON. A party member reads their numbers off the sheet and writes through applyRulesetSheetOp, so a fight can never do to a sheet what the sheet's own rules would refuse. Every event carries the dice as they fell, the modifier, the total and what it was compared with.
  • What it resolves: initiative and its ties; budgets spent and refilled; attack rolls with advantage, disadvantage and the two cancelling; natural results and critical hits by the declared rule; typed damage with resist, vulnerable and immune, temporary points first; healing; saves for none, half or negates; an area rolling its dice once and an ability that rolls to hit each target rolling them per hit; costs paid from the real pools, a higher pool of the same group with the extra dice per step; scaled amounts; conditions applied, ticking, ended by a save, and their effects changing later rolls; concentration (a second one ends the first, damage forces the save, going down ends it with no roll); dying, stabilising (which clears the counts), a blow while stable, revival and healing from zero; dodge and help.
  • Examples: the 5e example gets a full block on its existing fields (ac, speed, the derived initiative, spell_attack and spell_save_dc, the death save tracks, the concentration text), with a threat table measured from the SRD creatures in the Open5e data (CC-BY-4.0) rather than copied from any table. Ember Roads gets a 2d6 block, so the non-d20 case is real.
  • Capability API 1.26 gates the block and the new mechanics keys for packages, inline and in catalog files.
  • Docs: the authoring guide (Combat), a status header on the combat handoff document pointing at #6361 while its Traditional ruleset and its invariants stand, the plan, docs/development/optional-agent-packages.md, the generated schema.
  • Regression game-ruleset-combat-core: scripted dice on the 5e example and on Ember Roads, asserting the events' numbers, plus a JSON round trip mid-fight.

Not in this slice, and said in the guide: positions, ranges, movement, reactions, multiattack and recharge, enemy AI, anything a player can click.

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, 327 of 327), and the new regression. Six complete local CodeRabbit sweeps were run before opening (1, 1, 1, 3, 2 and 0 findings), and every finding was fixed; several were real rules: natural results for the dying roll need a single die, becoming stable clears both counts and a blow while stable opens a new one, a save always has something to be rolled against, a reaction comes back on the holder's own turn, and the blow that takes somebody down ends their concentration without a roll. There is no UI and no route in this slice, so there is nothing to click and no e2e surface; no existing battle path is touched.

Still to verify by hand:

  • Manually read the 5e example's combat block against the SRD: the condition effects it maps, the dying rule, concentration, and the threat table (measured from the SRD creatures of each challenge rating; the comment in the file says how).
  • Manually import the Ember Roads example and the 5e example through Import ruleset and confirm both are accepted with their new blocks.
  • Manually confirm a battle in a game on a ruleset still runs exactly as before (the bridge), since nothing calls the resolver yet.

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/extending/writing-rulesets.md, docs/development/game-combat-rulesets-implementation.md, the plan, docs/development/optional-agent-packages.md, both example rulesets and the generated schema. The [docs-i18n] follow-up is batched for the ruleset series.

UI evidence (if applicable)

None: this slice has no UI.

Summary by CodeRabbit

  • New Features

    • Added an optional ruleset combat format for attacks, defenses, initiative, actions, abilities, conditions, concentration, damage, and dying rules.
    • Added shared combat-resolution groundwork for turns, targeting, effects, resources, saves, and encounter outcomes; gameplay integration is not yet available.
    • Added catalog mechanics for targets, automatic hits, applied conditions, scaling, temporary points, and action costs.
    • Updated the 5e and Ember Roads examples.
  • Documentation

    • Added ruleset combat authoring and implementation guidance.
  • Compatibility

    • Combat-enabled packages require Capability API 1.26; other rulesets remain unchanged.

🔄 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/6372 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/19/2026 **Status:** ✅ Merged **Merged:** 9/19/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/ruleset-combat-core` --- ### 📝 Commits (10+) - [`b3b0c8f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b3b0c8fea449a8ce23dc2d88012562ea125721bf) feat(rulesets): a combat block and the mechanics a fight reads - [`9626ae7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9626ae720162f5f352d69379737bb244b21e8704) feat(game): a pure resolver for ruleset combat - [`9174902`](https://github.com/Pasta-Devs/Marinara-Engine/commit/917490214cf12422cc498a2def458136ea62afd2) feat(rulesets): a combat block in both example rulesets - [`2a6d8d7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2a6d8d72b6ba3d115b6f95bcbb9db91959fba787) feat(packages): capability api 1.26 for ruleset combat - [`188a99d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/188a99d1ef66cc45f8c51de6796fa429e778b09b) test(game): pin ruleset combat on the 5e example - [`f49ccfb`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f49ccfb4bda1293181113135eb9c5050e5a9fe8a) test(game): pin ruleset combat on the 2d6 example too - [`acd8b38`](https://github.com/Pasta-Devs/Marinara-Engine/commit/acd8b38c600500f1eaddaa5bcbe41b985b64e202) test(packages): pin the 1.26 install gate for ruleset combat - [`3ea5840`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3ea5840456a6824f059f71deb6d73430a5a47604) docs(rulesets): record real ruleset combat and its first slice - [`8ee90b1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8ee90b1497ecd8d0f90ef6486c81e11e606f9bd3) test(game): drop an unused helper from the combat regression - [`f7daafa`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f7daafa1dd48941233d55f06fbfeb81a1bd25ebe) docs(game): measure the 5e example's threat tiers from the SRD creatures ### 📊 Changes **22 files changed** (+5996 additions, -84 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/development/game-combat-rulesets-implementation.md` (+40 -28) 📝 `docs/development/game-rulesets-and-sheets-implementation.md` (+90 -1) 📝 `docs/development/optional-agent-packages.md` (+27 -0) 📝 `docs/development/ruleset-5e-2014.example.json` (+212 -0) 📝 `docs/examples/rulesets/ember-roads.json` (+53 -5) 📝 `docs/extending/ruleset.schema.json` (+1116 -0) 📝 `docs/extending/writing-rulesets.md` (+175 -5) 📝 `packages/server/src/services/capability-packages/package-manager.service.ts` (+24 -0) ➕ `packages/shared/src/features/ruleset-combat/encounter.ts` (+605 -0) ➕ `packages/shared/src/features/ruleset-combat/index.ts` (+51 -0) ➕ `packages/shared/src/features/ruleset-combat/options.ts` (+259 -0) ➕ `packages/shared/src/features/ruleset-combat/resolve.ts` (+914 -0) ➕ `packages/shared/src/features/ruleset-combat/types.ts` (+350 -0) 📝 `packages/shared/src/index.ts` (+1 -0) 📝 `packages/shared/src/schemas/capability-package.schema.ts` (+9 -1) 📝 `packages/shared/src/schemas/ruleset.schema.ts` (+480 -28) 📝 `scripts/generate-ruleset-schema.mjs` (+13 -0) 📝 `scripts/regressions/capability-package-lifecycle.regression.ts` (+5 -5) 📝 `scripts/regressions/game-ruleset-catalogs.regression.ts` (+21 -8) _...and 2 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 #6361 (real ruleset combat, slice C1 of 5; it does not close the issue) and of #6314. Builds on #6370 (layers, merged). ## Why this change - A game on a ruleset keeps a real character sheet, but a battle still runs on Marinara's own numbers: about 60 health, damage as a multiplier, no attack rolls and no saving throws. The combat bridge (#6348) only carries numbers across that seam. People who pick a real system want the fight itself to be that system. - The decision recorded on #6361: battles are resolved by **data-driven combat kinds**. The Engine knows a small closed set of kinds, a ruleset fills one in, and nothing in the Engine is hard-wired to one game. This slice is the format and the pure resolver. **Nothing is playable yet**: no session, no route and no UI ship here, so no existing battle changes. ## What changed - **An optional `combat` block in `ruleset.json`**, kind `attack-vs-defense`: the health pool, a defense value reference, initiative, the attack roll (dice, advantage, what the extreme faces do, how a critical hit grows), the action economy (named budgets that refill on the holder's own turn or each round, and a movement reference), which sheet lists are attacks and which are abilities, the standard actions, the sheet's own conditions mapped onto a **closed list of effects**, concentration, dying, damage types, and a threat tier table for later slices. Everything is cross-checked against the sheet it names. - **Catalog `mechanics` grows, additively**: `targetCount`, `autoHit`, `applies` (conditions with a duration and an optional save to end them), `temporary`, `scales` (an amount that grows with a sheet value) and `budget`. An entry that asks for a save in a list whose abilities source declares no save difficulty is refused, because a save against nothing always succeeds. - **A pure resolver** in `packages/shared/src/features/ruleset-combat/`: `createRulesetEncounter`, `rulesetCombatOptions` (the legal menu for whoever's turn it is, with costs checked against the live sheet and a forecast), `applyRulesetCombatChoice`, `advanceRulesetTurn`, `rulesetEncounterOutcome`, `rulesetEncounterSummary`. It never throws, takes an injected seeded roller, and its state is plain JSON. A party member reads their numbers off the sheet and writes through `applyRulesetSheetOp`, so a fight can never do to a sheet what the sheet's own rules would refuse. Every event carries the dice as they fell, the modifier, the total and what it was compared with. - **What it resolves**: initiative and its ties; budgets spent and refilled; attack rolls with advantage, disadvantage and the two cancelling; natural results and critical hits by the declared rule; typed damage with resist, vulnerable and immune, temporary points first; healing; saves for none, half or negates; an area rolling its dice once and an ability that rolls to hit each target rolling them per hit; costs paid from the real pools, a higher pool of the same group with the extra dice per step; scaled amounts; conditions applied, ticking, ended by a save, and their effects changing later rolls; concentration (a second one ends the first, damage forces the save, going down ends it with no roll); dying, stabilising (which clears the counts), a blow while stable, revival and healing from zero; dodge and help. - **Examples**: the 5e example gets a full block on its existing fields (`ac`, `speed`, the derived `initiative`, `spell_attack` and `spell_save_dc`, the death save tracks, the concentration text), with a threat table **measured from the SRD creatures in the Open5e data (CC-BY-4.0)** rather than copied from any table. Ember Roads gets a 2d6 block, so the non-d20 case is real. - **Capability API 1.26** gates the block and the new mechanics keys for packages, inline and in catalog files. - Docs: the authoring guide (Combat), a status header on the combat handoff document pointing at #6361 while its Traditional ruleset and its invariants stand, the plan, `docs/development/optional-agent-packages.md`, the generated schema. - Regression `game-ruleset-combat-core`: scripted dice on the 5e example and on Ember Roads, asserting the events' numbers, plus a JSON round trip mid-fight. Not in this slice, and said in the guide: positions, ranges, movement, reactions, multiattack and recharge, enemy AI, anything a player can click. ## 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`, 327 of 327), and the new regression. Six complete local CodeRabbit sweeps were run before opening (1, 1, 1, 3, 2 and 0 findings), and every finding was fixed; several were real rules: natural results for the dying roll need a single die, becoming stable clears both counts and a blow while stable opens a new one, a save always has something to be rolled against, a reaction comes back on the holder's own turn, and the blow that takes somebody down ends their concentration without a roll. There is no UI and no route in this slice, so there is nothing to click and no e2e surface; no existing battle path is touched. Still to verify by hand: - Manually read the 5e example's `combat` block against the SRD: the condition effects it maps, the dying rule, concentration, and the threat table (measured from the SRD creatures of each challenge rating; the comment in the file says how). - Manually import the Ember Roads example and the 5e example through **Import ruleset** and confirm both are accepted with their new blocks. - Manually confirm a battle in a game on a ruleset still runs exactly as before (the bridge), since nothing calls the resolver yet. ## 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/extending/writing-rulesets.md`, `docs/development/game-combat-rulesets-implementation.md`, the plan, `docs/development/optional-agent-packages.md`, both example rulesets and the generated schema. The `[docs-i18n]` follow-up is batched for the ruleset series. ## UI evidence (if applicable) None: this slice has no UI. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added an optional ruleset combat format for attacks, defenses, initiative, actions, abilities, conditions, concentration, damage, and dying rules. * Added shared combat-resolution groundwork for turns, targeting, effects, resources, saves, and encounter outcomes; gameplay integration is not yet available. * Added catalog mechanics for targets, automatic hits, applied conditions, scaling, temporary points, and action costs. * Updated the 5e and Ember Roads examples. * **Documentation** * Added ruleset combat authoring and implementation guidance. * **Compatibility** * Combat-enabled packages require Capability API 1.26; other rulesets remain unchanged. <!-- 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:17:01 +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#7154
No description provided.