Initial commit
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
// Roll-Your-Character build flow tables — see /docs/ROLL_YOUR_CHARACTER.md.
|
||||
// Dice are always rolled server-side (crypto.randomInt), never trusted from the client.
|
||||
|
||||
const crypto = require('crypto');
|
||||
const { SPECIES } = require('./data/species');
|
||||
const { CLASSES } = require('./data/classes');
|
||||
|
||||
const ALL_SPECIES = Object.keys(SPECIES);
|
||||
const ALL_CLASSES = Object.keys(CLASSES);
|
||||
|
||||
const SPECIES_ROLL_TABLE = {
|
||||
1: ['HUMAN', 'HALF_ELF'],
|
||||
2: ['ELF', 'GNOME'],
|
||||
3: ['DWARF', 'HALFLING'],
|
||||
4: ['DRAGONBORN', 'TIEFLING'],
|
||||
5: ['HALF_ORC', 'ORC'],
|
||||
6: 'WILDCARD',
|
||||
};
|
||||
|
||||
const CLASS_ROLL_TABLE = {
|
||||
1: ['FIGHTER', 'BARBARIAN'],
|
||||
2: ['ROGUE', 'RANGER'],
|
||||
3: ['WIZARD', 'SORCERER'],
|
||||
4: ['CLERIC', 'PALADIN'],
|
||||
5: ['BARD', 'WARLOCK'],
|
||||
6: ['DRUID', 'MONK'],
|
||||
7: 'REROLL',
|
||||
8: 'WILDCARD',
|
||||
};
|
||||
|
||||
const MOTIVATION_TABLE = {
|
||||
1: 'Revenge for a past wrong',
|
||||
2: 'Seeking fortune or wealth',
|
||||
3: 'Protecting someone they love',
|
||||
4: 'Redemption for a past mistake',
|
||||
5: 'Driven by curiosity or knowledge',
|
||||
6: 'Duty or oath to a cause or order',
|
||||
};
|
||||
|
||||
function rollDie(sides) {
|
||||
return crypto.randomInt(1, sides + 1);
|
||||
}
|
||||
|
||||
// Standard method: 4d6, drop the lowest, sum the rest.
|
||||
function rollAbilityScore() {
|
||||
const dice = Array.from({ length: 4 }, () => rollDie(6));
|
||||
const sorted = [...dice].sort((a, b) => a - b);
|
||||
const dropped = sorted[0];
|
||||
const total = sorted.slice(1).reduce((a, b) => a + b, 0);
|
||||
return { dice, dropped, total };
|
||||
}
|
||||
|
||||
function speciesChoicesForRoll(roll) {
|
||||
const entry = SPECIES_ROLL_TABLE[roll];
|
||||
if (entry === 'WILDCARD') return { type: 'wildcard', options: ALL_SPECIES };
|
||||
return { type: 'choice', options: entry };
|
||||
}
|
||||
|
||||
function classChoicesForRoll(roll) {
|
||||
const entry = CLASS_ROLL_TABLE[roll];
|
||||
if (entry === 'WILDCARD') return { type: 'wildcard', options: ALL_CLASSES };
|
||||
if (entry === 'REROLL') return { type: 'reroll', options: [] };
|
||||
return { type: 'choice', options: entry };
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
SPECIES_ROLL_TABLE,
|
||||
CLASS_ROLL_TABLE,
|
||||
MOTIVATION_TABLE,
|
||||
ALL_SPECIES,
|
||||
ALL_CLASSES,
|
||||
rollDie,
|
||||
rollAbilityScore,
|
||||
speciesChoicesForRoll,
|
||||
classChoicesForRoll,
|
||||
};
|
||||
@@ -0,0 +1,250 @@
|
||||
// D&D 5e rules calculation engine — the ONLY place these formulas may live.
|
||||
// See /docs/GAME_RULES_REFERENCE.md for the spec this implements.
|
||||
// Pure and dependency-free on purpose: no DB calls, no framework imports.
|
||||
|
||||
const { SPECIES } = require('./data/species');
|
||||
const { CLASSES } = require('./data/classes');
|
||||
const { SKILLS } = require('./data/skills');
|
||||
|
||||
const ABILITIES = ['STR', 'DEX', 'CON', 'INT', 'WIS', 'CHA'];
|
||||
|
||||
function abilityModifier(score) {
|
||||
return Math.floor((score - 10) / 2);
|
||||
}
|
||||
|
||||
function proficiencyBonus(level) {
|
||||
return 2 + Math.floor((level - 1) / 4);
|
||||
}
|
||||
|
||||
// Half-Elf's flexible +1/+1 lands on whichever two abilities the player picked
|
||||
// (halfElfBonusAbilities), on top of the fixed +2 CHA in the species table.
|
||||
function speciesAbilityBonus(ability, species, halfElfBonusAbilities = []) {
|
||||
const speciesData = species ? SPECIES[species] : null;
|
||||
if (!speciesData) return 0;
|
||||
let bonus = speciesData.abilityBonuses[ability] || 0;
|
||||
if (species === 'HALF_ELF' && halfElfBonusAbilities.includes(ability)) {
|
||||
bonus += 1;
|
||||
}
|
||||
return bonus;
|
||||
}
|
||||
|
||||
function finalAbilityScore(rolledScore, ability, species, halfElfBonusAbilities = []) {
|
||||
return rolledScore + speciesAbilityBonus(ability, species, halfElfBonusAbilities);
|
||||
}
|
||||
|
||||
function speciesSpeed(species) {
|
||||
return species && SPECIES[species] ? SPECIES[species].speed : 30;
|
||||
}
|
||||
|
||||
function effectiveSpeed(species, speedOverride) {
|
||||
return speedOverride != null ? speedOverride : speciesSpeed(species);
|
||||
}
|
||||
|
||||
function saveBonus(abilityMod, proficient, profBonus) {
|
||||
return abilityMod + (proficient ? profBonus : 0);
|
||||
}
|
||||
|
||||
// expertise (e.g. Rogue) doubles the proficiency portion of the bonus.
|
||||
function skillBonus(abilityMod, proficient, profBonus, expertise = false) {
|
||||
if (!proficient) return abilityMod;
|
||||
return abilityMod + profBonus * (expertise ? 2 : 1);
|
||||
}
|
||||
|
||||
function passivePerception(perceptionSkillBonus) {
|
||||
return 10 + perceptionSkillBonus;
|
||||
}
|
||||
|
||||
function armorClass(dexMod, armorBonus = 0) {
|
||||
return 10 + dexMod + armorBonus;
|
||||
}
|
||||
|
||||
function initiative(dexMod) {
|
||||
return dexMod;
|
||||
}
|
||||
|
||||
// Level 1 always uses the maximum possible Hit Die roll; every level after
|
||||
// that uses the fixed "average" value (floor(hitDieSize / 2) + 1). Do not
|
||||
// regress this to a flat average-for-all-levels formula — that was a bug
|
||||
// caught while building the reference Excel calculator.
|
||||
function hpMax(level, hitDieSize, conMod) {
|
||||
const base = hitDieSize + conMod;
|
||||
if (level <= 1) return base;
|
||||
const perLevelAverage = Math.floor(hitDieSize / 2) + 1;
|
||||
return base + (level - 1) * (perLevelAverage + conMod);
|
||||
}
|
||||
|
||||
function spellSaveDC(profBonus, spellAbilityMod) {
|
||||
return 8 + profBonus + spellAbilityMod;
|
||||
}
|
||||
|
||||
function spellAttackBonus(profBonus, spellAbilityMod) {
|
||||
return profBonus + spellAbilityMod;
|
||||
}
|
||||
|
||||
// attackAbility is "STR" | "DEX" | "FINESSE" (finesse = better of STR/DEX).
|
||||
function weaponAbilityModifier(attackAbility, strMod, dexMod) {
|
||||
if (attackAbility === 'STR') return strMod;
|
||||
if (attackAbility === 'DEX') return dexMod;
|
||||
if (attackAbility === 'FINESSE') return Math.max(strMod, dexMod);
|
||||
throw new Error(`Unknown attackAbility: ${attackAbility}`);
|
||||
}
|
||||
|
||||
function weaponAttackBonus({ attackAbility, strMod, dexMod, proficient, profBonus }) {
|
||||
const abilityMod = weaponAbilityModifier(attackAbility, strMod, dexMod);
|
||||
return abilityMod + (proficient ? profBonus : 0);
|
||||
}
|
||||
|
||||
function weaponDamageBonus({ attackAbility, strMod, dexMod }) {
|
||||
return weaponAbilityModifier(attackAbility, strMod, dexMod);
|
||||
}
|
||||
|
||||
function getGoverningAbilityForSkill(skill) {
|
||||
const data = SKILLS[skill];
|
||||
if (!data) throw new Error(`Unknown skill: ${skill}`);
|
||||
return data.ability;
|
||||
}
|
||||
|
||||
// Saving throw proficiencies are fixed per class, not a player choice —
|
||||
// use this at character-build finalize time to seed CharacterSaveProficiency.
|
||||
function getClassSaveProficiencies(characterClass) {
|
||||
const data = characterClass ? CLASSES[characterClass] : null;
|
||||
return data ? data.saveProficiencies : [];
|
||||
}
|
||||
|
||||
function getClassHitDieSize(characterClass) {
|
||||
const data = characterClass ? CLASSES[characterClass] : null;
|
||||
return data ? data.hitDie : 8;
|
||||
}
|
||||
|
||||
function getClassSpellcastingAbility(characterClass) {
|
||||
const data = characterClass ? CLASSES[characterClass] : null;
|
||||
return data ? data.spellcastingAbility : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assembles the full derived character sheet from raw stored data. This is
|
||||
* the single function the API and quick-stats view should call rather than
|
||||
* re-deriving any of the above by hand.
|
||||
*
|
||||
* @param {object} character - rolled scores, species/class, level, armorBonus, etc.
|
||||
* @param {Array<{skill: string, proficient: boolean, expertise: boolean}>} skillProficiencies
|
||||
* @param {Array<{ability: string, proficient: boolean}>} saveProficiencies
|
||||
*/
|
||||
function computeCharacterSheet(character, skillProficiencies = [], saveProficiencies = []) {
|
||||
const {
|
||||
level = 1,
|
||||
species = null,
|
||||
characterClass = null,
|
||||
strScore = 10,
|
||||
dexScore = 10,
|
||||
conScore = 10,
|
||||
intScore = 10,
|
||||
wisScore = 10,
|
||||
chaScore = 10,
|
||||
halfElfBonusAbility1 = null,
|
||||
halfElfBonusAbility2 = null,
|
||||
armorBonus = 0,
|
||||
speedOverride = null,
|
||||
} = character;
|
||||
|
||||
const halfElfBonusAbilities = [halfElfBonusAbility1, halfElfBonusAbility2].filter(Boolean);
|
||||
const rolled = { STR: strScore, DEX: dexScore, CON: conScore, INT: intScore, WIS: wisScore, CHA: chaScore };
|
||||
|
||||
const abilities = {};
|
||||
for (const ability of ABILITIES) {
|
||||
const final = finalAbilityScore(rolled[ability], ability, species, halfElfBonusAbilities);
|
||||
abilities[ability] = {
|
||||
rolled: rolled[ability],
|
||||
final,
|
||||
modifier: abilityModifier(final),
|
||||
};
|
||||
}
|
||||
|
||||
const profBonus = proficiencyBonus(level);
|
||||
|
||||
const saves = {};
|
||||
for (const ability of ABILITIES) {
|
||||
const entry = saveProficiencies.find((s) => s.ability === ability);
|
||||
const proficient = entry ? entry.proficient : false;
|
||||
saves[ability] = { proficient, bonus: saveBonus(abilities[ability].modifier, proficient, profBonus) };
|
||||
}
|
||||
|
||||
const skills = {};
|
||||
for (const skillKey of Object.keys(SKILLS)) {
|
||||
const ability = getGoverningAbilityForSkill(skillKey);
|
||||
const entry = skillProficiencies.find((s) => s.skill === skillKey);
|
||||
const proficient = entry ? entry.proficient : false;
|
||||
const expertise = entry ? Boolean(entry.expertise) : false;
|
||||
skills[skillKey] = {
|
||||
ability,
|
||||
proficient,
|
||||
expertise,
|
||||
bonus: skillBonus(abilities[ability].modifier, proficient, profBonus, expertise),
|
||||
};
|
||||
}
|
||||
|
||||
const hitDieSize = getClassHitDieSize(characterClass);
|
||||
const spellcastingAbility = getClassSpellcastingAbility(characterClass);
|
||||
|
||||
return {
|
||||
abilities,
|
||||
proficiencyBonus: profBonus,
|
||||
armorClass: armorClass(abilities.DEX.modifier, armorBonus),
|
||||
initiative: initiative(abilities.DEX.modifier),
|
||||
speed: effectiveSpeed(species, speedOverride),
|
||||
hp: { max: hpMax(level, hitDieSize, abilities.CON.modifier) },
|
||||
hitDice: { size: hitDieSize, count: level },
|
||||
saves,
|
||||
skills,
|
||||
passivePerception: passivePerception(skills.PERCEPTION.bonus),
|
||||
spellcasting: spellcastingAbility
|
||||
? {
|
||||
ability: spellcastingAbility,
|
||||
saveDC: spellSaveDC(profBonus, abilities[spellcastingAbility].modifier),
|
||||
attackBonus: spellAttackBonus(profBonus, abilities[spellcastingAbility].modifier),
|
||||
}
|
||||
: null,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Attack/damage bonus for a specific weapon against a character's abilities —
|
||||
* used by the quick-stats panel and weapon list.
|
||||
*/
|
||||
function computeWeaponStats(weapon, abilities, profBonus, proficient = true) {
|
||||
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,
|
||||
damageType: weapon.damageType,
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ABILITIES,
|
||||
abilityModifier,
|
||||
proficiencyBonus,
|
||||
speciesAbilityBonus,
|
||||
finalAbilityScore,
|
||||
speciesSpeed,
|
||||
effectiveSpeed,
|
||||
saveBonus,
|
||||
skillBonus,
|
||||
passivePerception,
|
||||
armorClass,
|
||||
initiative,
|
||||
hpMax,
|
||||
spellSaveDC,
|
||||
spellAttackBonus,
|
||||
weaponAbilityModifier,
|
||||
weaponAttackBonus,
|
||||
weaponDamageBonus,
|
||||
getGoverningAbilityForSkill,
|
||||
getClassSaveProficiencies,
|
||||
getClassHitDieSize,
|
||||
getClassSpellcastingAbility,
|
||||
computeCharacterSheet,
|
||||
computeWeaponStats,
|
||||
};
|
||||
@@ -0,0 +1,214 @@
|
||||
const {
|
||||
abilityModifier,
|
||||
proficiencyBonus,
|
||||
finalAbilityScore,
|
||||
saveBonus,
|
||||
skillBonus,
|
||||
passivePerception,
|
||||
armorClass,
|
||||
initiative,
|
||||
hpMax,
|
||||
spellSaveDC,
|
||||
spellAttackBonus,
|
||||
weaponAttackBonus,
|
||||
weaponDamageBonus,
|
||||
computeCharacterSheet,
|
||||
computeWeaponStats,
|
||||
} = require('./calculations');
|
||||
|
||||
describe('abilityModifier', () => {
|
||||
test('floors toward negative infinity, not toward zero', () => {
|
||||
expect(abilityModifier(7)).toBe(-2); // (7-10)/2 = -1.5 -> floor = -2
|
||||
expect(abilityModifier(10)).toBe(0);
|
||||
expect(abilityModifier(11)).toBe(0);
|
||||
expect(abilityModifier(12)).toBe(1);
|
||||
expect(abilityModifier(20)).toBe(5);
|
||||
expect(abilityModifier(1)).toBe(-5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('proficiencyBonus', () => {
|
||||
test('matches the 5e level bands', () => {
|
||||
expect(proficiencyBonus(1)).toBe(2);
|
||||
expect(proficiencyBonus(4)).toBe(2);
|
||||
expect(proficiencyBonus(5)).toBe(3);
|
||||
expect(proficiencyBonus(8)).toBe(3);
|
||||
expect(proficiencyBonus(9)).toBe(4);
|
||||
expect(proficiencyBonus(12)).toBe(4);
|
||||
expect(proficiencyBonus(13)).toBe(5);
|
||||
expect(proficiencyBonus(16)).toBe(5);
|
||||
expect(proficiencyBonus(17)).toBe(6);
|
||||
expect(proficiencyBonus(20)).toBe(6);
|
||||
});
|
||||
});
|
||||
|
||||
describe('finalAbilityScore / species bonuses', () => {
|
||||
test('applies a flat species bonus', () => {
|
||||
expect(finalAbilityScore(14, 'DEX', 'ELF')).toBe(16);
|
||||
expect(finalAbilityScore(14, 'STR', 'ELF')).toBe(14);
|
||||
});
|
||||
|
||||
test('human gets +1 to every ability', () => {
|
||||
expect(finalAbilityScore(10, 'STR', 'HUMAN')).toBe(11);
|
||||
expect(finalAbilityScore(10, 'CHA', 'HUMAN')).toBe(11);
|
||||
});
|
||||
|
||||
test('half-elf gets fixed +2 CHA plus chosen +1/+1', () => {
|
||||
expect(finalAbilityScore(10, 'CHA', 'HALF_ELF', ['STR', 'INT'])).toBe(12);
|
||||
expect(finalAbilityScore(10, 'STR', 'HALF_ELF', ['STR', 'INT'])).toBe(11);
|
||||
expect(finalAbilityScore(10, 'INT', 'HALF_ELF', ['STR', 'INT'])).toBe(11);
|
||||
expect(finalAbilityScore(10, 'WIS', 'HALF_ELF', ['STR', 'INT'])).toBe(10);
|
||||
});
|
||||
|
||||
test('no species leaves score untouched', () => {
|
||||
expect(finalAbilityScore(10, 'STR', null)).toBe(10);
|
||||
});
|
||||
});
|
||||
|
||||
describe('saveBonus / skillBonus', () => {
|
||||
test('save bonus adds proficiency only when proficient', () => {
|
||||
expect(saveBonus(3, true, 2)).toBe(5);
|
||||
expect(saveBonus(3, false, 2)).toBe(3);
|
||||
});
|
||||
|
||||
test('skill bonus with expertise doubles the proficiency portion', () => {
|
||||
expect(skillBonus(2, true, 2, false)).toBe(4);
|
||||
expect(skillBonus(2, true, 2, true)).toBe(6);
|
||||
expect(skillBonus(2, false, 2, true)).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('passivePerception / armorClass / initiative', () => {
|
||||
test('passive perception is 10 + perception bonus', () => {
|
||||
expect(passivePerception(3)).toBe(13);
|
||||
});
|
||||
|
||||
test('armor class is 10 + dex mod + armor bonus', () => {
|
||||
expect(armorClass(2, 3)).toBe(15);
|
||||
expect(armorClass(-1, 0)).toBe(9);
|
||||
});
|
||||
|
||||
test('initiative equals dex modifier', () => {
|
||||
expect(initiative(3)).toBe(3);
|
||||
});
|
||||
});
|
||||
|
||||
describe('hpMax — the level-1-max-die rule', () => {
|
||||
test('level 1 uses the max die roll, not the average', () => {
|
||||
expect(hpMax(1, 10, 2)).toBe(12); // 10 (max d10) + 2 CON
|
||||
expect(hpMax(1, 6, 0)).toBe(6);
|
||||
});
|
||||
|
||||
test('level 2+ adds the fixed average per additional level', () => {
|
||||
// d10 average = floor(10/2)+1 = 6
|
||||
expect(hpMax(2, 10, 2)).toBe(12 + (6 + 2)); // 20
|
||||
expect(hpMax(5, 10, 2)).toBe(12 + 4 * (6 + 2)); // 44
|
||||
});
|
||||
|
||||
test('d6 and d12 averages', () => {
|
||||
expect(Math.floor(6 / 2) + 1).toBe(4);
|
||||
expect(Math.floor(12 / 2) + 1).toBe(7);
|
||||
expect(hpMax(2, 6, 0)).toBe(6 + 4);
|
||||
expect(hpMax(2, 12, 0)).toBe(12 + 7);
|
||||
});
|
||||
});
|
||||
|
||||
describe('spellcasting', () => {
|
||||
test('spell save DC and attack bonus', () => {
|
||||
expect(spellSaveDC(3, 4)).toBe(15);
|
||||
expect(spellAttackBonus(3, 4)).toBe(7);
|
||||
});
|
||||
});
|
||||
|
||||
describe('weapon bonuses', () => {
|
||||
test('STR weapon uses STR modifier', () => {
|
||||
expect(weaponAttackBonus({ attackAbility: 'STR', strMod: 3, dexMod: 1, proficient: true, profBonus: 2 })).toBe(5);
|
||||
expect(weaponDamageBonus({ attackAbility: 'STR', strMod: 3, dexMod: 1 })).toBe(3);
|
||||
});
|
||||
|
||||
test('DEX weapon uses DEX modifier', () => {
|
||||
expect(weaponAttackBonus({ attackAbility: 'DEX', strMod: 3, dexMod: 1, proficient: false, profBonus: 2 })).toBe(1);
|
||||
});
|
||||
|
||||
test('FINESSE weapon uses the better of STR/DEX', () => {
|
||||
expect(weaponDamageBonus({ attackAbility: 'FINESSE', strMod: 1, dexMod: 4 })).toBe(4);
|
||||
expect(weaponDamageBonus({ attackAbility: 'FINESSE', strMod: 5, dexMod: 2 })).toBe(5);
|
||||
});
|
||||
|
||||
test('unknown attackAbility throws rather than silently defaulting', () => {
|
||||
expect(() => weaponDamageBonus({ attackAbility: 'BOGUS', strMod: 1, dexMod: 1 })).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('computeCharacterSheet — full assembly', () => {
|
||||
test('level 1 human fighter', () => {
|
||||
const sheet = computeCharacterSheet(
|
||||
{
|
||||
level: 1,
|
||||
species: 'HUMAN',
|
||||
characterClass: 'FIGHTER',
|
||||
strScore: 15,
|
||||
dexScore: 13,
|
||||
conScore: 14,
|
||||
intScore: 10,
|
||||
wisScore: 12,
|
||||
chaScore: 8,
|
||||
armorBonus: 4,
|
||||
},
|
||||
[{ skill: 'ATHLETICS', proficient: true, expertise: false }],
|
||||
[
|
||||
{ ability: 'STR', proficient: true },
|
||||
{ ability: 'CON', proficient: true },
|
||||
]
|
||||
);
|
||||
|
||||
// Human: +1 to every score -> STR 16 (+3), DEX 14 (+2), CON 15 (+2)
|
||||
expect(sheet.abilities.STR.final).toBe(16);
|
||||
expect(sheet.abilities.STR.modifier).toBe(3);
|
||||
expect(sheet.abilities.CON.modifier).toBe(2);
|
||||
expect(sheet.proficiencyBonus).toBe(2);
|
||||
expect(sheet.armorClass).toBe(10 + sheet.abilities.DEX.modifier + 4);
|
||||
expect(sheet.hp.max).toBe(10 + sheet.abilities.CON.modifier); // d10 fighter, level 1 max die
|
||||
expect(sheet.saves.STR.proficient).toBe(true);
|
||||
expect(sheet.saves.STR.bonus).toBe(sheet.abilities.STR.modifier + 2);
|
||||
expect(sheet.saves.DEX.proficient).toBe(false);
|
||||
expect(sheet.skills.ATHLETICS.bonus).toBe(sheet.abilities.STR.modifier + 2);
|
||||
expect(sheet.spellcasting).toBeNull(); // Fighter has no spellcasting ability
|
||||
});
|
||||
|
||||
test('spellcasting classes expose saveDC/attackBonus', () => {
|
||||
const sheet = computeCharacterSheet({
|
||||
level: 5,
|
||||
species: 'ELF',
|
||||
characterClass: 'WIZARD',
|
||||
intScore: 16,
|
||||
});
|
||||
expect(sheet.spellcasting).not.toBeNull();
|
||||
expect(sheet.spellcasting.ability).toBe('INT');
|
||||
expect(sheet.spellcasting.saveDC).toBe(8 + sheet.proficiencyBonus + sheet.abilities.INT.modifier);
|
||||
});
|
||||
|
||||
test('half-elf bonus abilities flow through the full sheet', () => {
|
||||
const sheet = computeCharacterSheet({
|
||||
level: 1,
|
||||
species: 'HALF_ELF',
|
||||
characterClass: 'BARD',
|
||||
strScore: 10,
|
||||
chaScore: 10,
|
||||
halfElfBonusAbility1: 'STR',
|
||||
halfElfBonusAbility2: 'INT',
|
||||
});
|
||||
expect(sheet.abilities.CHA.final).toBe(12); // fixed +2
|
||||
expect(sheet.abilities.STR.final).toBe(11); // chosen +1
|
||||
});
|
||||
});
|
||||
|
||||
describe('computeWeaponStats', () => {
|
||||
test('assembles attack/damage bonus for a weapon from a computed sheet', () => {
|
||||
const sheet = computeCharacterSheet({ level: 1, strScore: 16, dexScore: 12 });
|
||||
const stats = computeWeaponStats({ attackAbility: 'STR', damageDice: '1d8', damageType: 'slashing' }, sheet.abilities, sheet.proficiencyBonus, true);
|
||||
expect(stats.attackBonus).toBe(sheet.abilities.STR.modifier + sheet.proficiencyBonus);
|
||||
expect(stats.damageBonus).toBe(sheet.abilities.STR.modifier);
|
||||
expect(stats.damageDice).toBe('1d8');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,19 @@
|
||||
// Generated from /seed-data/classes.json — keep in sync by hand if that file changes.
|
||||
// See docs/GAME_RULES_REFERENCE.md "Class Quick Facts".
|
||||
|
||||
const CLASSES = {
|
||||
FIGHTER: { key: 'FIGHTER', name: 'Fighter', hitDie: 10, primaryAbility: 'Str/Dex', saveProficiencies: ['STR', 'CON'], spellcastingAbility: null },
|
||||
BARBARIAN: { key: 'BARBARIAN', name: 'Barbarian', hitDie: 12, primaryAbility: 'Str', saveProficiencies: ['STR', 'CON'], spellcastingAbility: null },
|
||||
ROGUE: { key: 'ROGUE', name: 'Rogue', hitDie: 8, primaryAbility: 'Dex', saveProficiencies: ['DEX', 'INT'], spellcastingAbility: null },
|
||||
RANGER: { key: 'RANGER', name: 'Ranger', hitDie: 10, primaryAbility: 'Dex/Wis', saveProficiencies: ['STR', 'DEX'], spellcastingAbility: 'WIS' },
|
||||
WIZARD: { key: 'WIZARD', name: 'Wizard', hitDie: 6, primaryAbility: 'Int', saveProficiencies: ['INT', 'WIS'], spellcastingAbility: 'INT' },
|
||||
SORCERER: { key: 'SORCERER', name: 'Sorcerer', hitDie: 6, primaryAbility: 'Cha', saveProficiencies: ['CON', 'CHA'], spellcastingAbility: 'CHA' },
|
||||
CLERIC: { key: 'CLERIC', name: 'Cleric', hitDie: 8, primaryAbility: 'Wis', saveProficiencies: ['WIS', 'CHA'], spellcastingAbility: 'WIS' },
|
||||
PALADIN: { key: 'PALADIN', name: 'Paladin', hitDie: 10, primaryAbility: 'Str/Cha', saveProficiencies: ['WIS', 'CHA'], spellcastingAbility: 'CHA' },
|
||||
BARD: { key: 'BARD', name: 'Bard', hitDie: 8, primaryAbility: 'Cha', saveProficiencies: ['DEX', 'CHA'], spellcastingAbility: 'CHA' },
|
||||
WARLOCK: { key: 'WARLOCK', name: 'Warlock', hitDie: 8, primaryAbility: 'Cha', saveProficiencies: ['WIS', 'CHA'], spellcastingAbility: 'CHA' },
|
||||
DRUID: { key: 'DRUID', name: 'Druid', hitDie: 8, primaryAbility: 'Wis', saveProficiencies: ['INT', 'WIS'], spellcastingAbility: 'WIS' },
|
||||
MONK: { key: 'MONK', name: 'Monk', hitDie: 8, primaryAbility: 'Dex/Wis', saveProficiencies: ['STR', 'DEX'], spellcastingAbility: null },
|
||||
};
|
||||
|
||||
module.exports = { CLASSES };
|
||||
@@ -0,0 +1,25 @@
|
||||
// Generated from /seed-data/skills.json — keep in sync by hand if that file changes.
|
||||
// See docs/GAME_RULES_REFERENCE.md "Skill -> Governing Ability".
|
||||
|
||||
const SKILLS = {
|
||||
ACROBATICS: { key: 'ACROBATICS', name: 'Acrobatics', ability: 'DEX' },
|
||||
ANIMAL_HANDLING: { key: 'ANIMAL_HANDLING', name: 'Animal Handling', ability: 'WIS' },
|
||||
ARCANA: { key: 'ARCANA', name: 'Arcana', ability: 'INT' },
|
||||
ATHLETICS: { key: 'ATHLETICS', name: 'Athletics', ability: 'STR' },
|
||||
DECEPTION: { key: 'DECEPTION', name: 'Deception', ability: 'CHA' },
|
||||
HISTORY: { key: 'HISTORY', name: 'History', ability: 'INT' },
|
||||
INSIGHT: { key: 'INSIGHT', name: 'Insight', ability: 'WIS' },
|
||||
INTIMIDATION: { key: 'INTIMIDATION', name: 'Intimidation', ability: 'CHA' },
|
||||
INVESTIGATION: { key: 'INVESTIGATION', name: 'Investigation', ability: 'INT' },
|
||||
MEDICINE: { key: 'MEDICINE', name: 'Medicine', ability: 'WIS' },
|
||||
NATURE: { key: 'NATURE', name: 'Nature', ability: 'INT' },
|
||||
PERCEPTION: { key: 'PERCEPTION', name: 'Perception', ability: 'WIS' },
|
||||
PERFORMANCE: { key: 'PERFORMANCE', name: 'Performance', ability: 'CHA' },
|
||||
PERSUASION: { key: 'PERSUASION', name: 'Persuasion', ability: 'CHA' },
|
||||
RELIGION: { key: 'RELIGION', name: 'Religion', ability: 'INT' },
|
||||
SLEIGHT_OF_HAND: { key: 'SLEIGHT_OF_HAND', name: 'Sleight of Hand', ability: 'DEX' },
|
||||
STEALTH: { key: 'STEALTH', name: 'Stealth', ability: 'DEX' },
|
||||
SURVIVAL: { key: 'SURVIVAL', name: 'Survival', ability: 'WIS' },
|
||||
};
|
||||
|
||||
module.exports = { SKILLS };
|
||||
@@ -0,0 +1,23 @@
|
||||
// Generated from /seed-data/species.json — keep in sync by hand if that file changes.
|
||||
// See docs/GAME_RULES_REFERENCE.md "Species Ability Score Increases & Speed".
|
||||
|
||||
const SPECIES = {
|
||||
HUMAN: { key: 'HUMAN', name: 'Human', abilityBonuses: { STR: 1, DEX: 1, CON: 1, INT: 1, WIS: 1, CHA: 1 }, speed: 30, notes: null },
|
||||
HALF_ELF: {
|
||||
key: 'HALF_ELF',
|
||||
name: 'Half-Elf',
|
||||
abilityBonuses: { STR: 0, DEX: 0, CON: 0, INT: 0, WIS: 0, CHA: 2 },
|
||||
speed: 30,
|
||||
notes: "Fixed +2 CHA plus a flexible +1/+1 to two other abilities of the player's choice. The builder UI must prompt for this choice; do not hardcode a default.",
|
||||
},
|
||||
ELF: { key: 'ELF', name: 'Elf', abilityBonuses: { STR: 0, DEX: 2, CON: 0, INT: 0, WIS: 0, CHA: 0 }, speed: 30, notes: null },
|
||||
GNOME: { key: 'GNOME', name: 'Gnome', abilityBonuses: { STR: 0, DEX: 0, CON: 0, INT: 2, WIS: 0, CHA: 0 }, speed: 25, notes: null },
|
||||
DWARF: { key: 'DWARF', name: 'Dwarf', abilityBonuses: { STR: 0, DEX: 0, CON: 2, INT: 0, WIS: 0, CHA: 0 }, speed: 25, notes: null },
|
||||
HALFLING: { key: 'HALFLING', name: 'Halfling', abilityBonuses: { STR: 0, DEX: 2, CON: 0, INT: 0, WIS: 0, CHA: 0 }, speed: 25, notes: null },
|
||||
DRAGONBORN: { key: 'DRAGONBORN', name: 'Dragonborn', abilityBonuses: { STR: 2, DEX: 0, CON: 0, INT: 0, WIS: 0, CHA: 1 }, speed: 30, notes: null },
|
||||
TIEFLING: { key: 'TIEFLING', name: 'Tiefling', abilityBonuses: { STR: 0, DEX: 0, CON: 0, INT: 1, WIS: 0, CHA: 2 }, speed: 30, notes: null },
|
||||
HALF_ORC: { key: 'HALF_ORC', name: 'Half-Orc', abilityBonuses: { STR: 2, DEX: 0, CON: 1, INT: 0, WIS: 0, CHA: 0 }, speed: 30, notes: null },
|
||||
ORC: { key: 'ORC', name: 'Orc', abilityBonuses: { STR: 2, DEX: 0, CON: 1, INT: 0, WIS: 0, CHA: 0 }, speed: 30, notes: null },
|
||||
};
|
||||
|
||||
module.exports = { SPECIES };
|
||||
Reference in New Issue
Block a user