forked from hermannm/foundry-macros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmagicweapon.js
45 lines (45 loc) · 1.44 KB
/
magicweapon.js
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
const effect = {
name: "Magic Weapon",
modifier: {
stat: "attack",
value: 1,
type: "item",
},
damageDice: {
selector: "damage",
diceNumber: 1,
},
iconPath: "systems/pf2e/icons/spells/magic-weapon.jpg",
};
(async () => {
if (
(actor.data.data.customModifiers[effect.modifier.stat] || []).some(
(customModifier) => customModifier.name === effect.name
)
) {
if (token.data.effects.includes(effect.iconPath)) {
await token.toggleEffect(effect.iconPath);
}
await actor.removeCustomModifier(effect.modifier.stat, effect.name);
await actor.removeDamageDice(damageDice.selector, damageDice.name);
} else {
const itemID =
actor.items
.filter((item) => item.data.type === "action")
.find((item) => item.data.name === effect.name)?._id ??
actor.items.find((item) => item.data.name === effect.name)?._id;
if (itemID) {
game.pf2e.rollItemMacro(itemID);
}
if (!token.data.effects.includes(effect.iconPath)) {
await token.toggleEffect(effect.iconPath);
}
await actor.addCustomModifier(
effect.modifier.stat,
effect.name,
effect.modifier.value,
effect.modifier.type
);
await actor.addDamageDice({ ...effect.damageDice, name: effect.name });
}
})();