mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-21 23:13:39 +02:00
More fixes
This commit is contained in:
parent
caea55ade4
commit
b3e298693a
7 changed files with 57 additions and 36 deletions
|
|
@ -89,11 +89,15 @@ export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel {
|
|||
return true;
|
||||
}
|
||||
|
||||
get armorChange() {
|
||||
return this.changes.find(x => x.type === CONFIG.DH.GENERAL.activeEffectModes.armor.id);
|
||||
}
|
||||
|
||||
get armorData() {
|
||||
const armorChange = this.changes.find(x => x.type === CONFIG.DH.GENERAL.activeEffectModes.armor.id);
|
||||
const armorChange = this.armorChange;
|
||||
if (!armorChange) return null;
|
||||
|
||||
return armorChange.armorData;
|
||||
return armorChange.typeData.getArmorData(armorChange);
|
||||
}
|
||||
|
||||
static getDefaultObject() {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import { itemAbleRollParse } from '../../../helpers/utils.mjs';
|
||||
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
export default class Armor extends foundry.abstract.DataModel {
|
||||
|
|
@ -76,14 +78,14 @@ export default class Armor extends foundry.abstract.DataModel {
|
|||
|
||||
/* Helpers */
|
||||
|
||||
get armorData() {
|
||||
getArmorData(parentChange) {
|
||||
const actor = this.parent.parent?.actor?.type === 'character' ? this.parent.parent.actor : null;
|
||||
const maxParse = actor ? itemAbleRollParse(this.max, actor, this.parent.parent.parent) : null;
|
||||
const maxRoll = maxParse ? new Roll(maxParse).evaluateSync() : null;
|
||||
const maxEvaluated = maxRoll ? (maxRoll.isDeterministic ? maxRoll.total : null) : null;
|
||||
|
||||
return {
|
||||
value: this.value,
|
||||
value: parentChange.value,
|
||||
max: maxEvaluated ?? this.max
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -469,8 +469,8 @@ export default class DhCharacter extends DhCreature {
|
|||
|
||||
const increasing = armorChange >= 0;
|
||||
let remainingChange = Math.abs(armorChange);
|
||||
const armorEffects = Array.from(this.parent.allApplicableEffects()).filter(x => x.type === 'armor');
|
||||
const orderedEffects = game.system.api.data.activeEffects.ArmorEffect.orderEffectsForAutoChange(
|
||||
const armorEffects = Array.from(this.parent.allApplicableEffects()).filter(x => x.system.armorData);
|
||||
const orderedEffects = game.system.api.data.activeEffects.changeTypes.armor.orderEffectsForAutoChange(
|
||||
armorEffects,
|
||||
increasing
|
||||
);
|
||||
|
|
@ -482,11 +482,11 @@ export default class DhCharacter extends DhCreature {
|
|||
usedArmorChange -= armorEffect.system.armorChange.value;
|
||||
} else {
|
||||
if (increasing) {
|
||||
const remainingArmor = armorEffect.system.armorChange.max - armorEffect.system.armorChange.value;
|
||||
const remainingArmor = armorEffect.system.armorData.max - armorEffect.system.armorData.value;
|
||||
usedArmorChange = Math.min(remainingChange, remainingArmor);
|
||||
remainingChange -= usedArmorChange;
|
||||
} else {
|
||||
const changeChange = Math.min(armorEffect.system.armorChange.value, remainingChange);
|
||||
const changeChange = Math.min(armorEffect.system.armorData.value, remainingChange);
|
||||
usedArmorChange -= changeChange;
|
||||
remainingChange -= changeChange;
|
||||
}
|
||||
|
|
@ -499,12 +499,13 @@ export default class DhCharacter extends DhCreature {
|
|||
|
||||
embeddedUpdates[armorEffect.parent.id].updates.push({
|
||||
'_id': armorEffect.id,
|
||||
'system.changes': [
|
||||
{
|
||||
...armorEffect.system.armorChange,
|
||||
value: armorEffect.system.armorChange.value + usedArmorChange
|
||||
}
|
||||
]
|
||||
'system.changes': armorEffect.system.changes.map(change => ({
|
||||
...change,
|
||||
value:
|
||||
change.type === 'armor'
|
||||
? armorEffect.system.armorChange.value + usedArmorChange
|
||||
: change.value
|
||||
}))
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue