Corrections StatusEffect
changement du hook, et des méthodes pour les ajouter
This commit is contained in:
parent
049b46e3cc
commit
68cd086a2f
@ -37,11 +37,15 @@ import { Monnaie } from "./item-monnaie.js";
|
|||||||
export class RdDActor extends Actor {
|
export class RdDActor extends Actor {
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
static init() {
|
static init() {
|
||||||
Hooks.on("deleteActiveEffect", (actor, effect, options) => actor.onDeleteActiveEffect(effect, options));
|
Hooks.on("deleteActiveEffect", (effect, options, userId) => RdDActor.getParentActor(effect)?.onDeleteActiveEffect(effect, options));
|
||||||
Hooks.on("createActiveEffect", (actor, effect, options) => actor.onCreateActiveEffect(effect, options));
|
|
||||||
Hooks.on("createOwnedItem", (actor, item, options, id) => actor.onCreateOwnedItem(item, options, id));
|
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("deleteOwnedItem", (actor, item, options, id) => actor.onDeleteOwnedItem(item, options, id));
|
||||||
Hooks.on("updateActor", (actor, update, options, actorId) => actor.onUpdateActor(update, options, actorId));
|
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) {
|
async setStatusDemiReve(status) {
|
||||||
|
const demiReve = StatusEffects.demiReve();
|
||||||
if (status) {
|
if (status) {
|
||||||
await this.addStatusEffect(StatusEffects.demiReve())
|
await this.addStatusEffect(demiReve)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.deleteStatusEffect(StatusEffects.demiReve())
|
this.deleteStatusEffect(demiReve)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3093,8 +3098,8 @@ export class RdDActor extends Actor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
async forceStatusEffectId(statusId, sonne) {
|
async forceStatusEffectId(statusId, isSet) {
|
||||||
if (sonne) {
|
if (isSet) {
|
||||||
await this.addStatusEffectById(statusId);
|
await this.addStatusEffectById(statusId);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -3104,21 +3109,17 @@ export class RdDActor extends Actor {
|
|||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
deleteStatusEffectById(id) {
|
deleteStatusEffectById(id) {
|
||||||
const effects = Array.from(this.effects?.values())
|
const ids = Array.from(this.effects?.values())
|
||||||
.filter(it => it.data.flags.core?.statusId == id);
|
.filter(it => it.data.flags.core?.statusId == id)
|
||||||
this._deleteStatusEffects(effects);
|
.map(it => it.id);
|
||||||
|
this.deleteEmbeddedDocuments('ActiveEffect', ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
deleteStatusEffect(effect) {
|
deleteStatusEffect(effect) {
|
||||||
const toDelete = Array.from(this.effects?.values())
|
const ids = Array.from(this.effects?.values())
|
||||||
.filter(it => StatusEffects.statusId(it.data) == StatusEffects.statusId(effect));
|
.filter(it => StatusEffects.statusId(it.data) == StatusEffects.statusId(effect))
|
||||||
this._deleteStatusEffects(toDelete);
|
.map(it => it.id);
|
||||||
}
|
|
||||||
|
|
||||||
/* -------------------------------------------- */
|
|
||||||
_deleteStatusEffects(effects) {
|
|
||||||
const ids = effects.map(it => it.id);
|
|
||||||
this.deleteEmbeddedDocuments('ActiveEffect', ids);
|
this.deleteEmbeddedDocuments('ActiveEffect', ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3130,9 +3131,9 @@ export class RdDActor extends Actor {
|
|||||||
|
|
||||||
/* -------------------------------------------- */
|
/* -------------------------------------------- */
|
||||||
async addStatusEffect(statusEffect) {
|
async addStatusEffect(statusEffect) {
|
||||||
this.deleteStatusEffectById(statusEffect.id);
|
|
||||||
const effet = duplicate(statusEffect);
|
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]);
|
await this.createEmbeddedDocuments('ActiveEffect', [effet]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user