43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
export interface RollOptions {
|
|
maxCritSucc: number;
|
|
minCritFail: number;
|
|
useSlayingDice: boolean;
|
|
slayingDiceRepetition: boolean;
|
|
}
|
|
|
|
export class DefaultRollOptions implements RollOptions {
|
|
public maxCritSucc = 1;
|
|
public minCritFail = 20;
|
|
public useSlayingDice = false;
|
|
public slayingDiceRepetition = false;
|
|
|
|
mergeWith(other: Partial<RollOptions>): RollOptions {
|
|
return { ...this, ...other } as RollOptions;
|
|
}
|
|
}
|
|
|
|
export class RollResult {
|
|
constructor(
|
|
public result: number,
|
|
public status: RollResultStatus,
|
|
public dice: Array<number>,
|
|
public active: boolean = true,
|
|
public exploded: boolean = false,
|
|
) {
|
|
if (this.status == RollResultStatus.CRITICAL_FAILURE) {
|
|
this.failure = true;
|
|
} else if (this.status == RollResultStatus.CRITICAL_SUCCESS) {
|
|
this.success = true;
|
|
}
|
|
}
|
|
|
|
public failure: boolean | void = undefined;
|
|
public success: boolean | void = undefined;
|
|
}
|
|
|
|
export enum RollResultStatus {
|
|
FAILURE = "FAILURE",
|
|
SUCCESS = "SUCCESS",
|
|
CRITICAL_FAILURE = "CRITICAL_FAILURE",
|
|
CRITICAL_SUCCESS = "CRITICAL_SUCCESS",
|
|
}
|