Skip to content

Commit

Permalink
feat: Adds option to autoroll damage on a hit. On a critical success …
Browse files Browse the repository at this point in the history
…it rolls critical damage. Needs the PF2e system setting 'Show results on attacks and saves' to be set so that the attacker can see the result in the chat. (E.g. for non-gm use either 'Owner' or 'All')
  • Loading branch information
xdy committed Jan 23, 2022
1 parent 91cf955 commit dd9b70b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/module/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ export function registerSettings() {

//TODO Make a settings menu with the following settings that is set to be restricted to GMs

game.settings.register(MODULENAME, "autoRollDamageForStrike", {
name: "SETTINGS.autoRollDamageForStrike.name",
hint: "SETTINGS.autoRollDamageForStrike.hint",
scope: "client",
config: true,
default: false,
type: Boolean,
});

game.settings.register(MODULENAME, "autoCollapseItemChatCardContent", {
name: "SETTINGS.autoCollapseItemChatCardContent.name",
hint: "SETTINGS.autoCollapseItemChatCardContent.hint",
Expand Down
35 changes: 35 additions & 0 deletions src/module/xdy-pf2e-workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,41 @@ Hooks.on("renderTokenHUD", (_app: TokenHUD, html: JQuery, data: any) => {
}
});

Hooks.on("createChatMessage", (message: ChatMessage) => {
if (game.settings.get(MODULENAME, "autoRollDamageForStrike")) {
if (message.data.type === 5) {
//TODO Localize this
const strikeName = message.data.flavor?.match("(<strong>Strike): (.*?)<\\/strong>");
if (strikeName && strikeName[1] && strikeName[2]) {
const degreeOfSuccess = message.data.flavor?.match('(<b>Result): <span class="(.*?)">');
if (degreeOfSuccess && degreeOfSuccess[1] && degreeOfSuccess[2]) {
// @ts-ignore
const relevantStrike = game.actors
// @ts-ignore
?.get(message.data.speaker.actor)
// @ts-ignore
?.data.data?.actions.filter((a: { type: string }) => a.type === "strike")
.find((action: { name: string }) => action.name === strikeName[2]);
const rollOptions = game.actors
// @ts-ignore
?.get(message.data.speaker.actor)
// @ts-ignore
?.getRollOptions(["all", "damage-roll"]);
if (degreeOfSuccess[2] === "success") {
relevantStrike?.damage({
options: rollOptions,
});
} else if (degreeOfSuccess[2] === "criticalSuccess") {
relevantStrike?.critical({
options: rollOptions,
});
}
}
}
}
}
});

Hooks.on("renderChatMessage", (message: ChatMessage, html: JQuery) => {
if (game.settings.get(MODULENAME, "npcMystifierUseMystifiedNameInChat")) {
mangleChatMessage(message, html);
Expand Down
4 changes: 4 additions & 0 deletions static/lang/en.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"SETTINGS": {
"autoRollDamageForStrike": {
"name": "Automatically roll damage for strikes.",
"hint": "Automatically roll damage for strikes."
},
"autoCollapseItemChatCardContent": {
"name": "Automatically collapse item chat card content.",
"hint": "Automatically collapse item chat card content. Click the card title to expand."
Expand Down
4 changes: 4 additions & 0 deletions static/lang/sv.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"SETTINGS": {
"autoRollDamageForStrike": {
"name": "Rulla skador automatiskt för anfall.",
"hint": "Rulla skador automatiskt för anfall."
},
"autoCollapseItemChatCardContent": {
"name": "Fäll automatiskt ihop chatkorts beskrivning.",
"hint": "Fäll automatiskt ihop chatkorts beskrivning. Klicka kort-titeln för att expandera."
Expand Down

0 comments on commit dd9b70b

Please sign in to comment.