Fixed effect stacking

This commit is contained in:
WBHarry 2026-02-17 21:15:36 +01:00
parent 79057b0718
commit 617f1d64c1
7 changed files with 37 additions and 28 deletions

View file

@ -95,7 +95,10 @@ export default class DhEffectsDisplay extends HandlebarsApplicationMixin(Applica
if (!effect.system.stacking?.enabled) return;
const newValue = Math.min(effect.system.stacking.value + 1, effect.system.stacking.max);
const incrementedValue = effect.system.stacking.value + 1;
const newValue = effect.system.stacking.max
? Math.min(incrementedValue, effect.system.stacking.max)
: incrementedValue;
await effect.update({ 'system.stacking.value': newValue });
this.render();
}

View file

@ -52,7 +52,7 @@ export default class DhTokenPlaceable extends foundry.canvas.placeables.Token {
const icon = new PIXI.Sprite(tex);
icon.tint = tint ?? 0xffffff;
if (effect?.system?.stacking?.enabled) {
if (effect?.system?.stacking?.enabled && effect.system.stacking.value > 1) {
const stackOverlay = new PIXI.Text(effect.system.stacking.value, {
fill: '#f3c267',
stroke: '#000000',

View file

@ -75,8 +75,7 @@ export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel {
nullable: false,
label: 'DAGGERHEART.GENERAL.value'
}),
max: new fields.NumberField({ label: 'DAGGERHEART.GENERAL.max' })
// max: new fields.StringField({ required: true, nullable: false }),
max: new fields.NumberField({ integer: true, label: 'DAGGERHEART.GENERAL.max' })
})
};
}

View file

@ -106,22 +106,11 @@ export default class EffectsField extends fields.ArrayField {
}
/**
* Apply an Effect to a target or enable it if already on it
* Apply an Effect to a target
* @param {object} effect Effect object containing ActiveEffect UUID
* @param {object} actor Actor Document
*/
static async applyEffect(effect, actor) {
const existingEffect = actor.effects.find(e => e.origin === effect.uuid);
if (existingEffect) {
return effect.update(
foundry.utils.mergeObject({
...effect.constructor.getInitialDuration(),
disabled: false
})
);
}
// Otherwise, create a new effect on the target
const effectData = foundry.utils.mergeObject({
...(effect.toObject?.() ?? effect),
disabled: false,

View file

@ -106,6 +106,20 @@ export default class DhActiveEffect extends foundry.documents.ActiveEffect {
update.img = 'icons/magic/life/heart-cross-blue.webp';
}
const existingEffect = this.actor.effects.find(x => x.origin === data.origin);
const stacks = data.system?.stacking?.enabled;
if (existingEffect && !stacks) return false;
if (existingEffect && stacks) {
const incrementedValue = existingEffect.system.stacking.value + 1;
await existingEffect.update({
'system.stacking.value': existingEffect.system.stacking.max
? Math.min(incrementedValue, existingEffect.system.stacking.max)
: incrementedValue
});
return false;
}
const statuses = Object.keys(data.statuses ?? {});
const immuneStatuses =
statuses.filter(

View file

@ -8,7 +8,7 @@
<a {{#if effect.condition}}disabled{{/if}}>
<img src="{{effect.img}}" />
</a>
{{#if effect.system.stacking.enabled}}
{{#if (and effect.system.stacking.enabled (gt effect.system.stacking.value 1))}}
<span class="stacking-value">{{effect.system.stacking.value}}</span>
{{/if}}
{{#if effect.condition}}<i class="effect-locked fa-solid fa-lock"></i>{{/if}}

View file

@ -25,7 +25,7 @@
</div>
{{/if}}
{{#if effect.system.stacking.enabled}}
{{#if (and effect.system.stacking.enabled effect.system.stacking.max)}}
<div class="effect-stacks-outer-container">
<div class="effect-stacks-title">{{localize "Stacks"}}</div>
<div class="effect-stacks-container">
@ -33,12 +33,10 @@
<span class="effect-stack-title">{{localize "Current"}}</span>
<span>{{effect.system.stacking.value}}</span>
</div>
{{#if effect.system.stacking.max}}
<div class="effect-stacks-inner-container">
<span class="effect-stack-title">{{localize "Max"}}</span>
<span>{{effect.system.stacking.max}}</span>
</div>
{{/if}}
<div class="effect-stacks-inner-container">
<span class="effect-stack-title">{{localize "Max"}}</span>
<span>{{effect.system.stacking.max}}</span>
</div>
</div>
</div>
{{/if}}
@ -49,9 +47,15 @@
<p class="close-hint">
<i class="fa-solid fa-computer-mouse"></i> {{localize "DAGGERHEART.UI.EffectsDisplay.increaseStacks"}}
</p>
<p class="close-hint">
<i class="fa-solid fa-computer-mouse"></i> {{localize "DAGGERHEART.UI.EffectsDisplay.decreaseStacks"}}
</p>
{{#if (gt effect.system.stacking.value 1)}}
<p class="close-hint">
<i class="fa-solid fa-computer-mouse"></i> {{localize "DAGGERHEART.UI.EffectsDisplay.decreaseStacks"}}
</p>
{{else}}
<p class="close-hint">
<i class="fa-solid fa-computer-mouse"></i> {{localize "DAGGERHEART.UI.EffectsDisplay.removeThing" thing=(localize "DAGGERHEART.GENERAL.Effect.single")}}
</p>
{{/if}}
{{else}}
<p class="close-hint">
<i class="fa-solid fa-computer-mouse"></i> {{localize "DAGGERHEART.UI.EffectsDisplay.removeThing" thing=(localize "DAGGERHEART.GENERAL.Effect.single")}}