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 pathDND5eStat.ts
52 lines (48 loc) · 1.87 KB
/
DND5eStat.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
50
51
52
import { CombatDetailType } from "../enums";
import Logger from "../Helpers/Logger";
import Stat from "./Stat";
export default class DND5eStat 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.ItemCard) {
const newCombatantEvent = combatantStat.events
.filter((f) => f.id === workflow.id)
.reverse()[0];
if (workflow.type === CombatDetailType.Damage) {
newCombatantEvent.damageTotal = workflow.damageTotal;
newCombatantEvent.damageMultipleEnemiesTotal =
workflow.damageMultipleEnemiesTotal;
newCombatantEvent.isCritical = workflow.isCritical;
} else if (workflow.type === CombatDetailType.Attack) {
newCombatantEvent.attackTotal = workflow.attackTotal;
newCombatantEvent.isFumble = workflow.isFumble;
newCombatantEvent.advantage = workflow.advantage;
newCombatantEvent.disadvantage = workflow.disadvantage;
}
} else {
if (workflow.type === CombatDetailType.ItemCard) {
const newCombatantEvent = <CombatantEvent>{
id: workflow.id,
actorId: workflow.actor.id,
item: workflow.item,
round: this.currentRound,
attackTotal: 0,
damageTotal: 0,
actionType: workflow.actionType,
};
combatantStat.events.push(newCombatantEvent);
}
}
}
}