Add game end status with an end_game DM tool and automatic 0-HP detection

Games now have a status/ended_reason pair. The DM can call the new
end_game tool when the story reaches a real conclusion (victory,
defeat, or a resolved one-shot), and the backend independently ends
the game whenever a character's HP drops to 0 or below, regardless of
whether the DM narrates it. The frontend shows a banner and a
"Beendet" badge once a game ends.

HP moves from the freeform combat_stats bag into dedicated
current_hp/max_hp columns on Character, since reliably detecting 0 HP
requires a real integer rather than parsing strings like "3/10" out of
an LLM-authored key/value dict. Also fixed combat_stats to fully
replace on each upsert instead of merging, matching its documented
contract — the merge was leaving stale keys (old HP/TP text) behind
after the model stopped sending them.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Thorsten
2026-09-01 17:44:46 +02:00
parent 2b99451fdf
commit 8da834c5c1
17 changed files with 196 additions and 8 deletions
@@ -0,0 +1,34 @@
"""add game status/ended_reason and character current_hp/max_hp
Revision ID: c9a1d5e7f316
Revises: b8e4f1a9c203
Create Date: 2026-09-01 16:00:00.000000
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision: str = 'c9a1d5e7f316'
down_revision: Union[str, None] = 'b8e4f1a9c203'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def upgrade() -> None:
op.add_column(
'games',
sa.Column('status', sa.String(length=20), nullable=False, server_default='active'),
)
op.add_column('games', sa.Column('ended_reason', sa.Text(), nullable=True))
op.add_column('characters', sa.Column('current_hp', sa.Integer(), nullable=True))
op.add_column('characters', sa.Column('max_hp', sa.Integer(), nullable=True))
def downgrade() -> None:
op.drop_column('characters', 'max_hp')
op.drop_column('characters', 'current_hp')
op.drop_column('games', 'ended_reason')
op.drop_column('games', 'status')