mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-22 07:23:37 +02:00
Readded so that armor items have their system defined armor instead of using an ActiveEffect
This commit is contained in:
parent
50dcbf4396
commit
1cdabf15a5
11 changed files with 198 additions and 161 deletions
|
|
@ -21,15 +21,17 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap
|
||||||
this.rulesDefault
|
this.rulesDefault
|
||||||
);
|
);
|
||||||
|
|
||||||
const allArmorEffects = Array.from(actor.allApplicableEffects()).filter(x => x.system.armorData);
|
const allArmorSources = Array.from(actor.allApplicableEffects()).filter(x => x.system.armorData);
|
||||||
const orderedArmorEffects = game.system.api.data.activeEffects.changeTypes.armor.orderEffectsForAutoChange(
|
if (actor.system.armor) allArmorSources.push(actor.system.armor);
|
||||||
allArmorEffects,
|
|
||||||
|
const orderedArmorSources = game.system.api.data.activeEffects.changeTypes.armor.orderEffectsForAutoChange(
|
||||||
|
allArmorSources,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
const armor = orderedArmorEffects.reduce((acc, effect) => {
|
const armor = orderedArmorSources.reduce((acc, source) => {
|
||||||
const { current, max } = effect.system.armorData;
|
const { current, max } = source.type === 'armor' ? source.system.armor : source.system.armorData;
|
||||||
acc.push({
|
acc.push({
|
||||||
effect: effect,
|
effect: source,
|
||||||
marks: [...Array(max).keys()].reduce((acc, _, index) => {
|
marks: [...Array(max).keys()].reduce((acc, _, index) => {
|
||||||
const spent = index < current;
|
const spent = index < current;
|
||||||
acc[foundry.utils.randomID()] = { selected: false, disabled: spent, spent };
|
acc[foundry.utils.randomID()] = { selected: false, disabled: spent, spent };
|
||||||
|
|
@ -159,8 +161,11 @@ export default class DamageReductionDialog extends HandlebarsApplicationMixin(Ap
|
||||||
const parent = source.effect.origin
|
const parent = source.effect.origin
|
||||||
? await foundry.utils.fromUuid(source.effect.origin)
|
? await foundry.utils.fromUuid(source.effect.origin)
|
||||||
: source.effect.parent;
|
: source.effect.parent;
|
||||||
|
|
||||||
|
const useEffectName = parent.type === 'armor' || parent instanceof Actor;
|
||||||
|
const label = useEffectName ? source.effect.name : parent.name;
|
||||||
armorSources.push({
|
armorSources.push({
|
||||||
label: parent.name,
|
label: label,
|
||||||
uuid: source.effect.uuid,
|
uuid: source.effect.uuid,
|
||||||
marks: source.marks
|
marks: source.marks
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -948,8 +948,8 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
||||||
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.system.armorData || effect.disabled || effect.isSuppressed) continue;
|
if (!effect.system.armorData || effect.disabled || effect.isSuppressed) continue;
|
||||||
|
|
||||||
const originIsActor = origin instanceof Actor;
|
const useEffectName = origin.type === 'armor' || origin instanceof Actor;
|
||||||
const name = originIsActor ? effect.name : origin.name;
|
const name = useEffectName ? effect.name : origin.name;
|
||||||
armorSources.push({
|
armorSources.push({
|
||||||
uuid: effect.uuid,
|
uuid: effect.uuid,
|
||||||
name,
|
name,
|
||||||
|
|
@ -957,6 +957,15 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.document.system.armor) {
|
||||||
|
armorSources.push({
|
||||||
|
...this.document.system.armor.system.armor,
|
||||||
|
uuid: this.document.system.armor.uuid,
|
||||||
|
name: this.document.system.armor.name,
|
||||||
|
isArmorItem: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!armorSources.length) return;
|
if (!armorSources.length) return;
|
||||||
|
|
||||||
const useResourcePips = game.settings.get(
|
const useResourcePips = game.settings.get(
|
||||||
|
|
@ -980,11 +989,6 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
||||||
direction: 'DOWN'
|
direction: 'DOWN'
|
||||||
});
|
});
|
||||||
|
|
||||||
html.querySelectorAll('.armor-marks-input').forEach(element => {
|
|
||||||
element.addEventListener('blur', CharacterSheet.armorSourceUpdate);
|
|
||||||
element.addEventListener('input', CharacterSheet.armorSourceInput);
|
|
||||||
});
|
|
||||||
|
|
||||||
html.querySelectorAll('.armor-slot').forEach(element => {
|
html.querySelectorAll('.armor-slot').forEach(element => {
|
||||||
element.addEventListener('click', CharacterSheet.armorSourcePipUpdate);
|
element.addEventListener('click', CharacterSheet.armorSourcePipUpdate);
|
||||||
});
|
});
|
||||||
|
|
@ -999,49 +1003,49 @@ export default class CharacterSheet extends DHBaseActorSheet {
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Update specific armor source */
|
/** Update specific armor source */
|
||||||
static async armorSourceUpdate(event) {
|
|
||||||
const effect = await foundry.utils.fromUuid(event.target.dataset.uuid);
|
|
||||||
const armorChange = effect.system.armorChange;
|
|
||||||
if (!armorChange) return;
|
|
||||||
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' ? { ...change.value, current } : change.value
|
|
||||||
}));
|
|
||||||
|
|
||||||
event.target.value = current;
|
|
||||||
const progressBar = event.target.closest('.status-bar.armor-slots').querySelector('progress');
|
|
||||||
progressBar.value = current;
|
|
||||||
|
|
||||||
await effect.update({ 'system.changes': newChanges });
|
|
||||||
}
|
|
||||||
|
|
||||||
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 { uuid, value, isArmorItem: isArmorItemString } = target.dataset;
|
||||||
const armorChange = effect.system.armorChange;
|
const isArmorItem = Boolean(isArmorItemString);
|
||||||
if (!armorChange) return;
|
|
||||||
|
|
||||||
const { current } = effect.system.armorData;
|
let inputValue = Number.parseInt(value);
|
||||||
|
let decreasing = false;
|
||||||
|
let newCurrent = 0;
|
||||||
|
|
||||||
const inputValue = Number.parseInt(target.dataset.value);
|
if (isArmorItem) {
|
||||||
const decreasing = current >= inputValue;
|
const armor = await foundry.utils.fromUuid(uuid);
|
||||||
const newCurrent = decreasing ? inputValue - 1 : inputValue;
|
decreasing = armor.system.armor.current >= inputValue;
|
||||||
|
newCurrent = decreasing ? inputValue - 1 : inputValue;
|
||||||
|
|
||||||
const newChanges = effect.system.changes.map(change => ({
|
await armor.update({ 'system.armor.current': newCurrent });
|
||||||
...change,
|
} else {
|
||||||
value: change.type === 'armor' ? { ...change.value, current: newCurrent } : change.value
|
const effect = await foundry.utils.fromUuid(uuid);
|
||||||
}));
|
const armorChange = effect.system.armorChange;
|
||||||
|
if (!armorChange) return;
|
||||||
|
|
||||||
|
const { current } = effect.system.armorData;
|
||||||
|
decreasing = current >= inputValue;
|
||||||
|
newCurrent = decreasing ? inputValue - 1 : inputValue;
|
||||||
|
|
||||||
|
const newChanges = effect.system.changes.map(change => ({
|
||||||
|
...change,
|
||||||
|
value: change.type === 'armor' ? { ...change.value, current: newCurrent } : change.value
|
||||||
|
}));
|
||||||
|
|
||||||
|
await effect.update({ 'system.changes': newChanges });
|
||||||
|
}
|
||||||
|
|
||||||
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')) {
|
||||||
const marked = !decreasing && Number.parseInt(armorSlot.dataset.index) < newCurrent;
|
const index = Number.parseInt(armorSlot.dataset.index);
|
||||||
armorSlot.classList.toggle('fa-shield', marked);
|
if (decreasing && index >= newCurrent) {
|
||||||
armorSlot.classList.toggle('fa-shield-halved', !marked);
|
armorSlot.classList.remove('fa-shield');
|
||||||
|
armorSlot.classList.add('fa-shield-halved');
|
||||||
|
} else if (!decreasing && index < newCurrent) {
|
||||||
|
armorSlot.classList.add('fa-shield');
|
||||||
|
armorSlot.classList.remove('fa-shield-halved');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await effect.update({ 'system.changes': newChanges });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #toggleResourceManagement(event, button) {
|
static async #toggleResourceManagement(event, button) {
|
||||||
|
|
|
||||||
|
|
@ -34,13 +34,6 @@ export default class ArmorSheet extends ItemAttachmentSheet(DHBaseItemSheet) {
|
||||||
...super.PARTS
|
...super.PARTS
|
||||||
};
|
};
|
||||||
|
|
||||||
_attachPartListeners(partId, htmlElement, options) {
|
|
||||||
super._attachPartListeners(partId, htmlElement, options);
|
|
||||||
|
|
||||||
for (const element of htmlElement.querySelectorAll('.base-score-input'))
|
|
||||||
element.addEventListener('change', this.updateArmorEffect.bind(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**@inheritdoc */
|
/**@inheritdoc */
|
||||||
async _preparePartContext(partId, context) {
|
async _preparePartContext(partId, context) {
|
||||||
await super._preparePartContext(partId, context);
|
await super._preparePartContext(partId, context);
|
||||||
|
|
@ -48,11 +41,6 @@ export default class ArmorSheet extends ItemAttachmentSheet(DHBaseItemSheet) {
|
||||||
switch (partId) {
|
switch (partId) {
|
||||||
case 'settings':
|
case 'settings':
|
||||||
context.features = this.document.system.armorFeatures.map(x => x.value);
|
context.features = this.document.system.armorFeatures.map(x => x.value);
|
||||||
context.armorScore = this.document.system.armorData.max;
|
|
||||||
break;
|
|
||||||
case 'effects':
|
|
||||||
context.effects.actives = context.effects.actives.filter(x => !x.system.armorData);
|
|
||||||
context.effects.inactives = context.effects.inactives.filter(x => !x.system.armorData);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -151,7 +151,7 @@ export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel {
|
||||||
const newArmorTotal = (changed.system?.changes ?? []).reduce((acc, change) => {
|
const newArmorTotal = (changed.system?.changes ?? []).reduce((acc, change) => {
|
||||||
if (change.type === 'armor') acc += change.value.current;
|
if (change.type === 'armor') acc += change.value.current;
|
||||||
return acc;
|
return acc;
|
||||||
}, 0);
|
}, this.parent.actor.system.armor?.system?.armor?.current ?? 0);
|
||||||
|
|
||||||
const armorData = getScrollTextData(this.parent.actor, { value: newArmorTotal }, 'armor');
|
const armorData = getScrollTextData(this.parent.actor, { value: newArmorTotal }, 'armor');
|
||||||
options.scrollingTextData = [armorData];
|
options.scrollingTextData = [armorData];
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import DhCreature from './creature.mjs';
|
||||||
import { attributeField, stressDamageReductionRule, bonusField } from '../fields/actorField.mjs';
|
import { attributeField, stressDamageReductionRule, bonusField } from '../fields/actorField.mjs';
|
||||||
import { ActionField } from '../fields/actionField.mjs';
|
import { ActionField } from '../fields/actionField.mjs';
|
||||||
import DHCharacterSettings from '../../applications/sheets-configs/character-settings.mjs';
|
import DHCharacterSettings from '../../applications/sheets-configs/character-settings.mjs';
|
||||||
|
import { orderSourcesForArmorAutoChange } from '../../helpers/utils.mjs';
|
||||||
|
|
||||||
export default class DhCharacter extends DhCreature {
|
export default class DhCharacter extends DhCreature {
|
||||||
/**@override */
|
/**@override */
|
||||||
|
|
@ -469,43 +470,60 @@ 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.system.armorData);
|
const armorSources = Array.from(this.parent.allApplicableEffects()).filter(x => x.system.armorData);
|
||||||
const orderedEffects = game.system.api.data.activeEffects.changeTypes.armor.orderEffectsForAutoChange(
|
if (this.armor) armorSources.push(this.armor);
|
||||||
armorEffects,
|
|
||||||
increasing
|
|
||||||
);
|
|
||||||
|
|
||||||
const embeddedUpdates = [];
|
const orderedSources = orderSourcesForArmorAutoChange(armorSources, increasing);
|
||||||
for (const armorEffect of orderedEffects) {
|
|
||||||
|
const handleArmorData = (embeddedUpdates, doc, armorData) => {
|
||||||
let usedArmorChange = 0;
|
let usedArmorChange = 0;
|
||||||
if (clear) {
|
if (clear) {
|
||||||
usedArmorChange -= armorEffect.system.armorChange.value.current;
|
usedArmorChange -= armorData.current;
|
||||||
} else {
|
} else {
|
||||||
if (increasing) {
|
if (increasing) {
|
||||||
const remainingArmor = armorEffect.system.armorData.max - armorEffect.system.armorData.current;
|
const remainingArmor = armorData.max - armorData.current;
|
||||||
usedArmorChange = Math.min(remainingChange, remainingArmor);
|
usedArmorChange = Math.min(remainingChange, remainingArmor);
|
||||||
remainingChange -= usedArmorChange;
|
remainingChange -= usedArmorChange;
|
||||||
} else {
|
} else {
|
||||||
const changeChange = Math.min(armorEffect.system.armorData.current, remainingChange);
|
const changeChange = Math.min(armorData.current, remainingChange);
|
||||||
usedArmorChange -= changeChange;
|
usedArmorChange -= changeChange;
|
||||||
remainingChange -= changeChange;
|
remainingChange -= changeChange;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!usedArmorChange) continue;
|
if (!usedArmorChange) return usedArmorChange;
|
||||||
else {
|
else {
|
||||||
if (!embeddedUpdates[armorEffect.parent.id])
|
if (!embeddedUpdates[doc.id]) embeddedUpdates[doc.id] = { doc: doc, updates: [] };
|
||||||
embeddedUpdates[armorEffect.parent.id] = { doc: armorEffect.parent, updates: [] };
|
|
||||||
|
|
||||||
embeddedUpdates[armorEffect.parent.id].updates.push({
|
return usedArmorChange;
|
||||||
'_id': armorEffect.id,
|
}
|
||||||
'system.changes': armorEffect.system.changes.map(change => ({
|
};
|
||||||
|
|
||||||
|
const armorUpdates = [];
|
||||||
|
const effectUpdates = [];
|
||||||
|
for (const armorSource of orderedSources) {
|
||||||
|
const usedArmorChange = handleArmorData(
|
||||||
|
armorSource.type === 'armor' ? armorUpdates : effectUpdates,
|
||||||
|
armorSource.parent,
|
||||||
|
armorSource.type === 'armor' ? armorSource.system.armor : armorSource.system.armorData
|
||||||
|
);
|
||||||
|
if (!usedArmorChange) continue;
|
||||||
|
|
||||||
|
if (armorSource.type === 'armor') {
|
||||||
|
armorUpdates[armorSource.parent.id].updates.push({
|
||||||
|
'_id': armorSource.id,
|
||||||
|
'system.armor.current': armorSource.system.armor.current + usedArmorChange
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
effectUpdates[armorSource.parent.id].updates.push({
|
||||||
|
'_id': armorSource.id,
|
||||||
|
'system.changes': armorSource.system.changes.map(change => ({
|
||||||
...change,
|
...change,
|
||||||
value:
|
value:
|
||||||
change.type === 'armor'
|
change.type === 'armor'
|
||||||
? {
|
? {
|
||||||
...change.value,
|
...change.value,
|
||||||
current: armorEffect.system.armorChange.value.current + usedArmorChange
|
current: armorSource.system.armorChange.value.current + usedArmorChange
|
||||||
}
|
}
|
||||||
: change.value
|
: change.value
|
||||||
}))
|
}))
|
||||||
|
|
@ -515,22 +533,34 @@ export default class DhCharacter extends DhCreature {
|
||||||
if (remainingChange === 0 && !clear) break;
|
if (remainingChange === 0 && !clear) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
const updateValues = Object.values(embeddedUpdates);
|
const armorUpdateValues = Object.values(armorUpdates);
|
||||||
for (const [index, { doc, updates }] of updateValues.entries())
|
for (const [index, { doc, updates }] of armorUpdateValues.entries())
|
||||||
await doc.updateEmbeddedDocuments('ActiveEffect', updates, { render: index === updateValues.length - 1 });
|
await doc.updateEmbeddedDocuments('Item', updates, { render: index === armorUpdateValues.length - 1 });
|
||||||
|
|
||||||
|
const effectUpdateValues = Object.values(effectUpdates);
|
||||||
|
for (const [index, { doc, updates }] of effectUpdateValues.entries())
|
||||||
|
await doc.updateEmbeddedDocuments('ActiveEffect', updates, {
|
||||||
|
render: index === effectUpdateValues.length - 1
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateArmorEffectValue({ uuid, value }) {
|
async updateArmorEffectValue({ uuid, value }) {
|
||||||
const effect = await foundry.utils.fromUuid(uuid);
|
const source = await foundry.utils.fromUuid(uuid);
|
||||||
const effectValue = effect.system.armorChange.value;
|
if (source.type === 'armor') {
|
||||||
await effect.update({
|
await source.update({
|
||||||
'system.changes': [
|
'system.armor.current': source.system.armor.current + value
|
||||||
{
|
});
|
||||||
...effect.system.armorChange,
|
} else {
|
||||||
value: { ...effectValue, current: effectValue.current + value }
|
const effectValue = source.system.armorChange.value;
|
||||||
}
|
await source.update({
|
||||||
]
|
'system.changes': [
|
||||||
});
|
{
|
||||||
|
...source.system.armorChange,
|
||||||
|
value: { ...effectValue, current: effectValue.current + value }
|
||||||
|
}
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get sheetLists() {
|
get sheetLists() {
|
||||||
|
|
@ -657,8 +687,8 @@ export default class DhCharacter extends DhCreature {
|
||||||
prepareBaseData() {
|
prepareBaseData() {
|
||||||
super.prepareBaseData();
|
super.prepareBaseData();
|
||||||
this.armorScore = {
|
this.armorScore = {
|
||||||
max: 0,
|
max: this.armor?.system.armor.max ?? 0,
|
||||||
value: 0
|
value: this.armor?.system.armor.current ?? 0
|
||||||
};
|
};
|
||||||
this.evasion += this.class.value?.system?.evasion ?? 0;
|
this.evasion += this.class.value?.system?.evasion ?? 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,14 @@ export default class DHArmor extends AttachableItem {
|
||||||
...super.defineSchema(),
|
...super.defineSchema(),
|
||||||
tier: new fields.NumberField({ required: true, integer: true, initial: 1, min: 1 }),
|
tier: new fields.NumberField({ required: true, integer: true, initial: 1, min: 1 }),
|
||||||
equipped: new fields.BooleanField({ initial: false }),
|
equipped: new fields.BooleanField({ initial: false }),
|
||||||
|
armor: new fields.SchemaField({
|
||||||
|
current: new fields.NumberField({ integer: true, min: 0, initial: 0 }),
|
||||||
|
max: new fields.NumberField({ required: true, integer: true, initial: 0 })
|
||||||
|
}),
|
||||||
|
baseThresholds: new fields.SchemaField({
|
||||||
|
major: new fields.NumberField({ integer: true, initial: 0 }),
|
||||||
|
severe: new fields.NumberField({ integer: true, initial: 0 })
|
||||||
|
}),
|
||||||
armorFeatures: new fields.ArrayField(
|
armorFeatures: new fields.ArrayField(
|
||||||
new fields.SchemaField({
|
new fields.SchemaField({
|
||||||
value: new fields.StringField({
|
value: new fields.StringField({
|
||||||
|
|
@ -27,11 +35,7 @@ export default class DHArmor extends AttachableItem {
|
||||||
effectIds: new fields.ArrayField(new fields.StringField({ required: true })),
|
effectIds: new fields.ArrayField(new fields.StringField({ required: true })),
|
||||||
actionIds: new fields.ArrayField(new fields.StringField({ required: true }))
|
actionIds: new fields.ArrayField(new fields.StringField({ required: true }))
|
||||||
})
|
})
|
||||||
),
|
)
|
||||||
baseThresholds: new fields.SchemaField({
|
|
||||||
major: new fields.NumberField({ integer: true, initial: 0 }),
|
|
||||||
severe: new fields.NumberField({ integer: true, initial: 0 })
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,17 +52,6 @@ export default class DHArmor extends AttachableItem {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get armorEffect() {
|
|
||||||
return this.parent.effects.find(x => x.system.armorData);
|
|
||||||
}
|
|
||||||
|
|
||||||
get armorData() {
|
|
||||||
const armorEffect = this.armorEffect;
|
|
||||||
if (!armorEffect) return { value: 0, max: 0 };
|
|
||||||
|
|
||||||
return armorEffect.system.armorData;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**@inheritdoc */
|
/**@inheritdoc */
|
||||||
async getDescriptionData() {
|
async getDescriptionData() {
|
||||||
const baseDescription = this.description;
|
const baseDescription = this.description;
|
||||||
|
|
@ -73,17 +66,6 @@ export default class DHArmor extends AttachableItem {
|
||||||
return { prefix, value: baseDescription, suffix: null };
|
return { prefix, value: baseDescription, suffix: null };
|
||||||
}
|
}
|
||||||
|
|
||||||
/**@inheritdoc */
|
|
||||||
async _onCreate(_data, _options, userId) {
|
|
||||||
if (userId !== game.user.id) return;
|
|
||||||
|
|
||||||
if (!this.parent.effects.some(x => x.system.armorData)) {
|
|
||||||
this.parent.createEmbeddedDocuments('ActiveEffect', [
|
|
||||||
game.system.api.data.activeEffects.changeTypes.armor.getDefaultArmorEffect()
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**@inheritdoc */
|
/**@inheritdoc */
|
||||||
async _preUpdate(changes, options, user) {
|
async _preUpdate(changes, options, user) {
|
||||||
const allowed = await super._preUpdate(changes, options, user);
|
const allowed = await super._preUpdate(changes, options, user);
|
||||||
|
|
@ -184,7 +166,7 @@ export default class DHArmor extends AttachableItem {
|
||||||
*/
|
*/
|
||||||
_getTags() {
|
_getTags() {
|
||||||
const tags = [
|
const tags = [
|
||||||
`${game.i18n.localize('DAGGERHEART.ITEMS.Armor.baseScore')}: ${this.armorData.max}`,
|
`${game.i18n.localize('DAGGERHEART.ITEMS.Armor.baseScore')}: ${this.armor.max}`,
|
||||||
`${game.i18n.localize('DAGGERHEART.ITEMS.Armor.baseThresholds.base')}: ${this.baseThresholds.major} / ${this.baseThresholds.severe}`
|
`${game.i18n.localize('DAGGERHEART.ITEMS.Armor.baseThresholds.base')}: ${this.baseThresholds.major} / ${this.baseThresholds.severe}`
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -196,7 +178,7 @@ export default class DHArmor extends AttachableItem {
|
||||||
* @returns {(string | { value: string, icons: string[] })[]} An array of localized strings and damage label objects.
|
* @returns {(string | { value: string, icons: string[] })[]} An array of localized strings and damage label objects.
|
||||||
*/
|
*/
|
||||||
_getLabels() {
|
_getLabels() {
|
||||||
const labels = [`${game.i18n.localize('DAGGERHEART.ITEMS.Armor.baseScore')}: ${this.armorData.max}`];
|
const labels = [`${game.i18n.localize('DAGGERHEART.ITEMS.Armor.baseScore')}: ${this.armor.max}`];
|
||||||
return labels;
|
return labels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -220,6 +220,19 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
||||||
|
|
||||||
addLinkedItemsDiff(changed.system?.features, this.features, options);
|
addLinkedItemsDiff(changed.system?.features, this.features, options);
|
||||||
|
|
||||||
|
const autoSettings = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation);
|
||||||
|
const armorChanged =
|
||||||
|
changed.system?.armor?.current !== undefined && changed.system.armor.current !== this.armor.current;
|
||||||
|
if (armorChanged && autoSettings.resourceScrollTexts && this.parent.parent?.type === 'character') {
|
||||||
|
const armorChangeValue = changed.system.armor.current - this.armor.current;
|
||||||
|
const armorData = getScrollTextData(
|
||||||
|
this.parent.parent,
|
||||||
|
{ value: armorChangeValue + this.parent.parent.system.armorScore.value },
|
||||||
|
'armor'
|
||||||
|
);
|
||||||
|
options.scrollingTextData = [armorData];
|
||||||
|
}
|
||||||
|
|
||||||
if (changed.system?.actions) {
|
if (changed.system?.actions) {
|
||||||
const triggersToRemove = Object.keys(changed.system.actions).reduce((acc, key) => {
|
const triggersToRemove = Object.keys(changed.system.actions).reduce((acc, key) => {
|
||||||
const action = changed.system.actions[key];
|
const action = changed.system.actions[key];
|
||||||
|
|
|
||||||
|
|
@ -743,3 +743,40 @@ export function getUnusedDamageTypes(parts) {
|
||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {{ type: string, parent: Object, disabled: boolean, isSuppressed: boolean }} sources
|
||||||
|
* @param { boolean } increasing
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export function orderSourcesForArmorAutoChange(sources, increasing) {
|
||||||
|
const getSourceWeight = source => {
|
||||||
|
switch (source.type) {
|
||||||
|
case 'class':
|
||||||
|
case 'subclass':
|
||||||
|
case 'ancestry':
|
||||||
|
case 'community':
|
||||||
|
case 'feature':
|
||||||
|
case 'domainCard':
|
||||||
|
return 2;
|
||||||
|
case 'armor':
|
||||||
|
return 3;
|
||||||
|
case 'loot':
|
||||||
|
case 'consumable':
|
||||||
|
return 4;
|
||||||
|
case 'weapon':
|
||||||
|
return 5;
|
||||||
|
case 'character':
|
||||||
|
return 6;
|
||||||
|
default:
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return sources
|
||||||
|
.filter(x => !x.disabled && !x.isSuppressed)
|
||||||
|
.sort((a, b) =>
|
||||||
|
increasing ? getSourceWeight(b) - getSourceWeight(a) : getSourceWeight(a) - getSourceWeight(b)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
</h3>
|
</h3>
|
||||||
<h3>
|
<h3>
|
||||||
{{localize "DAGGERHEART.ITEMS.Armor.baseScore"}}:
|
{{localize "DAGGERHEART.ITEMS.Armor.baseScore"}}:
|
||||||
{{source.system.armorData.max}}
|
{{source.system.armor.max}}
|
||||||
<span>-</span>
|
<span>-</span>
|
||||||
{{localize "DAGGERHEART.ITEMS.Armor.baseThresholds.base"}}:
|
{{localize "DAGGERHEART.ITEMS.Armor.baseThresholds.base"}}:
|
||||||
{{source.system.baseThresholds.major}}
|
{{source.system.baseThresholds.major}}
|
||||||
|
|
|
||||||
|
|
@ -6,13 +6,9 @@
|
||||||
<fieldset class="two-columns">
|
<fieldset class="two-columns">
|
||||||
<legend>{{localize tabs.settings.label}}</legend>
|
<legend>{{localize tabs.settings.label}}</legend>
|
||||||
<span>{{localize "DAGGERHEART.GENERAL.Tiers.singular"}}</span>
|
<span>{{localize "DAGGERHEART.GENERAL.Tiers.singular"}}</span>
|
||||||
{{formField systemFields.tier value=source.system.tier}}
|
{{ formField systemFields.tier value=source.system.tier }}
|
||||||
{{#if this.armorScore includeZero=true}}
|
<span>{{localize "DAGGERHEART.ITEMS.Armor.baseScore"}}</span>
|
||||||
<span>{{localize "DAGGERHEART.ITEMS.Armor.baseScore"}}</span>
|
{{ formField systemFields.armor.fields.max value=source.system.armor.max }}
|
||||||
<div class="form-fields">
|
|
||||||
<input type="text" data-dtype="Number" class="base-score-input" value="{{this.armorScore}}" />
|
|
||||||
</div>
|
|
||||||
{{/if}}
|
|
||||||
|
|
||||||
<span>{{localize "TYPES.Item.feature"}}</span>
|
<span>{{localize "TYPES.Item.feature"}}</span>
|
||||||
<input type="text" class="features-input" value="{{features}}" />
|
<input type="text" class="features-input" value="{{features}}" />
|
||||||
|
|
|
||||||
|
|
@ -1,37 +1,19 @@
|
||||||
<div class="daggerheart armor-management-container">
|
<div class="daggerheart armor-management-container">
|
||||||
<h3>{{localize "DAGGERHEART.GENERAL.armorSlots"}}</h3>
|
<h3>{{localize "DAGGERHEART.GENERAL.armorSlots"}}</h3>
|
||||||
{{#each sources as |source|}}
|
{{#each sources as |source|}}
|
||||||
{{#if ../useResourcePips}}
|
<div class="armor-source-container">
|
||||||
<div class="armor-source-container">
|
<p class="armor-source-label">{{source.name}}</p>
|
||||||
<p class="armor-source-label">{{source.name}}</p>
|
<div class="slot-bar">
|
||||||
<div class="slot-bar">
|
{{#times source.max}}
|
||||||
{{#times source.max}}
|
<a class='armor-slot' data-value="{{add this 1}}" data-uuid="{{source.uuid}}" data-is-armor-item="{{source.isArmorItem}}">
|
||||||
<a class='armor-slot' data-value="{{add this 1}}" data-uuid="{{source.uuid}}">
|
{{#if (gte ../current (add this 1))}}
|
||||||
{{#if (gte ../current (add this 1))}}
|
<i class="fa-solid fa-shield" data-index="{{this}}"></i>
|
||||||
<i class="fa-solid fa-shield" data-index="{{this}}"></i>
|
{{else}}
|
||||||
{{else}}
|
<i class="fa-solid fa-shield-halved" data-index="{{this}}"></i>
|
||||||
<i class="fa-solid fa-shield-halved" data-index="{{this}}"></i>
|
{{/if}}
|
||||||
{{/if}}
|
</a>
|
||||||
</a>
|
{{/times}}
|
||||||
{{/times}}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
{{else}}
|
</div>
|
||||||
<div class="armor-source-container">
|
|
||||||
<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.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.current}}'
|
|
||||||
max='{{source.max}}'
|
|
||||||
></progress>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{{/if}}
|
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue