Skip to content

Commit

Permalink
Fix regression with actor fallback and kingdom rolls in chat messages (
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosFdez committed Jun 19, 2024
1 parent beb0256 commit de37a21
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions src/scripts/ui/inline-roll-links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,25 +137,24 @@ export class InlineRollLinks {
return parent?.canUserModify(game.user, "update") ? [parent] : [];
case "party":
if (parent?.isOfType("party")) return [parent];
return R.compact([game.actors.party]);
return R.filter([game.actors.party], R.isTruthy);
}

// Use the DOM document as a fallback if it's an actor and the check isn't a saving throw
const sheetActor = ((): ActorPF2e | null => {
const maybeActor: ActorPF2e | null =
foundryDoc instanceof ActorPF2e
? foundryDoc
: foundryDoc instanceof ItemPF2e && foundryDoc.actor
? foundryDoc.actor
: null;
return maybeActor?.isOwner && !maybeActor.isOfType("loot", "party") ? maybeActor : null;
})();
const rollingActors = [
sheetActor ?? getSelectedActors({ exclude: ["loot"], assignedFallback: true }),
].flat();
// If this is inside a sheet, return the actor always
const actorFromSheet = resolveActor(resolveSheetDocument(link), link);
if (actorFromSheet && !actorFromSheet.isOfType("loot", "party") && actorFromSheet.isOwner) {
return [actorFromSheet];
}

// If the parent is a party actor, return it (likely kingmaker)
if (parent?.isOfType("party")) {
return [parent];
}

// Get selected actors, but fallback to parent if its not a save
const rollingActors = getSelectedActors({ exclude: ["loot"], assignedFallback: true });
const isSave = tupleHasValue(SAVE_TYPES, pf2Check);
if (parent?.isOfType("party") || (rollingActors.length === 0 && parent && !isSave)) {
if (rollingActors.length === 0 && parent && !isSave) {
return [parent];
}

Expand Down Expand Up @@ -428,7 +427,7 @@ function resolveSheetDocument(html: HTMLElement): ClientDocument | null {
return doc && (doc instanceof ActorPF2e || doc instanceof ItemPF2e || doc instanceof JournalEntry) ? doc : null;
}

/** If the provided document exists returns it, otherwise attempt to derive it from the sheet */
/** Attempt to derive the related document via the sheet or chat message, handling any item summaries */
function resolveDocument(html: HTMLElement): ClientDocument | null {
// Retrieve the sheet document first
const sheetDocument = resolveSheetDocument(html);
Expand All @@ -439,7 +438,13 @@ function resolveDocument(html: HTMLElement): ClientDocument | null {
return sheetDocument.items.get(itemId) ?? null;
}

return sheetDocument;
if (sheetDocument) {
return sheetDocument;
}

// Return the chat message if there is one
const messageId = htmlClosest(html, "[data-message-id]")?.dataset.messageId;
return messageId ? game.messages.get(messageId) ?? null : null;
}

/** Retrieve an actor via a passed document or item UUID in the dataset of a link */
Expand Down

0 comments on commit de37a21

Please sign in to comment.