Files
dnd_stat_roll_distribution/StatRoll.js
T
2024-03-12 17:28:38 +04:00

33 lines
613 B
JavaScript

'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('/')}}`;
}
}