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
+20 -1
View File
@@ -87,12 +87,31 @@ export default function CharacterDetail() {
</div>
)}
{Object.keys(character.combat_stats).length > 0 && (
{(character.current_hp !== null || Object.keys(character.combat_stats).length > 0) && (
<div className="mt-6">
<h2 className="mb-3 text-sm font-semibold uppercase tracking-wide text-slate-500">
Kampfwerte
</h2>
<div className="flex flex-wrap gap-3">
{character.current_hp !== null && (
<div
className={`rounded-lg border px-4 py-2 text-center ${
character.current_hp <= 0
? "border-red-500/50 bg-red-500/10"
: "border-slate-700 bg-slate-800"
}`}
>
<div className="text-xs font-semibold uppercase tracking-wide text-slate-400">
Trefferpunkte
</div>
<div
className={`text-lg font-bold ${character.current_hp <= 0 ? "text-red-400" : "text-slate-100"}`}
>
{character.current_hp}
{character.max_hp !== null ? ` / ${character.max_hp}` : ""}
</div>
</div>
)}
{Object.entries(character.combat_stats).map(([key, value]) => (
<div
key={key}
+9
View File
@@ -21,11 +21,13 @@ export default function GameSession() {
const [joinError, setJoinError] = useState<string | null>(null);
const [isTyping, setIsTyping] = useState(false);
const [rollingNotation, setRollingNotation] = useState<string | null>(null);
const [endedReason, setEndedReason] = useState<string | null>(null);
async function loadGame() {
if (!gameId) return;
const g = await getGame(gameId);
setGame(g);
setEndedReason(g.status === "ended" ? g.ended_reason : null);
return g;
}
@@ -102,6 +104,7 @@ export default function GameSession() {
},
() => setIsTyping(true),
(notation) => setRollingNotation(notation),
(reason) => setEndedReason(reason),
);
async function handleSend(content: string) {
@@ -180,6 +183,12 @@ export default function GameSession() {
</div>
</div>
{endedReason && (
<div className="mb-3 rounded-lg border border-amber-500/50 bg-amber-500/10 px-4 py-3 text-sm text-amber-300">
<span className="font-semibold">Spiel beendet.</span> {endedReason}
</div>
)}
<div className="flex flex-1 flex-col overflow-hidden rounded-lg border border-slate-800 bg-slate-900">
<TranscriptPane messages={messages} typing={isTyping} rolling={rollingNotation} />
<SendMessageForm onSend={handleSend} />