Initial commit

This commit is contained in:
2026-09-22 16:27:53 +02:00
commit 9b29dc8253
70 changed files with 14726 additions and 0 deletions
+76
View File
@@ -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,
};