From 68cd086a2fc7d33860922be38bf8b8c20851f251 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Mon, 29 Mar 2021 20:09:25 +0200 Subject: [PATCH] Corrections StatusEffect MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit changement du hook, et des méthodes pour les ajouter --- module/actor.js | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/module/actor.js b/module/actor.js index 7b09ba3f..173e375f 100644 --- a/module/actor.js +++ b/module/actor.js @@ -37,11 +37,15 @@ import { Monnaie } from "./item-monnaie.js"; export class RdDActor extends Actor { /* -------------------------------------------- */ static init() { - Hooks.on("deleteActiveEffect", (actor, effect, options) => actor.onDeleteActiveEffect(effect, options)); - Hooks.on("createActiveEffect", (actor, effect, options) => actor.onCreateActiveEffect(effect, options)); + Hooks.on("deleteActiveEffect", (effect, options, userId) => RdDActor.getParentActor(effect)?.onDeleteActiveEffect(effect, options)); Hooks.on("createOwnedItem", (actor, item, options, id) => actor.onCreateOwnedItem(item, options, id)); Hooks.on("deleteOwnedItem", (actor, item, options, id) => actor.onDeleteOwnedItem(item, options, id)); Hooks.on("updateActor", (actor, update, options, actorId) => actor.onUpdateActor(update, options, actorId)); + Hooks.on("createActiveEffect", (effect, options, userId) => RdDActor.getParentActor(effect)?.onCreateActiveEffect(effect, options)); + } + + static getParentActor(document){ + return document?.parent instanceof Actor ? document.parent : undefined } /* -------------------------------------------- */ @@ -3076,11 +3080,12 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async setStatusDemiReve(status) { + const demiReve = StatusEffects.demiReve(); if (status) { - await this.addStatusEffect(StatusEffects.demiReve()) + await this.addStatusEffect(demiReve) } else { - this.deleteStatusEffect(StatusEffects.demiReve()) + this.deleteStatusEffect(demiReve) } } @@ -3093,8 +3098,8 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ - async forceStatusEffectId(statusId, sonne) { - if (sonne) { + async forceStatusEffectId(statusId, isSet) { + if (isSet) { await this.addStatusEffectById(statusId); } else { @@ -3104,21 +3109,17 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ deleteStatusEffectById(id) { - const effects = Array.from(this.effects?.values()) - .filter(it => it.data.flags.core?.statusId == id); - this._deleteStatusEffects(effects); + const ids = Array.from(this.effects?.values()) + .filter(it => it.data.flags.core?.statusId == id) + .map(it => it.id); + this.deleteEmbeddedDocuments('ActiveEffect', ids); } /* -------------------------------------------- */ deleteStatusEffect(effect) { - const toDelete = Array.from(this.effects?.values()) - .filter(it => StatusEffects.statusId(it.data) == StatusEffects.statusId(effect)); - this._deleteStatusEffects(toDelete); - } - - /* -------------------------------------------- */ - _deleteStatusEffects(effects) { - const ids = effects.map(it => it.id); + const ids = Array.from(this.effects?.values()) + .filter(it => StatusEffects.statusId(it.data) == StatusEffects.statusId(effect)) + .map(it => it.id); this.deleteEmbeddedDocuments('ActiveEffect', ids); } @@ -3130,9 +3131,9 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async addStatusEffect(statusEffect) { - this.deleteStatusEffectById(statusEffect.id); const effet = duplicate(statusEffect); - effet["flags.core.statusId"] = effet.id; + this.deleteStatusEffectById(effet.id); + effet.flags.core.statusId = effet.id; await this.createEmbeddedDocuments('ActiveEffect', [effet]); }