Skip to content

Commit

Permalink
Fix familiar level 0 in world actors and party errors based off initi…
Browse files Browse the repository at this point in the history
…alization order (foundryvtt#14257)
  • Loading branch information
CarlosFdez authored Mar 19, 2024
1 parent 060968a commit d60566c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/module/actor/familiar/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class FamiliarPF2e<TParent extends TokenDocumentPF2e | null = TokenDocumentPF2e
};
system.attributes.speed = {
value: 25,
total: 25,
label: CONFIG.PF2E.speedTypes.land,
otherSpeeds: [],
};
Expand Down
5 changes: 3 additions & 2 deletions src/module/actor/party/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class PartyPF2e<TParent extends TokenDocumentPF2e | null = TokenDocumentPF2e | n
return R.isEmpty(campaignDiff) ? diff : fu.mergeObject(diff, campaignDiff);
}

/** Only prepare rule elements for non-physical items (in case campaigin items exist) */
/** Only prepare rule elements for non-physical items (in case campaign items exist) */
protected override prepareRuleElements(): RuleElementPF2e<RuleElementSchema>[] {
return this.items.contents
.filter((item) => !item.isOfType("physical"))
Expand All @@ -105,7 +105,6 @@ class PartyPF2e<TParent extends TokenDocumentPF2e | null = TokenDocumentPF2e | n
.map((m) => fromUuidSync(m.uuid))
.filter((a): a is CreaturePF2e => a instanceof ActorPF2e && a.isOfType("creature"))
.sort((a, b) => a.name.localeCompare(b.name, game.i18n.lang));

for (const member of this.members) {
member?.parties.add(this);
}
Expand Down Expand Up @@ -167,6 +166,8 @@ class PartyPF2e<TParent extends TokenDocumentPF2e | null = TokenDocumentPF2e | n

override prepareDerivedData(): void {
super.prepareDerivedData();
if (!game.ready) return; // exit early if game isn't ready yet

// Compute travel speed. Creature travel speed isn't implemented yet
const travelSpeed = Math.min(...this.members.map((m) => m.attributes.speed.total));
this.attributes.speed = { total: travelSpeed };
Expand Down
10 changes: 5 additions & 5 deletions src/scripts/hooks/ready.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ export const Ready = {
});

// Now that all game data is available, Determine what actors we need to reprepare.
// Add actors currently in an encounter, a party, and all familiars (last)
// Add actors currently in an encounter, then in a party, then all familiars, then parties
const parties = game.actors.filter((a): a is PartyPF2e<null> => a.isOfType("party"));
const actorsToReprepare = R.compact([
...game.combats.contents.flatMap((e) => e.combatants.contents).map((c) => c.actor),
...game.actors
.filter((a): a is PartyPF2e<null> => a.isOfType("party"))
.flatMap((p) => p.members)
.filter((a) => !a.isOfType("familiar")),
...parties.flatMap((p) => p.members).filter((a) => !a.isOfType("familiar")),
...game.actors.filter((a) => a.type === "familiar"),
...parties,
]);
resetActors(new Set(actorsToReprepare), { sheets: false });
ui.actors.render();

// Show the GM the Remaster changes journal entry if they haven't seen it already.
if (game.user.isGM && !game.settings.get("pf2e", "seenRemasterJournalEntry")) {
Expand Down

0 comments on commit d60566c

Please sign in to comment.