Small check factory cleanup and use foundry form formating for roll dialog
This commit is contained in:
parent
b6e9ae2599
commit
115d6113de
5 changed files with 81 additions and 59 deletions
|
@ -93,8 +93,8 @@ export class DS4Item extends Item<DS4ItemData> {
|
|||
const checkTargetValue = (ownerDataData.combatValues[combatValue].total as number) + weaponBonus;
|
||||
await createCheckRoll(checkTargetValue, {
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
maxCritSuccess: ownerDataData.rolling.maximumCoupResult,
|
||||
minCritFailure: ownerDataData.rolling.minimumFumbleResult,
|
||||
maximumCoupResult: ownerDataData.rolling.maximumCoupResult,
|
||||
minimumFumbleResult: ownerDataData.rolling.minimumFumbleResult,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -135,8 +135,8 @@ export class DS4Item extends Item<DS4ItemData> {
|
|||
|
||||
await createCheckRoll(checkTargetValue, {
|
||||
rollMode: game.settings.get("core", "rollMode"),
|
||||
maxCritSuccess: ownerDataData.rolling.maximumCoupResult,
|
||||
minCritFailure: ownerDataData.rolling.minimumFumbleResult,
|
||||
maximumCoupResult: ownerDataData.rolling.maximumCoupResult,
|
||||
minimumFumbleResult: ownerDataData.rolling.minimumFumbleResult,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
import { DS4 } from "../config";
|
||||
|
||||
/**
|
||||
* Provides default values for all arguments the `CheckFactory` expects.
|
||||
*/
|
||||
class DefaultCheckOptions implements DS4CheckFactoryOptions {
|
||||
readonly maxCritSuccess = 1;
|
||||
readonly minCritFailure = 20;
|
||||
readonly maximumCoupResult = 1;
|
||||
readonly minimumFumbleResult = 20;
|
||||
readonly useSlayingDice = false;
|
||||
readonly rollMode: Const.DiceRollMode = "roll";
|
||||
|
||||
|
@ -52,11 +50,13 @@ class CheckFactory {
|
|||
}
|
||||
|
||||
createCritTerm(): string | null {
|
||||
const minCritRequired = this.checkOptions.minCritFailure !== defaultCheckOptions.minCritFailure;
|
||||
const maxCritRequired = this.checkOptions.maxCritSuccess !== defaultCheckOptions.maxCritSuccess;
|
||||
const minCritRequired = this.checkOptions.minimumFumbleResult !== defaultCheckOptions.minimumFumbleResult;
|
||||
const maxCritRequired = this.checkOptions.maximumCoupResult !== defaultCheckOptions.maximumCoupResult;
|
||||
|
||||
if (minCritRequired || maxCritRequired) {
|
||||
return "c" + (this.checkOptions.maxCritSuccess ?? "") + ":" + (this.checkOptions.minCritFailure ?? "");
|
||||
return (
|
||||
"c" + (this.checkOptions.maximumCoupResult ?? "") + ":" + (this.checkOptions.minimumFumbleResult ?? "")
|
||||
);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -75,11 +75,11 @@ export async function createCheckRoll(
|
|||
// Ask for additional required data;
|
||||
const gmModifierData = await askGmModifier(targetValue, options);
|
||||
|
||||
const newTargetValue = gmModifierData.checkTargetValue ?? targetValue;
|
||||
const newTargetValue = gmModifierData.checkTargetNumber ?? targetValue;
|
||||
const gmModifier = gmModifierData.gmModifier ?? 0;
|
||||
const newOptions: Partial<DS4CheckFactoryOptions> = {
|
||||
maxCritSuccess: gmModifierData.maxCritSuccess ?? options.maxCritSuccess ?? undefined,
|
||||
minCritFailure: gmModifierData.minCritFailure ?? options.minCritFailure ?? undefined,
|
||||
maximumCoupResult: gmModifierData.maximumCoupResult ?? options.maximumCoupResult ?? undefined,
|
||||
minimumFumbleResult: gmModifierData.minimumFumbleResult ?? options.minimumFumbleResult ?? undefined,
|
||||
useSlayingDice: gmModifierData.useSlayingDice ?? options.useSlayingDice ?? undefined,
|
||||
rollMode: gmModifierData.rollMode ?? options.rollMode ?? undefined,
|
||||
};
|
||||
|
@ -102,7 +102,7 @@ export async function createCheckRoll(
|
|||
* @returns The data given by the user.
|
||||
*/
|
||||
async function askGmModifier(
|
||||
targetValue: number,
|
||||
checkTargetNumber: number,
|
||||
options: Partial<DS4CheckFactoryOptions> = {},
|
||||
{ template, title }: { template?: string; title?: string } = {},
|
||||
): Promise<Partial<IntermediateGmModifierData>> {
|
||||
|
@ -110,11 +110,10 @@ async function askGmModifier(
|
|||
const usedTemplate = template ?? "systems/ds4/templates/roll/roll-options.hbs";
|
||||
const usedTitle = title ?? game.i18n.localize("DS4.RollDialogDefaultTitle");
|
||||
const templateData = {
|
||||
cssClass: "roll-option",
|
||||
title: usedTitle,
|
||||
checkTargetValue: targetValue,
|
||||
maxCritSuccess: options.maxCritSuccess ?? defaultCheckOptions.maxCritSuccess,
|
||||
minCritFailure: options.minCritFailure ?? defaultCheckOptions.minCritFailure,
|
||||
checkTargetNumber: checkTargetNumber,
|
||||
maximumCoupResult: options.maximumCoupResult ?? defaultCheckOptions.maximumCoupResult,
|
||||
minimumFumbleResult: options.minimumFumbleResult ?? defaultCheckOptions.minimumFumbleResult,
|
||||
rollMode: options.rollMode,
|
||||
rollModes: CONFIG.Dice.rollModes,
|
||||
};
|
||||
|
@ -168,11 +167,11 @@ async function askGmModifier(
|
|||
*/
|
||||
function parseDialogFormData(formData: HTMLFormElement): Partial<IntermediateGmModifierData> {
|
||||
return {
|
||||
checkTargetValue: parseInt(formData["ctv"]?.value),
|
||||
gmModifier: parseInt(formData["gmmod"]?.value),
|
||||
maxCritSuccess: parseInt(formData["maxcoup"]?.value),
|
||||
minCritFailure: parseInt(formData["minfumble"]?.value),
|
||||
rollMode: formData["visibility"]?.value,
|
||||
checkTargetNumber: parseInt(formData["check-target-number"]?.value),
|
||||
gmModifier: parseInt(formData["gm-modifier"]?.value),
|
||||
maximumCoupResult: parseInt(formData["maximum-coup-result"]?.value),
|
||||
minimumFumbleResult: parseInt(formData["minimum-fumble-result"]?.value),
|
||||
rollMode: formData["roll-mode"]?.value,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -189,10 +188,10 @@ interface GmModifierData {
|
|||
*
|
||||
* @deprecated
|
||||
* Quite a lot of this information is requested due to a lack of automation:
|
||||
* - maxCritSuccess
|
||||
* - minCritFailure
|
||||
* - maximumCoupResult
|
||||
* - minimumFumbleResult
|
||||
* - useSlayingDice
|
||||
* - checkTargetValue
|
||||
* - checkTargetNumber
|
||||
*
|
||||
* They will and should be removed once effects and data retrieval is in place.
|
||||
* If a "raw" roll dialog is necessary, create another pre-processing Dialog
|
||||
|
@ -200,10 +199,10 @@ interface GmModifierData {
|
|||
* This interface should then be replaced with the `GmModifierData`.
|
||||
*/
|
||||
interface IntermediateGmModifierData extends GmModifierData {
|
||||
checkTargetValue: number;
|
||||
checkTargetNumber: number;
|
||||
gmModifier: number;
|
||||
maxCritSuccess: number;
|
||||
minCritFailure: number;
|
||||
maximumCoupResult: number;
|
||||
minimumFumbleResult: number;
|
||||
// TODO: In final version from system settings
|
||||
useSlayingDice: boolean;
|
||||
rollMode: Const.DiceRollMode;
|
||||
|
@ -213,8 +212,8 @@ interface IntermediateGmModifierData extends GmModifierData {
|
|||
* The minimum behavioral options that need to be passed to the factory.
|
||||
*/
|
||||
export interface DS4CheckFactoryOptions {
|
||||
maxCritSuccess: number;
|
||||
minCritFailure: number;
|
||||
maximumCoupResult: number;
|
||||
minimumFumbleResult: number;
|
||||
useSlayingDice: boolean;
|
||||
rollMode: Const.DiceRollMode;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue