fix: broadcast character:updated on rest to clear Dying; clamp HP to 0 minimum
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7cfe677126
commit
6114aef307
2 changed files with 13 additions and 4 deletions
|
|
@ -312,7 +312,8 @@ export default function CampaignView() {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleHpChange(characterId: number, hp: number) {
|
async function handleHpChange(characterId: number, hp: number) {
|
||||||
await updateCharacter(characterId, { hp_current: hp });
|
const clampedHp = Math.max(0, hp);
|
||||||
|
await updateCharacter(characterId, { hp_current: clampedHp });
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleStatChange(
|
async function handleStatChange(
|
||||||
|
|
|
||||||
|
|
@ -721,9 +721,17 @@ router.post("/:id/rest", requireAuth, async (req, res, next) => {
|
||||||
"DELETE FROM character_conditions WHERE character_id = ?",
|
"DELETE FROM character_conditions WHERE character_id = ?",
|
||||||
[req.params.id]
|
[req.params.id]
|
||||||
);
|
);
|
||||||
const io = req.app.get("io");
|
const [charRow] = await db.execute<RowDataPacket[]>(
|
||||||
const char = await getCharacterCampaignId(Number(req.params.id));
|
"SELECT * FROM characters WHERE id = ?",
|
||||||
io.to(String(char.campaign_id)).emit("character:rested", { characterId: Number(req.params.id) });
|
[req.params.id]
|
||||||
|
);
|
||||||
|
const io: Server = req.app.get("io");
|
||||||
|
broadcastToCampaign(io, Number(charRow[0].campaign_id), "character:updated", {
|
||||||
|
...charRow[0],
|
||||||
|
overrides: parseJson(charRow[0].overrides),
|
||||||
|
conditions: [],
|
||||||
|
});
|
||||||
|
io.to(String(charRow[0].campaign_id)).emit("character:rested", { characterId: Number(req.params.id) });
|
||||||
res.json({ ok: true });
|
res.json({ ok: true });
|
||||||
} catch (err) { next(err); }
|
} catch (err) { next(err); }
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue