Initital commit
This commit is contained in:
+33
@@ -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('/')}}`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user