diff --git a/module/applications/dialogs/damageReductionDialog.mjs b/module/applications/dialogs/damageReductionDialog.mjs index cd0a5cf7..494bad0f 100644 --- a/module/applications/dialogs/damageReductionDialog.mjs +++ b/module/applications/dialogs/damageReductionDialog.mjs @@ -21,7 +21,7 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap ); const canApplyArmor = damageType.every(t => actor.system.armorApplicableDamageTypes[t] === true); - const availableArmor = actor.system.armorScore - actor.system.armor.system.marks.value; + const availableArmor = actor.system.armorScore.max - actor.system.armorScore.value; const maxArmorMarks = canApplyArmor ? availableArmor : 0; const armor = [...Array(maxArmorMarks).keys()].reduce((acc, _) => { @@ -124,7 +124,7 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap const { selectedArmorMarks, selectedStressMarks, stressReductions, currentMarks, currentDamage } = this.getDamageInfo(); - context.armorScore = this.actor.system.armorScore; + context.armorScore = this.actor.system.armorScore.max; context.armorMarks = currentMarks; context.basicMarksUsed = selectedArmorMarks.length === this.actor.system.rules.damageReduction.maxArmorMarked.value; @@ -218,7 +218,7 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap } if (this.rulesOn) { - if (!currentMark.selected && currentMarks === this.actor.system.armorScore) { + if (!currentMark.selected && currentMarks === this.actor.system.armorScore.max) { ui.notifications.info(game.i18n.localize('DAGGERHEART.UI.Notifications.noAvailableArmorMarks')); return; } diff --git a/module/applications/sheets/api/base-actor.mjs b/module/applications/sheets/api/base-actor.mjs index 85ecd616..e619daad 100644 --- a/module/applications/sheets/api/base-actor.mjs +++ b/module/applications/sheets/api/base-actor.mjs @@ -36,7 +36,7 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) { ], dragDrop: [ { dragSelector: '.inventory-item[data-type="attack"]', dropSelector: null }, - { dragSelector: ".currency[data-currency] .drag-handle", dropSelector: null } + { dragSelector: '.currency[data-currency] .drag-handle', dropSelector: null } ] }; @@ -92,7 +92,7 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) { value: context.source.system.gold[key] }; } - context.inventory.hasCurrency = Object.values(context.inventory.currencies).some((c) => c.enabled); + context.inventory.hasCurrency = Object.values(context.inventory.currencies).some(c => c.enabled); } return context; @@ -160,7 +160,7 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) { inactives: [] }; - for (const effect of this.actor.allApplicableEffects()) { + for (const effect of this.actor.allApplicableEffects({ noArmor: true })) { const list = effect.active ? context.effects.actives : context.effects.inactives; list.push(effect); } @@ -270,7 +270,9 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) { currency }); if (quantity) { - originActor.update({ [`system.gold.${currency}`]: Math.max(0, originActor.system.gold[currency] - quantity) }); + originActor.update({ + [`system.gold.${currency}`]: Math.max(0, originActor.system.gold[currency] - quantity) + }); this.document.update({ [`system.gold.${currency}`]: this.document.system.gold[currency] + quantity }); } return; @@ -339,7 +341,7 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) { */ async _onDragStart(event) { // Handle drag/dropping currencies - const currencyEl = event.currentTarget.closest(".currency[data-currency]"); + const currencyEl = event.currentTarget.closest('.currency[data-currency]'); if (currencyEl) { const currency = currencyEl.dataset.currency; const data = { type: 'Currency', currency, originActor: this.document.uuid }; @@ -359,8 +361,8 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) { event.dataTransfer.setData('text/plain', JSON.stringify(attackData)); event.dataTransfer.setDragImage(attackItem.querySelector('img'), 60, 0); return; - } - + } + const item = await getDocFromElement(event.target); if (item) { const dragData = { diff --git a/module/applications/sheets/items/armor.mjs b/module/applications/sheets/items/armor.mjs index de61e5b1..4c69c822 100644 --- a/module/applications/sheets/items/armor.mjs +++ b/module/applications/sheets/items/armor.mjs @@ -50,6 +50,10 @@ export default class ArmorSheet extends ItemAttachmentSheet(DHBaseItemSheet) { context.features = this.document.system.armorFeatures.map(x => x.value); context.armorScore = this.document.system.armorData.max; break; + case 'effects': + context.effects.actives = context.effects.actives.filter(x => x.type !== 'armor'); + context.effects.inactives = context.effects.actives.filter(x => x.type !== 'armor'); + break; } return context; diff --git a/module/data/actor/character.mjs b/module/data/actor/character.mjs index 294fa77e..87f203ec 100644 --- a/module/data/actor/character.mjs +++ b/module/data/actor/character.mjs @@ -507,8 +507,8 @@ export default class DhCharacter extends BaseDataActor { } } - async updateArmorValue(armorChange) { - if (armorChange === 0) return; + async updateArmorValue({ value: armorChange = 0, clear = false }) { + if (armorChange === 0 && !clear) return; const increasing = armorChange >= 0; let remainingChange = Math.abs(armorChange); @@ -521,14 +521,18 @@ export default class DhCharacter extends BaseDataActor { const embeddedUpdates = []; for (const armorEffect of orderedEffects) { let usedArmorChange = 0; - if (increasing) { - const remainingArmor = armorEffect.system.armorChange.max - armorEffect.system.armorChange.value; - usedArmorChange = Math.min(remainingChange, remainingArmor); - remainingChange -= usedArmorChange; + if (clear) { + usedArmorChange -= armorEffect.system.armorChange.value; } else { - const changeChange = Math.min(armorEffect.system.armorChange.value, remainingChange); - usedArmorChange -= changeChange; - remainingChange -= changeChange; + if (increasing) { + const remainingArmor = armorEffect.system.armorChange.max - armorEffect.system.armorChange.value; + usedArmorChange = Math.min(remainingChange, remainingArmor); + remainingChange -= usedArmorChange; + } else { + const changeChange = Math.min(armorEffect.system.armorChange.value, remainingChange); + usedArmorChange -= changeChange; + remainingChange -= changeChange; + } } if (!usedArmorChange) continue; @@ -547,11 +551,12 @@ export default class DhCharacter extends BaseDataActor { }); } - if (remainingChange === 0) break; + if (remainingChange === 0 && !clear) break; } - for (const { doc, updates } of Object.values(embeddedUpdates)) - doc.updateEmbeddedDocuments('ActiveEffect', updates); + const updateValues = Object.values(embeddedUpdates); + for (const [index, { doc, updates }] of updateValues.entries()) + doc.updateEmbeddedDocuments('ActiveEffect', updates, { render: index === updateValues.length - 1 }); } get sheetLists() { diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index 4807f497..2eafc70f 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -784,12 +784,7 @@ export default class DhpActor extends Actor { ); break; case 'armor': - if (this.system.armor?.system?.marks) { - updates.armor.resources['system.marks.value'] = Math.max( - Math.min(valueFunc(this.system.armor.system.marks, r), this.system.armorScore), - 0 - ); - } + this.system.updateArmorValue(r); break; default: if (this.system.resources?.[r.key]) { @@ -993,7 +988,15 @@ export default class DhpActor extends Actor { return allTokens; } - applyActiveEffects(phase) { - super.applyActiveEffects(phase); + /**@inheritdoc */ + *allApplicableEffects({ noArmor } = {}) { + for (const effect of this.effects) { + yield effect; + } + for (const item of this.items) { + for (const effect of item.effects) { + if (effect.transfer && (!noArmor || effect.type !== 'armor')) yield effect; + } + } } }