Changes to permit dice variations from the frontend to Asphodice class, successCutOff in particulartags/v0.3.0
@@ -27,6 +27,10 @@ interface Dice { | |||||
readonly type: string; | readonly type: string; | ||||
} | } | ||||
interface DiceOptions { | |||||
successCutOff?: number, | |||||
} | |||||
export enum Outcomes { | export enum Outcomes { | ||||
Success = "Success", | Success = "Success", | ||||
Fail = "Failure", | Fail = "Failure", | ||||
@@ -88,6 +92,17 @@ export class Asphodice extends D10 { | |||||
readonly failCrit: number = 1; | readonly failCrit: number = 1; | ||||
readonly successCutOff: number = 6; // this or larger | readonly successCutOff: number = 6; // this or larger | ||||
/** | |||||
* Modify successCutOff | |||||
*/ | |||||
constructor (diceOptions?: DiceOptions) { | |||||
super(); | |||||
if (diceOptions) { | |||||
if (diceOptions.successCutOff) { | |||||
this.successCutOff = diceOptions.successCutOff; | |||||
} | |||||
} | |||||
} | |||||
/** | /** | ||||
* Re-roll the high dice (ie >= 6) for a chance of failure | * Re-roll the high dice (ie >= 6) for a chance of failure | ||||
* happens on eg 1 | * happens on eg 1 | ||||
@@ -379,11 +379,11 @@ function addResults(rollstats: RollStats): void { | |||||
function resultsControlCard(): string { | function resultsControlCard(): string { | ||||
let resultsControl = `<div id="resultsControl" class="card my-3 mx-2 border border-2 border-info">`; | let resultsControl = `<div id="resultsControl" class="card my-3 mx-2 border border-2 border-info">`; | ||||
resultsControl += `<h2 class="card-title mx-3 my-2">Results</h5>`; | resultsControl += `<h2 class="card-title mx-3 my-2">Results</h5>`; | ||||
resultsControl += `<div class="progress mx-3"> | resultsControl += `<div class="progress mx-3"> | ||||
<div class="progress-bar" id="resultsProgress"></div> | |||||
<div class="progress-bar" id="resultsProgress"></div> | |||||
</div>`; | </div>`; | ||||
resultsControl += `<div class="card-body"> | resultsControl += `<div class="card-body"> | ||||
<button class="btn btn-primary" type="button" | <button class="btn btn-primary" type="button" | ||||
data-bs-toggle="collapse" data-bs-target=".resultsToggle" | data-bs-toggle="collapse" data-bs-target=".resultsToggle" | ||||
@@ -408,7 +408,8 @@ function getResults():void { | |||||
let maxDice = 10; | let maxDice = 10; | ||||
for (let i = 1; i < maxDice; i++) { | for (let i = 1; i < maxDice; i++) { | ||||
let rollstats = new RollStats(i); | |||||
let rsSetup = { numDice: i }; | |||||
let rollstats = new RollStats(rsSetup); | |||||
rollstats.doRolls(); | rollstats.doRolls(); | ||||
addResults(rollstats); | addResults(rollstats); | ||||
$("#resultsProgress").width(`${i/maxDice*100}%`); | $("#resultsProgress").width(`${i/maxDice*100}%`); | ||||
@@ -12,6 +12,11 @@ declare let ItemCountSet: Array<ItemCount>; | |||||
type EnumObject<T extends string> = { [K in T]?: number }; | type EnumObject<T extends string> = { [K in T]?: number }; | ||||
type outcomeCountObject = EnumObject<Outcomes>; | type outcomeCountObject = EnumObject<Outcomes>; | ||||
interface RollStatsSetup { | |||||
numDice?: number, | |||||
diceOptions?: object | |||||
} | |||||
/** | /** | ||||
* Singleton-type class for all dice-statistic related needs | * Singleton-type class for all dice-statistic related needs | ||||
*/ | */ | ||||
@@ -21,15 +26,21 @@ export class RollStats { | |||||
balanceCounts: { [balance: string]: number } = {}; | balanceCounts: { [balance: string]: number } = {}; | ||||
outcomeCounts: outcomeCountObject = {}; | outcomeCounts: outcomeCountObject = {}; | ||||
diceCounts: { [dice: string]: number} = {}; | diceCounts: { [dice: string]: number} = {}; | ||||
diceOptions = {}; | |||||
numRolls = 100000; | numRolls = 100000; | ||||
maxDice = 10; | maxDice = 10; | ||||
numDice = 4; | numDice = 4; | ||||
constructor(numDice?:number) { | |||||
constructor(rsSetup?: RollStatsSetup) { | |||||
this.resetCounts(); | this.resetCounts(); | ||||
if (numDice) { | |||||
this.numDice = numDice; | |||||
if (rsSetup) { | |||||
if (rsSetup.numDice) { | |||||
this.numDice = rsSetup.numDice; | |||||
} | |||||
if (rsSetup.diceOptions) { | |||||
this.diceOptions = rsSetup.diceOptions; | |||||
} | |||||
} | } | ||||
} | } | ||||
@@ -46,7 +57,7 @@ export class RollStats { | |||||
} | } | ||||
doRolls(): void { | doRolls(): void { | ||||
let asphodice = new Asphodice(); | |||||
let asphodice = new Asphodice(this.diceOptions); | |||||
// count rerolls, totals and outcome balances | // count rerolls, totals and outcome balances | ||||
for (let i = 0; i < this.numRolls; i++) { | for (let i = 0; i < this.numRolls; i++) { | ||||