import { ALL_STATS, Skill, Stat, SuccessorOption } from "./datatypes.ts"; import { generateName, generateTitle } from "./namegen.ts"; import { choose } from "./utils.ts"; import { getPlayerProgress } from "./playerprogress.ts"; export function generateSuccessors( nImprovements: number, penance: boolean, ): SuccessorOption[] { if (penance) { return [generateSuccessorFromPlayer()]; } let options = []; while (options.length < 3) { let option = generateSuccessor(nImprovements); if (!isEligible(options, option)) { continue; } options.push(option); } return options; } function isEligible(existing: SuccessorOption[], added: SuccessorOption) { for (let e of existing.values()) { if (e.name == added.name || e.title == added.title) { return false; } } return true; } export function generateSuccessorFromPlayer(): SuccessorOption { let progress = getPlayerProgress(); let successor = { name: progress.name, title: "Penitent", note: "Failed at Master's bidding", stats: { ...progress.getStats() }, talents: { ...progress.getTalents() }, skills: [...progress.getLearnedSkills()], inPenance: true, isCompulsory: true, }; for (let stat of ALL_STATS.values()) { successor.talents[stat] = -8; } return successor; } export function generateSuccessor(nImprovements: number): SuccessorOption { let name = generateName(); let title = generateTitle(); let note = null; let stats: Record = { AGI: 10 + choose([1, 2]), INT: 10 + choose([1, 2]), CHA: 10 + choose([1, 2]), PSI: 10 + choose([1, 2]), }; let talents: Record = { AGI: 0, INT: 0, CHA: 0, PSI: 0, }; let improvements = [ () => { stats[choose(ALL_STATS)] += choose([3, 4, 5, 6]); }, // avg 4.5 () => { talents[choose(ALL_STATS)] += 1; }, ]; let nTotalImprovements = nImprovements + 5; for (let i = 0; i < nTotalImprovements; i++) { let improvement = improvements[Math.floor(Math.random() * improvements.length)]; improvement(); } let skills: Skill[] = []; let inPenance = false; let isCompulsory = false; return { name, title, note, stats, talents, skills, inPenance, isCompulsory }; }