diff --git a/module/actor.js b/module/actor.js index 7f72ad01..03dbd000 100644 --- a/module/actor.js +++ b/module/actor.js @@ -399,7 +399,7 @@ export class RdDActor extends RdDBaseActorSang { content: 'Remise à neuf de ' + this.name }); await this.supprimerBlessures(it => true); - await this.removeEffects(e => e.flags.core.statusId !== STATUSES.StatusDemiReve); + await this.removeEffects(e => e.id != STATUSES.StatusDemiReve); const updates = { 'system.sante.endurance.value': this.system.sante.endurance.max, 'system.sante.vie.value': this.system.sante.vie.max, @@ -2923,9 +2923,7 @@ export class RdDActor extends RdDBaseActorSang { } /* -------------------------------------------- */ - isEffectAllowed(statusId) { - return true - } + isEffectAllowed(effectId) { return true } /* -------------------------------------------- */ async onPreUpdateItem(item, change, options, id) { diff --git a/module/actor/base-actor-reve.js b/module/actor/base-actor-reve.js index 6a361f74..1765340d 100644 --- a/module/actor/base-actor-reve.js +++ b/module/actor/base-actor-reve.js @@ -180,32 +180,32 @@ export class RdDBaseActorReve extends RdDBaseActor { } /* -------------------------------------------- */ - isEffectAllowed(statusId) { return true } + isEffectAllowed(effectId) { return true } getEffects(filter = e => true) { return this.getEmbeddedCollection("ActiveEffect").filter(filter); } - getEffect(statusId) { - return this.getEmbeddedCollection("ActiveEffect").find(it => it.flags?.core?.statusId == statusId); + getEffect(effectId) { + return this.getEmbeddedCollection("ActiveEffect").find(it => it.statuses?.has(effectId)); } - - async setEffect(statusId, status) { - if (this.isEffectAllowed(statusId)) { - const effect = this.getEffect(statusId); + + async setEffect(effectId, status) { + if (this.isEffectAllowed(effectId)) { + const effect = this.getEffect(effectId); if (!status && effect) { await this.deleteEmbeddedDocuments('ActiveEffect', [effect.id]); } if (status && !effect) { - await this.createEmbeddedDocuments("ActiveEffect", [StatusEffects.status(statusId)]); + await this.createEmbeddedDocuments("ActiveEffect", [StatusEffects.prepareActiveEffect(effectId)]); } } } - - async removeEffect(statusId) { - const effect = this.getEffect(statusId); + + async removeEffect(id) { + const effect = this.getEmbeddedCollection("ActiveEffect").find(it => it.id == id); if (effect) { - await this.deleteEmbeddedDocuments('ActiveEffect', [effect.id]); + await this.deleteEmbeddedDocuments('ActiveEffect', [id]); } } diff --git a/module/actor/creature.js b/module/actor/creature.js index 08eb6672..b6656b43 100644 --- a/module/actor/creature.js +++ b/module/actor/creature.js @@ -33,8 +33,8 @@ export class RdDCreature extends RdDBaseActorSang { } } - isEffectAllowed(statusId) { - return [STATUSES.StatusComma].includes(statusId); + isEffectAllowed(effectId) { + return [STATUSES.StatusComma].includes(effectId); } isEntiteAccordee(attacker) { diff --git a/module/actor/entite.js b/module/actor/entite.js index 7e971249..2b005c87 100644 --- a/module/actor/entite.js +++ b/module/actor/entite.js @@ -70,8 +70,8 @@ export class RdDEntite extends RdDBaseActorReve { await RdDEncaisser.encaisser(this) } - isEffectAllowed(statusId) { - return [STATUSES.StatusComma].includes(statusId); + isEffectAllowed(effectId) { + return [STATUSES.StatusComma].includes(effectId); } async onAppliquerJetEncaissement(encaissement, attacker) { diff --git a/module/settings/status-effects.js b/module/settings/status-effects.js index 406797bc..052da02c 100644 --- a/module/settings/status-effects.js +++ b/module/settings/status-effects.js @@ -1,13 +1,13 @@ import { SYSTEM_RDD } from "../constants.js"; export const STATUSES = { - StatusStunned : 'stun', + StatusStunned: 'stun', StatusBleeding: 'bleeding', StatusProne: 'prone', StatusGrappling: 'grappling', StatusGrappled: 'grappled', StatusRestrained: 'restrain', - StatusUnconscious: 'unconscious', + StatusUnconscious: 'unconscious', StatusBlind: 'blind', StatusComma: 'comma', StatusDead: 'dead', @@ -29,13 +29,16 @@ const rddStatusEffects = [ ]; const demiReveStatusEffect = rddStatusEffects.find(it => it.id == STATUSES.StatusDemiReve); -const statusDemiSurprise = [STATUSES.StatusStunned, STATUSES.StatusProne, STATUSES.StatusRestrained]; -const statusSurpriseTotale = [STATUSES.StatusUnconscious, STATUSES.StatusBlind, STATUSES.StatusComma]; +const statusDemiSurprise = new Set([STATUSES.StatusStunned, STATUSES.StatusProne, STATUSES.StatusRestrained]) +const statusSurpriseTotale = new Set([STATUSES.StatusUnconscious, STATUSES.StatusBlind, STATUSES.StatusComma]) export class StatusEffects extends FormApplication { static onReady() { - const rddStatusIds = rddStatusEffects.map(it => it.id); - rddStatusEffects.forEach(it => it.flags = { core: { statusId: it.id } }); + const rddEffectIds = rddStatusEffects.map(it => it.id); + rddStatusEffects.forEach(it => { + it.statuses = new Set() + it.statuses.add(it.id) + }) const defaultStatusEffectIds = CONFIG.statusEffects.map(it => it.id); game.settings.register(SYSTEM_RDD, "use-status-effects", { name: "use-status-effects", @@ -54,37 +57,47 @@ export class StatusEffects extends FormApplication { restricted: true }); - CONFIG.RDD.allEffects = rddStatusEffects.concat(CONFIG.statusEffects.filter(it => !rddStatusIds.includes(it.id))); + CONFIG.RDD.allEffects = rddStatusEffects.concat(CONFIG.statusEffects.filter(it => !rddEffectIds.includes(it.id))); StatusEffects._setUseStatusEffects(StatusEffects._getUseStatusEffects()); console.log('statusEffects', CONFIG.statusEffects); } static valeurSurprise(effect, isCombat) { - // const id = StatusEffects.statusId(effect); - if (statusSurpriseTotale.includes(effect.flags?.core?.statusId)) { + if (statusSurpriseTotale.intersects(effect.statuses)) { return 2; } - return statusDemiSurprise.includes(effect.flags?.core?.statusId) || (isCombat && effect.flags?.core?.statusId == STATUSES.StatusDemiReve) ? 1 : 0; + if (statusDemiSurprise.intersects(effect.statuses)) { + return 1 + } + if (isCombat && effect.statuses.includes(STATUSES.StatusDemiReve)) { + return 1 + } + return 0 } static _getUseStatusEffects() { - return game.settings.get(SYSTEM_RDD, "use-status-effects")?.split(',') ?? []; + return game.settings.get(SYSTEM_RDD, "use-status-effects")?.split(',') ?? []; } - static _setUseStatusEffects(statusIds) { + static _setUseStatusEffects(effectIds) { if (game.user.isGM) { - game.settings.set(SYSTEM_RDD, "use-status-effects", statusIds.join()); + game.settings.set(SYSTEM_RDD, "use-status-effects", effectIds.join()); } for (let effect of CONFIG.RDD.allEffects) { - effect.active = effect.rdd || statusIds.includes(effect.flags?.core?.statusId); + effect.active = effect.rdd || effectIds.includes(effect.id); } CONFIG.statusEffects = CONFIG.RDD.allEffects.filter(it => it.active); } - static status(statusId) { - return rddStatusEffects.find(it => it.flags?.core?.statusId == statusId); + static prepareActiveEffect(effectId) { + let status = rddStatusEffects.find(it => it.id == effectId) + if (status) { + status = duplicate(status) + status.statuses = [effectId] + } + return status; } static demiReve() { diff --git a/templates/actor/header-effects.html b/templates/actor/header-effects.html index 2dacf380..201f755b 100644 --- a/templates/actor/header-effects.html +++ b/templates/actor/header-effects.html @@ -1,7 +1,7 @@