V1.1.0: gear levels, encounter overhaul, guided builder, trading, docs
Characters - Builder: pick-then-Next on every step with live preview, Back button, plain-language help throughout, and "Suggest for me" for ability scores - Motivation is picked from a list; new steps for special abilities, background and appearance, all composed from fixed lists and DM-only to edit afterwards - Copy a character to another campaign - Characters can give gold, weapons, items and spells to each other - Money tracker: gold only changes through a logged ledger - Fixes: level/XP/location are DM-only, HP stays within 0..max, physical dice ability rolls, every die is rolled once Gear - DM-managed item pool; weapons, items and spells are handed out by the DM - Starting-option flag per pool entry - Gear levels 1-9 per held copy with a damage ladder, growth rate and starting level; spells gated by spell level with a fixed damage value - Spell library carries default damage; damage is picked from a list Encounters - Battle and NPC quest modes, turn tracking, scene description, DM notes - NPCs, richer combatant cards, conditions from a list - Rewards (gold, weapons, items) lined up and awarded, with gold splitting - Character HP is shared between the sheet and the encounter - Monster stat blocks and NPC secrets are never sent to players Other - Dice roller on every page - Docs for characters, weapons, spells, items, encounters, monsters and NPCs, with full lists generated from the data (npm run docs:lists) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -207,17 +207,122 @@ function computeCharacterSheet(character, skillProficiencies = [], saveProficien
|
||||
};
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Gear levels (house rule, not SRD). A held weapon or item has its own level,
|
||||
// 1-9 (the same span as spell levels), and its dice climb a fixed ladder as it
|
||||
// levels:
|
||||
//
|
||||
// 1d4 1d6 1d8 1d10 1d12 2d6 1d6+1d8 2d8 1d8+1d10 2d10 ...
|
||||
//
|
||||
// Each rung is the smallest possible step up in average damage: +1, or +0.5
|
||||
// where the ladder has to add a die (1d12 -> 2d6, 2d12 -> 3d8, ...).
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const MAX_GEAR_LEVEL = 9;
|
||||
const DIE_SIZES = [4, 6, 8, 10, 12];
|
||||
// Rungs a piece of gear climbs per level: 1 = standard, 2 = powerful, 3 = legendary.
|
||||
const MAX_DAMAGE_SCALING = 3;
|
||||
|
||||
function formatDice(sizes) {
|
||||
const counts = new Map();
|
||||
for (const size of sizes) counts.set(size, (counts.get(size) || 0) + 1);
|
||||
return [...counts].map(([size, count]) => `${count}d${size}`).join('+');
|
||||
}
|
||||
|
||||
// k dice whose sizes are as even as possible, `steps` die-size steps above k d4s.
|
||||
function evenDice(k, steps) {
|
||||
const sizes = [];
|
||||
for (let i = 0; i < k; i++) {
|
||||
const share = Math.floor(steps / k) + (i >= k - (steps % k) ? 1 : 0);
|
||||
sizes.push(DIE_SIZES[share]);
|
||||
}
|
||||
return sizes;
|
||||
}
|
||||
|
||||
function buildDamageLadder(rungs) {
|
||||
const ladder = [];
|
||||
let k = 1;
|
||||
let steps = 0;
|
||||
while (ladder.length < rungs) {
|
||||
const maxSteps = k * (DIE_SIZES.length - 1);
|
||||
if (steps > maxSteps) {
|
||||
// Out of room at this many dice: add one, landing just above the last rung.
|
||||
const previousAverage = ladder[ladder.length - 1].average;
|
||||
k += 1;
|
||||
steps = Math.floor(previousAverage - k * 2.5) + 1;
|
||||
continue;
|
||||
}
|
||||
ladder.push({ dice: formatDice(evenDice(k, steps)), average: k * 2.5 + steps });
|
||||
steps += 1;
|
||||
}
|
||||
return ladder;
|
||||
}
|
||||
|
||||
// Far longer than max level at legendary scaling needs, so heavy base dice
|
||||
// (a "10d6" item, say) still have room to climb.
|
||||
const DAMAGE_LADDER = buildDamageLadder(120);
|
||||
|
||||
// Average roll of a dice expression like "1d8", "2d6", "1d6+1d8" or "2d4+2".
|
||||
// Returns null for anything else (free text is allowed in the pool).
|
||||
function diceAverage(expression) {
|
||||
if (typeof expression !== 'string' || !expression.trim()) return null;
|
||||
let total = 0;
|
||||
for (const term of expression.replace(/\s+/g, '').toLowerCase().replace(/-/g, '+-').split('+')) {
|
||||
if (!term) continue;
|
||||
const die = /^(-?)(\d*)d(\d+)$/.exec(term);
|
||||
if (die) {
|
||||
total += (die[1] ? -1 : 1) * (Number(die[2]) || 1) * ((Number(die[3]) + 1) / 2);
|
||||
} else if (/^-?\d+$/.test(term)) {
|
||||
total += Number(term);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
function clampGearLevel(level) {
|
||||
return Math.min(Math.max(Math.round(Number(level) || 1), 1), MAX_GEAR_LEVEL);
|
||||
}
|
||||
|
||||
// Dice for a piece of gear at a given level. `minLevel` is the level the gear
|
||||
// starts at (most gear: 1; a greatsword might only exist from level 3). At its
|
||||
// starting level it is always the base dice exactly as the DM wrote them;
|
||||
// above that it climbs `scaling` rungs per level, starting from the highest
|
||||
// rung that doesn't beat the base (so "1d4+1" starts from 1d6, and a flat "1"
|
||||
// starts below the ladder). Dice the ladder can't read (free text) never scale.
|
||||
function scaledDamageDice(baseDice, level = 1, scaling = 1, minLevel = 1) {
|
||||
const levelsGained = clampGearLevel(level) - clampGearLevel(minLevel);
|
||||
if (levelsGained <= 0) return baseDice;
|
||||
const baseAverage = diceAverage(baseDice);
|
||||
if (baseAverage === null) return baseDice;
|
||||
|
||||
let baseRung = -1;
|
||||
while (baseRung + 1 < DAMAGE_LADDER.length && DAMAGE_LADDER[baseRung + 1].average <= baseAverage) baseRung += 1;
|
||||
const rungsPerLevel = Math.min(Math.max(Math.round(Number(scaling) || 1), 1), MAX_DAMAGE_SCALING);
|
||||
const rung = Math.min(baseRung + levelsGained * rungsPerLevel, DAMAGE_LADDER.length - 1);
|
||||
return DAMAGE_LADDER[rung].dice;
|
||||
}
|
||||
|
||||
// A character can use gear and spells of their own level or lower. For
|
||||
// weapons and items the required level is the held copy's level; for spells
|
||||
// it is the classic spell level (cantrips, level 0, are open to everyone).
|
||||
function canUseGear(characterLevel, requiredLevel) {
|
||||
return characterLevel >= requiredLevel;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attack/damage bonus for a specific weapon against a character's abilities —
|
||||
* used by the quick-stats panel and weapon list.
|
||||
* used by the quick-stats panel and weapon list. `gearLevel` is the level of
|
||||
* the copy the character holds.
|
||||
*/
|
||||
function computeWeaponStats(weapon, abilities, profBonus, proficient = true) {
|
||||
function computeWeaponStats(weapon, abilities, profBonus, proficient = true, gearLevel = 1) {
|
||||
const strMod = abilities.STR.modifier;
|
||||
const dexMod = abilities.DEX.modifier;
|
||||
return {
|
||||
attackBonus: weaponAttackBonus({ attackAbility: weapon.attackAbility, strMod, dexMod, proficient, profBonus }),
|
||||
damageBonus: weaponDamageBonus({ attackAbility: weapon.attackAbility, strMod, dexMod }),
|
||||
damageDice: weapon.damageDice,
|
||||
damageDice: scaledDamageDice(weapon.damageDice, gearLevel, weapon.damageScaling, weapon.minLevel),
|
||||
damageType: weapon.damageType,
|
||||
};
|
||||
}
|
||||
@@ -247,4 +352,10 @@ module.exports = {
|
||||
getClassSpellcastingAbility,
|
||||
computeCharacterSheet,
|
||||
computeWeaponStats,
|
||||
MAX_GEAR_LEVEL,
|
||||
MAX_DAMAGE_SCALING,
|
||||
DAMAGE_LADDER,
|
||||
diceAverage,
|
||||
scaledDamageDice,
|
||||
canUseGear,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user