Added ArmorChange DamageThresholds

This commit is contained in:
WBHarry 2026-03-21 13:34:27 +01:00
parent 482fb33a67
commit f751c0ed41
8 changed files with 162 additions and 75 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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

View file

@ -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(

View file

@ -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": "<p>You use the following as your base damage thresholds:</p><ul><li class=\"vertical-card-list-found\"><p><em><strong>Tier 1:</strong></em> 9/19</p></li><li class=\"vertical-card-list-found\"><p><em><strong>Tier 2:</strong></em> 11/24</p></li><li class=\"vertical-card-list-found\"><p><em><strong>Tier 3:</strong></em> 13/31</p></li><li class=\"vertical-card-list-found\"><p><em><strong>Tier 4:</strong></em> 15/38</p></li></ul>",
"origin": null,
"tint": "#ffffff",
"transfer": true,
"statuses": [],
"showIcon": 1,
"folder": null,
"sort": 0,
"flags": {},
"_stats": {
"compendiumSource": null
},
"_key": "!items.effects!l5D9kq901JDESaXw.8flPpWNoBeuFPFTK"
}
],
"ownership": {

View file

@ -52,6 +52,49 @@
ol {
grid-template-columns: 5rem 7rem 12rem 4rem;
}
.damage-thresholds-container {
width: 100%;
display: flex;
flex-direction: column;
gap: 4px;
.damage-threshold-title {
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
&::before,
&::after {
content: '';
flex: 1;
height: 2px;
}
&::before {
background: linear-gradient(90deg, rgba(0, 0, 0, 0) 0%, light-dark(@dark-blue, @golden) 100%);
}
&::after {
background: linear-gradient(90deg, light-dark(@dark-blue, @golden) 0%, rgba(0, 0, 0, 0) 100%);
}
span {
font-size: var(--font-size-18);
}
}
.form-group {
flex-direction: column;
gap: 0;
label {
color: inherit;
line-height: 16px;
}
}
}
}
}
}

View file

@ -17,15 +17,7 @@
<fieldset class="armor-change-container">
<legend>{{localize "DAGGERHEART.GENERAL.armor"}} <input type="checkbox" class="armor-change-checkbox" data-index="{{typedChanges.armor.index}}" {{checked typedChanges.armor}} /></legend>
{{#if typedChanges.armor}}
<header>
<div>{{localize "EFFECT.FIELDS.changes.element.value.label"}}</div>
<div>{{localize "DAGGERHEART.GENERAL.max"}}</div>
<div>{{localize "DAGGERHEART.EFFECTS.ChangeTypes.armor.FIELDS.interaction.label"}}</div>
<div>{{localize "EFFECT.FIELDS.changes.element.priority.label"}}</div>
</header>
<ol class="scrollable">
{{> "systems/daggerheart/templates/sheets/activeEffect/typeChanges/armorChange.hbs" typedChanges.armor fields=@root.systemFields.changes.element.types.armor.fields}}
</ol>
{{/if}}
</fieldset>
</section>

View file

@ -1,8 +1,28 @@
<li data-index="{{index}}">
<input type="hidden" name="{{concat "system.changes." index ".type"}}" value="{{type}}" />
<input type="hidden" name="{{concat "system.changes." index ".phase"}}" value="{{phase}}" />
{{formInput fields.value.fields.current name=(concat "system.changes." index ".value.current") value=value.current data-dtype="Number"}}
{{formInput fields.value.fields.max name=(concat "system.changes." index ".value.max") value=value.max data-dtype="Number"}}
{{formInput fields.value.fields.interaction name=(concat "system.changes." index ".value.interaction") value=value.interaction localize=true}}
{{formInput fields.priority name=(concat "system.changes." index ".priority") value=priority}}
</li>
<header>
<div>{{localize "EFFECT.FIELDS.changes.element.value.label"}}</div>
<div>{{localize "DAGGERHEART.GENERAL.max"}}</div>
<div>{{localize "DAGGERHEART.EFFECTS.ChangeTypes.armor.FIELDS.interaction.label"}}</div>
<div>{{localize "EFFECT.FIELDS.changes.element.priority.label"}}</div>
</header>
<ol class="scrollable">
<li data-index="{{index}}">
<input type="hidden" name="{{concat "system.changes." index ".type"}}" value="{{type}}" />
<input type="hidden" name="{{concat "system.changes." index ".phase"}}" value="{{phase}}" />
{{formInput fields.value.fields.current name=(concat "system.changes." index ".value.current") value=value.current data-dtype="Number"}}
{{formInput fields.value.fields.max name=(concat "system.changes." index ".value.max") value=value.max data-dtype="Number"}}
{{formInput fields.value.fields.interaction name=(concat "system.changes." index ".value.interaction") value=value.interaction localize=true}}
{{formInput fields.priority name=(concat "system.changes." index ".priority") value=priority}}
</li>
</ol>
<div class="damage-thresholds-container">
<div class="damage-threshold-title">
<span>{{localize "DAGGERHEART.GENERAL.DamageThresholds.title"}}</span>
<input type="checkbox" class="armor-damage-thresholds-checkbox" data-index="{{index}}" {{checked value.damageThresholds}} />
</div>
{{#if value.damageThresholds}}
<div class="flexrow">
{{formGroup fields.value.fields.damageThresholds.fields.major name=(concat "system.changes." index ".value.damageThresholds.major") value=value.damageThresholds.major localize=true }}
{{formGroup fields.value.fields.damageThresholds.fields.severe name=(concat "system.changes." index ".value.damageThresholds.severe") value=value.damageThresholds.severe localize=true }}
</div>
{{/if}}
</div>