[PR #6891] [MERGED] feat(rulesets): charges regained on rests, and items that break when emptied (#6888) #7370

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

📋 Pull Request Information

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

Base: staging ← Head: feat/ruleset-items-charges-over-time


📝 Commits (4)

  • 65c4f26 feat(rulesets): charges regained on rests, and items that break when emptied (#6888)
  • 73d33d7 Merge commit '60fb1aad7' into feat/ruleset-items-charges-over-time
  • 71bb8d5 fix(rulesets): the Rest buttons wait for the Engine's answer, so a double click rests once (#6888)
  • 0d9e0fe Merge remote-tracking branch 'origin/staging' into feat/ruleset-items-charges-over-time

📊 Changes

37 files changed (+1437 additions, -63 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 docs/development/game-rulesets-and-sheets-implementation.md (+30 -0)
📝 docs/examples/rulesets/gravewatch.json (+6 -1)
📝 docs/extending/ruleset.schema.json (+65 -0)
📝 docs/extending/writing-rulesets.md (+9 -2)
📝 docs/game/party-and-npcs.md (+1 -1)
➕ e2e/game-ruleset-item-charges.e2e.ts (+111 -0)
📝 e2e/game-ruleset-item-use.e2e.ts (+4 -1)
📝 packages/client/src/components/game/GameCharacterSheet.tsx (+3 -0)
📝 packages/client/src/components/game/GameRulesetSheet.tsx (+18 -2)
📝 packages/client/src/components/game/GameSurface.tsx (+37 -1)
📝 packages/client/src/components/game/RulesetItemPicker.tsx (+16 -0)
📝 packages/client/src/lib/ruleset-combat-log.ts (+2 -0)
📝 packages/client/src/localization/locales/en.json (+8 -1)
📝 packages/server/src/routes/game-inventory.routes.ts (+24 -1)
📝 packages/server/src/routes/generate.routes.ts (+47 -13)
📝 packages/server/src/services/capability-packages/package-manager.service.ts (+16 -0)
📝 packages/server/src/services/game/game-item-use.service.ts (+143 -0)
📝 packages/server/src/services/game/gm-prompts.ts (+10 -1)
📝 packages/server/src/services/game/ruleset-sheet-turn.service.ts (+4 -2)

...and 17 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

Closes #6888

This builds on #6889 (using items outside a fight), now merged; staging is merged in, so the diff is this slice alone.

Why this change

  • With #6882 and #6889 a ruleset's items can hold charges that a use spends, in a fight and outside one, but nothing ever gave them back: a wand used up in one fight stayed empty forever, whatever rest the party took, unless the Game Master edited the item by hand. And an item could never break when its last charge was spent, as a 5e wand crumbles on a 1. The Game Master was not even shown how many charges an item had left. This is slice I6-3 of the ruleset items plan; scroll gate checks follow as I6-4.

What changed

  • charges.recharge (Capability API 1.61): which of the ruleset's rests bring the charges back, and how many ("max", or an amount with the Engine's dice), never past the most. A rest refills the items its character carries (the player's own bag for the player's card), and a full count reads as full again.
  • The sheet's Rest button, where the ruleset has items, goes through a new route (POST /api/game/inventory/rest): the rest on the character's sheet and the charges it brings back to their bag, in one transaction, after any sheet edit still waiting to be saved has landed. The screen takes the sheet from the answer the same way #6889's Use does, so an older answer never puts back a newer one. The line under the rest buttons says what came back ("Stand down from the vigil; Dawn bell 3/3 charges"). A game whose ruleset has no items rests on the sheet as before.
  • The Game Master's rest ([sheet: op="rest"], including a party rest) refills what each rested character carries when the reply is saved, from where the turn began, so a regenerated reply recharges once. Sheet commands now report each rest taken, per character.
  • charges.breaksOn: when a use spends the last charge, the Engine rolls a ddie, and at or under atMost the item breaks and is gone from the bag, in a fight and outside one. The fight log says so ("Dawn bell breaks (a 1 on its die)."), the Use button's report does, and the journal counts the item lost.
  • The Game Master sees charges left: each charged stack in its inventory block says what it has ("2 of 3 charges left"), and an item's cost now reads "spends 1 of 3 charges" so it is never mistaken for what is left. Item facts and details say what recharges and what breaks ("regains all on Stand down from the vigil, breaks on a 1 on a d20 when emptied").
  • Checked at import: an unknown rest, a recharge amount of nothing, and a break past the die's faces. The install gate asks for 1.61 in the ruleset file and in catalog files.
  • Examples: Gravewatch's dawn bell regains its charges on standing down from the vigil, and may crack when rung empty.
  • Docs: the recharge and breaksOn keys and the capability list in docs/extending/writing-rulesets.md (whose line saying nothing refills charges yet is replaced), the Rest buttons in docs/game/party-and-npcs.md, the 1.61 record in docs/development/game-rulesets-and-sheets-implementation.md, the regenerated JSON schema and a CHANGELOG entry.

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

Local run on this branch (Fedora):

  • pnpm check, pnpm localization:check and prettier: clean.
  • pnpm regression: 475 of 476 on the full run. The one failure was termux-sharp, whose offline install found two tarballs missing from this machine's pnpm store (@emnapi/runtime 1.11.3, @img/sharp-wasm32 0.35.4). With them added to the store it passes; this PR changes nothing it covers.
  • pnpm smoke:ui: 7 passed.
  • Desktop e2e (every ruleset, inventory and Game Mode dice/combat spec): 36 passed. Mobile e2e (every ruleset spec): 17 passed. Rerun on the final commit, the charges and use-outside specs pass on both.

Lanes:

  • New game-ruleset-item-charges.regression.ts: every import refusal; the 1.61 gate (the example, a break alone, a catalog file); a bell cracking on its last charge in a fight (the event, the log line, the write-back and a "lost" journal line), holding on anything over the break, never rolling while charges remain, and never breaking without breaksOn; the same outside a fight; recharging one bag for one rest (all, an amount, never past the most, another bag or rest untouched, a full item left alone); the Game Master's party rest counted per character and refilling the player's and a member's bag; the charges left in the Game Master's inventory line; the Rest route through Fastify (the sheet and the bag written together, a member's own bag, 404, 409 with its reason, 400); item facts and the Game Master's line.
  • game-inventory-turn.regression.ts gains a real turn: the Game Master's rest refills the bell by one, a regenerated reply leaves it at one, and the next prompt says "1 of 3 charges left".
  • Lanes that pin the 1.60 gate, the supported API, the examples' items, the charges wording or the fight log's events were brought up to date.
  • e2e/game-ruleset-item-charges.e2e.ts: in Gravewatch, a bound dawn bell rung empty shows what refills and breaks it and "0 of 3 charges left", and standing Bram down from the vigil on his sheet says "Dawn bell 3/3 charges" and leaves the saved bell full.

35 deliberate breaks, each caught by these lanes (two were missed on the first run, a spare charge rolling for a break outside a fight and the Rest route dropping a pool it left low, and each got its own case).

Local CodeRabbit on this slice raised two trivial findings, both declined with reasons: the Rest button's onRest promise never rejects (its only implementation catches every failure, toasts and resolves null), and a negative rolled recharge cannot take charges away (Math.max(before, ...) already keeps them).

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: docs/extending/writing-rulesets.md, docs/game/party-and-npcs.md and docs/development/game-rulesets-and-sheets-implementation.md (all carried by docs-i18n), CHANGELOG.md, the generated docs/extending/ruleset.schema.json and the Gravewatch example. Translations: #6813 is the items arc's follow-up; this PR is added to it there.

UI evidence (if applicable)

In a Gravewatch game, Bram's sheet after "Stand down from the vigil" says "Stand down from the vigil; Dawn bell 3/3 charges", and the bell's details read "Use (Act): Steel save of 7 negates it, Rattled, spends 1 of 3 charges, regains all on Stand down from the vigil, breaks on a 1 on a d20 when emptied" (captured by e2e/game-ruleset-item-charges.e2e.ts as ruleset-rest-recharge.png).

Summary by CodeRabbit

  • New Features
    • Use supported ruleset items outside combat to heal, apply effects, or restore resource pools; results appear in the game and update inventory and character sheets.
    • Recover item charges during eligible rests. Items can also break when their final charge is spent.
    • Game Masters can use items through inventory commands, with charge counts and item-use outcomes included in game prompts and logs.
  • Documentation
    • Updated ruleset guidance and examples to cover item use, pool restoration, charge recovery, and breakage.

🔄 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/6891 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/30/2026 **Status:** ✅ Merged **Merged:** 9/30/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `feat/ruleset-items-charges-over-time` --- ### 📝 Commits (4) - [`65c4f26`](https://github.com/Pasta-Devs/Marinara-Engine/commit/65c4f26a7e09d3bf660db697d5e582a8bb2be588) feat(rulesets): charges regained on rests, and items that break when emptied (#6888) - [`73d33d7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/73d33d74b0769e25ddfcfeeb6a239d0dcad9077c) Merge commit '60fb1aad7' into feat/ruleset-items-charges-over-time - [`71bb8d5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/71bb8d5527fbf715221037edb8849b521d261d9e) fix(rulesets): the Rest buttons wait for the Engine's answer, so a double click rests once (#6888) - [`0d9e0fe`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0d9e0fea38964c72d3216ca27eb84f35248f0601) Merge remote-tracking branch 'origin/staging' into feat/ruleset-items-charges-over-time ### 📊 Changes **37 files changed** (+1437 additions, -63 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `docs/development/game-rulesets-and-sheets-implementation.md` (+30 -0) 📝 `docs/examples/rulesets/gravewatch.json` (+6 -1) 📝 `docs/extending/ruleset.schema.json` (+65 -0) 📝 `docs/extending/writing-rulesets.md` (+9 -2) 📝 `docs/game/party-and-npcs.md` (+1 -1) ➕ `e2e/game-ruleset-item-charges.e2e.ts` (+111 -0) 📝 `e2e/game-ruleset-item-use.e2e.ts` (+4 -1) 📝 `packages/client/src/components/game/GameCharacterSheet.tsx` (+3 -0) 📝 `packages/client/src/components/game/GameRulesetSheet.tsx` (+18 -2) 📝 `packages/client/src/components/game/GameSurface.tsx` (+37 -1) 📝 `packages/client/src/components/game/RulesetItemPicker.tsx` (+16 -0) 📝 `packages/client/src/lib/ruleset-combat-log.ts` (+2 -0) 📝 `packages/client/src/localization/locales/en.json` (+8 -1) 📝 `packages/server/src/routes/game-inventory.routes.ts` (+24 -1) 📝 `packages/server/src/routes/generate.routes.ts` (+47 -13) 📝 `packages/server/src/services/capability-packages/package-manager.service.ts` (+16 -0) 📝 `packages/server/src/services/game/game-item-use.service.ts` (+143 -0) 📝 `packages/server/src/services/game/gm-prompts.ts` (+10 -1) 📝 `packages/server/src/services/game/ruleset-sheet-turn.service.ts` (+4 -2) _...and 17 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 Closes #6888 This builds on #6889 (using items outside a fight), now merged; staging is merged in, so the diff is this slice alone. ## Why this change - With #6882 and #6889 a ruleset's items can hold charges that a use spends, in a fight and outside one, but nothing ever gave them back: a wand used up in one fight stayed empty forever, whatever rest the party took, unless the Game Master edited the item by hand. And an item could never break when its last charge was spent, as a 5e wand crumbles on a 1. The Game Master was not even shown how many charges an item had left. This is slice I6-3 of the ruleset items plan; scroll gate checks follow as I6-4. ## What changed - **`charges.recharge`** (Capability API 1.61): which of the ruleset's `rests` bring the charges back, and how many (`"max"`, or an amount with the Engine's dice), never past the most. A rest refills the items its character carries (the player's own bag for the player's card), and a full count reads as full again. - **The sheet's Rest button**, where the ruleset has items, goes through a new route (`POST /api/game/inventory/rest`): the rest on the character's sheet and the charges it brings back to their bag, in one transaction, after any sheet edit still waiting to be saved has landed. The screen takes the sheet from the answer the same way #6889's Use does, so an older answer never puts back a newer one. The line under the rest buttons says what came back ("Stand down from the vigil; Dawn bell 3/3 charges"). A game whose ruleset has no items rests on the sheet as before. - **The Game Master's rest** (`[sheet: op="rest"]`, including a party rest) refills what each rested character carries when the reply is saved, from where the turn began, so a regenerated reply recharges once. Sheet commands now report each rest taken, per character. - **`charges.breaksOn`**: when a use spends the last charge, the Engine rolls a d`die`, and at or under `atMost` the item breaks and is gone from the bag, in a fight and outside one. The fight log says so ("Dawn bell breaks (a 1 on its die)."), the Use button's report does, and the journal counts the item lost. - **The Game Master sees charges left**: each charged stack in its inventory block says what it has ("2 of 3 charges left"), and an item's cost now reads "spends 1 of 3 charges" so it is never mistaken for what is left. Item facts and details say what recharges and what breaks ("regains all on Stand down from the vigil, breaks on a 1 on a d20 when emptied"). - **Checked at import**: an unknown rest, a recharge amount of nothing, and a break past the die's faces. The install gate asks for 1.61 in the ruleset file and in catalog files. - **Examples**: Gravewatch's dawn bell regains its charges on standing down from the vigil, and may crack when rung empty. - **Docs**: the `recharge` and `breaksOn` keys and the capability list in `docs/extending/writing-rulesets.md` (whose line saying nothing refills charges yet is replaced), the Rest buttons in `docs/game/party-and-npcs.md`, the 1.61 record in `docs/development/game-rulesets-and-sheets-implementation.md`, the regenerated JSON schema and a CHANGELOG entry. ## 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 Local run on this branch (Fedora): - `pnpm check`, `pnpm localization:check` and prettier: clean. - `pnpm regression`: 475 of 476 on the full run. The one failure was `termux-sharp`, whose offline install found two tarballs missing from this machine's pnpm store (`@emnapi/runtime` 1.11.3, `@img/sharp-wasm32` 0.35.4). With them added to the store it passes; this PR changes nothing it covers. - `pnpm smoke:ui`: 7 passed. - Desktop e2e (every ruleset, inventory and Game Mode dice/combat spec): 36 passed. Mobile e2e (every ruleset spec): 17 passed. Rerun on the final commit, the charges and use-outside specs pass on both. Lanes: - New `game-ruleset-item-charges.regression.ts`: every import refusal; the 1.61 gate (the example, a break alone, a catalog file); a bell cracking on its last charge in a fight (the event, the log line, the write-back and a "lost" journal line), holding on anything over the break, never rolling while charges remain, and never breaking without `breaksOn`; the same outside a fight; recharging one bag for one rest (all, an amount, never past the most, another bag or rest untouched, a full item left alone); the Game Master's party rest counted per character and refilling the player's and a member's bag; the charges left in the Game Master's inventory line; the Rest route through Fastify (the sheet and the bag written together, a member's own bag, 404, 409 with its reason, 400); item facts and the Game Master's line. - `game-inventory-turn.regression.ts` gains a real turn: the Game Master's rest refills the bell by one, a regenerated reply leaves it at one, and the next prompt says "1 of 3 charges left". - Lanes that pin the 1.60 gate, the supported API, the examples' items, the charges wording or the fight log's events were brought up to date. - `e2e/game-ruleset-item-charges.e2e.ts`: in Gravewatch, a bound dawn bell rung empty shows what refills and breaks it and "0 of 3 charges left", and standing Bram down from the vigil on his sheet says "Dawn bell 3/3 charges" and leaves the saved bell full. 35 deliberate breaks, each caught by these lanes (two were missed on the first run, a spare charge rolling for a break outside a fight and the Rest route dropping a pool it left low, and each got its own case). Local CodeRabbit on this slice raised two trivial findings, both declined with reasons: the Rest button's `onRest` promise never rejects (its only implementation catches every failure, toasts and resolves null), and a negative rolled recharge cannot take charges away (`Math.max(before, ...)` already keeps them). ## 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: `docs/extending/writing-rulesets.md`, `docs/game/party-and-npcs.md` and `docs/development/game-rulesets-and-sheets-implementation.md` (all carried by `docs-i18n`), `CHANGELOG.md`, the generated `docs/extending/ruleset.schema.json` and the Gravewatch example. Translations: #6813 is the items arc's follow-up; this PR is added to it there. ## UI evidence (if applicable) In a Gravewatch game, Bram's sheet after "Stand down from the vigil" says "Stand down from the vigil; Dawn bell 3/3 charges", and the bell's details read "Use (Act): Steel save of 7 negates it, Rattled, spends 1 of 3 charges, regains all on Stand down from the vigil, breaks on a 1 on a d20 when emptied" (captured by `e2e/game-ruleset-item-charges.e2e.ts` as `ruleset-rest-recharge.png`). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Use supported ruleset items outside combat to heal, apply effects, or restore resource pools; results appear in the game and update inventory and character sheets. * Recover item charges during eligible rests. Items can also break when their final charge is spent. * Game Masters can use items through inventory commands, with charge counts and item-use outcomes included in game prompts and logs. * **Documentation** * Updated ruleset guidance and examples to cover item use, pool restoration, charge recovery, and breakage. <!-- 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:19:06 +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#7370
No description provided.