Initital commit

This commit is contained in:
2024-03-12 17:28:38 +04:00
commit 2e55d7c3fe
9 changed files with 558 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
'use strict';
const Stat = require("./Stat.js");
module.exports = class StatRoll {
/**
* @prop {Stat[6]} rolls
*/
rolls;
/**
* @prop {number} sum
*/
sum;
constructor(rolls) {
this.rolls = Array.from({length: 6}, _ => new Stat("4d6"));
this.rolls.sort((r1, r2) => r1.result - r2.result).reverse();
this.sum = this.rolls.map(r => r.result).reduce((r, s) => s += r);
}
toString() {
return `{${this.rolls.join(' / ')}}`;
}
toShortString() {
return `{${this.rolls.map(r => r.result).join('/')}}`;
}
}