V1.0.1: Aldenfell campaign seed, content library, party overview
- Seed now resets the database and seeds the Aldenfell campaign from the campaign book: admin DM user, default weapons, locations, bestiary, pre-built encounters, and DM/shared notes - Default weapon/spell/monster library, character profile fields, locations and dice mode (new migration) - Party overview page, pagination, info tips, build preview calc - Remove stale demo-login hint; notes preserve line breaks Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,8 @@ const {
|
||||
rollAbilityScore,
|
||||
speciesChoicesForRoll,
|
||||
classChoicesForRoll,
|
||||
autoSelectSkills,
|
||||
validateManualRoll,
|
||||
MOTIVATION_TABLE,
|
||||
} = require('../game/buildFlow');
|
||||
const { SKILLS } = require('../game/data/skills');
|
||||
@@ -32,11 +34,14 @@ async function loadFullCharacter(id) {
|
||||
inventoryItems: true,
|
||||
weapons: { include: { weapon: true } },
|
||||
spells: { include: { spell: true } },
|
||||
currentLocation: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function serializeCharacter(character) {
|
||||
// privateNotes is a real privacy boundary, not a UI hide — it's only ever
|
||||
// included in the payload for the character's own owning player.
|
||||
function serializeCharacter(character, isOwner) {
|
||||
const sheet = computeCharacterSheet(character, character.skillProficiencies, character.saveProficiencies);
|
||||
return {
|
||||
id: character.id,
|
||||
@@ -63,6 +68,12 @@ function serializeCharacter(character) {
|
||||
tempHp: character.tempHp,
|
||||
armorBonus: character.armorBonus,
|
||||
specialAbilities: character.specialAbilities,
|
||||
background: character.background,
|
||||
appearance: character.appearance,
|
||||
privateNotes: isOwner ? character.privateNotes : undefined,
|
||||
diceMode: character.diceMode,
|
||||
currentLocationId: character.currentLocationId,
|
||||
currentLocation: character.currentLocation || null,
|
||||
gold: character.gold,
|
||||
buildStage: character.buildStage,
|
||||
buildState: character.buildStage === 'COMPLETE' ? null : character.buildState,
|
||||
@@ -78,7 +89,7 @@ function serializeCharacter(character) {
|
||||
router.get('/:id', requireCharacterAccess(), async (req, res, next) => {
|
||||
try {
|
||||
const character = await loadFullCharacter(req.character.id);
|
||||
res.json({ character: serializeCharacter(character) });
|
||||
res.json({ character: serializeCharacter(character, req.isOwner) });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
@@ -91,6 +102,10 @@ const patchCharacterSchema = z.object({
|
||||
armorBonus: z.number().int().min(0).optional(),
|
||||
speedOverride: z.number().int().min(0).nullable().optional(),
|
||||
specialAbilities: z.string().max(4000).nullable().optional(),
|
||||
background: z.string().max(4000).nullable().optional(),
|
||||
appearance: z.string().max(4000).nullable().optional(),
|
||||
privateNotes: z.string().max(4000).nullable().optional(),
|
||||
currentLocationId: z.string().nullable().optional(),
|
||||
gold: z.number().int().min(0).optional(),
|
||||
level: z.number().int().min(1).max(20).optional(),
|
||||
xp: z.number().int().min(0).optional(),
|
||||
@@ -101,12 +116,28 @@ router.patch('/:id', requireCharacterAccess({ write: true }), async (req, res, n
|
||||
const parsed = patchCharacterSchema.safeParse(req.body);
|
||||
if (!parsed.success) return res.status(400).json({ error: parsed.error.flatten() });
|
||||
|
||||
// privateNotes is for the owning player only — a DM editing someone
|
||||
// else's character (or another player, though write access already
|
||||
// blocks that) should never be able to set it through this route.
|
||||
if (parsed.data.privateNotes !== undefined && !req.isOwner) {
|
||||
return res.status(403).json({ error: 'Only the owning player can edit private notes.' });
|
||||
}
|
||||
|
||||
if (parsed.data.currentLocationId) {
|
||||
const location = await prisma.location.findUnique({ where: { id: parsed.data.currentLocationId } });
|
||||
if (!location || location.campaignId !== req.character.campaignId) {
|
||||
return res.status(400).json({ error: 'That location is not part of this campaign.' });
|
||||
}
|
||||
}
|
||||
|
||||
const updated = await prisma.character.update({ where: { id: req.character.id }, data: parsed.data });
|
||||
const full = await loadFullCharacter(updated.id);
|
||||
const payload = serializeCharacter(full);
|
||||
|
||||
req.app.get('io').to(`campaign:${updated.campaignId}`).emit('character:updated', { character: payload });
|
||||
res.json({ character: payload });
|
||||
// Broadcast payload never includes privateNotes — a socket room has
|
||||
// every campaign member in it, not just the owner. Only the direct HTTP
|
||||
// response (below) is allowed to include it.
|
||||
req.app.get('io').to(`campaign:${updated.campaignId}`).emit('character:updated', { character: serializeCharacter(full, false) });
|
||||
res.json({ character: serializeCharacter(full, req.isOwner) });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
@@ -126,38 +157,90 @@ router.delete('/:id', requireCharacterAccess(), async (req, res, next) => {
|
||||
// Roll-Your-Character build flow — docs/ROLL_YOUR_CHARACTER.md
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
// Digital mode rolls server-side (crypto.randomInt) as before. Physical mode
|
||||
// requires the value(s) the roller typed in from their real dice — this
|
||||
// helper validates them against the step's real die range/count and throws
|
||||
// a user-facing error string on failure, otherwise returns the value(s) in
|
||||
// the exact same shape the digital path would have produced.
|
||||
function resolveSingleRoll(character, body, sides) {
|
||||
if (character.diceMode !== 'PHYSICAL') return rollDie(sides);
|
||||
const value = Number(body?.value);
|
||||
if (!validateManualRoll(sides, value)) {
|
||||
throw new Error(`Enter the d${sides} you rolled — a whole number from 1 to ${sides}.`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
function resolveAbilityRolls(character, body) {
|
||||
if (character.diceMode !== 'PHYSICAL') {
|
||||
return Array.from({ length: 6 }, () => rollAbilityScore());
|
||||
}
|
||||
const sets = body?.abilitySets;
|
||||
if (!Array.isArray(sets) || sets.length !== 6) {
|
||||
throw new Error('Enter all six 4d6 sets you rolled at the table.');
|
||||
}
|
||||
return sets.map((dice, i) => {
|
||||
if (!Array.isArray(dice) || dice.length !== 4 || !dice.every((d) => validateManualRoll(6, d))) {
|
||||
throw new Error(`Ability set ${i + 1}: enter four d6 results, each a whole number from 1 to 6.`);
|
||||
}
|
||||
return abilityScoreFromDice(dice);
|
||||
});
|
||||
}
|
||||
|
||||
router.patch('/:id/build/dice-mode', requireCharacterAccess({ write: true }), async (req, res, next) => {
|
||||
try {
|
||||
const character = req.character;
|
||||
const parsed = z.object({ diceMode: z.enum(['DIGITAL', 'PHYSICAL']) }).safeParse(req.body);
|
||||
if (!parsed.success) return res.status(400).json({ error: parsed.error.flatten() });
|
||||
|
||||
const alreadyRolling = character.buildStage !== 'ROLLING_SPECIES' || Boolean((character.buildState || {}).speciesRoll);
|
||||
if (alreadyRolling) {
|
||||
return res.status(400).json({ error: 'Dice mode can only be chosen before the first roll of the build.' });
|
||||
}
|
||||
|
||||
const updated = await prisma.character.update({ where: { id: character.id }, data: { diceMode: parsed.data.diceMode } });
|
||||
res.json({ diceMode: updated.diceMode });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/:id/build/roll', requireCharacterAccess({ write: true }), async (req, res, next) => {
|
||||
try {
|
||||
const character = req.character;
|
||||
const stage = character.buildStage;
|
||||
const buildState = { ...(character.buildState || {}) };
|
||||
|
||||
if (stage === 'ROLLING_SPECIES') {
|
||||
const roll = rollDie(6);
|
||||
buildState.speciesRoll = roll;
|
||||
buildState.speciesChoices = speciesChoicesForRoll(roll);
|
||||
delete buildState.species;
|
||||
delete buildState.halfElfBonusAbilities;
|
||||
} else if (stage === 'ROLLING_CLASS') {
|
||||
const alreadyRolled = buildState.classChoices && buildState.classChoices.type !== 'reroll';
|
||||
if (alreadyRolled) {
|
||||
return res.status(400).json({ error: 'Class die already rolled for this character — submit a choice, or reroll if the current roll allows it.' });
|
||||
try {
|
||||
if (stage === 'ROLLING_SPECIES') {
|
||||
const roll = resolveSingleRoll(character, req.body, 6);
|
||||
buildState.speciesRoll = roll;
|
||||
buildState.speciesChoices = speciesChoicesForRoll(roll);
|
||||
delete buildState.species;
|
||||
delete buildState.halfElfBonusAbilities;
|
||||
} else if (stage === 'ROLLING_CLASS') {
|
||||
const alreadyRolled = buildState.classChoices && buildState.classChoices.type !== 'reroll';
|
||||
if (alreadyRolled) {
|
||||
return res.status(400).json({ error: 'Class die already rolled for this character — submit a choice, or reroll if the current roll allows it.' });
|
||||
}
|
||||
const roll = resolveSingleRoll(character, req.body, 8);
|
||||
buildState.classRoll = roll;
|
||||
buildState.classChoices = classChoicesForRoll(roll);
|
||||
delete buildState.characterClass;
|
||||
} else if (stage === 'ROLLING_MOTIVATION') {
|
||||
const roll = resolveSingleRoll(character, req.body, 6);
|
||||
buildState.motivationRoll = roll;
|
||||
buildState.motivationText = MOTIVATION_TABLE[roll];
|
||||
} else if (stage === 'ASSIGNING_SCORES') {
|
||||
if (buildState.abilityRolls) {
|
||||
return res.status(400).json({ error: 'Ability scores were already rolled for this character.' });
|
||||
}
|
||||
buildState.abilityRolls = resolveAbilityRolls(character, req.body);
|
||||
} else {
|
||||
return res.status(400).json({ error: `No die roll is required at the "${stage}" step.` });
|
||||
}
|
||||
const roll = rollDie(8);
|
||||
buildState.classRoll = roll;
|
||||
buildState.classChoices = classChoicesForRoll(roll);
|
||||
delete buildState.characterClass;
|
||||
} else if (stage === 'ROLLING_MOTIVATION') {
|
||||
const roll = rollDie(6);
|
||||
buildState.motivationRoll = roll;
|
||||
buildState.motivationText = MOTIVATION_TABLE[roll];
|
||||
} else if (stage === 'ASSIGNING_SCORES') {
|
||||
if (buildState.abilityRolls) {
|
||||
return res.status(400).json({ error: 'Ability scores were already rolled for this character.' });
|
||||
}
|
||||
buildState.abilityRolls = Array.from({ length: 6 }, () => rollAbilityScore());
|
||||
} else {
|
||||
return res.status(400).json({ error: `No die roll is required at the "${stage}" step.` });
|
||||
} catch (rollErr) {
|
||||
return res.status(400).json({ error: rollErr.message });
|
||||
}
|
||||
|
||||
const updated = await prisma.character.update({ where: { id: character.id }, data: { buildState } });
|
||||
@@ -186,14 +269,19 @@ const chooseSchemas = {
|
||||
CHA: z.number().int().min(0).max(5),
|
||||
}),
|
||||
}),
|
||||
// Skill proficiencies are now auto-generated (see autoSelectSkills, applied
|
||||
// when this stage is entered from ASSIGNING_SCORES below) — this payload is
|
||||
// an optional DM correction, not the normal path.
|
||||
ASSIGNING_PROFICIENCIES: z.object({
|
||||
skillProficiencies: z.array(
|
||||
z.object({
|
||||
skill: z.enum(Object.keys(SKILLS)),
|
||||
proficient: z.boolean().default(true),
|
||||
expertise: z.boolean().default(false),
|
||||
})
|
||||
),
|
||||
skillProficiencies: z
|
||||
.array(
|
||||
z.object({
|
||||
skill: z.enum(Object.keys(SKILLS)),
|
||||
proficient: z.boolean().default(true),
|
||||
expertise: z.boolean().default(false),
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
}),
|
||||
CHOOSING_EQUIPMENT: z.object({
|
||||
weaponIds: z.array(z.string()).default([]),
|
||||
@@ -274,8 +362,16 @@ router.post('/:id/build/choose', requireCharacterAccess({ write: true }), async
|
||||
return res.status(400).json({ error: 'Each of the 6 rolled scores must be assigned to exactly one ability.' });
|
||||
}
|
||||
buildState.abilityAssignments = assignments;
|
||||
// Skill proficiencies are auto-generated per the class's SRD "choose N"
|
||||
// rule the moment ability scores are locked in, so the next step has
|
||||
// something to show immediately rather than an empty picker.
|
||||
buildState.skillProficiencies = autoSelectSkills(buildState.characterClass);
|
||||
} else if (stage === 'ASSIGNING_PROFICIENCIES') {
|
||||
buildState.skillProficiencies = parsed.data.skillProficiencies;
|
||||
// Optional DM override of the auto-generated picks; if omitted, the
|
||||
// auto-generated set from the previous step stands as-is.
|
||||
if (parsed.data.skillProficiencies) {
|
||||
buildState.skillProficiencies = parsed.data.skillProficiencies;
|
||||
}
|
||||
} else if (stage === 'CHOOSING_EQUIPMENT') {
|
||||
const { weaponIds, spellIds } = parsed.data;
|
||||
const maxItems = req.campaign.startingItemCount;
|
||||
@@ -373,9 +469,8 @@ router.post('/:id/build/finalize', requireCharacterAccess({ write: true }), asyn
|
||||
});
|
||||
|
||||
const full = await loadFullCharacter(result.id);
|
||||
const payload = serializeCharacter(full);
|
||||
req.app.get('io').to(`campaign:${result.campaignId}`).emit('character:created', { character: payload });
|
||||
res.json({ character: payload });
|
||||
req.app.get('io').to(`campaign:${result.campaignId}`).emit('character:created', { character: serializeCharacter(full, false) });
|
||||
res.json({ character: serializeCharacter(full, req.isOwner) });
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user