This commit is contained in:
WBHarry 2026-02-09 22:43:21 +01:00
parent 9dc5830e18
commit a76479e9b7
5 changed files with 44 additions and 30 deletions

View file

@ -21,7 +21,7 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap
); );
const canApplyArmor = damageType.every(t => actor.system.armorApplicableDamageTypes[t] === true); 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 maxArmorMarks = canApplyArmor ? availableArmor : 0;
const armor = [...Array(maxArmorMarks).keys()].reduce((acc, _) => { const armor = [...Array(maxArmorMarks).keys()].reduce((acc, _) => {
@ -124,7 +124,7 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap
const { selectedArmorMarks, selectedStressMarks, stressReductions, currentMarks, currentDamage } = const { selectedArmorMarks, selectedStressMarks, stressReductions, currentMarks, currentDamage } =
this.getDamageInfo(); this.getDamageInfo();
context.armorScore = this.actor.system.armorScore; context.armorScore = this.actor.system.armorScore.max;
context.armorMarks = currentMarks; context.armorMarks = currentMarks;
context.basicMarksUsed = context.basicMarksUsed =
selectedArmorMarks.length === this.actor.system.rules.damageReduction.maxArmorMarked.value; selectedArmorMarks.length === this.actor.system.rules.damageReduction.maxArmorMarked.value;
@ -218,7 +218,7 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap
} }
if (this.rulesOn) { 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')); ui.notifications.info(game.i18n.localize('DAGGERHEART.UI.Notifications.noAvailableArmorMarks'));
return; return;
} }

View file

@ -36,7 +36,7 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
], ],
dragDrop: [ dragDrop: [
{ dragSelector: '.inventory-item[data-type="attack"]', dropSelector: null }, { 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] 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; return context;
@ -160,7 +160,7 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
inactives: [] 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; const list = effect.active ? context.effects.actives : context.effects.inactives;
list.push(effect); list.push(effect);
} }
@ -270,7 +270,9 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
currency currency
}); });
if (quantity) { 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 }); this.document.update({ [`system.gold.${currency}`]: this.document.system.gold[currency] + quantity });
} }
return; return;
@ -339,7 +341,7 @@ export default class DHBaseActorSheet extends DHApplicationMixin(ActorSheetV2) {
*/ */
async _onDragStart(event) { async _onDragStart(event) {
// Handle drag/dropping currencies // Handle drag/dropping currencies
const currencyEl = event.currentTarget.closest(".currency[data-currency]"); const currencyEl = event.currentTarget.closest('.currency[data-currency]');
if (currencyEl) { if (currencyEl) {
const currency = currencyEl.dataset.currency; const currency = currencyEl.dataset.currency;
const data = { type: 'Currency', currency, originActor: this.document.uuid }; const data = { type: 'Currency', currency, originActor: this.document.uuid };

View file

@ -50,6 +50,10 @@ export default class ArmorSheet extends ItemAttachmentSheet(DHBaseItemSheet) {
context.features = this.document.system.armorFeatures.map(x => x.value); context.features = this.document.system.armorFeatures.map(x => x.value);
context.armorScore = this.document.system.armorData.max; context.armorScore = this.document.system.armorData.max;
break; 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; return context;

View file

@ -507,8 +507,8 @@ export default class DhCharacter extends BaseDataActor {
} }
} }
async updateArmorValue(armorChange) { async updateArmorValue({ value: armorChange = 0, clear = false }) {
if (armorChange === 0) return; if (armorChange === 0 && !clear) return;
const increasing = armorChange >= 0; const increasing = armorChange >= 0;
let remainingChange = Math.abs(armorChange); let remainingChange = Math.abs(armorChange);
@ -521,14 +521,18 @@ export default class DhCharacter extends BaseDataActor {
const embeddedUpdates = []; const embeddedUpdates = [];
for (const armorEffect of orderedEffects) { for (const armorEffect of orderedEffects) {
let usedArmorChange = 0; let usedArmorChange = 0;
if (increasing) { if (clear) {
const remainingArmor = armorEffect.system.armorChange.max - armorEffect.system.armorChange.value; usedArmorChange -= armorEffect.system.armorChange.value;
usedArmorChange = Math.min(remainingChange, remainingArmor);
remainingChange -= usedArmorChange;
} else { } else {
const changeChange = Math.min(armorEffect.system.armorChange.value, remainingChange); if (increasing) {
usedArmorChange -= changeChange; const remainingArmor = armorEffect.system.armorChange.max - armorEffect.system.armorChange.value;
remainingChange -= changeChange; usedArmorChange = Math.min(remainingChange, remainingArmor);
remainingChange -= usedArmorChange;
} else {
const changeChange = Math.min(armorEffect.system.armorChange.value, remainingChange);
usedArmorChange -= changeChange;
remainingChange -= changeChange;
}
} }
if (!usedArmorChange) continue; 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)) const updateValues = Object.values(embeddedUpdates);
doc.updateEmbeddedDocuments('ActiveEffect', updates); for (const [index, { doc, updates }] of updateValues.entries())
doc.updateEmbeddedDocuments('ActiveEffect', updates, { render: index === updateValues.length - 1 });
} }
get sheetLists() { get sheetLists() {

View file

@ -784,12 +784,7 @@ export default class DhpActor extends Actor {
); );
break; break;
case 'armor': case 'armor':
if (this.system.armor?.system?.marks) { this.system.updateArmorValue(r);
updates.armor.resources['system.marks.value'] = Math.max(
Math.min(valueFunc(this.system.armor.system.marks, r), this.system.armorScore),
0
);
}
break; break;
default: default:
if (this.system.resources?.[r.key]) { if (this.system.resources?.[r.key]) {
@ -993,7 +988,15 @@ export default class DhpActor extends Actor {
return allTokens; return allTokens;
} }
applyActiveEffects(phase) { /**@inheritdoc */
super.applyActiveEffects(phase); *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;
}
}
} }
} }