mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-22 07:23:37 +02:00
More fixes
This commit is contained in:
parent
caea55ade4
commit
b3e298693a
7 changed files with 57 additions and 36 deletions
|
|
@ -8,10 +8,7 @@ export default class DhActiveEffectConfig extends foundry.applications.sheets.Ac
|
||||||
}
|
}
|
||||||
|
|
||||||
static DEFAULT_OPTIONS = {
|
static DEFAULT_OPTIONS = {
|
||||||
classes: ['daggerheart', 'sheet', 'dh-style'],
|
classes: ['daggerheart', 'sheet', 'dh-style']
|
||||||
actions: {
|
|
||||||
addTypedChange: DhActiveEffectConfig.#addTypedChange
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static PARTS = {
|
static PARTS = {
|
||||||
|
|
|
||||||
|
|
@ -966,10 +966,13 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
||||||
const armorSources = [];
|
const armorSources = [];
|
||||||
for (var effect of Array.from(this.document.allApplicableEffects())) {
|
for (var effect of Array.from(this.document.allApplicableEffects())) {
|
||||||
const origin = effect.origin ? await foundry.utils.fromUuid(effect.origin) : effect.parent;
|
const origin = effect.origin ? await foundry.utils.fromUuid(effect.origin) : effect.parent;
|
||||||
if (effect.type !== 'armor' || effect.disabled || effect.isSuppressed) continue;
|
if (!effect.system.armorData || effect.disabled || effect.isSuppressed) continue;
|
||||||
|
|
||||||
|
const originIsActor = origin instanceof Actor;
|
||||||
|
const name = originIsActor ? effect.name : origin.name;
|
||||||
armorSources.push({
|
armorSources.push({
|
||||||
uuid: effect.uuid,
|
uuid: effect.uuid,
|
||||||
name: origin.name,
|
name,
|
||||||
...effect.system.armorData
|
...effect.system.armorData
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -1018,15 +1021,14 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
||||||
/** Update specific armor source */
|
/** Update specific armor source */
|
||||||
static async armorSourceUpdate(event) {
|
static async armorSourceUpdate(event) {
|
||||||
const effect = await foundry.utils.fromUuid(event.target.dataset.uuid);
|
const effect = await foundry.utils.fromUuid(event.target.dataset.uuid);
|
||||||
if (effect.system.changes.length !== 1) return;
|
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 value = Math.max(Math.min(Number.parseInt(event.target.value), effect.system.armorData.max), 0);
|
||||||
|
|
||||||
const newChanges = [
|
const newChanges = effect.system.changes.map(change => ({
|
||||||
{
|
...change,
|
||||||
...effect.system.changes[0],
|
value: change.type === 'armor' ? value : change.value
|
||||||
value
|
}));
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
event.target.value = value;
|
event.target.value = value;
|
||||||
const progressBar = event.target.closest('.status-bar.armor-slots').querySelector('progress');
|
const progressBar = event.target.closest('.status-bar.armor-slots').querySelector('progress');
|
||||||
|
|
@ -1038,19 +1040,19 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
||||||
static async armorSourcePipUpdate(event) {
|
static async armorSourcePipUpdate(event) {
|
||||||
const target = event.target.closest('.armor-slot');
|
const target = event.target.closest('.armor-slot');
|
||||||
const effect = await foundry.utils.fromUuid(target.dataset.uuid);
|
const effect = await foundry.utils.fromUuid(target.dataset.uuid);
|
||||||
if (effect.system.changes.length !== 1) return;
|
const armorChange = effect.system.armorChange;
|
||||||
const { value, max } = effect.system.armorData;
|
if (!armorChange) return;
|
||||||
|
|
||||||
|
const { value } = effect.system.armorData;
|
||||||
|
|
||||||
const inputValue = Number.parseInt(target.dataset.value);
|
const inputValue = Number.parseInt(target.dataset.value);
|
||||||
const decreasing = value >= inputValue;
|
const decreasing = value >= inputValue;
|
||||||
const newValue = decreasing ? inputValue - 1 : inputValue;
|
const newValue = decreasing ? inputValue - 1 : inputValue;
|
||||||
|
|
||||||
const newChanges = [
|
const newChanges = effect.system.changes.map(change => ({
|
||||||
{
|
...change,
|
||||||
...effect.system.changes[0],
|
value: change.type === 'armor' ? newValue : change.value
|
||||||
value: newValue
|
}));
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
const container = target.closest('.slot-bar');
|
const container = target.closest('.slot-bar');
|
||||||
for (const armorSlot of container.querySelectorAll('.armor-slot i')) {
|
for (const armorSlot of container.querySelectorAll('.armor-slot i')) {
|
||||||
|
|
|
||||||
|
|
@ -89,11 +89,15 @@ export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get armorChange() {
|
||||||
|
return this.changes.find(x => x.type === CONFIG.DH.GENERAL.activeEffectModes.armor.id);
|
||||||
|
}
|
||||||
|
|
||||||
get armorData() {
|
get armorData() {
|
||||||
const armorChange = this.changes.find(x => x.type === CONFIG.DH.GENERAL.activeEffectModes.armor.id);
|
const armorChange = this.armorChange;
|
||||||
if (!armorChange) return null;
|
if (!armorChange) return null;
|
||||||
|
|
||||||
return armorChange.armorData;
|
return armorChange.typeData.getArmorData(armorChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getDefaultObject() {
|
static getDefaultObject() {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
import { itemAbleRollParse } from '../../../helpers/utils.mjs';
|
||||||
|
|
||||||
const fields = foundry.data.fields;
|
const fields = foundry.data.fields;
|
||||||
|
|
||||||
export default class Armor extends foundry.abstract.DataModel {
|
export default class Armor extends foundry.abstract.DataModel {
|
||||||
|
|
@ -76,14 +78,14 @@ export default class Armor extends foundry.abstract.DataModel {
|
||||||
|
|
||||||
/* Helpers */
|
/* Helpers */
|
||||||
|
|
||||||
get armorData() {
|
getArmorData(parentChange) {
|
||||||
const actor = this.parent.parent?.actor?.type === 'character' ? this.parent.parent.actor : null;
|
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.max, actor, this.parent.parent.parent) : null;
|
||||||
const maxRoll = maxParse ? new Roll(maxParse).evaluateSync() : null;
|
const maxRoll = maxParse ? new Roll(maxParse).evaluateSync() : null;
|
||||||
const maxEvaluated = maxRoll ? (maxRoll.isDeterministic ? maxRoll.total : null) : null;
|
const maxEvaluated = maxRoll ? (maxRoll.isDeterministic ? maxRoll.total : null) : null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
value: this.value,
|
value: parentChange.value,
|
||||||
max: maxEvaluated ?? this.max
|
max: maxEvaluated ?? this.max
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -469,8 +469,8 @@ export default class DhCharacter extends DhCreature {
|
||||||
|
|
||||||
const increasing = armorChange >= 0;
|
const increasing = armorChange >= 0;
|
||||||
let remainingChange = Math.abs(armorChange);
|
let remainingChange = Math.abs(armorChange);
|
||||||
const armorEffects = Array.from(this.parent.allApplicableEffects()).filter(x => x.type === 'armor');
|
const armorEffects = Array.from(this.parent.allApplicableEffects()).filter(x => x.system.armorData);
|
||||||
const orderedEffects = game.system.api.data.activeEffects.ArmorEffect.orderEffectsForAutoChange(
|
const orderedEffects = game.system.api.data.activeEffects.changeTypes.armor.orderEffectsForAutoChange(
|
||||||
armorEffects,
|
armorEffects,
|
||||||
increasing
|
increasing
|
||||||
);
|
);
|
||||||
|
|
@ -482,11 +482,11 @@ export default class DhCharacter extends DhCreature {
|
||||||
usedArmorChange -= armorEffect.system.armorChange.value;
|
usedArmorChange -= armorEffect.system.armorChange.value;
|
||||||
} else {
|
} else {
|
||||||
if (increasing) {
|
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);
|
usedArmorChange = Math.min(remainingChange, remainingArmor);
|
||||||
remainingChange -= usedArmorChange;
|
remainingChange -= usedArmorChange;
|
||||||
} else {
|
} else {
|
||||||
const changeChange = Math.min(armorEffect.system.armorChange.value, remainingChange);
|
const changeChange = Math.min(armorEffect.system.armorData.value, remainingChange);
|
||||||
usedArmorChange -= changeChange;
|
usedArmorChange -= changeChange;
|
||||||
remainingChange -= changeChange;
|
remainingChange -= changeChange;
|
||||||
}
|
}
|
||||||
|
|
@ -499,12 +499,13 @@ export default class DhCharacter extends DhCreature {
|
||||||
|
|
||||||
embeddedUpdates[armorEffect.parent.id].updates.push({
|
embeddedUpdates[armorEffect.parent.id].updates.push({
|
||||||
'_id': armorEffect.id,
|
'_id': armorEffect.id,
|
||||||
'system.changes': [
|
'system.changes': armorEffect.system.changes.map(change => ({
|
||||||
{
|
...change,
|
||||||
...armorEffect.system.armorChange,
|
value:
|
||||||
value: armorEffect.system.armorChange.value + usedArmorChange
|
change.type === 'armor'
|
||||||
}
|
? armorEffect.system.armorChange.value + usedArmorChange
|
||||||
]
|
: change.value
|
||||||
|
}))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,21 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.armor-change-container {
|
.armor-change-container {
|
||||||
|
padding-top: 0;
|
||||||
|
padding-bottom: 4px;
|
||||||
|
row-gap: 0;
|
||||||
|
|
||||||
|
legend {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
padding-left: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
header {
|
||||||
|
padding: 0;
|
||||||
|
left: -0.25rem; // TODO: Find why this header is offset 0.25rem to the right so this can be removed.
|
||||||
|
}
|
||||||
|
|
||||||
header,
|
header,
|
||||||
ol {
|
ol {
|
||||||
grid-template-columns: 6rem 6rem 12rem 4rem;
|
grid-template-columns: 6rem 6rem 12rem 4rem;
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</ol>
|
</ol>
|
||||||
|
|
||||||
<fieldset class="armor-change-container">
|
<fieldset class="armor-change-container {{#unless typedChanges.armor}}empty{{/unless}}">
|
||||||
<legend>{{localize "DAGGERHEART.GENERAL.armor"}} <input type="checkbox" class="armor-change-checkbox" data-index="{{typedChanges.armor.index}}" {{checked typedChanges.armor}} /></legend>
|
<legend>{{localize "DAGGERHEART.GENERAL.armor"}} <input type="checkbox" class="armor-change-checkbox" data-index="{{typedChanges.armor.index}}" {{checked typedChanges.armor}} /></legend>
|
||||||
{{#if typedChanges.armor}}
|
{{#if typedChanges.armor}}
|
||||||
<header>
|
<header>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue