Skip to content

Commit

Permalink
Identify the correct statistic when using a pre-existing roll for ini…
Browse files Browse the repository at this point in the history
…tiative (foundryvtt#16822)
  • Loading branch information
7H3LaughingMan authored Oct 9, 2024
1 parent 9a7e335 commit 6a3e30c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/module/actor/initiative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ActorInitiative {
// Update the tracker unless requested not to
const updateTracker = args.updateTracker ?? true;
if (updateTracker) {
combatant.encounter.setInitiative(combatant.id, roll.total);
combatant.encounter.setInitiative(combatant.id, roll.total, this.statistic.base?.slug);
}

return { combatant, roll };
Expand Down
6 changes: 5 additions & 1 deletion src/module/apps/sidebar/chat-log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,11 @@ class ChatLogPF2e extends ChatLog<ChatMessagePF2e> {
const combatant = await CombatantPF2e.fromActor(actor);
if (!combatant) return;
const value = message.rolls.at(0)?.total ?? 0;
await combatant.encounter.setInitiative(combatant.id, value);
await combatant.encounter.setInitiative(
combatant.id,
value,
message.flags.pf2e.modifierName ? String(message.flags.pf2e.modifierName) : undefined,
);

ui.notifications.info(
game.i18n.format("PF2E.Encounter.InitiativeSet", { actor: token.name, initiative: value }),
Expand Down
8 changes: 6 additions & 2 deletions src/module/encounter/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { calculateXP } from "@scripts/macros/index.ts";
import { ThreatRating } from "@scripts/macros/xp/index.ts";
import * as R from "remeda";
import type { CombatantFlags, CombatantPF2e, RolledCombatant } from "./combatant.ts";
import { objectHasKey } from "@util";

class EncounterPF2e extends Combat {
/** Has this document completed `DataModel` initialization? */
Expand Down Expand Up @@ -212,14 +213,17 @@ class EncounterPF2e extends Combat {
if (this.turn !== null) await this.update({ turn: this.turns.findIndex((c) => c.id === currentId) });
}

override async setInitiative(id: string, value: number): Promise<void> {
override async setInitiative(id: string, value: number, statistic?: string): Promise<void> {
const combatant = this.combatants.get(id, { strict: true });
if (combatant.actor?.isOfType("character", "npc")) {
return this.setMultipleInitiatives([
{
id: combatant.id,
value,
statistic: combatant.actor.system.initiative.statistic || "perception",
statistic:
objectHasKey(CONFIG.PF2E.skills, statistic) || statistic === "perception"
? statistic
: combatant.actor.system.initiative.statistic || "perception",
},
]);
}
Expand Down

0 comments on commit 6a3e30c

Please sign in to comment.