Ver a proveniência

(BE) Modify Asphodice/RollStats for variations

Changes to permit dice variations from the frontend to Asphodice class,
successCutOff in particular
tags/v0.3.0
bertieb há 3 anos
ascendente
cometimento
15489c73bc
3 ficheiros alterados com 35 adições e 8 eliminações
  1. +15
    -0
      src/ts/asphodice.ts
  2. +5
    -4
      src/ts/frontend.ts
  3. +15
    -4
      src/ts/rollstats.ts

+ 15
- 0
src/ts/asphodice.ts Ver ficheiro

@@ -27,6 +27,10 @@ interface Dice {
readonly type: string;
}

interface DiceOptions {
successCutOff?: number,
}

export enum Outcomes {
Success = "Success",
Fail = "Failure",
@@ -88,6 +92,17 @@ export class Asphodice extends D10 {
readonly failCrit: number = 1;
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
* happens on eg 1


+ 5
- 4
src/ts/frontend.ts Ver ficheiro

@@ -379,11 +379,11 @@ function addResults(rollstats: RollStats): void {
function resultsControlCard(): string {
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 += `<div class="progress mx-3">
<div class="progress-bar" id="resultsProgress"></div>
<div class="progress-bar" id="resultsProgress"></div>
</div>`;
resultsControl += `<div class="card-body">
<button class="btn btn-primary" type="button"
data-bs-toggle="collapse" data-bs-target=".resultsToggle"
@@ -408,7 +408,8 @@ function getResults():void {

let maxDice = 10;
for (let i = 1; i < maxDice; i++) {
let rollstats = new RollStats(i);
let rsSetup = { numDice: i };
let rollstats = new RollStats(rsSetup);
rollstats.doRolls();
addResults(rollstats);
$("#resultsProgress").width(`${i/maxDice*100}%`);


+ 15
- 4
src/ts/rollstats.ts Ver ficheiro

@@ -12,6 +12,11 @@ declare let ItemCountSet: Array<ItemCount>;
type EnumObject<T extends string> = { [K in T]?: number };
type outcomeCountObject = EnumObject<Outcomes>;

interface RollStatsSetup {
numDice?: number,
diceOptions?: object
}

/**
* Singleton-type class for all dice-statistic related needs
*/
@@ -21,15 +26,21 @@ export class RollStats {
balanceCounts: { [balance: string]: number } = {};
outcomeCounts: outcomeCountObject = {};
diceCounts: { [dice: string]: number} = {};
diceOptions = {};

numRolls = 100000;
maxDice = 10;
numDice = 4;

constructor(numDice?:number) {
constructor(rsSetup?: RollStatsSetup) {
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 {
let asphodice = new Asphodice();
let asphodice = new Asphodice(this.diceOptions);
// count rerolls, totals and outcome balances

for (let i = 0; i < this.numRolls; i++) {


Carregando…
Cancelar
Guardar