Skip to content

Instantly share code, notes, and snippets.

@Kadajett
Created November 18, 2023 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kadajett/4f3614f48f6c8fc78eaa45f630ad4215 to your computer and use it in GitHub Desktop.
Save Kadajett/4f3614f48f6c8fc78eaa45f630ad4215 to your computer and use it in GitHub Desktop.
Calculate Bonus Spells Pathfinder 1e
function calculateAbilityModifier(abilityScore: number): number {
return Math.floor((abilityScore - 10) / 2);
}
function generateBonusSpellTable(abilityScore: number): {
[level: number]: number;
} {
const modifier = calculateAbilityModifier(abilityScore);
let bonusSpells: { [level: number]: number } = {};
for (let spellLevel = 1; spellLevel <= 9; spellLevel++) {
if (modifier >= spellLevel) {
// Calculate bonus spells for this level
bonusSpells[spellLevel] = Math.floor((modifier - spellLevel) / 4) + 1;
} else {
bonusSpells[spellLevel] = 0;
}
}
return bonusSpells;
}
// Example usage
const abilityScore = 44;
const bonusSpells = generateBonusSpellTable(abilityScore);
console.log(`Bonus spells for ability score ${abilityScore}:`, bonusSpells);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment