mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-21 23:13:39 +02:00
Fixed so changing armor values and taking damage works again
This commit is contained in:
parent
809bdc8678
commit
e83d3f7d44
7 changed files with 42 additions and 32 deletions
|
|
@ -27,11 +27,11 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap
|
|||
true
|
||||
);
|
||||
const armor = orderedArmorEffects.reduce((acc, effect) => {
|
||||
const { value, max } = effect.system.armorData;
|
||||
const { current, max } = effect.system.armorData;
|
||||
acc.push({
|
||||
effect: effect,
|
||||
marks: [...Array(max).keys()].reduce((acc, _, index) => {
|
||||
const spent = index < value;
|
||||
const spent = index < current;
|
||||
acc[foundry.utils.randomID()] = { selected: false, disabled: spent, spent };
|
||||
return acc;
|
||||
}, {})
|
||||
|
|
@ -192,7 +192,7 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap
|
|||
const stressReductions = this.availableStressReductions
|
||||
? Object.values(this.availableStressReductions).filter(red => red.selected)
|
||||
: [];
|
||||
const currentMarks = this.actor.system.armorScore.value + selectedArmorMarks.length;
|
||||
const currentMarks = this.actor.system.armorScore.current + selectedArmorMarks.length;
|
||||
|
||||
const maxArmorUsed = this.actor.system.rules.damageReduction.maxArmorMarked.value + selectedStressMarks.length;
|
||||
const availableArmor =
|
||||
|
|
|
|||
|
|
@ -1003,16 +1003,16 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
const effect = await foundry.utils.fromUuid(event.target.dataset.uuid);
|
||||
const armorChange = effect.system.armorChange;
|
||||
if (!armorChange) return;
|
||||
const value = Math.max(Math.min(Number.parseInt(event.target.value), effect.system.armorData.max), 0);
|
||||
const current = Math.max(Math.min(Number.parseInt(event.target.value), effect.system.armorData.max), 0);
|
||||
|
||||
const newChanges = effect.system.changes.map(change => ({
|
||||
...change,
|
||||
value: change.type === 'armor' ? value : change.value
|
||||
value: change.type === 'armor' ? { ...change.value, current } : change.value
|
||||
}));
|
||||
|
||||
event.target.value = value;
|
||||
event.target.value = current;
|
||||
const progressBar = event.target.closest('.status-bar.armor-slots').querySelector('progress');
|
||||
progressBar.value = value;
|
||||
progressBar.value = current;
|
||||
|
||||
await effect.update({ 'system.changes': newChanges });
|
||||
}
|
||||
|
|
@ -1023,24 +1023,24 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
|||
const armorChange = effect.system.armorChange;
|
||||
if (!armorChange) return;
|
||||
|
||||
const { value } = effect.system.armorData;
|
||||
const { current } = effect.system.armorData;
|
||||
|
||||
const inputValue = Number.parseInt(target.dataset.value);
|
||||
const decreasing = value >= inputValue;
|
||||
const newValue = decreasing ? inputValue - 1 : inputValue;
|
||||
const decreasing = current >= inputValue;
|
||||
const newCurrent = decreasing ? inputValue - 1 : inputValue;
|
||||
|
||||
const newChanges = effect.system.changes.map(change => ({
|
||||
...change,
|
||||
value: change.type === 'armor' ? newValue : change.value
|
||||
value: change.type === 'armor' ? { ...change.value, current: newCurrent } : change.value
|
||||
}));
|
||||
|
||||
const container = target.closest('.slot-bar');
|
||||
for (const armorSlot of container.querySelectorAll('.armor-slot i')) {
|
||||
const index = Number.parseInt(armorSlot.dataset.index);
|
||||
if (decreasing && index >= newValue) {
|
||||
if (decreasing && index >= newCurrent) {
|
||||
armorSlot.classList.remove('fa-shield');
|
||||
armorSlot.classList.add('fa-shield-halved');
|
||||
} else if (!decreasing && index < newValue) {
|
||||
} else if (!decreasing && index < newCurrent) {
|
||||
armorSlot.classList.add('fa-shield');
|
||||
armorSlot.classList.remove('fa-shield-halved');
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,8 +51,8 @@ export default class ArmorSheet extends ItemAttachmentSheet(DHBaseItemSheet) {
|
|||
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');
|
||||
context.effects.actives = context.effects.actives.filter(x => !x.system.armorData);
|
||||
context.effects.inactives = context.effects.inactives.filter(x => !x.system.armorData);
|
||||
break;
|
||||
}
|
||||
|
||||
|
|
@ -64,7 +64,7 @@ export default class ArmorSheet extends ItemAttachmentSheet(DHBaseItemSheet) {
|
|||
const armorEffect = this.document.system.armorEffect;
|
||||
if (Number.isNaN(value) || !armorEffect) return;
|
||||
|
||||
await armorEffect.system.armorChange.typeData.updateArmorMax(value);
|
||||
await armorEffect.system.armorChange.updateArmorMax(value);
|
||||
this.render();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel {
|
|||
const armorChange = this.armorChange;
|
||||
if (!armorChange) return null;
|
||||
|
||||
return armorChange.getArmorData(armorChange);
|
||||
return armorChange.getArmorData();
|
||||
}
|
||||
|
||||
static getDefaultObject() {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ export default class ArmorChange extends foundry.abstract.DataModel {
|
|||
label: 'DAGGERHEART.EFFECTS.ChangeTypes.armor.FIELDS.interaction.label',
|
||||
hint: 'DAGGERHEART.EFFECTS.ChangeTypes.armor.FIELDS.interaction.hint'
|
||||
})
|
||||
}),
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -94,15 +94,15 @@ export default class ArmorChange extends foundry.abstract.DataModel {
|
|||
|
||||
/* Helpers */
|
||||
|
||||
getArmorData(parentChange) {
|
||||
getArmorData() {
|
||||
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 maxParse = actor ? itemAbleRollParse(this.value.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: parentChange.value,
|
||||
max: maxEvaluated ?? this.max
|
||||
current: this.value.current,
|
||||
max: maxEvaluated ?? this.value.max
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -110,8 +110,14 @@ export default class ArmorChange extends foundry.abstract.DataModel {
|
|||
const newChanges = [
|
||||
...this.parent.changes.map(change => ({
|
||||
...change,
|
||||
value: change.type === 'armor' ? Math.min(change.value, newMax) : change.value,
|
||||
typeData: change.type === 'armor' ? { ...change.typeData, max: newMax } : change.typeData
|
||||
value:
|
||||
change.type === 'armor'
|
||||
? {
|
||||
...change.value,
|
||||
current: Math.min(change.value.current, newMax),
|
||||
max: newMax
|
||||
}
|
||||
: change.value
|
||||
}))
|
||||
];
|
||||
await this.parent.parent.update({ 'system.changes': newChanges });
|
||||
|
|
|
|||
|
|
@ -479,14 +479,14 @@ export default class DhCharacter extends DhCreature {
|
|||
for (const armorEffect of orderedEffects) {
|
||||
let usedArmorChange = 0;
|
||||
if (clear) {
|
||||
usedArmorChange -= armorEffect.system.armorChange.value;
|
||||
usedArmorChange -= armorEffect.system.armorChange.value.current;
|
||||
} else {
|
||||
if (increasing) {
|
||||
const remainingArmor = armorEffect.system.armorData.max - armorEffect.system.armorData.value;
|
||||
const remainingArmor = armorEffect.system.armorData.max - armorEffect.system.armorData.current;
|
||||
usedArmorChange = Math.min(remainingChange, remainingArmor);
|
||||
remainingChange -= usedArmorChange;
|
||||
} else {
|
||||
const changeChange = Math.min(armorEffect.system.armorData.value, remainingChange);
|
||||
const changeChange = Math.min(armorEffect.system.armorData.current, remainingChange);
|
||||
usedArmorChange -= changeChange;
|
||||
remainingChange -= changeChange;
|
||||
}
|
||||
|
|
@ -503,7 +503,10 @@ export default class DhCharacter extends DhCreature {
|
|||
...change,
|
||||
value:
|
||||
change.type === 'armor'
|
||||
? armorEffect.system.armorChange.value + usedArmorChange
|
||||
? {
|
||||
...change.value,
|
||||
current: armorEffect.system.armorChange.value.current + usedArmorChange
|
||||
}
|
||||
: change.value
|
||||
}))
|
||||
});
|
||||
|
|
@ -519,11 +522,12 @@ export default class DhCharacter extends DhCreature {
|
|||
|
||||
async updateArmorEffectValue({ uuid, value }) {
|
||||
const effect = await foundry.utils.fromUuid(uuid);
|
||||
const effectValue = effect.system.armorChange.value;
|
||||
await effect.update({
|
||||
'system.changes': [
|
||||
{
|
||||
...effect.system.armorChange,
|
||||
value: effect.system.armorChange.value + value
|
||||
value: { ...effectValue, current: effectValue.current + value }
|
||||
}
|
||||
]
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
<div class="slot-bar">
|
||||
{{#times source.max}}
|
||||
<a class='armor-slot' data-value="{{add this 1}}" data-uuid="{{source.uuid}}">
|
||||
{{#if (gte ../value (add this 1))}}
|
||||
{{#if (gte ../current (add this 1))}}
|
||||
<i class="fa-solid fa-shield" data-index="{{this}}"></i>
|
||||
{{else}}
|
||||
<i class="fa-solid fa-shield-halved" data-index="{{this}}"></i>
|
||||
|
|
@ -21,13 +21,13 @@
|
|||
<p class="armor-source-label">{{source.name}}</p>
|
||||
<div class="status-bar armor-slots">
|
||||
<div class='status-value'>
|
||||
<input class="bar-input armor-marks-input" value="{{source.value}}" data-uuid="{{source.uuid}}" type="number">
|
||||
<input class="bar-input armor-marks-input" value="{{source.current}}" data-uuid="{{source.uuid}}" type="number">
|
||||
<span>/</span>
|
||||
<span class="bar-label">{{source.max}}</span>
|
||||
</div>
|
||||
<progress
|
||||
class='progress-bar stress-color'
|
||||
value='{{source.value}}'
|
||||
value='{{source.current}}'
|
||||
max='{{source.max}}'
|
||||
></progress>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue