Get basic features to work.
This commit is contained in:
parent
ab450808f5
commit
1422f28760
3 changed files with 63 additions and 12 deletions
|
@ -1,17 +1,44 @@
|
|||
import { RollResult, RollResultStatus } from "./roll-data";
|
||||
import { ds4roll } from "./roll-executor";
|
||||
|
||||
interface TermData {
|
||||
number: number;
|
||||
faces: number;
|
||||
modifiers: Array<string>;
|
||||
options: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export class DS4Roll extends DiceTerm {
|
||||
constructor({ faces = 20, modifiers = [], options = {} } = {}) {
|
||||
super({ number: 1, faces: faces, modifiers: modifiers, options: options });
|
||||
constructor(termData: Partial<TermData>) {
|
||||
super({
|
||||
number: 1,
|
||||
faces: termData.number ?? -1,
|
||||
modifiers: termData.modifiers ?? [],
|
||||
options: termData.options ?? {},
|
||||
});
|
||||
console.log("This @ constructor: ", termData);
|
||||
}
|
||||
|
||||
success = null;
|
||||
failure = null;
|
||||
number = 1;
|
||||
|
||||
/**
|
||||
* @override
|
||||
* @param param0
|
||||
*
|
||||
* @private_notes This gets only called once for the first roll.
|
||||
*/
|
||||
roll({ minimize = false, maximize = false } = {}): RollResult {
|
||||
return this.rollWithDifferentBorders(1, 20, { minimize, maximize });
|
||||
console.log(`This faces @ roll: ${this.faces}`);
|
||||
const rollResult = this.rollWithDifferentBorders(1, 20, { minimize, maximize });
|
||||
this.results.push(rollResult);
|
||||
if (rollResult.status == RollResultStatus.CRITICAL_SUCCESS) {
|
||||
this.success = true;
|
||||
} else if (rollResult.status == RollResultStatus.CRITICAL_FAILURE) {
|
||||
this.failure = true;
|
||||
}
|
||||
return rollResult;
|
||||
}
|
||||
|
||||
rollWithDifferentBorders(
|
||||
|
@ -45,9 +72,17 @@ export class DS4Roll extends DiceTerm {
|
|||
}, []);
|
||||
}
|
||||
|
||||
get expression(): string {
|
||||
return `${this.faces}ds${this.modifiers.join("")}`;
|
||||
}
|
||||
|
||||
get formula(): string {
|
||||
return this.expression;
|
||||
}
|
||||
|
||||
/** Term Modifiers */
|
||||
crits(modifier: string): this {
|
||||
const rgx: RegExp = /[c([0-9]+)?,([0-9]+)?]/;
|
||||
const rgx = new RegExp("c([0-9]+)?,([0-9]+)?");
|
||||
const match = modifier.match(rgx);
|
||||
if (!match) return this;
|
||||
const [parseCritSucc, parsedCritFail] = match.slice(1);
|
||||
|
@ -66,8 +101,7 @@ export class DS4Roll extends DiceTerm {
|
|||
explode(modifier: string): this {
|
||||
// There should only ever be a single dice in the results-array at this point!
|
||||
if (this.results.length != 1) {
|
||||
// TODO: Add 'expression' to types!
|
||||
// console.error(`Skipped explode for term ${this.expression}`);
|
||||
console.error(`Skipped explode for term ${this.expression}`);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -86,10 +120,18 @@ export class DS4Roll extends DiceTerm {
|
|||
|
||||
if (r.dice[0] <= maxCritSucc) {
|
||||
r.exploded = true;
|
||||
this.rollWithDifferentBorders(maxCritSucc, 21);
|
||||
const newRoll = this.rollWithDifferentBorders(maxCritSucc, 21);
|
||||
this.results.push(newRoll);
|
||||
}
|
||||
|
||||
if (checked > 1000) throw new Error("Maximum recursion depth for explodign dice roll exceeded");
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: To Types
|
||||
static DENOMINATION = "s";
|
||||
static MODIFIERS = {
|
||||
x: "explode",
|
||||
c: "crits",
|
||||
};
|
||||
}
|
||||
|
|
|
@ -18,12 +18,21 @@ export class DefaultRollOptions implements RollOptions {
|
|||
|
||||
export class RollResult {
|
||||
constructor(
|
||||
public value: number,
|
||||
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 {
|
||||
|
|
|
@ -43,9 +43,9 @@ export function rollCheckSingleDie(
|
|||
const usedOptions = new DefaultRollOptions().mergeWith(rollOptions);
|
||||
|
||||
if (dice == null || dice.length != 1) {
|
||||
console.error("Rolled a dice!");
|
||||
// TODO: Make "twist" from foundry.js available!
|
||||
console.error(`Rolled a dice. Target: ${checkTargetValue}`);
|
||||
dice = [new DS4RollProvider().getNextRoll()];
|
||||
console.log(dice);
|
||||
}
|
||||
const usedDice = dice;
|
||||
const rolledDie = usedDice[0];
|
||||
|
@ -118,7 +118,7 @@ export function rollCheckMultipleDice(
|
|||
|
||||
const evaluationResult = calculateRollResult(sortedRollResults, remainderTargetValue, usedOptions);
|
||||
|
||||
if (usedOptions.useSlayingDice && firstResult <= usedOptions.maxCritSucc) {
|
||||
if (firstResult <= usedOptions.maxCritSucc) {
|
||||
return new RollResult(evaluationResult, RollResultStatus.CRITICAL_SUCCESS, usedDice, true);
|
||||
} else {
|
||||
return new RollResult(evaluationResult, RollResultStatus.SUCCESS, usedDice, true);
|
||||
|
|
Loading…
Reference in a new issue