remove warpgate active effect handling from power management

This commit is contained in:
2024-05-15 23:34:02 -05:00
parent 5151634e8b
commit 4c00d7116e
5 changed files with 84 additions and 120 deletions
-11
View File
@@ -132,17 +132,6 @@ export class PowerEffect {
async applyActiveEffects(token, effectDocuments) {
await token.actor.createEmbeddedDocuments('ActiveEffect', effectDocuments);
// const mutation = {
// embedded: { ActiveEffect: {} },
// };
// const mutateOptions = {
// permanent: true,
// description: `${this.source.name} applying ${effectDocuments[effectDocuments.length - 1]?.name} to ${token.name}`,
// };
// for (const effectDocument of effectDocuments) {
// mutation.embedded.ActiveEffect[effectDocument.name] = effectDocument;
// }
// await warpgate.mutate(token.document, mutation, {}, mutateOptions);
}
get name() {
+4 -15
View File
@@ -1,4 +1,3 @@
/* globals warpgate */
import { moduleName } from '../globals.js';
import { ArcaneProtectionEffect } from './arcaneProtection.js';
import { BanishEffect } from './banish.js';
@@ -54,27 +53,17 @@ export async function powerEffectManagementHook(effect, data, userId) {
if (!maintId) {
return;
}
const mutateOptions = {
permanent: true,
comparisonKeys: {
ActiveEffect: 'id',
},
};
const targetIds = effect.getFlag(moduleName, 'targetIds') || [];
for (const targetId of targetIds) {
const mutation = {
embedded: { ActiveEffect: {} },
};
const target = canvas.tokens.get(targetId);
if (!target) {
continue;
}
const effects = target.actor.effects.filter((e) => e.getFlag(moduleName, 'maintId') === maintId);
for (const efct of effects) {
mutation.embedded.ActiveEffect[efct.id] = warpgate.CONST.DELETE;
const effectIds = target.actor.effects.filter((e) => e.getFlag(moduleName, 'maintId') === maintId).map((e) => e.id);
if (effectIds.length === 0) {
continue;
}
mutateOptions.description = `${effect.parent.name} is no longer ${effect.name} on ${target.name}`;
await warpgate.mutate(target.document, mutation, {}, mutateOptions);
await target.actor.deleteEmbeddedDocuments('ActiveEffects', effectIds);
}
}