UNPKG

osr-generators

Version:

Generators for OSR-style tabletop roleplaying games

701 lines (692 loc) 14.4 kB
// src/dice/Dice.ts var _Dice = class _Dice { }; _Dice.roll = (dieSize, numberOfDice = 1) => { const rolls = new Array(numberOfDice).fill(void 0).map(() => _Dice.randomNumber(dieSize)); return rolls.reduce((acc, curr) => acc + curr, 0); }; _Dice.randomNumber = (max) => { return Math.floor(Math.random() * max + 1); }; var Dice = _Dice; var Dice_default = Dice; // src/dice/Randomization.ts var Randomization = class { }; Randomization.getRandomItem = (list) => { if (list.length === 0) { throw new Error("Cannot get a random item from an empty array"); } const randomIndex = Math.floor(Math.random() * list.length); return list[randomIndex]; }; var Randomization_default = Randomization; // src/knave/Character.ts var Character = class { constructor() { this.armor = { count: 0, defense: 0, name: "", quality: 0, slots: 0, type: "armor" }; this.copperPieces = 0; this.items = [{ name: "", count: 0, type: "food", slots: 0 }]; this.itemSlots = 13; this.level = 1; this.maxHp = 4; this.traits = { physique: "", face: "", skin: "", hair: "", clothing: "", virtue: "", vice: "", speech: "", background: "", misfortune: "" }; this.weapon = { count: 0, damage: "", hand: 0, name: "", quality: 0, slots: 1, type: "weapon" }; this.abilities = { charisma: { bonus: 3, defense: 13 }, constitution: { bonus: 3, defense: 13 }, dexterity: { bonus: 3, defense: 13 }, intelligence: { bonus: 3, defense: 13 }, strength: { bonus: 3, defense: 13 }, wisdom: { bonus: 3, defense: 13 } }; this.generate = () => { this.level = 1; this.abilities = this.generateAbilities(); this.copperPieces = this.rollForCopperPieces(); this.itemSlots = this.constitution.defense; this.maxHp = this.rollHitPoints(); const gear = new Gear_default(this.itemSlots); this.traits = this.generateTraits(); this.items = gear.items; this.armor = gear.armor; this.weapon = gear.weapon; }; // END PUBLIC METHODS this.rollForCopperPieces = () => { return Dice_default.roll(6, 3) + 20; }; this.rollHitPoints = () => { return Dice_default.roll(8); }; this.generateAbilities = () => { const { charisma, constitution, dexterity, intelligence, strength, wisdom } = { charisma: this.rollAbilityScore(), constitution: this.rollAbilityScore(), dexterity: this.rollAbilityScore(), intelligence: this.rollAbilityScore(), strength: this.rollAbilityScore(), wisdom: this.rollAbilityScore() }; const abilities = { charisma: { bonus: charisma, defense: charisma + 10 }, constitution: { bonus: constitution, defense: constitution + 10 }, dexterity: { bonus: dexterity, defense: dexterity + 10 }, intelligence: { bonus: intelligence, defense: intelligence + 10 }, strength: { bonus: strength, defense: strength + 10 }, wisdom: { bonus: wisdom, defense: wisdom + 10 } }; return abilities; }; this.rollAbilityScore = () => { const rolls = new Array(3).fill(void 0).map(() => Dice_default.roll(6)); return Math.min(...rolls); }; this.generateTraits = () => { return new Description_default().traits; }; this.generate(); } get abilityScores() { return this.abilities; } get charisma() { return this.abilities.charisma; } get constitution() { return this.abilities.constitution; } get dexterity() { return this.abilities.dexterity; } get intelligence() { return this.abilities.intelligence; } get strength() { return this.abilities.strength; } get wisdom() { return this.abilities.wisdom; } }; var Character_default = Character; // src/knave/data/armor.ts var armorData = { armor: [ { name: "gambeson armor", count: 1, defense: 12, slots: 1, type: "armor", quality: 3 }, { name: "brigandine armor", count: 1, defense: 13, slots: 2, type: "armor", quality: 4 }, { name: "chain armor", count: 1, defense: 14, slots: 3, type: "armor", quality: 5 }, { name: "shield", count: 1, defense: 1, slots: 1, type: "armor", quality: 1 }, { name: "helmet", count: 1, defense: 1, slots: 1, type: "armor", quality: 1 }, { name: "half plate armor", count: 1, defense: 15, slots: 4, type: "armor", quality: 6 }, { name: "full plate armor", count: 1, defense: 16, slots: 5, type: "armor", quality: 7 } ] }; // src/knave/data/gear.ts var gearData = { dungeoneeringGear: [ { name: "rope (50 ft.)", slots: 1, type: "tool", count: 1 }, { name: "pulley", slots: 1, type: "tool", count: 1 }, { name: "candles", slots: 1, type: "light", count: 5 }, { name: "chain (10 ft.)", slots: 1, type: "tool", count: 1 }, { name: "chalk", slots: 1, type: "tool", count: 10 } ], generalGearSetOne: [ { name: "air bladder", slots: 1, type: "tool", count: 1 }, { name: "bear trap", slots: 1, type: "tool", count: 1 }, { name: "shovel", slots: 1, type: "tool", count: 1 }, { name: "bellows", slots: 1, type: "tool", count: 1 }, { name: "grease", slots: 1, type: "tool", count: 1 } ], generalGearSetTwo: [ { name: "incense", slots: 1, type: "tool", count: 1 }, { name: "sponge", slots: 1, type: "tool", count: 1 }, { name: "lens", slots: 1, type: "tool", count: 1 }, { name: "perfume", slots: 1, type: "tool", count: 1 }, { name: "horn", slots: 1, type: "tool", count: 1 } ] }; // src/knave/data/weapons.ts var weaponData = { weapons: [ { count: 1, damage: "d6", hand: 1, name: "dagger", quality: 3, slots: 1, type: "weapon" }, { count: 1, damage: "d6", hand: 1, name: "cudgel", quality: 3, slots: 1, type: "weapon" }, { count: 1, damage: "d6", hand: 1, name: "sickle", quality: 3, slots: 1, type: "weapon" }, { count: 1, damage: "d6", hand: 1, name: "staff", quality: 3, slots: 1, type: "weapon" }, { count: 1, damage: "d8", hand: 1, name: "spear", quality: 3, slots: 2, type: "weapon" }, { count: 1, damage: "d8", hand: 1, name: "sword", quality: 3, slots: 2, type: "weapon" }, { count: 1, damage: "d8", hand: 1, name: "mace", quality: 3, slots: 2, type: "weapon" }, { count: 1, damage: "d8", hand: 1, name: "axe", quality: 3, slots: 2, type: "weapon" }, { count: 1, damage: "d8", hand: 1, name: "flail", quality: 3, slots: 2, type: "weapon" }, { count: 1, damage: "d10", hand: 2, name: "halberd", quality: 3, slots: 3, type: "weapon" }, { count: 1, damage: "d10", hand: 2, name: "warhammer", quality: 3, slots: 3, type: "weapon" }, { name: "longsword", count: 1, damage: "d10", hand: 2, quality: 3, slots: 3, type: "weapon" }, { name: "battleaxe", count: 1, damage: "d10", hand: 2, quality: 3, slots: 3, type: "weapon" }, { count: 1, damage: "d4", hand: 1, name: "sling", quality: 1, slots: 1, type: "weapon" }, { count: 1, damage: "d6", hand: 2, name: "bow", quality: 3, slots: 2, type: "weapon" }, { count: 1, damage: "d8", hand: 2, name: "crossbow", quality: 3, slots: 3, type: "weapon" } ] }; // src/knave/data/traits.ts var traitsData = { physique: [ "athletic", "brawny", "corpulent", "delicate", "gaunt", "hulking", "lanky", "ripped", "rugged", "scrawny", "short", "sinewy", "slender", "flabby", "statuesque", "stout", "tiny", "towering", "willowy", "wiry" ], face: [ "bloated", "blunt", "bony", "chiseled", "delicate", "elongated", "patrician", "pinched", "hawkish", "broken", "impish", "narrow", "ratlike", "round", "sunken", "sharp", "soft", "square", "wide", "wolfish" ], skin: [ "battle scarred", "birthmarked", "burn scarred", "dark", "madeup", "oily", "pale", "perfect", "pierced", "pockmarked", "reeking", "tattooed", "rosy", "sallow", "sunburned", "tanned", "war painted", "weathered", "whip scarred" ], hair: [ "bald", "braided", "cropped", "curly", "disheveled", "dreadlocks", "filthy", "frizzy", "greased", "limp", "long", "luxurious", "mohawk", "oily", "ponytail", "silky", "topknot", "wavy", "wispy" ], clothing: [ "antique", "bloody", "ceremonial", "decorated", "eccentric", "elegant", "fashionable", "filthy", "flamboyant", "stained", "foreign", "frayed", "frumpy", "livery", "oversized", "patched", "perfumed", "rancid", "torn", "undersized" ], virtue: [ "ambitious", "cautious", "courageous", "courteous", "curious", "disciplined", "focused", "generous", "gregarious", "honest", "honorable", "humble", "idealistic", "just", "loyal", "merciful", "righteous", "serene", "stoic", "tolerant" ], vice: [ "aggressive", "arrogant", "bitter", "cowardly", "cruel", "deceitful", "flippant", "gluttonous ", "greedy", "irascible", "lazy", "nervous", "prejudiced", "reckless", "rude", "suspicious", "vain", "vengeful", "wasteful", "whiny" ], speech: [ "blunt", "booming", "breathy", "cryptic", "drawling", "droning", "flowery", "formal", "gravelly", "hoarse", "mumbling", "precise", "quaint", "rambling", "rapid-fire", "dialect", "slow", "squeaky", "stuttering", "whispery" ], background: [ "alchemist", "beggar", "butcher", "burglar", "charlatan", "cleric", "cook", "cultist", "gambler", "herbalist", "magician", "mariner", "mercenary", "merchant", "outlaw", "performer", "pickpocket", "smuggler", "student", "tracker" ], misfortune: [ "abandoned", "addicted", "blackmailed", "condemned", "cursed", "defrauded", "demoted", "discredited", "disowned", "exiled", "framed", "haunted", "kidnapped", "mutilated", "poor", "pursued", "rejected", "replaced", "robbed", "suspected" ] }; // src/knave/Description.ts var Description = class { constructor() { this.generateRandomTraits = () => { const defaultTraits = { physique: "", face: "", skin: "", hair: "", clothing: "", virtue: "", vice: "", speech: "", background: "", misfortune: "" }; const parsedTraitData = this.getTraitData(); const nouns = Object.keys(parsedTraitData); const randomTraits = nouns.reduce((acc, curr) => { const currentTrait = curr; const randomTraitValue = Randomization_default.getRandomItem( parsedTraitData[currentTrait] ); acc[currentTrait] = randomTraitValue; return acc; }, defaultTraits); return randomTraits; }; this.getTraitData = () => { return traitsData; }; this.traits = this.generateRandomTraits(); } }; var Description_default = Description; // src/knave/Gear.ts var Gear = class { constructor(itemSlots) { this.getRandomArmor = () => { const slotsRemaining = this.itemSlots - this.itemSlotsUsed; const availableArmor = armorData.armor.filter((armor2) => { return armor2.slots < slotsRemaining; }); const armor = Randomization_default.getRandomItem(availableArmor); this.itemSlotsUsed += armor.slots; this.items.push(armor); return armor; }; this.getRandomWeapon = () => { const slotsRemaining = this.itemSlots - this.itemSlotsUsed; const availableWeapons = weaponData.weapons.filter( (weapon2) => { return weapon2.slots <= slotsRemaining; } ); const weapon = Randomization_default.getRandomItem(availableWeapons); this.itemSlotsUsed += weapon.slots; this.items.push(weapon); return weapon; }; this.itemSlots = itemSlots; this.itemSlotsUsed = 0; this.items = this.getRandomGear(); this.armor = this.getRandomArmor(); this.weapon = this.getRandomWeapon(); } getRandomGear() { const dg = gearData.dungeoneeringGear; const gen1 = gearData.generalGearSetOne; const gen2 = gearData.generalGearSetTwo; const startingGear = [ { name: "rations", count: 1, slots: 1, type: "food" }, { name: "rations", count: 1, slots: 1, type: "food" } ]; const dungeoneeringGear = new Array(2).fill(void 0).map(() => Randomization_default.getRandomItem(dg)); const generalGear1 = Randomization_default.getRandomItem(gen1); const generalGear2 = Randomization_default.getRandomItem(gen2); const gear = [ ...startingGear, ...dungeoneeringGear, generalGear1, generalGear2 ]; const itemSlotsUsed = gear.reduce((acc, curr) => acc += curr.slots, 0); this.itemSlotsUsed = itemSlotsUsed; return gear; } }; var Gear_default = Gear; export { Character_default as KnaveCharacter };