V1.14.0: spell slots, rests, and a level-up checklist
- Spell slots. Every class that casts has a slot tracker, worked out from class and level: the full-caster table for bards, clerics, druids, sorcerers and wizards, the half-caster table for paladins and rangers (from level 2), and a warlock's few slots of one level. It is in the Spellcasting card on the sheet and in the character panel, and the party overview has a column for it. A player presses Use to spend a slot; only the DM gives one back. - Rests. The DM's "Rest…" button, beside the character list and on the party overview, rests any of the party at once. A short rest shows which Hit Dice each character can roll and heals from what they rolled (typed in, or rolled by the site), and gives a warlock their slots. A long rest puts back HP, every spell slot and half the level in Hit Dice, and clears temp HP. - Hit Dice are counted: one per level, shown on the sheet, the panel and the party overview. - Level Up. "Level Up…" on a sheet takes a character up one level with the whole checklist: the new max HP and a full heal, the class's new special abilities for levels 2 to 10, a Boon where the level grants one (Toughened raises Extra AC, Hardy gives temp HP now and after each long rest), fresh spell slots and new spells, and the free upgrade of one standard weapon. - A level typed into the Level field still writes down what the class gains on the way up, and leaves a line where a Boon is owed. - The docs cover all of it, with a generated list of what each class gains at each level. The Hollowcrown seed's note no longer says to track spell slots on paper. - New migration: spent spell slots and Hit Dice on a character. - All packages at version 1.14.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
// Levelling up: the Hollowcrown book's "Levelling-Up Checklist" (Rules Cheat
|
||||
// Sheet). Works out what a character gains at a level, and rewrites their
|
||||
// special abilities to say so. Pure: no DB calls.
|
||||
|
||||
const { LEVEL_FEATURES, MAX_FEATURE_LEVEL, CANTRIP_LEVEL, CANTRIP_FEATURE, BOONS } = require('./data/levelFeatures');
|
||||
const { CASTER_KIND } = require('./data/spellSlots');
|
||||
const { getClassSpellcastingAbility, maxSpellLevel, scaledDamageDice, MAX_GEAR_LEVEL } = require('./calculations');
|
||||
|
||||
// A choice that cannot be made: the message is for whoever made it.
|
||||
class LevelUpError extends Error {}
|
||||
|
||||
// What a class gains on reaching `level`, in the order it is written down.
|
||||
// An entry is { name, text, upgrade? } or { boon: true }.
|
||||
function featuresAt(characterClass, level) {
|
||||
const features = [...((LEVEL_FEATURES[characterClass] || {})[level] || [])];
|
||||
if (level === CANTRIP_LEVEL && getClassSpellcastingAbility(characterClass)) features.push(CANTRIP_FEATURE);
|
||||
return features;
|
||||
}
|
||||
|
||||
// Special abilities are one per line, "Name — what it does". The builder
|
||||
// writes a long dash; a DM typing by hand may use "--".
|
||||
const featureLine = (feature) => `${feature.name} — ${feature.text}`;
|
||||
|
||||
function lineName(line) {
|
||||
const match = /^\s*(.+?)\s*(?:—|–|--)\s/.exec(line);
|
||||
return match ? match[1].toLowerCase() : null;
|
||||
}
|
||||
|
||||
const toLines = (specialAbilities) => (specialAbilities ? specialAbilities.split(/\r?\n/) : []);
|
||||
const fromLines = (lines) => lines.join('\n') || null;
|
||||
const findLine = (lines, name) => lines.findIndex((line) => lineName(line) === name.toLowerCase());
|
||||
|
||||
// Writes features into the text. An upgrade takes the place of the line with
|
||||
// its name (Sneak Attack growing a die); anything else goes on the end, unless
|
||||
// that very line is there already.
|
||||
function addFeatures(specialAbilities, features) {
|
||||
const lines = toLines(specialAbilities);
|
||||
for (const feature of features) {
|
||||
const line = featureLine(feature);
|
||||
const at = feature.upgrade ? findLine(lines, feature.name) : -1;
|
||||
if (at >= 0) lines[at] = line;
|
||||
else if (!lines.includes(line)) lines.push(line);
|
||||
}
|
||||
return fromLines(lines);
|
||||
}
|
||||
|
||||
// How many times a Boon has been taken, read off its line ("Hardy — +10
|
||||
// maximum HP…" is twice).
|
||||
function boonTaken(specialAbilities, boon) {
|
||||
const lines = toLines(specialAbilities);
|
||||
const at = findLine(lines, boon.name);
|
||||
if (at < 0) return 0;
|
||||
const amount = /\+\s*(\d+)/.exec(lines[at]);
|
||||
return Math.max(1, Math.round((amount ? Number(amount[1]) : boon.per) / boon.per));
|
||||
}
|
||||
|
||||
// Every Boon, with what taking it now would write and whether it still can be.
|
||||
function boonOptions(specialAbilities) {
|
||||
return BOONS.map((boon) => {
|
||||
const taken = boonTaken(specialAbilities, boon);
|
||||
return { key: boon.key, name: boon.name, taken, max: boon.max, available: taken < boon.max, text: boon.text((Math.min(taken, boon.max - 1) + 1) * boon.per) };
|
||||
});
|
||||
}
|
||||
|
||||
// Temp HP the Hardy Boon gives after each long rest; 0 without it.
|
||||
function hardyTempHp(specialAbilities) {
|
||||
const hardy = BOONS.find((boon) => boon.key === 'HARDY');
|
||||
return boonTaken(specialAbilities, hardy) * hardy.per;
|
||||
}
|
||||
|
||||
// What reaching `level` does to a character's special abilities. `boonKey` is
|
||||
// the Boon picked, at a level that grants one; without it the line says a
|
||||
// choice is still owed. Also returns what the Boon does beyond the text: how
|
||||
// much Extra AC it adds, and the Temp HP it gives straight away.
|
||||
function advance(specialAbilities, characterClass, level, boonKey) {
|
||||
const entries = featuresAt(characterClass, level);
|
||||
let text = addFeatures(specialAbilities, entries.filter((entry) => !entry.boon));
|
||||
const result = { armorBonus: 0, tempHp: 0 };
|
||||
|
||||
if (entries.some((entry) => entry.boon)) {
|
||||
if (!boonKey) {
|
||||
text = addFeatures(text, [{ name: `Boon (level ${level})`, text: `Choose one with your DM: ${BOONS.map((boon) => boon.name).join(', ')}.` }]);
|
||||
} else {
|
||||
const boon = BOONS.find((b) => b.key === boonKey);
|
||||
if (!boon) throw new LevelUpError('That is not one of the Boons.');
|
||||
const taken = boonTaken(text, boon);
|
||||
if (taken >= boon.max) {
|
||||
throw new LevelUpError(`${boon.name} can be taken ${boon.max === 1 ? 'only once' : `at most ${boon.max} times`}. Pick a different Boon.`);
|
||||
}
|
||||
const amount = (taken + 1) * boon.per;
|
||||
text = addFeatures(text, [{ name: boon.name, text: boon.text(amount), upgrade: true }]);
|
||||
if (boon.key === 'TOUGHENED') result.armorBonus = 1;
|
||||
if (boon.key === 'HARDY') result.tempHp = amount;
|
||||
}
|
||||
}
|
||||
return { specialAbilities: text, ...result };
|
||||
}
|
||||
|
||||
// The book's unlock schedule: what a caster may be granted on reaching
|
||||
// `level`. Null for a class with no spells.
|
||||
function spellsGainedAt(characterClass, level) {
|
||||
const kind = CASTER_KIND[characterClass];
|
||||
if (!kind) return null;
|
||||
const highest = maxSpellLevel(characterClass, level);
|
||||
// Half casters: two spells at level 2, then one at each odd level.
|
||||
const halfCasterSpells = level === 2 ? 2 : level > 2 && level % 2 === 1 ? 1 : 0;
|
||||
return {
|
||||
maxSpellLevel: highest,
|
||||
// Set when this level opens up a new level of spells.
|
||||
unlocksSpellLevel: highest > maxSpellLevel(characterClass, level - 1) ? highest : null,
|
||||
newSpells: kind === 'HALF' ? halfCasterSpells : characterClass === 'WIZARD' ? 2 : 1,
|
||||
newCantrips: kind !== 'HALF' && (level === 4 || level === 10) ? 1 : 0,
|
||||
};
|
||||
}
|
||||
|
||||
// The checklist for a character's next level. Takes the character with its
|
||||
// weapons loaded (each with its pool entry).
|
||||
function levelUpPlan(character) {
|
||||
const toLevel = character.level + 1;
|
||||
const entries = featuresAt(character.characterClass, toLevel);
|
||||
return {
|
||||
fromLevel: character.level,
|
||||
toLevel,
|
||||
features: entries.filter((entry) => !entry.boon).map(({ name, text, upgrade }) => ({ name, text, upgrade: Boolean(upgrade) })),
|
||||
boon: entries.some((entry) => entry.boon) ? boonOptions(character.specialAbilities) : null,
|
||||
spells: spellsGainedAt(character.characterClass, toLevel),
|
||||
// The free upgrade: one weapon of standard growth goes up a level, never
|
||||
// past its holder.
|
||||
weapons: (character.weapons || [])
|
||||
.filter((cw) => cw.weapon.damageScaling === 1 && cw.level < Math.min(toLevel, MAX_GEAR_LEVEL))
|
||||
.map((cw) => ({
|
||||
weaponId: cw.weaponId,
|
||||
name: cw.weapon.name,
|
||||
equipped: cw.equipped,
|
||||
level: cw.level,
|
||||
damageDice: scaledDamageDice(cw.weapon.damageDice, cw.level, cw.weapon.damageScaling, cw.weapon.minLevel),
|
||||
nextDamageDice: scaledDamageDice(cw.weapon.damageDice, cw.level + 1, cw.weapon.damageScaling, cw.weapon.minLevel),
|
||||
})),
|
||||
// The class tables stop at level 10; past it only the numbers move.
|
||||
beyondTables: toLevel > MAX_FEATURE_LEVEL,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = { LevelUpError, featuresAt, addFeatures, boonTaken, boonOptions, hardyTempHp, advance, spellsGainedAt, levelUpPlan };
|
||||
Reference in New Issue
Block a user