[PR #553] [MERGED] fix(combat): use configured persona/character HP at combat init #4673

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

📋 Pull Request Information

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

Base: main ← Head: fix/combat-init-hp


📝 Commits (2)

  • f19f45f fix(combat): use configured persona/character HP at combat init
  • df52b68 fix(combat): guard HP context against malformed numeric values

📊 Changes

1 file changed (+60 additions, -2 deletions)

View changed files

📝 packages/server/src/routes/encounter.routes.ts (+60 -2)

📄 Description

Linked issue

Closes #551

Why this change

In Game Mode, when the GM emits [state: combat] the client calls POST /encounter/init to generate the combat blueprint. The init-prompt builders sent no HP information about the configured persona or party characters, so the AI had nothing to copy from and was forced to invent fresh HP/maxHp for every party combatant — and the explicit instruction "Ensure HP values are realistic for the setting" further encouraged invention. A persona configured with Max HP 1000 would routinely enter combat with some unrelated lower number; companions with character-card RPG stats got the same treatment.

What changed

In packages/server/src/routes/encounter.routes.ts:

  • buildPersonaContext now parses persona.personaStats and surfaces the configured stat bars (max only) and personaStats.rpgStats (Max HP + attributes) when enabled.
  • buildCharacterContext now surfaces each ally's data.extensions.rpgStats (Max HP + attributes) when enabled.
  • The buildInitPrompt instruction line was rewritten: if a combatant has a configured Max HP in the context, copy it into maxHp and set hp = maxHp so combat starts at full health. Enemies and unstatted combatants still get AI-generated HP.

Only max is exposed (not the running value field) so a depleted in-narrative HP value doesn't drag the player into a fresh fight at low/zero HP — combat entry is always full health, and the GM can apply damage tags afterwards if narration calls for it.

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

Tested on a Docker-deployed dev instance against the live /encounter/init route with a frontier model:

  1. Started a Game Mode chat with a persona configured via personaStats.bars (HP bar set with max = 1000) and a party that included a companion character card with extensions.rpgStats.enabled = true, hp.max = 100.
  2. Played until the GM emitted [state: combat].
  3. Before fix: persona showed up at e.g. 100/1000 (or unrelated values), party characters at 0/100 with KO icons.
  4. After fix: persona entered combat at 1000/1000, party characters at 100/100, all at full health. Enemies still received sensible AI-generated HP.

Edge cases not exercised in browser:

  • A persona/character with no configured stats — the gating if branches simply skip the extra context, and the AI-invents path still applies as before. No regression expected.

Docs and release impact

  • No docs changes needed

UI evidence (if applicable)

Server-side prompt fix; no UI changes.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced encounter generation to properly honor user-configured character HP and persona statistics. Combat encounters now consistently use configured maximum HP values and character attributes as defined in character/persona settings.

🔄 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/553 **Author:** [@Romuromylus](https://github.com/Romuromylus) **Created:** 5/8/2026 **Status:** ✅ Merged **Merged:** 5/8/2026 **Merged by:** [@Romuromylus](https://github.com/Romuromylus) **Base:** `main` ← **Head:** `fix/combat-init-hp` --- ### 📝 Commits (2) - [`f19f45f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/f19f45fe2e7fc969db8d9c2eb14ec635d9bb698e) fix(combat): use configured persona/character HP at combat init - [`df52b68`](https://github.com/Pasta-Devs/Marinara-Engine/commit/df52b68ca720be3a79f7b1a127b439e3bd9ecacb) fix(combat): guard HP context against malformed numeric values ### 📊 Changes **1 file changed** (+60 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/encounter.routes.ts` (+60 -2) </details> ### 📄 Description ## Linked issue Closes #551 ## Why this change In Game Mode, when the GM emits `[state: combat]` the client calls `POST /encounter/init` to generate the combat blueprint. The init-prompt builders sent no HP information about the configured persona or party characters, so the AI had nothing to copy from and was forced to invent fresh HP/maxHp for every party combatant — and the explicit instruction "Ensure HP values are realistic for the setting" further encouraged invention. A persona configured with Max HP 1000 would routinely enter combat with some unrelated lower number; companions with character-card RPG stats got the same treatment. ## What changed In `packages/server/src/routes/encounter.routes.ts`: - `buildPersonaContext` now parses `persona.personaStats` and surfaces the configured stat bars (max only) and `personaStats.rpgStats` (Max HP + attributes) when enabled. - `buildCharacterContext` now surfaces each ally's `data.extensions.rpgStats` (Max HP + attributes) when enabled. - The `buildInitPrompt` instruction line was rewritten: if a combatant has a configured Max HP in the context, copy it into `maxHp` and set `hp = maxHp` so combat starts at full health. Enemies and unstatted combatants still get AI-generated HP. Only `max` is exposed (not the running `value` field) so a depleted in-narrative HP value doesn't drag the player into a fresh fight at low/zero HP — combat entry is always full health, and the GM can apply damage tags afterwards if narration calls for it. ## 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 Tested on a Docker-deployed dev instance against the live `/encounter/init` route with a frontier model: 1. Started a Game Mode chat with a persona configured via `personaStats.bars` (HP bar set with `max = 1000`) and a party that included a companion character card with `extensions.rpgStats.enabled = true, hp.max = 100`. 2. Played until the GM emitted `[state: combat]`. 3. **Before fix:** persona showed up at e.g. `100/1000` (or unrelated values), party characters at `0/100` with KO icons. 4. **After fix:** persona entered combat at `1000/1000`, party characters at `100/100`, all at full health. Enemies still received sensible AI-generated HP. Edge cases not exercised in browser: - A persona/character with no configured stats — the gating `if` branches simply skip the extra context, and the AI-invents path still applies as before. No regression expected. ## Docs and release impact - [x] No docs changes needed ## UI evidence (if applicable) Server-side prompt fix; no UI changes. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Enhanced encounter generation to properly honor user-configured character HP and persona statistics. Combat encounters now consistently use configured maximum HP values and character attributes as defined in character/persona settings. <!-- 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:40 +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#4673
No description provided.