Add a macro to perform generic checks
This commit is contained in:
parent
441e907b8a
commit
24725c15f9
9 changed files with 138 additions and 29 deletions
|
@ -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,
|
||||
};
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,13 +156,16 @@ export class DS4Item extends Item<DS4ItemData, DS4ItemPreparedData> {
|
|||
if (attackType === "meleeRanged") {
|
||||
const { melee, ranged } = { ...DS4.i18n.attackTypes };
|
||||
const identifier = "attack-type-selection";
|
||||
const label = game.i18n.localize("DS4.AttackType");
|
||||
const answer = Dialog.prompt({
|
||||
title: game.i18n.localize("DS4.AttackTypeSelection"),
|
||||
title: game.i18n.localize("DS4.DialogAttackTypeSelection"),
|
||||
content: await renderTemplate("systems/ds4/templates/dialogs/simple-select-form.hbs", {
|
||||
label,
|
||||
identifier,
|
||||
options: { melee, ranged },
|
||||
selects: [
|
||||
{
|
||||
label: game.i18n.localize("DS4.AttackType"),
|
||||
identifier,
|
||||
options: { melee, ranged },
|
||||
},
|
||||
],
|
||||
}),
|
||||
label: game.i18n.localize("DS4.GenericOkButton"),
|
||||
callback: (html) => {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
import { rollCheck } from "./roll-check";
|
||||
import { rollGenericCheck } from "./roll-generic-check";
|
||||
import { rollItem } from "./roll-item";
|
||||
|
||||
export const macros = {
|
||||
rollCheck,
|
||||
rollGenericCheck,
|
||||
rollItem,
|
||||
};
|
||||
|
|
13
src/module/macros/roll-generic-check.ts
Normal file
13
src/module/macros/roll-generic-check.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import notifications from "../ui/notifications";
|
||||
import { getActiveActor } from "./helpers";
|
||||
/**
|
||||
* Executes the roll generic check macro.
|
||||
*/
|
||||
export async function rollGenericCheck(): Promise<void> {
|
||||
const actor = getActiveActor();
|
||||
if (!actor) {
|
||||
return notifications.warn(game.i18n.localize("DS4.WarningMustControlActorToUseRollCheckMacro"));
|
||||
}
|
||||
|
||||
return actor.rollGenericCheck();
|
||||
}
|
|
@ -107,7 +107,7 @@ async function askGmModifier(
|
|||
{ template, title }: { template?: string; title?: string } = {},
|
||||
): Promise<Partial<IntermediateGmModifierData>> {
|
||||
const usedTemplate = template ?? "systems/ds4/templates/dialogs/roll-options.hbs";
|
||||
const usedTitle = title ?? game.i18n.localize("DS4.RollDialogDefaultTitle");
|
||||
const usedTitle = title ?? game.i18n.localize("DS4.DialogRollOptionsDefaultTitle");
|
||||
const templateData = {
|
||||
title: usedTitle,
|
||||
checkTargetNumber: checkTargetNumber,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue