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 pathDND5e.ts
71 lines (68 loc) · 1.99 KB
/
DND5e.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
62
63
64
65
66
67
68
69
70
71
import { EncounterWorkflow } from "EncounterWorkflow";
import { CombatDetailType } from "../enums";
export default class DND5e {
static async ParseHook(
item: Item,
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: item.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: item.id + actor.id,
actor: {
id: actor.id,
},
tokenName: actor.prototypeToken.name,
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,
type: type,
diceTotal: roll?.dice[0]?.total,
};
} else if (type === CombatDetailType.ItemCard) {
return <EncounterWorkflow>{
id: item.id + actor.id,
actor: {
id: actor.id,
},
tokenName: actor.prototypeToken.name,
item: {
id: item.id,
name: item.name,
link: item.link,
type: item.type,
img: item.img,
},
actionType: item.system.actionType,
enemyHit: enemiesHit,
type: type,
};
}
}
}