// Subclasses: the path a character takes within their class, one file per // class. Every official subclass is here (2014 books, and the 2024 Player’s // Handbook where it brought a new one), as listed at // dungeonsanddragonsfan.com/all-dnd-5e-classes-subclasses-complete-guide. // // Each entry is { key, name, source, edition, replaces?, summary, features }. // - `key` is unique across all classes; it is what Character.subclass holds. // - `source` is the book, `edition` '2014' or '2024'. // - `replaces` names the 2014 subclass a 2024 one updates (Wild Heart for the // Totem Warrior). A character on the old one can switch to the new. // - `features` are by character level, in the same shape as LEVEL_FEATURES // (levelFeatures.js): each becomes a line of the special abilities, and an // `upgrade` rewrites the line that already has its name. A subclass's gifts // from before its class chooses (a cleric domain's 1st-level ones) arrive // with the choice. None of it feeds the calculation engine. // // The first subclass of each class is the path every character of that class // followed before subclasses could be chosen (the Champion fighter, the Life // cleric...), and the one a campaign without subclasses gives everybody. Its // lines are word for word what the class tables used to write, so sheets // written back then still match. // The level at which a class chooses. const SUBCLASS_LEVEL = { ARTIFICER: 3, BARBARIAN: 3, BARD: 3, CLERIC: 2, DRUID: 2, FIGHTER: 3, MONK: 3, PALADIN: 3, RANGER: 3, ROGUE: 3, SORCERER: 3, WARLOCK: 3, WIZARD: 2, }; const SUBCLASSES = { ARTIFICER: require('./artificer'), BARBARIAN: require('./barbarian'), BARD: require('./bard'), CLERIC: require('./cleric'), DRUID: require('./druid'), FIGHTER: require('./fighter'), MONK: require('./monk'), PALADIN: require('./paladin'), RANGER: require('./ranger'), ROGUE: require('./rogue'), SORCERER: require('./sorcerer'), WARLOCK: require('./warlock'), WIZARD: require('./wizard'), }; function subclassesOf(characterClass) { return SUBCLASSES[characterClass] || []; } // One subclass of a class by its key; null when the class has no such subclass. function findSubclass(characterClass, key) { return subclassesOf(characterClass).find((subclass) => subclass.key === key) || null; } function subclassName(characterClass, key) { const subclass = findSubclass(characterClass, key); return subclass ? subclass.name : null; } // The path a class followed before subclasses could be chosen. function defaultSubclass(characterClass) { return subclassesOf(characterClass)[0] || null; } // The 2024 subclass that updates this one, if there is one. function newerVersionOf(characterClass, key) { return subclassesOf(characterClass).find((subclass) => subclass.replaces === key) || null; } // What a list of subclasses to choose from shows of each: everything but the // features. const subclassSummary = ({ key, name, summary, source, edition, replaces = null }) => ({ key, name, summary, source, edition, replaces }); module.exports = { SUBCLASS_LEVEL, SUBCLASSES, subclassesOf, findSubclass, subclassName, defaultSubclass, newerVersionOf, subclassSummary };