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 pathPF2e.ts
61 lines (58 loc) · 1.79 KB
/
PF2e.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
53
54
55
56
57
58
59
60
61
import { EncounterWorkflow } from "EncounterWorkflow";
import { CombatDetailType } from "../enums";
export default class PF2e {
static async ParseHook(
chatMessage: ChatMessage,
actor: Actor,
type: CombatDetailType,
roll: Roll | undefined
): Promise<EncounterWorkflow | undefined> {
const enemiesHit: Array<EnemyHit> = game.user?.targets.map(
(m) =>
<EnemyHit>{
tokenId: m.id,
name: m.name,
}
);
const numberOfEnemiesHit =
Array.from(enemiesHit).length > 0 ? Array.from(enemiesHit).length : 1;
if (type === CombatDetailType.Damage) {
return <EncounterWorkflow>{
id: chatMessage.id + actor.id,
actor: {
id: actor.id,
actorName: actor.name,
},
damageTotal: roll?.total ?? 0,
damageMultipleEnemiesTotal: roll?.total
? roll.total * numberOfEnemiesHit
: 0,
isCritical: roll?.options.critical ?? false,
type: type,
};
} else if (type === CombatDetailType.Attack) {
return <EncounterWorkflow>{
id: chatMessage.id + actor.id,
actor: {
id: actor.id,
},
item: {
id: chatMessage.id,
name: chatMessage.name,
link: chatMessage.link,
type: chatMessage.type,
img: chatMessage.img,
},
attackTotal: roll?.total ?? 0,
isFumble:
roll?.terms[0]?.results?.find((f) => f.active === true).result === 1,
advantage: roll?.options.advantageMode === 1 ? true : false,
disadvantage: roll?.options.advantageMode === -1 ? true : false,
actionType: "mwak", // TODO: Parse different attack types
enemyHit: enemiesHit,
type: type,
diceTotal: roll?.dice[0]?.total,
};
}
}
}