Fix: deprecation effects flags.core.statusId

Remplacement de la logique basée sur les flags par le set de "statuses"
This commit is contained in:
Vincent Vandemeulebrouck 2023-12-08 23:50:16 +01:00
parent 56a5d06f16
commit 05cd02b694
6 changed files with 48 additions and 37 deletions

View File

@ -399,7 +399,7 @@ export class RdDActor extends RdDBaseActorSang {
content: 'Remise à neuf de ' + this.name content: 'Remise à neuf de ' + this.name
}); });
await this.supprimerBlessures(it => true); 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 = { const updates = {
'system.sante.endurance.value': this.system.sante.endurance.max, 'system.sante.endurance.value': this.system.sante.endurance.max,
'system.sante.vie.value': this.system.sante.vie.max, 'system.sante.vie.value': this.system.sante.vie.max,
@ -2923,9 +2923,7 @@ export class RdDActor extends RdDBaseActorSang {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
isEffectAllowed(statusId) { isEffectAllowed(effectId) { return true }
return true
}
/* -------------------------------------------- */ /* -------------------------------------------- */
async onPreUpdateItem(item, change, options, id) { async onPreUpdateItem(item, change, options, id) {

View File

@ -180,32 +180,32 @@ export class RdDBaseActorReve extends RdDBaseActor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
isEffectAllowed(statusId) { return true } isEffectAllowed(effectId) { return true }
getEffects(filter = e => true) { getEffects(filter = e => true) {
return this.getEmbeddedCollection("ActiveEffect").filter(filter); return this.getEmbeddedCollection("ActiveEffect").filter(filter);
} }
getEffect(statusId) { getEffect(effectId) {
return this.getEmbeddedCollection("ActiveEffect").find(it => it.flags?.core?.statusId == statusId); return this.getEmbeddedCollection("ActiveEffect").find(it => it.statuses?.has(effectId));
} }
async setEffect(statusId, status) { async setEffect(effectId, status) {
if (this.isEffectAllowed(statusId)) { if (this.isEffectAllowed(effectId)) {
const effect = this.getEffect(statusId); const effect = this.getEffect(effectId);
if (!status && effect) { if (!status && effect) {
await this.deleteEmbeddedDocuments('ActiveEffect', [effect.id]); await this.deleteEmbeddedDocuments('ActiveEffect', [effect.id]);
} }
if (status && !effect) { if (status && !effect) {
await this.createEmbeddedDocuments("ActiveEffect", [StatusEffects.status(statusId)]); await this.createEmbeddedDocuments("ActiveEffect", [StatusEffects.prepareActiveEffect(effectId)]);
} }
} }
} }
async removeEffect(statusId) { async removeEffect(id) {
const effect = this.getEffect(statusId); const effect = this.getEmbeddedCollection("ActiveEffect").find(it => it.id == id);
if (effect) { if (effect) {
await this.deleteEmbeddedDocuments('ActiveEffect', [effect.id]); await this.deleteEmbeddedDocuments('ActiveEffect', [id]);
} }
} }

View File

@ -33,8 +33,8 @@ export class RdDCreature extends RdDBaseActorSang {
} }
} }
isEffectAllowed(statusId) { isEffectAllowed(effectId) {
return [STATUSES.StatusComma].includes(statusId); return [STATUSES.StatusComma].includes(effectId);
} }
isEntiteAccordee(attacker) { isEntiteAccordee(attacker) {

View File

@ -70,8 +70,8 @@ export class RdDEntite extends RdDBaseActorReve {
await RdDEncaisser.encaisser(this) await RdDEncaisser.encaisser(this)
} }
isEffectAllowed(statusId) { isEffectAllowed(effectId) {
return [STATUSES.StatusComma].includes(statusId); return [STATUSES.StatusComma].includes(effectId);
} }
async onAppliquerJetEncaissement(encaissement, attacker) { async onAppliquerJetEncaissement(encaissement, attacker) {

View File

@ -29,13 +29,16 @@ const rddStatusEffects = [
]; ];
const demiReveStatusEffect = rddStatusEffects.find(it => it.id == STATUSES.StatusDemiReve); const demiReveStatusEffect = rddStatusEffects.find(it => it.id == STATUSES.StatusDemiReve);
const statusDemiSurprise = [STATUSES.StatusStunned, STATUSES.StatusProne, STATUSES.StatusRestrained]; const statusDemiSurprise = new Set([STATUSES.StatusStunned, STATUSES.StatusProne, STATUSES.StatusRestrained])
const statusSurpriseTotale = [STATUSES.StatusUnconscious, STATUSES.StatusBlind, STATUSES.StatusComma]; const statusSurpriseTotale = new Set([STATUSES.StatusUnconscious, STATUSES.StatusBlind, STATUSES.StatusComma])
export class StatusEffects extends FormApplication { export class StatusEffects extends FormApplication {
static onReady() { static onReady() {
const rddStatusIds = rddStatusEffects.map(it => it.id); const rddEffectIds = rddStatusEffects.map(it => it.id);
rddStatusEffects.forEach(it => it.flags = { core: { statusId: it.id } }); rddStatusEffects.forEach(it => {
it.statuses = new Set()
it.statuses.add(it.id)
})
const defaultStatusEffectIds = CONFIG.statusEffects.map(it => it.id); const defaultStatusEffectIds = CONFIG.statusEffects.map(it => it.id);
game.settings.register(SYSTEM_RDD, "use-status-effects", { game.settings.register(SYSTEM_RDD, "use-status-effects", {
name: "use-status-effects", name: "use-status-effects",
@ -54,37 +57,47 @@ export class StatusEffects extends FormApplication {
restricted: true 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()); StatusEffects._setUseStatusEffects(StatusEffects._getUseStatusEffects());
console.log('statusEffects', CONFIG.statusEffects); console.log('statusEffects', CONFIG.statusEffects);
} }
static valeurSurprise(effect, isCombat) { static valeurSurprise(effect, isCombat) {
// const id = StatusEffects.statusId(effect); if (statusSurpriseTotale.intersects(effect.statuses)) {
if (statusSurpriseTotale.includes(effect.flags?.core?.statusId)) {
return 2; 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() { 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) { 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) { 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); CONFIG.statusEffects = CONFIG.RDD.allEffects.filter(it => it.active);
} }
static status(statusId) { static prepareActiveEffect(effectId) {
return rddStatusEffects.find(it => it.flags?.core?.statusId == statusId); let status = rddStatusEffects.find(it => it.id == effectId)
if (status) {
status = duplicate(status)
status.statuses = [effectId]
}
return status;
} }
static demiReve() { static demiReve() {

View File

@ -1,7 +1,7 @@
<div> <div>
{{#if effects}} {{#if effects}}
{{#each effects as |effect key|}} {{#each effects as |effect key|}}
<span class="active-effect" data-effect="{{effect.flags.core.statusId}}"> <span class="active-effect" data-effect="{{effect.id}}">
<img class="button-effect-img {{#if @root.options.isGM}}delete-active-effect{{/if}}" src="{{effect.icon}}" data-tooltip="{{localize effect.name}}" width="24" height="24" /> <img class="button-effect-img {{#if @root.options.isGM}}delete-active-effect{{/if}}" src="{{effect.icon}}" data-tooltip="{{localize effect.name}}" width="24" height="24" />
</span> </span>
{{/each}} {{/each}}