Skip to content

Commit

Permalink
feat: Instead of hiding autorolled damage rolls of privately cast spe…
Browse files Browse the repository at this point in the history
…lls (or, optionally, obfuscating the name of the spell) always show the damage roll with an obfuscated spell name.
  • Loading branch information
xdy committed Jun 21, 2024
1 parent daf4cc8 commit 51511df
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 33 deletions.
17 changes: 0 additions & 17 deletions src/module/feature/damageHandler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,18 +287,12 @@ async function handleSpell(
degreeOfSuccess: string,
) {
const castRank = await determineCastRank(origin.name, flags, numberOfMessagesToCheck, originUuid, origin.system);
let blind = determineBlindStatus(message);
const rollDamage = await noOrSuccessfulFlatcheck(message);

if (rollDamage) {
// Fakes the event.closest function that pf2e uses to parse spell level for heightening damage rolls.
const target = constructTargetElement(castRank);

// Make automatic damageRoll be private if the spell is private, unless hideNameOfPrivateSpell is set.
const shouldHideName = blind && game.settings.get(MODULENAME, "castPrivateSpellHideName");
if (shouldHideName) {
blind = false;
}
if (message.flags?.pf2e?.origin?.variant?.overlays?.length > 0) {
const variant = origin.loadVariant({
castRank,
Expand All @@ -309,14 +303,12 @@ async function handleSpell(
await variant.rollDamage({
outcome: degreeOfSuccess,
target,
ctrlKey: blind,
});
} else {
// @ts-ignore
await origin?.rollDamage({
outcome: degreeOfSuccess,
target,
ctrlKey: blind,
});
}
}
Expand All @@ -343,15 +335,6 @@ async function determineCastRank(
return castRank;
}

function determineBlindStatus(message: any): boolean {
const originalRollMode = game.settings.get("core", "rollMode");
return (
((message?.blind || (message?.whisper && message?.whisper.length > 0)) &&
originalRollMode !== CONST.DICE_ROLL_MODES.PRIVATE) ??
false
);
}

function constructTargetElement(castRank: number): HTMLDivElement {
const target = document.createElement("div");
target.dataset.castRank = castRank.toString();
Expand Down
3 changes: 1 addition & 2 deletions src/module/feature/qolHandler/handlePrivateSpellcasting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,9 @@ function buildSpellMessage(origin, tokenName: string, type, traditionString: str
return content;
}

export async function castPrivateSpellHideName(message: ChatMessagePF2e, html: HTMLElement) {
export async function hideSpellNameInDamageroll(message: ChatMessagePF2e, html: HTMLElement) {
const msg = game.messages.contents
.reverse()
// .filter((m) => m.type === 4) // Whisper, rollup can't resolve constant
.filter((m) => m.whisper?.length > 0)
.filter((m) => m.flags?.pf2e?.casting)
.filter((m) => m.flags?.pf2e?.origin?.uuid === message.flags?.pf2e?.origin?.uuid)
Expand Down
9 changes: 6 additions & 3 deletions src/module/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ import {
} from "./feature/damageHandler/dyingHandling.ts";
import { checkAttackValidity } from "./feature/reminders/checkAttackValidity.js";
import { reminderBreathWeapon } from "./feature/reminders/reminderBreathWeapon.js";
import { castPrivateSpellHideName, handlePrivateSpellcasting } from "./feature/qolHandler/handlePrivateSpellcasting.js";
import {
handlePrivateSpellcasting,
hideSpellNameInDamageroll,
} from "./feature/qolHandler/handlePrivateSpellcasting.js";
import { FeatPF2e } from "@item/feat/document.js";

export const preCreateChatMessageHook = (message: ChatMessagePF2e, data: any, _options, _user: UserPF2e) => {
Expand Down Expand Up @@ -163,11 +166,11 @@ export function renderChatMessageHook(message: ChatMessagePF2e, jq: JQuery) {
}

if (
game.settings.get(MODULENAME, "castPrivateSpellHideName") &&
game.settings.get(MODULENAME, "castPrivateSpell") &&
message?.flags?.pf2e?.origin?.type === "spell" &&
isActuallyDamageRoll(message)
) {
castPrivateSpellHideName(message, html);
hideSpellNameInDamageroll(message, html);
}

// Alert everyone that Keeley's hero point rule was invoked
Expand Down
11 changes: 0 additions & 11 deletions src/module/settings/qol-world.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@ export class WorkbenchQolWorldSettings extends SettingsMenuPF2eWorkbench {
onChange: () => updateHooks(),
requiresReload: true,
},
castPrivateSpellHideName: {
name: `${MODULENAME}.SETTINGS.castPrivateSpellHideName.name`,
hint: `${MODULENAME}.SETTINGS.castPrivateSpellHideName.hint`,
scope: "world",
config: true,
default: false,
type: Boolean,
onChange: () => updateHooks(),
requiresReload: true,
},
castPrivateSpellAlwaysFor: {
name: `${MODULENAME}.SETTINGS.castPrivateSpellAlwaysFor.name`,
hint: `${MODULENAME}.SETTINGS.castPrivateSpellAlwaysFor.hint`,
Expand Down Expand Up @@ -179,7 +169,6 @@ export class WorkbenchQolWorldSettings extends SettingsMenuPF2eWorkbench {
"castPrivateSpellAutoRevealIfKnown",
"castPrivateSpellAutoRevealPartyMembersThatKnowSpell",
"castPrivateSpellAutoRevealPartyMembersThatKnowSpell",
"castPrivateSpellHideName",
"castPrivateSpellAlwaysFor",
],
},
Expand Down

0 comments on commit 51511df

Please sign in to comment.