V1.23.0: every subclass, 43 species, the Artificer, and the road to level 20
- All 123 official subclasses (2014 books and the 2024 Player's Handbook), each with its book and features up to level 20; one file per class - The builder has a subclass step after the class: pick one, let a die suggest one, or decide later; its gifts arrive at the class's choice level - 2024 updates (Wild Heart, Warrior of the Elements) offer a one-click switch - The Road Ahead: a level 1-20 timeline on every sheet and in the builder - 33 new species (2024 Aasimar and Goliath, Monsters of the Multiverse) with chosen +2/+1 or +1/+1/+1 bonuses; species roll is now a d8 by family - The Artificer: class, half-caster slots from level 1, features, Flash of Genius - Class tables and counters run to level 20; a fifth Boon, Resolve Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -20,13 +20,15 @@ const {
|
||||
} = require('../game/calculations');
|
||||
const { LevelUpError, advance, levelUpPlan, switchSubclass, subclassByDefault } = require('../game/levelUp');
|
||||
const { resourceTally, MAX_EXHAUSTION } = require('../game/classResources');
|
||||
const { SUBCLASS_LEVEL, subclassesOf, findSubclass, subclassName } = require('../game/data/subclasses');
|
||||
const { SUBCLASS_LEVEL, SUBCLASSES, subclassesOf, findSubclass, subclassName, newerVersionOf, subclassSummary } = require('../game/data/subclasses');
|
||||
const {
|
||||
rollDie,
|
||||
rollAbilityScore,
|
||||
abilityScoreFromDice,
|
||||
speciesChoicesForRoll,
|
||||
classChoicesForRoll,
|
||||
SPECIES_ROLL_DIE,
|
||||
CLASS_ROLL_DIE,
|
||||
autoSelectSkills,
|
||||
validateManualRoll,
|
||||
validatePicks,
|
||||
@@ -39,6 +41,7 @@ const {
|
||||
effectiveDiceMode,
|
||||
} = require('../game/buildFlow');
|
||||
const characterOptions = require('../game/data/characterOptions');
|
||||
const { speciesBonusProblem } = require('../game/data/species');
|
||||
const { SKILLS } = require('../game/data/skills');
|
||||
const { CURRENCIES, COINS, COIN_VALUE, COIN_COLUMN, InsufficientGoldError, adjustGold, spendCoins, worthInGold, giveGear } = require('../utils/grants');
|
||||
const { recordVisits } = require('../utils/locations');
|
||||
@@ -93,13 +96,14 @@ function serializeCharacter(character, isOwner, isDM = true) {
|
||||
subclassName: subclasses ? subclassName(character.characterClass, character.subclass) : null,
|
||||
// What the class can choose from, and the level it chooses at.
|
||||
subclassLevel: subclasses ? (SUBCLASS_LEVEL[character.characterClass] ?? null) : null,
|
||||
subclassOptions: subclasses ? subclassesOf(character.characterClass).map(({ key, name, summary }) => ({ key, name, summary })) : [],
|
||||
subclassOptions: subclasses ? subclassesOf(character.characterClass).map(subclassSummary) : [],
|
||||
// The 2024 subclass that updates the one the character follows, if any.
|
||||
subclassUpgrade: subclasses && newerVersionOf(character.characterClass, character.subclass) ? subclassSummary(newerVersionOf(character.characterClass, character.subclass)) : null,
|
||||
level: character.level,
|
||||
xp: character.xp,
|
||||
xpProgress: xpProgress(character.xp, character.level),
|
||||
motivation: character.motivation,
|
||||
halfElfBonusAbility1: character.halfElfBonusAbility1,
|
||||
halfElfBonusAbility2: character.halfElfBonusAbility2,
|
||||
speciesBonusChoices: character.speciesBonusChoices || {},
|
||||
rolledScores: {
|
||||
STR: character.strScore,
|
||||
DEX: character.dexScore,
|
||||
@@ -171,6 +175,10 @@ router.get('/build/options', (req, res) => {
|
||||
talentPicks: TALENT_PICKS,
|
||||
background: BACKGROUND_GROUPS,
|
||||
appearance: APPEARANCE_GROUPS,
|
||||
// Each class's subclasses, as the builder's subclass step lists them, and
|
||||
// the level each class gets its subclass's first gifts at.
|
||||
subclasses: Object.fromEntries(Object.entries(SUBCLASSES).map(([cls, list]) => [cls, list.map(subclassSummary)])),
|
||||
subclassLevels: SUBCLASS_LEVEL,
|
||||
});
|
||||
});
|
||||
|
||||
@@ -272,9 +280,8 @@ router.patch('/:id', requireCharacterAccess({ write: true }), async (req, res, n
|
||||
const picked = askedSubclass;
|
||||
if (picked !== null) {
|
||||
if (!findSubclass(characterClass, picked)) return res.status(400).json({ error: 'That is not a subclass of this character\'s class.' });
|
||||
if (newLevel < SUBCLASS_LEVEL[characterClass]) {
|
||||
return res.status(400).json({ error: `${req.character.name} chooses a subclass at level ${SUBCLASS_LEVEL[characterClass]}.` });
|
||||
}
|
||||
// A path can be set before the class reaches it, as the builder does;
|
||||
// its lines are written as the levels come.
|
||||
}
|
||||
// The old subclass's lines come off the sheet and the new one's go on.
|
||||
if (writesAbilities) parsed.data.specialAbilities = switchSubclass(abilities, characterClass, newLevel, req.character.subclass, picked);
|
||||
@@ -745,8 +752,7 @@ router.post('/:id/copy', requireCharacterAccess(), async (req, res, next) => {
|
||||
intScore: source.intScore,
|
||||
wisScore: source.wisScore,
|
||||
chaScore: source.chaScore,
|
||||
halfElfBonusAbility1: source.halfElfBonusAbility1,
|
||||
halfElfBonusAbility2: source.halfElfBonusAbility2,
|
||||
speciesBonusChoices: source.speciesBonusChoices,
|
||||
currentHp: sheet.hp.max,
|
||||
armorBonus: source.armorBonus,
|
||||
speedOverride: source.speedOverride,
|
||||
@@ -865,18 +871,29 @@ router.post('/:id/build/roll', requireCharacterAccess({ write: true }), async (r
|
||||
if (buildState.speciesRoll) {
|
||||
return res.status(400).json({ error: 'Species die already rolled for this character — choose from what it offered.' });
|
||||
}
|
||||
const roll = resolveSingleRoll(character, req.body, 6);
|
||||
const roll = resolveSingleRoll(character, req.body, SPECIES_ROLL_DIE);
|
||||
buildState.speciesRoll = roll;
|
||||
buildState.speciesChoices = speciesChoicesForRoll(roll);
|
||||
} else if (stage === 'ROLLING_CLASS') {
|
||||
const alreadyRolled = buildState.classChoices && buildState.classChoices.type !== 'reroll';
|
||||
if (alreadyRolled) {
|
||||
// A 7 may be rerolled once (a build from before kept a bare "reroll").
|
||||
const previous = buildState.classChoices;
|
||||
const mayReroll = previous && (previous.canReroll || previous.type === 'reroll');
|
||||
if (previous && !mayReroll) {
|
||||
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);
|
||||
const roll = resolveSingleRoll(character, req.body, CLASS_ROLL_DIE);
|
||||
buildState.classRoll = roll;
|
||||
buildState.classChoices = classChoicesForRoll(roll);
|
||||
buildState.classChoices = classChoicesForRoll(roll, { rerolled: Boolean(mayReroll) });
|
||||
delete buildState.characterClass;
|
||||
} else if (stage === 'CHOOSING_SUBCLASS') {
|
||||
// A die with a face per subclass suggests one; the player still picks freely.
|
||||
if (buildState.subclassRoll) {
|
||||
return res.status(400).json({ error: 'The subclass die was already rolled — pick from the list.' });
|
||||
}
|
||||
const options = subclassesOf(buildState.characterClass);
|
||||
const roll = resolveSingleRoll(character, req.body, options.length);
|
||||
buildState.subclassRoll = roll;
|
||||
buildState.subclassSuggestion = options[roll - 1].key;
|
||||
} else if (stage === 'ASSIGNING_SCORES') {
|
||||
if (buildState.abilityRolls) {
|
||||
return res.status(400).json({ error: 'Ability scores were already rolled for this character.' });
|
||||
@@ -899,14 +916,17 @@ router.post('/:id/build/roll', requireCharacterAccess({ write: true }), async (r
|
||||
}
|
||||
});
|
||||
|
||||
const HALF_ELF_ELIGIBLE_ABILITIES = ABILITIES.filter((a) => a !== 'CHA');
|
||||
|
||||
const chooseSchemas = {
|
||||
// `bonusChoices` are the species' flexible bonuses, { ability: amount }.
|
||||
// `halfElfBonusAbilities` is the older way to give a Half-Elf's two +1s.
|
||||
ROLLING_SPECIES: z.object({
|
||||
species: z.string(),
|
||||
halfElfBonusAbilities: z.array(z.enum(HALF_ELF_ELIGIBLE_ABILITIES)).length(2).optional(),
|
||||
bonusChoices: z.partialRecord(z.enum(ABILITIES), z.number().int().min(0).max(2)).optional(),
|
||||
halfElfBonusAbilities: z.array(z.enum(ABILITIES)).length(2).optional(),
|
||||
}),
|
||||
ROLLING_CLASS: z.object({ characterClass: z.string() }),
|
||||
// null: decide later, at the level the class chooses.
|
||||
CHOOSING_SUBCLASS: z.object({ subclass: z.string().nullable() }),
|
||||
// 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() }),
|
||||
@@ -962,6 +982,7 @@ async function allStartingOptions(model, ids, campaignId, reach) {
|
||||
const STAGE_ORDER = [
|
||||
'ROLLING_SPECIES',
|
||||
'ROLLING_CLASS',
|
||||
'CHOOSING_SUBCLASS',
|
||||
'ROLLING_MOTIVATION',
|
||||
'ASSIGNING_SCORES',
|
||||
'ASSIGNING_PROFICIENCIES',
|
||||
@@ -972,9 +993,19 @@ const STAGE_ORDER = [
|
||||
'COMPLETE',
|
||||
];
|
||||
|
||||
function nextStage(current) {
|
||||
const idx = STAGE_ORDER.indexOf(current);
|
||||
return STAGE_ORDER[idx + 1];
|
||||
// Steps a campaign can leave out: the subclass (without subclasses) and the
|
||||
// motivation (when it skips it).
|
||||
function stageSkipped(stage, campaign) {
|
||||
if (stage === 'CHOOSING_SUBCLASS') return !campaign.subclassesEnabled;
|
||||
if (stage === 'ROLLING_MOTIVATION') return campaign.skipMotivationRoll;
|
||||
return false;
|
||||
}
|
||||
|
||||
// The next (or, with step -1, the previous) step this campaign uses.
|
||||
function nextStage(current, campaign, step = 1) {
|
||||
let idx = STAGE_ORDER.indexOf(current) + step;
|
||||
while (campaign && STAGE_ORDER[idx] && stageSkipped(STAGE_ORDER[idx], campaign)) idx += step;
|
||||
return STAGE_ORDER[idx];
|
||||
}
|
||||
|
||||
router.post('/:id/build/choose', requireCharacterAccess({ write: true }), async (req, res, next) => {
|
||||
@@ -988,7 +1019,7 @@ router.post('/:id/build/choose', requireCharacterAccess({ write: true }), async
|
||||
if (!parsed.success) return res.status(400).json({ error: parsed.error.flatten() });
|
||||
|
||||
const buildState = { ...(character.buildState || {}) };
|
||||
let advanceTo = nextStage(stage);
|
||||
let advanceTo = nextStage(stage, req.campaign);
|
||||
|
||||
if (stage === 'ROLLING_SPECIES') {
|
||||
const choices = buildState.speciesChoices;
|
||||
@@ -997,17 +1028,18 @@ router.post('/:id/build/choose', requireCharacterAccess({ write: true }), async
|
||||
if (choices.type !== 'wildcard' && !choices.options.includes(species)) {
|
||||
return res.status(400).json({ error: `${species} was not offered by this roll.` });
|
||||
}
|
||||
if (species === 'HALF_ELF') {
|
||||
if (!halfElfBonusAbilities) {
|
||||
return res.status(400).json({ error: 'Half-Elf requires choosing two abilities (other than CHA) for the +1/+1 bonus.' });
|
||||
}
|
||||
let bonusChoices = parsed.data.bonusChoices || {};
|
||||
if (halfElfBonusAbilities) {
|
||||
if (new Set(halfElfBonusAbilities).size !== 2) {
|
||||
return res.status(400).json({ error: 'The two Half-Elf bonus abilities must be different.' });
|
||||
}
|
||||
buildState.halfElfBonusAbilities = halfElfBonusAbilities;
|
||||
} else {
|
||||
delete buildState.halfElfBonusAbilities;
|
||||
bonusChoices = Object.fromEntries(halfElfBonusAbilities.map((ability) => [ability, 1]));
|
||||
}
|
||||
bonusChoices = Object.fromEntries(Object.entries(bonusChoices).filter(([, amount]) => amount));
|
||||
const problem = speciesBonusProblem(species, bonusChoices);
|
||||
if (problem) return res.status(400).json({ error: problem });
|
||||
delete buildState.halfElfBonusAbilities;
|
||||
buildState.speciesBonusChoices = bonusChoices;
|
||||
buildState.species = species;
|
||||
} else if (stage === 'ROLLING_CLASS') {
|
||||
const choices = buildState.classChoices;
|
||||
@@ -1018,11 +1050,20 @@ router.post('/:id/build/choose', requireCharacterAccess({ write: true }), async
|
||||
if (choices.type !== 'wildcard' && !choices.options.includes(characterClass)) {
|
||||
return res.status(400).json({ error: `${characterClass} was not offered by this roll.` });
|
||||
}
|
||||
buildState.characterClass = characterClass;
|
||||
if (req.campaign.skipMotivationRoll) {
|
||||
advanceTo = 'ASSIGNING_SCORES';
|
||||
buildState.motivationText = null;
|
||||
// A subclass picked for another class goes with it.
|
||||
if (buildState.characterClass !== characterClass) {
|
||||
delete buildState.subclass;
|
||||
delete buildState.subclassRoll;
|
||||
delete buildState.subclassSuggestion;
|
||||
}
|
||||
buildState.characterClass = characterClass;
|
||||
if (req.campaign.skipMotivationRoll) buildState.motivationText = null;
|
||||
} else if (stage === 'CHOOSING_SUBCLASS') {
|
||||
const { subclass } = parsed.data;
|
||||
if (subclass !== null && !findSubclass(buildState.characterClass, subclass)) {
|
||||
return res.status(400).json({ error: 'That is not a subclass of this class.' });
|
||||
}
|
||||
buildState.subclass = subclass;
|
||||
} else if (stage === 'ROLLING_MOTIVATION') {
|
||||
const motivation = characterOptions.MOTIVATIONS.find((m) => m.key === parsed.data.motivation);
|
||||
if (!motivation) return res.status(400).json({ error: 'Pick a motivation from the list.' });
|
||||
@@ -1141,8 +1182,7 @@ router.post('/:id/build/back', requireCharacterAccess({ write: true }), async (r
|
||||
if (idx <= 0 || stage === 'COMPLETE') {
|
||||
return res.status(400).json({ error: 'There is no earlier step to go back to.' });
|
||||
}
|
||||
backTo = STAGE_ORDER[idx - 1];
|
||||
if (backTo === 'ROLLING_MOTIVATION' && req.campaign.skipMotivationRoll) backTo = 'ROLLING_CLASS';
|
||||
backTo = nextStage(stage, req.campaign, -1);
|
||||
}
|
||||
delete buildState.equipment;
|
||||
|
||||
@@ -1173,7 +1213,9 @@ router.post('/:id/build/finalize', requireCharacterAccess({ write: true }), asyn
|
||||
rolledScores[ability] = bs.abilityRolls[rollIndex].total;
|
||||
}
|
||||
|
||||
const [halfElfBonusAbility1, halfElfBonusAbility2] = bs.halfElfBonusAbilities || [null, null];
|
||||
// A build begun before chosen bonuses were general kept a Half-Elf's two picks on their own.
|
||||
const speciesBonusChoices =
|
||||
bs.speciesBonusChoices || Object.fromEntries((bs.halfElfBonusAbilities || []).map((ability) => [ability, 1]));
|
||||
const saveProfs = getClassSaveProficiencies(bs.characterClass);
|
||||
|
||||
const result = await prisma.$transaction(async (tx) => {
|
||||
@@ -1185,6 +1227,8 @@ router.post('/:id/build/finalize', requireCharacterAccess({ write: true }), asyn
|
||||
data: {
|
||||
species: bs.species,
|
||||
characterClass: bs.characterClass,
|
||||
// Chosen now, its gifts still come at the level the class chooses at.
|
||||
subclass: req.campaign.subclassesEnabled && findSubclass(bs.characterClass, bs.subclass) ? bs.subclass : null,
|
||||
motivation: bs.motivationText || null,
|
||||
// Composed here, from the picks, so the text can only ever say what
|
||||
// the lists allow.
|
||||
@@ -1197,8 +1241,7 @@ router.post('/:id/build/finalize', requireCharacterAccess({ write: true }), asyn
|
||||
intScore: rolledScores.INT,
|
||||
wisScore: rolledScores.WIS,
|
||||
chaScore: rolledScores.CHA,
|
||||
halfElfBonusAbility1,
|
||||
halfElfBonusAbility2,
|
||||
speciesBonusChoices,
|
||||
buildStage: 'COMPLETE',
|
||||
buildState: null,
|
||||
skillProficiencies: {
|
||||
|
||||
Reference in New Issue
Block a user