Fix DS4Check for 0.8.x

This commit is contained in:
Johannes Loher 2021-07-01 00:36:41 +02:00
parent 61b757ae8f
commit 8f7f6af359
4 changed files with 21180 additions and 1549 deletions

20082
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -86,11 +86,7 @@ function shouldUseCoupForLastSubCheck(
); );
} }
interface SubCheckResult extends DieWithSubCheck, DiceTerm.Result { interface SubCheckResult extends DieWithSubCheck, DiceTerm.Result {}
success?: boolean;
failure?: boolean;
count?: number;
}
function evaluateDiceWithSubChecks( function evaluateDiceWithSubChecks(
results: DieWithSubCheck[], results: DieWithSubCheck[],

View file

@ -15,11 +15,12 @@ import evaluateCheck, { getRequiredNumberOfDice } from "./check-evaluation";
* - Roll a check with a racial ability that makes `5` a coup and default fumble: `/r dsv19c5` * - Roll a check with a racial ability that makes `5` a coup and default fumble: `/r dsv19c5`
*/ */
export class DS4Check extends DiceTerm { export class DS4Check extends DiceTerm {
constructor({ modifiers = [], options }: Partial<DiceTerm.TermData> = {}) { constructor({ modifiers = [], results = [], options }: Partial<DiceTerm.TermData> = {}) {
super({ super({
faces: 20, faces: 20,
modifiers: modifiers, results,
options: options, modifiers,
options,
}); });
// Parse and store check target number // Parse and store check target number
@ -57,6 +58,10 @@ export class DS4Check extends DiceTerm {
if (noFumbleModifier) { if (noFumbleModifier) {
this.canFumble = false; this.canFumble = false;
} }
if (this.results.length > 0) {
this.evaluateResults();
}
} }
coup: boolean | null = null; coup: boolean | null = null;
@ -78,8 +83,8 @@ export class DS4Check extends DiceTerm {
} }
/** @override */ /** @override */
evaluate({ minimize = false, maximize = false } = {}): this { _evaluateSync({ minimize = false, maximize = false } = {}): this {
super.evaluate({ minimize, maximize }); super._evaluateSync({ minimize, maximize });
this.evaluateResults(); this.evaluateResults();
return this; return this;
} }
@ -102,19 +107,6 @@ export class DS4Check extends DiceTerm {
this.fumble = results[0].failure ?? false; this.fumble = results[0].failure ?? false;
} }
/** @override */
static fromResults<T extends DS4Check>(
this: ConstructorOf<T>,
options: Partial<DiceTerm.TermData>,
results: DiceTerm.Result[],
): T {
const term = new this(options);
term.results = results;
term.evaluateResults();
term._evaluated = true;
return term;
}
static readonly DEFAULT_CHECK_TARGET_NUMBER = 10; static readonly DEFAULT_CHECK_TARGET_NUMBER = 10;
static readonly DEFAULT_MAXIMUM_COUP_RESULT = 1; static readonly DEFAULT_MAXIMUM_COUP_RESULT = 1;
static readonly DEFAULT_MINIMUM_FUMBLE_RESULT = 20; static readonly DEFAULT_MINIMUM_FUMBLE_RESULT = 20;

2613
yarn.lock

File diff suppressed because it is too large Load diff