This repository has been archived by the owner on Oct 11, 2024. It is now read-only.
generated from League-of-Foundry-Developers/FoundryVTT-Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPF2eStat.ts
49 lines (45 loc) · 1.74 KB
/
PF2eStat.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { CombatDetailType } from "../enums";
import Logger from "../Helpers/Logger";
import Stat from "./Stat";
export default class PF2eStat extends Stat {
AddAttack(workflow: EncounterWorkflow) {
if (!workflow?.actor?.id) {
Logger.error(`No Actor ID in encounter`, "dnd5estat.AddAttack", workflow);
return;
}
const combatantStat: EncounterCombatant | undefined =
this.GetCombatantStats(workflow.actor.id);
if (!combatantStat) return;
// Get any existing event, if so merge object and update
const isExistingEvent: boolean =
combatantStat.events.find(
(f) => f.id === workflow.id && f.round === this.currentRound
) !== undefined;
if (isExistingEvent && workflow.type === CombatDetailType.Damage) {
const newCombatantEvent = combatantStat.events
.filter((f) => f.id === workflow.id)
.reverse()[0];
newCombatantEvent.damageTotal = workflow.damageTotal;
newCombatantEvent.damageMultipleEnemiesTotal =
workflow.damageMultipleEnemiesTotal;
newCombatantEvent.isCritical = workflow.isCritical;
} else {
if (workflow.type === CombatDetailType.Attack) {
const newCombatantEvent = <CombatantEvent>{
id: workflow.id,
actorId: workflow.actor.id,
item: workflow.item,
round: this.currentRound,
attackTotal: 0,
damageTotal: 0,
actionType: workflow.actionType,
};
newCombatantEvent.attackTotal = workflow.attackTotal;
newCombatantEvent.isFumble = workflow.isFumble;
newCombatantEvent.advantage = workflow.advantage;
newCombatantEvent.disadvantage = workflow.disadvantage;
combatantStat.events.push(newCombatantEvent);
}
}
}
}