[PR #593] [MERGED] fix(game,combat): apply sheet attribute modifiers to skill checks and combat init #4688

Closed
opened 2026-10-22 04:09:49 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/593
Author: @Romuromylus
Created: 5/9/2026
Status: ✅ Merged
Merged: 5/9/2026
Merged by: @Romuromylus

Base: main ← Head: fix/game-mode-skill-check-attributes


📝 Commits (2)

  • 1c400b7 fix(game,combat): apply sheet attribute modifiers to skill checks and combat init
  • ab5082e fix(combat): guard chat.metadata JSON.parse in encounter init

📊 Changes

9 files changed (+183 additions, -26 deletions)

View changed files

📝 packages/client/src/components/game/GameCharacterSheet.tsx (+9 -0)
📝 packages/client/src/components/game/GameSurface.tsx (+1 -0)
📝 packages/client/src/hooks/use-game.ts (+8 -2)
📝 packages/client/src/lib/game-tag-parser.ts (+15 -0)
📝 packages/server/src/routes/encounter.routes.ts (+42 -1)
📝 packages/server/src/routes/game.routes.ts (+27 -6)
📝 packages/server/src/services/game/gm-prompts.ts (+2 -2)
📝 packages/server/src/services/game/skill-check.service.ts (+61 -9)
📝 packages/server/test/game-session-prompts.test.ts (+18 -6)

📄 Description

Linked issue

Closes #592

Why this change

  • Game Mode skill checks didn't actually use the character sheet's RPG attributes — the GM was instructed to invent the rolls/modifier/total/result itself, and the deterministic server resolver almost never ran. Setting STR 20 on the sheet made no difference to a Strength check outcome.
  • Combat Mode encounter init never received the player's character-sheet attributes either — the prompt builder reads from playerStats.attributes which is null for every chat. The LLM generated attack/defense/hp with no link to the player's intended build.
  • Three converging gaps caused this: PlayerStats.attributes is initialised to null in every game-state writer and never seeded; the GM prompt asked the AI to fill in roll math; and the sheet's free-form Array<{name,value}> shape never had a mapper to the strict RPGAttributes: { str, dex, con, int, wis, cha } shape the engine wants.

What changed

  • Sheet display (packages/client/src/components/game/GameCharacterSheet.tsx): show the D&D-style modifier next to each attribute on the read-only grid (STR 17 (+3)), using the same floor((score - 10) / 2) formula the server already implements for skill checks.
  • Name mapper + lazy fallback (packages/server/src/services/game/skill-check.service.ts): added mapSheetAttributesToRPG — case-insensitive map from Array<{name,value}> (sheet shape; accepts STR/Str/Strength, DEX/Dexterity, etc.) to Partial<RPGAttributes>. Custom names are dropped.
  • Skill-check route (packages/server/src/routes/game.routes.ts): when playerStats.attributes is null, falls back to mapping the player's gameCharacterCards[0].rpgStats.attributes from chat metadata. No DB migration; existing chats benefit immediately. Schema now also accepts preRolledD20: 1-20 so a player-submitted [dice:1d20] can be applied through the same modifier-aware code path.
  • resolveSkillCheck (packages/server/src/services/game/skill-check.service.ts): honours preRolledD20 — when present, skips internal d20 rolling and uses the player's number as the usedRoll, with the attribute modifier applied on top.
  • GM prompt (packages/server/src/services/game/gm-prompts.ts): emits sparse [skill_check: skill="..." dc="..."] (or …rolls="<player's d20>" after a player pre-roll). The instruction is explicit that the engine fills in modifier/total/result; do not invent them. The client at components/game/GameSurface.tsx already had a fallback path to call /skill-check when those fields are absent — this PR turns that fallback into the primary path.
  • Tag parser (packages/client/src/lib/game-tag-parser.ts): when a sparse tag carries a single integer in rolls=, surfaces it as preRolledD20 on the parsed tag so the client mutation forwards it to the server.
  • Combat init (packages/server/src/routes/encounter.routes.ts): same lazy fallback — when playerStats.attributes is null, reads the player's character-sheet attributes from chat metadata and emits a Character Sheet Attributes: STR x, DEX y, ... line in the encounter context. Adds a one-line prompt note instructing the LLM to scale generated attack/defense/hp (when not configured) by attribute values on a 10-as-average baseline. Configured Max HP still wins.
  • Tests (packages/server/test/game-session-prompts.test.ts): updated the skill_check format-reminder assertions for both the AI-initiated and player-prerolled prompt shapes; added a case for the player-prerolled branch.

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

  • Manually verify that the Game Mode character sheet now shows a (+N) / (−N) modifier underneath each attribute value in the read-only Attributes grid, matching floor((score - 10) / 2).
  • Manually verify that a Strength-governed skill check (e.g. forcing a door) on a character with STR 20 resolves with a noticeably higher success rate / final total than the same character with STR 1.
  • Manually verify that the GM no longer narrates invented rolls/modifier/total/result numbers — the resolved skill-check popup should reflect the server-rolled d20 plus the deterministic attribute modifier.
  • Manually verify the player-prerolled path: submit a [dice:1d20] first, then take an action; the resolved roll should equal your d20 plus the sheet's attribute modifier.
  • Manually verify a combat encounter init: trigger [state: combat] from the GM and confirm the generated party member's attack/defense/hp reflects the character's RPG attributes (high STR → noticeably higher attack power; high DEX → higher speed).
  • Manually verify the no-data fallback: a chat with no RPG stats configured should still produce a clean d20-vs-DC resolution (modifier 0), with no broken state.
  • Edge case: a chat created before this change has playerStats.attributes = null and no migration is needed — the lazy fallback should still pick up the sheet attributes.

Docs and release impact

  • No docs changes needed

UI evidence (if applicable)

The read-only attribute grid in GameCharacterSheet now renders a third row under each value:

STR        DEX        CON
17         24         18
+3         +7         +4
image

Summary by CodeRabbit

  • New Features

    • RPG attribute modifiers now display next to attribute values in character sheets
    • Skill checks now support player-submitted pre-rolled D20 values
    • Character sheet attributes serve as fallback data for combat encounter initialization
  • Improvements

    • Simplified skill check tag format in GM prompts for clearer instructions

Review Change Stack


🔄 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/593 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/9/2026 **Status:** ✅ Merged **Merged:** 5/9/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `main` ← **Head:** `fix/game-mode-skill-check-attributes` --- ### 📝 Commits (2) - [`1c400b7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1c400b774ba2e9f4812e26fc74bea262979334b8) fix(game,combat): apply sheet attribute modifiers to skill checks and combat init - [`ab5082e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/ab5082e8dedbc780abd653433edde22da7c490d9) fix(combat): guard chat.metadata JSON.parse in encounter init ### 📊 Changes **9 files changed** (+183 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `packages/client/src/components/game/GameCharacterSheet.tsx` (+9 -0) 📝 `packages/client/src/components/game/GameSurface.tsx` (+1 -0) 📝 `packages/client/src/hooks/use-game.ts` (+8 -2) 📝 `packages/client/src/lib/game-tag-parser.ts` (+15 -0) 📝 `packages/server/src/routes/encounter.routes.ts` (+42 -1) 📝 `packages/server/src/routes/game.routes.ts` (+27 -6) 📝 `packages/server/src/services/game/gm-prompts.ts` (+2 -2) 📝 `packages/server/src/services/game/skill-check.service.ts` (+61 -9) 📝 `packages/server/test/game-session-prompts.test.ts` (+18 -6) </details> ### 📄 Description ## Linked issue Closes #592 ## Why this change - Game Mode skill checks didn't actually use the character sheet's RPG attributes — the GM was instructed to invent the `rolls/modifier/total/result` itself, and the deterministic server resolver almost never ran. Setting `STR 20` on the sheet made no difference to a Strength check outcome. - Combat Mode encounter init never received the player's character-sheet attributes either — the prompt builder reads from `playerStats.attributes` which is `null` for every chat. The LLM generated `attack/defense/hp` with no link to the player's intended build. - Three converging gaps caused this: `PlayerStats.attributes` is initialised to `null` in every game-state writer and never seeded; the GM prompt asked the AI to fill in roll math; and the sheet's free-form `Array<{name,value}>` shape never had a mapper to the strict `RPGAttributes: { str, dex, con, int, wis, cha }` shape the engine wants. ## What changed - **Sheet display** (`packages/client/src/components/game/GameCharacterSheet.tsx`): show the D&D-style modifier next to each attribute on the read-only grid (`STR 17 (+3)`), using the same `floor((score - 10) / 2)` formula the server already implements for skill checks. - **Name mapper + lazy fallback** (`packages/server/src/services/game/skill-check.service.ts`): added `mapSheetAttributesToRPG` — case-insensitive map from `Array<{name,value}>` (sheet shape; accepts `STR/Str/Strength`, `DEX/Dexterity`, etc.) to `Partial<RPGAttributes>`. Custom names are dropped. - **Skill-check route** (`packages/server/src/routes/game.routes.ts`): when `playerStats.attributes` is null, falls back to mapping the player's `gameCharacterCards[0].rpgStats.attributes` from chat metadata. No DB migration; existing chats benefit immediately. Schema now also accepts `preRolledD20: 1-20` so a player-submitted `[dice:1d20]` can be applied through the same modifier-aware code path. - **`resolveSkillCheck`** (`packages/server/src/services/game/skill-check.service.ts`): honours `preRolledD20` — when present, skips internal d20 rolling and uses the player's number as the `usedRoll`, with the attribute modifier applied on top. - **GM prompt** (`packages/server/src/services/game/gm-prompts.ts`): emits sparse `[skill_check: skill="..." dc="..."]` (or `…rolls="<player's d20>"` after a player pre-roll). The instruction is explicit that the engine fills in modifier/total/result; do not invent them. The client at `components/game/GameSurface.tsx` already had a fallback path to call `/skill-check` when those fields are absent — this PR turns that fallback into the primary path. - **Tag parser** (`packages/client/src/lib/game-tag-parser.ts`): when a sparse tag carries a single integer in `rolls=`, surfaces it as `preRolledD20` on the parsed tag so the client mutation forwards it to the server. - **Combat init** (`packages/server/src/routes/encounter.routes.ts`): same lazy fallback — when `playerStats.attributes` is null, reads the player's character-sheet attributes from chat metadata and emits a `Character Sheet Attributes: STR x, DEX y, ...` line in the encounter context. Adds a one-line prompt note instructing the LLM to scale generated `attack/defense/hp` (when not configured) by attribute values on a 10-as-average baseline. Configured Max HP still wins. - **Tests** (`packages/server/test/game-session-prompts.test.ts`): updated the `skill_check` format-reminder assertions for both the AI-initiated and player-prerolled prompt shapes; added a case for the player-prerolled branch. ## Validation - [x] `pnpm check` passes locally - [x] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [x] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Manually verify that the Game Mode character sheet now shows a `(+N)` / `(−N)` modifier underneath each attribute value in the read-only Attributes grid, matching `floor((score - 10) / 2)`. - Manually verify that a Strength-governed skill check (e.g. forcing a door) on a character with `STR 20` resolves with a noticeably higher success rate / final total than the same character with `STR 1`. - Manually verify that the GM no longer narrates invented `rolls/modifier/total/result` numbers — the resolved skill-check popup should reflect the server-rolled d20 plus the deterministic attribute modifier. - Manually verify the player-prerolled path: submit a `[dice:1d20]` first, then take an action; the resolved roll should equal your d20 plus the sheet's attribute modifier. - Manually verify a combat encounter init: trigger `[state: combat]` from the GM and confirm the generated party member's `attack/defense/hp` reflects the character's RPG attributes (high STR → noticeably higher attack power; high DEX → higher speed). - Manually verify the no-data fallback: a chat with no RPG stats configured should still produce a clean d20-vs-DC resolution (modifier `0`), with no broken state. - Edge case: a chat created before this change has `playerStats.attributes = null` and no migration is needed — the lazy fallback should still pick up the sheet attributes. ## Docs and release impact - [x] No docs changes needed ## UI evidence (if applicable) The read-only attribute grid in `GameCharacterSheet` now renders a third row under each value: ``` STR DEX CON 17 24 18 +3 +7 +4 ``` <img width="993" height="280" alt="image" src="https://github.com/user-attachments/assets/44a046fd-0c2c-47e5-a88e-e310ae74110c" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * RPG attribute modifiers now display next to attribute values in character sheets * Skill checks now support player-submitted pre-rolled D20 values * Character sheet attributes serve as fallback data for combat encounter initialization * **Improvements** * Simplified skill check tag format in GM prompts for clearer instructions [![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/Pasta-Devs/Marinara-Engine/pull/593) <!-- 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-22 04:09:49 +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#4688
No description provided.