Skip to content

Commit

Permalink
Convery EV check roll into an action
Browse files Browse the repository at this point in the history
This reuses the SingleCheckAction class from the system for the mechanics of the
roll.  More of the system automation works this way.

The only thing it needs to do is setup the Diverse Lore DC text in the roll
note.  Maybe it's possible to get the system to inject that too?
  • Loading branch information
xyzzy42 committed Nov 12, 2024
1 parent 626d1af commit a296452
Showing 1 changed file with 56 additions and 119 deletions.
175 changes: 56 additions & 119 deletions src/module/feats/exploit-vulnerability/exploitVulnerability.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,140 +87,39 @@ async function exploitVuln() {
)
);
}
const dc = game.settings.get("pf2e", "proficiencyVariant")
? {
"-2": 13,
"-1": 13,
...Object.fromEntries(
Object.entries([
14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19,
19, 20, 20, 20, 21, 21, 21, 22, 22,
])
),
}[t.actor.level]
: {
"-2": 12,
"-1": 13,
...Object.fromEntries(
Object.entries([
14, 15, 16, 18, 19, 20, 22, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35,
36, 38, 39, 40, 42, 44, 46, 48, 50,
])
),
}[t.actor.level];
if (!dc) {
return ui.notifications.warn(
game.i18n.localize(
"pf2e-thaum-vuln.notifications.warn.exploitVulnerability.noMatchingDC"
)
);
}

const rollOptions = sa.getRollOptions(["skill-check", skill.slug]);

const outcomes = {
criticalSuccess: game.i18n.localize(
"pf2e-thaum-vuln.exploitVulnerability.degreeOfSuccess.criticalSuccess"
),
success: game.i18n.localize(
"pf2e-thaum-vuln.exploitVulnerability.degreeOfSuccess.success"
),
failure: game.i18n.localize(
"pf2e-thaum-vuln.exploitVulnerability.degreeOfSuccess.failure"
),
criticalFailure: game.i18n.localize(
"pf2e-thaum-vuln.exploitVulnerability.degreeOfSuccess.criticalFailure"
),
};

const notes = Object.entries(outcomes).map(([outcome, text]) => ({
title: game.i18n.localize("PF2E.Check.Result.Degree.Check." + outcome),
text,
outcome: [outcome],
}));

if (hasFeat(sa, "esoteric-warden")) {
notes.push({
title: game.i18n.localize("pf2e-thaum-vuln.esotericWarden.name"),
text: game.i18n.localize("pf2e-thaum-vuln.esotericWarden.flavor"),
outcome: ["success", "criticalSuccess"],
});
}

let notes = [];
if (hasFeat(sa, "diverse-lore")) {
// todo: put npc identify data in the document and then show secret text for it.
// TODO: Error checking for rolling against PCs
const dc =
(game.settings.get("pf2e", "proficiencyVariant")
? {
"-2": 13,
"-1": 13,
...Object.fromEntries(
Object.entries([
14, 14, 14, 15, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19,
19, 19, 20, 20, 20, 21, 21, 21, 22, 22,
])
),
}[t.actor.level]
: {
"-2": 12,
"-1": 13,
...Object.fromEntries(
Object.entries([
14, 15, 16, 18, 19, 20, 22, 23, 24, 26, 27, 28, 30, 31, 32, 34,
35, 36, 38, 39, 40, 42, 44, 46, 48, 50,
])
),
}[t.actor.level]) +
game.settings.get("pf2e-thaum-vuln", "esotericLoreModifier");
14 +
Math.floor(t.actor.level / 3) +
game.settings.get("pf2e-thaum-vuln", "esotericLoreModifier") +
(game.pf2e.settings.variants.pwol.enabled
? 0
: t.actor.level + (t.actor.level < 0));
const diverseLoreDC = dc
? `<br/><span data-visibility="gm">Recall Knowledge DC ${dc}</span>`
: "";

notes.push({
title: game.i18n.localize("pf2e-thaum-vuln.diverseLore.name"),
text: `${
game.i18n.localize("pf2e-thaum-vuln.diverseLore.flavor") + diverseLoreDC
}`,
text:
game.i18n.localize("pf2e-thaum-vuln.diverseLore.flavor") +
diverseLoreDC,
outcome: ["success", "criticalSuccess"],
predicate: ["feat:diverse-lore"],
});
}

const flavor = `${game.i18n.localize(
"pf2e-thaum-vuln.exploitVulnerability.name"
)}: ${skill.label}`;
const checkModifier = new game.pf2e.CheckModifier(flavor, skill);
const traits = ["esoterica", "manipulate", "thaumaturge"];
const evRoll = await game.pf2e.Check.roll(
checkModifier,
{
actor: sa,
target: {
actor: t.actor,
token: t.document,
},
type: "skill-check",
options: rollOptions,
notes,
dc: { value: dc },
traits: traits,
flavor: `
<strong>${game.i18n.localize(
"pf2e-thaum-vuln.exploitVulnerability.frequency.label"
)}</strong> ${game.i18n.localize(
"pf2e-thaum-vuln.exploitVulnerability.frequency.text"
)}<br/>
<strong>${game.i18n.localize(
"pf2e-thaum-vuln.exploitVulnerability.requirements.label"
)}</strong> ${game.i18n.localize(
"pf2e-thaum-vuln.exploitVulnerability.requirements.text"
)}<br/>
<hr/>
<p>${game.i18n.localize("pf2e-thaum-vuln.exploitVulnerability.flavor")}</p>
`,
},
event
);
const result = await game.pf2e.actions.get("exploit-vulnerability").use({
actors: [sa],
target: t.document,
notes,
event,
});
const evRoll = result[0].roll;

const rollDOS = evRoll?.degreeOfSuccess;
//Apply effect based on Degrees of success
Expand Down Expand Up @@ -268,4 +167,42 @@ function preDeleteEffect(a, sa = undefined) {
return effects;
}

Hooks.once("init", () => {
const hide = game.pf2e.actions.get("hide");
const SingleCheckAction = Object.getPrototypeOf(hide).constructor;
const notes = [
"criticalSuccess",
"success",
"failure",
"criticalFailure",
].map((dos) => ({
title: game.i18n.localize(`PF2E.Check.Result.Degree.Check.${dos}`),
text: game.i18n.localize(
`pf2e-thaum-vuln.exploitVulnerability.degreeOfSuccess.${dos}`
),
outcome: [dos],
}));

notes.push({
title: game.i18n.localize("pf2e-thaum-vuln.esotericWarden.name"),
text: game.i18n.localize("pf2e-thaum-vuln.esotericWarden.flavor"),
outcome: ["success", "criticalSuccess"],
predicate: ["feat:esoteric-warden"],
});

const ExploitVulnerability = new SingleCheckAction({
cost: 1,
description: "pf2e-thaum-vuln.exploitVulnerability.flavor",
name: "pf2e-thaum-vuln.exploitVulnerability.name",
notes,
rollOptions: ["action:exploit-vulnerability"],
slug: "exploit-vulnerability",
difficultyClass: "exploit-vulnerability",
statistic: "esoteric-lore",
traits: ["esoterica", "manipulate", "thaumaturge"],
});

game.pf2e.actions.set("exploit-vulnerability", ExploitVulnerability);
});

export { exploitVuln, preDeleteEffect };

0 comments on commit a296452

Please sign in to comment.