Skip to content

Instantly share code, notes, and snippets.

@LLBlumire
Created March 18, 2020 15:34
Show Gist options
  • Save LLBlumire/9091ef41f94584affd56a1c485e3862d to your computer and use it in GitHub Desktop.
Save LLBlumire/9091ef41f94584affd56a1c485e3862d to your computer and use it in GitHub Desktop.
import { AbilityScoresObject as ASO } from './types';
export function standardGenerator() {
return function* (i: ASO) {
const strVar = Math.max(0, i.str - 9);
const intVar = Math.max(0, i.int - 9);
const wisVar = Math.max(0, i.wis - 9);
for (let strI = 0; strI <= strVar; strI++) {
for (let intI = 0; intI <= intVar; intI++) {
for (let wisI = 0; wisI <= wisVar; wisI++) {
let poolVar = strI + intI + wisI;
if (poolVar % 2 != 0) {
continue;
}
poolVar /= 2;
for (let strB = 0; strB <= poolVar; strB++) {
const poolStr = poolVar - strB;
for (let intB = 0; intB <= poolStr; intB++) {
const poolInt = poolStr - intB;
for (let wisB = 0; wisB <= poolInt; wisB++) {
const poolWis = poolInt - wisB;
for (let dexB = 0; dexB <= poolWis; dexB++) {
const poolDex = poolWis - dexB;
for (let conB = 0; conB <= poolDex; conB++) {
const chaB = poolDex - conB;
yield {
scores: {
str: i.str - strI + strB,
int: i.int - intI + intB,
wis: i.wis - wisI + wisB,
dex: i.dex + dexB,
con: i.con + conB,
cha: i.cha + chaB
},
mod: poolVar * 2
}
}
}
}
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment