Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/module/actor/character/feats/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ class CharacterFeats<TActor extends CharacterPF2e> extends Collection<string, Fe
if (granter?.isOfType("feat") && granter.grants.includes(feat) && isNested) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the practicality of including the heritage in granter.grants? It looks like grants in FeatPF2e is FeatPF2e | HeritagePF2e, so doing granter?.isOfType("feat", "heritage") && granter.grants.includes(feat) && isNested should be more terse

continue;
}
if (granter?.isOfType("heritage") && isNested) {
continue;
}
}

// Find the group then assign the feat
Expand Down
42 changes: 40 additions & 2 deletions src/module/actor/character/sheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ import {
} from "./data.ts";
import type { CharacterPF2e } from "./document.ts";
import { ElementalBlast, ElementalBlastConfig } from "./elemental-blast.ts";
import type { FeatBrowserFilterProps, FeatGroup } from "./feats/index.ts";
import type { FeatBrowserFilterProps, FeatGroup, FeatSlot } from "./feats/index.ts";
import { getItemProficiencyRank } from "./helpers.ts";
import { PCSheetTabManager } from "./tab-manager.ts";
import { CHARACTER_SHEET_TABS } from "./values.ts";
Expand All @@ -85,6 +85,28 @@ class CharacterSheetPF2e<TActor extends CharacterPF2e> extends CreatureSheetPF2e
/** Non-persisted tweaks to formula data */
#formulaQuantities: Record<string, number> = {};

/** Nested feat rows for sheet UI from `flags.pf2e.itemGrants` (same rules as `FeatGroup.#getChildSlots`). */
#getNestedSlots(granter: ItemPF2e): FeatSlot<FeatPF2e<TActor>>[] {
const itemGrants = (granter.flags?.[SYSTEM_ID]?.itemGrants ?? {}) as Record<
string,
{ id?: string; nested?: boolean }
>;

return Object.values(itemGrants)
.filter((g) => (g?.nested ?? null) !== false)
.map((g) => (typeof g?.id === "string" && g.id.length > 0 ? (this.actor.items.get(g.id) ?? null) : null))
.filter((i): i is FeatPF2e<TActor> => !!i && i.isOfType("feat"))
.map(
(grant): FeatSlot<FeatPF2e<TActor>> => ({
id: grant.id,
label: null,
level: null,
feat: grant,
children: this.#getNestedSlots(grant),
}),
);
}

static override get defaultOptions(): ActorSheetOptions {
const options = super.defaultOptions;
options.classes = [...options.classes, "character"];
Expand Down Expand Up @@ -288,7 +310,23 @@ class CharacterSheetPF2e<TActor extends CharacterPF2e> extends CreatureSheetPF2e
// Is the stamina variant rule enabled?
sheetData.hasStamina = game.pf2e.settings.variants.stamina;
sheetData.actions = this.#prepareAbilities();
sheetData.feats = [...actor.feats, actor.feats.bonus];

const featGroups: FeatGroup[] = [...actor.feats, actor.feats.bonus];
const ancestryFeatures = featGroups.find((g) => g.id === "ancestryfeature");
// Add the heritage to the ancestry features if it is not already present
if (actor.heritage && ancestryFeatures) {
const alreadyPresent = ancestryFeatures.feats.some((f) => f.feat?.id === actor.heritage?.id);
if (!alreadyPresent) {
ancestryFeatures.feats.unshift({
id: "heritage",
label: null,
level: null,
feat: actor.heritage,
children: this.#getNestedSlots(actor.heritage),
} as never);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid casting to never. There's gotta be another way.

}
}
sheetData.feats = featGroups;

sheetData.crafting = await this.#prepareCrafting();

Expand Down
Loading