diff --git a/module/applications/sheets-configs/activeEffectConfig.mjs b/module/applications/sheets-configs/activeEffectConfig.mjs index 227fc627..9f970e1d 100644 --- a/module/applications/sheets-configs/activeEffectConfig.mjs +++ b/module/applications/sheets-configs/activeEffectConfig.mjs @@ -154,6 +154,10 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac htmlElement .querySelector('.armor-change-checkbox') ?.addEventListener('change', this.armorChangeToggle.bind(this)); + + htmlElement + .querySelector('.armor-damage-thresholds-checkbox') + ?.addEventListener('change', this.armorDamageThresholdToggle.bind(this)); } async _prepareContext(options) { @@ -229,6 +233,19 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac return this.submit({ updateData: { system: { changes } } }); } + armorDamageThresholdToggle(event) { + const submitData = this._processFormData(null, this.form, new FormDataExtended(this.form)); + const changes = Object.values(submitData.system?.changes ?? {}); + const index = Number(event.target.dataset.index); + if (event.target.checked) { + changes[index].value.damageThresholds = { major: 0, severe: 0 }; + } else { + changes[index].value.damageThresholds = null; + } + + return this.submit({ updateData: { system: { changes } } }); + } + /** @inheritdoc */ _renderChange(context) { const { change, index, defaultPriority } = context; diff --git a/module/data/activeEffect/baseEffect.mjs b/module/data/activeEffect/baseEffect.mjs index 5127d437..81ddb4ad 100644 --- a/module/data/activeEffect/baseEffect.mjs +++ b/module/data/activeEffect/baseEffect.mjs @@ -101,6 +101,12 @@ export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel { return true; } + get isSuppressed() { + for (const change of this.changes) { + if (change.isSuppressed) return true; + } + } + get armorChange() { return this.changes.find(x => x.type === CONFIG.DH.GENERAL.activeEffectModes.armor.id); } @@ -137,7 +143,11 @@ export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel { if (allowed === false) return false; const autoSettings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation); - if (autoSettings.resourceScrollTexts && this.parent.actor?.type === 'character') { + if ( + autoSettings.resourceScrollTexts && + this.parent.actor?.type === 'character' && + this.parent.actor.system.resources.armor + ) { const newArmorTotal = (changed.system?.changes ?? []).reduce((acc, change) => { if (change.type === 'armor') acc += change.value.current; return acc; diff --git a/module/data/activeEffect/changeTypes/armor.mjs b/module/data/activeEffect/changeTypes/armor.mjs index eee6f630..f400d41b 100644 --- a/module/data/activeEffect/changeTypes/armor.mjs +++ b/module/data/activeEffect/changeTypes/armor.mjs @@ -16,6 +16,19 @@ export default class ArmorChange extends foundry.abstract.DataModel { initial: '1', label: 'DAGGERHEART.GENERAL.max' }), + damageThresholds: new fields.SchemaField( + { + major: new fields.StringField({ + initial: '0', + label: 'DAGGERHEART.GENERAL.DamageThresholds.majorThreshold' + }), + severe: new fields.StringField({ + initial: '0', + label: 'DAGGERHEART.GENERAL.DamageThresholds.severeThreshold' + }) + }, + { nullable: true, initial: null } + ), interaction: new fields.StringField({ required: true, choices: CONFIG.DH.GENERAL.activeEffectArmorInteraction, @@ -52,6 +65,45 @@ export default class ArmorChange extends foundry.abstract.DataModel { }, replacementData ); + + if (change.value.damageThresholds) { + const getThresholdValue = value => { + const parsed = itemAbleRollParse(value, actor, change.effect.parent); + const roll = new Roll(parsed).evaluateSync(); + return roll ? (roll.isDeterministic ? roll.total : null) : null; + }; + const major = getThresholdValue(change.value.damageThresholds.major); + const severe = getThresholdValue(change.value.damageThresholds.severe); + + if (major) { + game.system.api.documents.DhActiveEffect.applyChange( + actor, + { + ...change, + key: 'system.damageThresholds.major', + type: CONFIG.DH.GENERAL.activeEffectModes.override.id, + priority: 50, + value: major + }, + replacementData + ); + } + + if (severe) { + game.system.api.documents.DhActiveEffect.applyChange( + actor, + { + ...change, + key: 'system.damageThresholds.severe', + type: CONFIG.DH.GENERAL.activeEffectModes.override.id, + priority: 50, + value: severe + }, + replacementData + ); + } + } + return {}; }, render: null diff --git a/module/data/actor/character.mjs b/module/data/actor/character.mjs index 72ed3c9d..b8846a75 100644 --- a/module/data/actor/character.mjs +++ b/module/data/actor/character.mjs @@ -42,15 +42,15 @@ export default class DhCharacter extends DhCreature { }), evasion: new fields.NumberField({ initial: 0, integer: true, label: 'DAGGERHEART.GENERAL.evasion' }), damageThresholds: new fields.SchemaField({ - severe: new fields.NumberField({ - integer: true, - initial: 0, - label: 'DAGGERHEART.GENERAL.DamageThresholds.severeThreshold' - }), major: new fields.NumberField({ integer: true, initial: 0, label: 'DAGGERHEART.GENERAL.DamageThresholds.majorThreshold' + }), + severe: new fields.NumberField({ + integer: true, + initial: 0, + label: 'DAGGERHEART.GENERAL.DamageThresholds.severeThreshold' }) }), experiences: new fields.TypedObjectField( diff --git a/src/packs/domains/domainCard_Bare_Bones_l5D9kq901JDESaXw.json b/src/packs/domains/domainCard_Bare_Bones_l5D9kq901JDESaXw.json index c2cb7ada..098f5f4c 100644 --- a/src/packs/domains/domainCard_Bare_Bones_l5D9kq901JDESaXw.json +++ b/src/packs/domains/domainCard_Bare_Bones_l5D9kq901JDESaXw.json @@ -21,7 +21,7 @@ "flags": {}, "effects": [ { - "name": "Bare Bones Armor", + "name": "Bare Bones", "type": "base", "system": { "changes": [ @@ -31,7 +31,11 @@ "priority": 20, "value": { "max": "3 + @system.traits.strength.value", - "interaction": "inactive" + "interaction": "inactive", + "damageThresholds": { + "major": "9 + (@tier - 1) * 5 + max(0, (@tier -2) * 2 )", + "severe": "19 + (@tier - 1) * 5 + max(0, (@tier -2) * 2 )" + } } } ] @@ -59,57 +63,6 @@ "compendiumSource": null }, "_key": "!items.effects!l5D9kq901JDESaXw.FCsgz7Tdsw6QUzBs" - }, - { - "name": "Bare Bones", - "type": "base", - "system": { - "changes": [ - { - "key": "system.damageThresholds.major", - "type": "add", - "value": "9 + (@tier - 1) * 5 + max(0, (@tier -2) * 2 )", - "priority": null, - "phase": "initial" - }, - { - "key": "system.damageThresholds.severe", - "type": "add", - "value": "19 + (@tier - 1) * 5 + max(0, (@tier -2) * 2 )", - "priority": null, - "phase": "initial" - } - ], - "rangeDependence": { - "enabled": false, - "type": "withinRange", - "target": "hostile", - "range": "melee" - } - }, - "_id": "8flPpWNoBeuFPFTK", - "img": "icons/magic/control/buff-strength-muscle-damage-orange.webp", - "disabled": false, - "start": null, - "duration": { - "value": null, - "units": "seconds", - "expiry": null, - "expired": false - }, - "description": "
You use the following as your base damage thresholds:
Tier 1: 9/19
Tier 2: 11/24
Tier 3: 13/31
Tier 4: 15/38