Add spell effect turn alert macros
This commit is contained in:
parent
9ed827aab2
commit
53251997b3
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
swade-mb-shared.lock
|
||||
65
macros/ApplySpellEffect.js
Normal file
65
macros/ApplySpellEffect.js
Normal file
@ -0,0 +1,65 @@
|
||||
let effect = args[0];
|
||||
let targets = args[1];
|
||||
let extra = args[2];
|
||||
if (!extra) {
|
||||
extra = {};
|
||||
}
|
||||
if (!extra.name) { extra.name = effect.label }
|
||||
if (!extra.duration) { extra.duration = effect.duration.rounds }
|
||||
if (!extra.startMessage) {
|
||||
extra.startMessage = `${effect.label}'s effects start`
|
||||
}
|
||||
if (!extra.endMessage) {
|
||||
extra.endMessage = `${effect.label}'s effects end`
|
||||
}
|
||||
if (!extra.fadeMessage) {
|
||||
extra.fadeMessage = `${effect.label}'s effects start to fade`
|
||||
}
|
||||
|
||||
if (canvas.tokens.controlled.length == 0) {
|
||||
ui.notifications.error("No tokens selected");
|
||||
return;
|
||||
}
|
||||
for (let tgt of targets) {
|
||||
let actor = tgt.actor;
|
||||
let active = actor.effects.find(i => i.data.label === effect.label);
|
||||
let chatData = {
|
||||
speaker: ChatMessage.getSpeaker(tgt),
|
||||
type: CONST.CHAT_MESSAGE_TYPES.OTHER,
|
||||
emote: true
|
||||
}
|
||||
if (extra.flavor) {
|
||||
chatData.flavor = extra.flavor;
|
||||
}
|
||||
if (active) {
|
||||
await tgt.toggleEffect(effect, { active: false })
|
||||
chatData.content = extra.endMessage;
|
||||
} else {
|
||||
await tgt.toggleEffect(effect, { active: true })
|
||||
chatData.content = extra.startMessage;
|
||||
}
|
||||
if (chatData.content) {
|
||||
ChatMessage.create(chatData);
|
||||
}
|
||||
}
|
||||
if (game.combat && extra.duration) {
|
||||
let alertData = {
|
||||
round: extra.duration-1,
|
||||
roundAbsolute: false,
|
||||
turnId: game.combat.combatant._id,
|
||||
message: extra.fadeMessage
|
||||
}
|
||||
await TurnAlert.create(alertData);
|
||||
|
||||
const targetIds = targets.map(t => t.id);
|
||||
alertData = {
|
||||
round: extra.duration-1,
|
||||
roundAbsolute: false,
|
||||
turnId: game.combat.combatant._id,
|
||||
endOfTurn: true,
|
||||
message: extra.endMessage,
|
||||
macro: "CancelSpellEffect",
|
||||
args: [effect, targetIds]
|
||||
}
|
||||
await TurnAlert.create(alertData);
|
||||
}
|
||||
17
macros/CancelSpellEffect.js
Normal file
17
macros/CancelSpellEffect.js
Normal file
@ -0,0 +1,17 @@
|
||||
const effect = args[0];
|
||||
const targetIds = args[1];
|
||||
const extra = args[2];
|
||||
|
||||
async function main() {
|
||||
for (const tokenId of targetIds) {
|
||||
let token = game.canvas.tokens.get(tokenId);
|
||||
let actor = token?.actor;
|
||||
if (!actor) continue;
|
||||
const active = actor.effects.find(e => e.data.label === effect.label);
|
||||
if (active) {
|
||||
await token.toggleEffect(effect, { active: false });
|
||||
console.log("Removed active effect", effect.label, token.name, token);
|
||||
}
|
||||
}
|
||||
}
|
||||
main();
|
||||
13
macros/SpellEffectSample.js
Normal file
13
macros/SpellEffectSample.js
Normal file
@ -0,0 +1,13 @@
|
||||
let effect = {
|
||||
changes: [
|
||||
],
|
||||
duration: { rounds: 5 },
|
||||
icon: 'icons/svg/holy-shield.svg',
|
||||
label: 'Sanctuary',
|
||||
id: 'sanctuary'
|
||||
}
|
||||
const targets = canvas.tokens.controlled;
|
||||
const extra = { flavor: "Sanctuary!" }
|
||||
const spellEffect = game.macros.getName("ApplySpellEffect");
|
||||
let value = await spellEffect.execute(effect, targets, extra);
|
||||
return value;
|
||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user