fix: sanitize weapon feature effect IDs and correctly remove single entries during augment removal

This commit is contained in:
CPTN Cosmo 2026-04-26 20:10:58 +02:00
parent 0d4446ece6
commit 204573de13

View file

@ -197,10 +197,22 @@ export function patchIkonisSheet() {
};
Weapon.prototype._onRemoveAugment = async function(event, target) {
const weaponFeatures = this.document.system.weaponFeatures || [];
const weaponFeatures = foundry.utils.deepClone(this.document.system.weaponFeatures || []);
const targetId = target.dataset.id;
const newFeatures = weaponFeatures.filter(f => f.value !== targetId);
await this.document.update({ "system.weaponFeatures": newFeatures });
// Find the index of the first matching feature to remove
const idx = weaponFeatures.findIndex(f => String(f.value) === String(targetId));
if (idx !== -1) {
// Sanitize effectIds to prevent system crash if effects are missing
const feature = weaponFeatures[idx];
if (Array.isArray(feature.effectIds)) {
feature.effectIds = feature.effectIds.filter(id => this.document.effects.has(id));
}
weaponFeatures.splice(idx, 1);
await this.document.update({ "system.weaponFeatures": weaponFeatures });
}
this.render(true);
};