Initital commit
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
const Chance = require("chance");
|
||||
|
||||
module.exports = class Stat {
|
||||
/**
|
||||
* @type {number{4}}
|
||||
*/
|
||||
dices;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
result
|
||||
|
||||
constructor(diceString) {
|
||||
this.dices = Stat.chance(diceString);
|
||||
// this.dices = Array.from({length: 4}, _ => Math.floor(Math.random() * 6 + 1));
|
||||
|
||||
this.dices.sort().reverse();
|
||||
|
||||
this.result = this.dices.reduce((a, s) => s + a, 0) - Math.min(...this.dices);
|
||||
}
|
||||
|
||||
toString() {
|
||||
return `${this.result} [${this.dices.join(',')}]`;
|
||||
}
|
||||
|
||||
static #chance;
|
||||
|
||||
static chance(diceString) {
|
||||
if (!this.#chance) {
|
||||
this.#chance = new Chance();
|
||||
}
|
||||
|
||||
return this.#chance.rpg(diceString);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user