V1.22.0: campaign settings for dice, scores, multiclassing, auto-rolls, XP and crits

- Settings grouped into Characters, Dice & rolls, Combat and Progression
- Dice: digital, physical or both; a campaign's own choice applies to every character
- Ability scores by 4d6, the standard array or point buy (27 points, 8 to 15)
- Track XP can be turned off for milestone levelling: XP is hidden and not awarded
- New settings saved ahead of their features: multiclassing, auto-rolled monster
  and NPC attacks, roll visibility, hidden monster rolls, HP on level up, crit rule
- docs/CAMPAIGN_SETTINGS.md lists every setting

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-11 15:12:05 +02:00
co-authored by Claude Opus 5.5
parent 57fba68a48
commit e7b6e0065a
24 changed files with 697 additions and 96 deletions
+50 -13
View File
@@ -33,6 +33,10 @@ const {
composeFromPicks,
validateTalents,
composeSpecialAbilities,
STANDARD_ARRAY,
POINT_BUY_BUDGET,
pointBuyCost,
effectiveDiceMode,
} = require('../game/buildFlow');
const characterOptions = require('../game/data/characterOptions');
const { SKILLS } = require('../game/data/skills');
@@ -55,7 +59,7 @@ async function loadFullCharacter(id) {
weapons: { include: { weapon: true } },
spells: { include: { spell: true } },
currentLocation: true,
campaign: { select: { subclassesEnabled: true } },
campaign: { select: { subclassesEnabled: true, diceMode: true } },
},
});
}
@@ -115,7 +119,10 @@ function serializeCharacter(character, isOwner, isDM = true) {
background: character.background,
appearance: character.appearance,
privateNotes: isOwner ? character.privateNotes : undefined,
diceMode: character.diceMode,
// The dice this character rolls with, and whether that is theirs to choose
// (the campaign leaves it to each character) or the campaign's.
diceMode: effectiveDiceMode(character.campaign, character),
diceModeChoosable: !character.campaign || character.campaign.diceMode === 'BOTH',
currentLocationId: restricted ? null : character.currentLocationId,
currentLocation: restricted ? null : character.currentLocation || null,
gold: restricted ? null : character.gold,
@@ -796,7 +803,7 @@ router.post('/:id/copy', requireCharacterAccess(), async (req, res, next) => {
// 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);
if (effectiveDiceMode(character.campaign, character) !== '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}.`);
@@ -805,7 +812,11 @@ function resolveSingleRoll(character, body, sides) {
}
function resolveAbilityRolls(character, body) {
if (character.diceMode !== 'PHYSICAL') {
// The standard array is not rolled at all: the same six scores for everyone.
if (character.campaign.abilityScoreMethod === 'STANDARD_ARRAY') {
return STANDARD_ARRAY.map((total) => ({ dice: [], dropped: null, total }));
}
if (effectiveDiceMode(character.campaign, character) !== 'PHYSICAL') {
return Array.from({ length: 6 }, () => rollAbilityScore());
}
const sets = body?.abilitySets;
@@ -826,6 +837,9 @@ router.patch('/:id/build/dice-mode', requireCharacterAccess({ write: true }), as
const parsed = z.object({ diceMode: z.enum(['DIGITAL', 'PHYSICAL']) }).safeParse(req.body);
if (!parsed.success) return res.status(400).json({ error: parsed.error.flatten() });
if (req.campaign.diceMode !== 'BOTH') {
return res.status(400).json({ error: `This campaign plays with ${req.campaign.diceMode === 'PHYSICAL' ? 'physical' : 'digital'} dice only.` });
}
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.' });
@@ -867,6 +881,9 @@ router.post('/:id/build/roll', requireCharacterAccess({ write: true }), async (r
if (buildState.abilityRolls) {
return res.status(400).json({ error: 'Ability scores were already rolled for this character.' });
}
if (req.campaign.abilityScoreMethod === 'POINT_BUY') {
return res.status(400).json({ error: 'This campaign uses point buy: nothing is rolled, the scores are bought.' });
}
buildState.abilityRolls = resolveAbilityRolls(character, req.body);
} else {
return res.status(400).json({ error: `No die roll is required at the "${stage}" step.` });
@@ -893,15 +910,20 @@ const chooseSchemas = {
// Motivation is story only, so it is simply picked from the list (the stage
// keeps its old name from when it was a die roll).
ROLLING_MOTIVATION: z.object({ motivation: z.number().int() }),
// Rolled scores (and the standard array) are assigned by index; point buy
// sends the six scores themselves.
ASSIGNING_SCORES: z.object({
assignments: z.object({
STR: z.number().int().min(0).max(5),
DEX: z.number().int().min(0).max(5),
CON: z.number().int().min(0).max(5),
INT: z.number().int().min(0).max(5),
WIS: z.number().int().min(0).max(5),
CHA: z.number().int().min(0).max(5),
}),
pointBuy: z.record(z.enum(ABILITIES), z.number().int().min(8).max(15)).optional(),
assignments: z
.object({
STR: z.number().int().min(0).max(5),
DEX: z.number().int().min(0).max(5),
CON: z.number().int().min(0).max(5),
INT: z.number().int().min(0).max(5),
WIS: z.number().int().min(0).max(5),
CHA: z.number().int().min(0).max(5),
})
.optional(),
}),
// Skill proficiencies are now auto-generated (see autoSelectSkills, applied
// when this stage is entered from ASSIGNING_SCORES below) — this payload is
@@ -1007,8 +1029,23 @@ router.post('/:id/build/choose', requireCharacterAccess({ write: true }), async
buildState.motivationChoice = motivation.key;
buildState.motivationText = motivation.label;
} else if (stage === 'ASSIGNING_SCORES') {
let { assignments } = parsed.data;
if (req.campaign.abilityScoreMethod === 'POINT_BUY') {
const scores = parsed.data.pointBuy;
if (!scores || ABILITIES.some((ability) => scores[ability] === undefined)) {
return res.status(400).json({ error: 'Buy a score for each of the six abilities.' });
}
const cost = pointBuyCost(scores);
if (cost === null || cost > POINT_BUY_BUDGET) {
return res.status(400).json({ error: `Those scores cost ${cost} points; you have ${POINT_BUY_BUDGET}.` });
}
// Kept the way rolled scores are, each assigned to its own ability.
buildState.abilityRolls = ABILITIES.map((ability) => ({ dice: [], dropped: null, total: scores[ability] }));
buildState.pointBuy = scores;
assignments = Object.fromEntries(ABILITIES.map((ability, i) => [ability, i]));
}
if (!buildState.abilityRolls) return res.status(400).json({ error: 'Roll ability scores first.' });
const { assignments } = parsed.data;
if (!assignments) return res.status(400).json({ error: 'Assign each score to an ability.' });
const usedIndexes = Object.values(assignments);
const uniqueIndexes = new Set(usedIndexes);
if (uniqueIndexes.size !== 6 || Math.max(...usedIndexes) > 5) {