Add a macro to perform generic checks

This commit is contained in:
Johannes Loher 2021-05-13 21:39:42 +02:00
parent 441e907b8a
commit 24725c15f9
9 changed files with 138 additions and 29 deletions

View file

@ -291,4 +291,80 @@ export class DS4Actor extends Actor<DS4ActorData, DS4Item, DS4ActorPreparedData>
flavor: game.i18n.format("DS4.ActorCheckFlavor", { actor: this.name, check: DS4.i18n.checks[check] }),
});
}
/**
* Roll a generic check. A dialog is presented to select the combination of
* Attribute and Trait to perform the check against.
*/
async rollGenericCheck(): Promise<void> {
const { attribute, trait } = await this.selectAttributeAndTrait();
const checkTargetNumber = this.data.data.attributes[attribute].total + this.data.data.traits[trait].total;
await createCheckRoll(checkTargetNumber, {
rollMode: game.settings.get("core", "rollMode") as Const.DiceRollMode, // TODO(types): Type this setting in upstream
maximumCoupResult: this.data.data.rolling.maximumCoupResult,
minimumFumbleResult: this.data.data.rolling.minimumFumbleResult,
flavor: game.i18n.format("DS4.ActorGenericCheckFlavor", {
actor: this.name,
attribute: DS4.i18n.attributes[attribute],
trait: DS4.i18n.traits[trait],
}),
});
}
protected async selectAttributeAndTrait(): Promise<{
attribute: keyof typeof DS4.i18n.attributes;
trait: keyof typeof DS4.i18n.traits;
}> {
const attributeIdentifier = "attribute-trait-selection-attribute";
const traitIdentifier = "attribute-trait-selection-trait";
return Dialog.prompt({
title: game.i18n.localize("DS4.DialogAttributeTraitSelection"),
content: await renderTemplate("systems/ds4/templates/dialogs/simple-select-form.hbs", {
selects: [
{
label: game.i18n.localize("DS4.Attribute"),
identifier: attributeIdentifier,
options: DS4.i18n.attributes,
},
{
label: game.i18n.localize("DS4.Trait"),
identifier: traitIdentifier,
options: DS4.i18n.traits,
},
],
}),
label: game.i18n.localize("DS4.GenericOkButton"),
callback: (html) => {
const selectedAttribute = html.find(`#${attributeIdentifier}`).val();
if (selectedAttribute !== "body" && selectedAttribute !== "mobility" && selectedAttribute !== "mind") {
throw new Error(
game.i18n.format("DS4.ErrorUnexpectedAttribute", {
actualAttribute: selectedAttribute,
expectedTypes: "'body', 'agility', 'mind'",
}),
);
}
const selectedTrait = html.find(`#${traitIdentifier}`).val();
if (
selectedTrait !== "strength" &&
selectedTrait !== "constitution" &&
selectedTrait !== "agility" &&
selectedTrait !== "dexterity" &&
selectedTrait !== "intellect" &&
selectedTrait !== "aura"
) {
throw new Error(
game.i18n.format("DS4.ErrorUnexpectedTrait", {
actualAttribute: selectedAttribute,
expectedTypes: "'strength', 'constitution', 'agility', 'dexterity', 'intellect', 'aura'",
}),
);
}
return {
attribute: selectedAttribute,
trait: selectedTrait,
};
},
});
}
}