Skip to content

Commit

Permalink
Add support for providing a numeric difficulty class parameter on act…
Browse files Browse the repository at this point in the history
…ion use (foundryvtt#12790)
  • Loading branch information
nikolaj-a committed Jan 14, 2024
1 parent 0c72b12 commit aacbeeb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/module/actor/actions/single-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ function toRollNoteSource(data: SingleCheckActionRollNoteData): RollNoteSource {
return data as RollNoteSource;
}

function isValidDifficultyClass(dc: unknown): dc is CheckDC | DCSlug {
return setHasElement(DC_SLUGS, dc) || (isObject<{ value: unknown }>(dc) && typeof dc.value === "number");
}

interface SingleCheckActionVariantData extends BaseActionVariantData {
difficultyClass?: CheckDC | DCSlug;
modifiers?: RawModifier[];
Expand Down Expand Up @@ -54,7 +58,7 @@ interface ActionCheckPreview {
}

interface SingleCheckActionUseOptions extends ActionUseOptions {
difficultyClass: CheckDC | string;
difficultyClass: CheckDC | DCSlug | number;
modifiers: ModifierPF2e[];
multipleAttackPenalty: number;
notes: SingleCheckActionRollNoteData[];
Expand Down Expand Up @@ -131,12 +135,12 @@ class SingleCheckActionVariant extends BaseActionVariant {
const title = this.name
? `${game.i18n.localize(this.#action.name)} - ${game.i18n.localize(this.name)}`
: game.i18n.localize(this.#action.name);
const difficultyClass = Number.isNumeric(options.difficultyClass)
? { value: Number(options.difficultyClass) }
: isValidDifficultyClass(options.difficultyClass)
? options.difficultyClass
: this.difficultyClass;
const results: CheckResultCallback[] = [];
const difficultyClass =
setHasElement(DC_SLUGS, options.difficultyClass) ||
(isObject<{ value: unknown }>(options.difficultyClass) && typeof options.difficultyClass.value === "number")
? options.difficultyClass
: this.difficultyClass;

await ActionMacroHelpers.simpleRollActionCheck({
actors: options.actors,
Expand Down

0 comments on commit aacbeeb

Please sign in to comment.