mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-22 07:23:37 +02:00
Refactor ArmorChange schema and fix some bugs
This commit is contained in:
parent
6193153596
commit
251baba5b3
60 changed files with 128 additions and 317 deletions
|
|
@ -18,23 +18,34 @@ export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel {
|
|||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
const baseChanges = Object.keys(CONFIG.DH.GENERAL.baseActiveEffectModes).reduce((r, type) => {
|
||||
r[type] = new fields.SchemaField({
|
||||
key: new fields.StringField({ required: true }),
|
||||
type: new fields.StringField({
|
||||
required: true,
|
||||
choices: [type],
|
||||
initial: type,
|
||||
validate: BaseEffect.#validateType
|
||||
}),
|
||||
value: new fields.AnyField({
|
||||
required: true,
|
||||
nullable: true,
|
||||
serializable: true,
|
||||
initial: ''
|
||||
}),
|
||||
phase: new fields.StringField({ required: true, blank: false, initial: 'initial' }),
|
||||
priority: new fields.NumberField()
|
||||
});
|
||||
return r;
|
||||
}, {});
|
||||
|
||||
return {
|
||||
...super.defineSchema(),
|
||||
changes: new fields.ArrayField(
|
||||
new fields.SchemaField({
|
||||
key: new fields.StringField({ required: true }),
|
||||
type: new fields.StringField({
|
||||
required: true,
|
||||
blank: false,
|
||||
choices: CONFIG.DH.GENERAL.activeEffectModes,
|
||||
initial: CONFIG.DH.GENERAL.activeEffectModes.add.id,
|
||||
validate: BaseEffect.#validateType
|
||||
}),
|
||||
value: new fields.AnyField({ required: true, nullable: true, serializable: true, initial: '' }),
|
||||
phase: new fields.StringField({ required: true, blank: false, initial: 'initial' }),
|
||||
priority: new fields.NumberField(),
|
||||
typeData: new fields.TypedSchemaField(changeTypes, { nullable: true, initial: null })
|
||||
})
|
||||
new fields.TypedSchemaField(
|
||||
{ ...changeTypes, ...baseChanges },
|
||||
{ initial: baseChanges.add.getInitialValue() }
|
||||
)
|
||||
),
|
||||
duration: new fields.SchemaField({
|
||||
type: new fields.StringField({
|
||||
|
|
@ -97,7 +108,7 @@ export default class BaseEffect extends foundry.data.ActiveEffectTypeDataModel {
|
|||
const armorChange = this.armorChange;
|
||||
if (!armorChange) return null;
|
||||
|
||||
return armorChange.typeData.getArmorData(armorChange);
|
||||
return armorChange.getArmorData(armorChange);
|
||||
}
|
||||
|
||||
static getDefaultObject() {
|
||||
|
|
|
|||
|
|
@ -2,42 +2,35 @@ import { itemAbleRollParse } from '../../../helpers/utils.mjs';
|
|||
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
export default class Armor extends foundry.abstract.DataModel {
|
||||
export default class ArmorChange extends foundry.abstract.DataModel {
|
||||
static defineSchema() {
|
||||
return {
|
||||
type: new fields.StringField({ required: true, initial: 'armor', blank: false }),
|
||||
max: new fields.StringField({
|
||||
required: true,
|
||||
nullable: false,
|
||||
initial: '1',
|
||||
label: 'DAGGERHEART.GENERAL.max'
|
||||
priority: new fields.NumberField(),
|
||||
phase: new fields.StringField({ required: true, blank: false, initial: 'initial' }),
|
||||
value: new fields.SchemaField({
|
||||
max: new fields.StringField({
|
||||
required: true,
|
||||
nullable: false,
|
||||
initial: '1',
|
||||
label: 'DAGGERHEART.GENERAL.max'
|
||||
}),
|
||||
interaction: new fields.StringField({
|
||||
required: true,
|
||||
choices: CONFIG.DH.GENERAL.activeEffectArmorInteraction,
|
||||
initial: CONFIG.DH.GENERAL.activeEffectArmorInteraction.none.id,
|
||||
label: 'DAGGERHEART.EFFECTS.ChangeTypes.armor.FIELDS.interaction.label',
|
||||
hint: 'DAGGERHEART.EFFECTS.ChangeTypes.armor.FIELDS.interaction.hint'
|
||||
})
|
||||
}),
|
||||
armorInteraction: new fields.StringField({
|
||||
required: true,
|
||||
choices: CONFIG.DH.GENERAL.activeEffectArmorInteraction,
|
||||
initial: CONFIG.DH.GENERAL.activeEffectArmorInteraction.none.id,
|
||||
label: 'DAGGERHEART.EFFECTS.ChangeTypes.armor.FIELDS.armorInteraction.label',
|
||||
hint: 'DAGGERHEART.EFFECTS.ChangeTypes.armor.FIELDS.armorInteraction.hint'
|
||||
})
|
||||
};
|
||||
}
|
||||
|
||||
static changeEffect = {
|
||||
label: 'Armor',
|
||||
defaultPriortiy: 20,
|
||||
defaultPriority: 20,
|
||||
handler: (actor, change, _options, _field, replacementData) => {
|
||||
const parsedMax = itemAbleRollParse(change.typeData.max, actor, change.effect.parent);
|
||||
|
||||
game.system.api.documents.DhActiveEffect.applyChange(
|
||||
actor,
|
||||
{
|
||||
...change,
|
||||
key: 'system.armorScore.value',
|
||||
type: CONFIG.DH.GENERAL.activeEffectModes.add.id,
|
||||
value: change.value
|
||||
},
|
||||
replacementData
|
||||
);
|
||||
const parsedMax = itemAbleRollParse(change.value.max, actor, change.effect.parent);
|
||||
game.system.api.documents.DhActiveEffect.applyChange(
|
||||
actor,
|
||||
{
|
||||
|
|
@ -54,7 +47,7 @@ export default class Armor extends foundry.abstract.DataModel {
|
|||
};
|
||||
|
||||
get isSuppressed() {
|
||||
switch (this.armorInteraction) {
|
||||
switch (this.value.interaction) {
|
||||
case CONFIG.DH.GENERAL.activeEffectArmorInteraction.active.id:
|
||||
return !this.parent.parent?.actor.system.armor;
|
||||
case CONFIG.DH.GENERAL.activeEffectArmorInteraction.inactive.id:
|
||||
|
|
@ -68,9 +61,7 @@ export default class Armor extends foundry.abstract.DataModel {
|
|||
return {
|
||||
key: 'Armor',
|
||||
type: CONFIG.DH.GENERAL.activeEffectModes.armor.id,
|
||||
value: 0,
|
||||
typeData: {
|
||||
type: 'armor',
|
||||
value: {
|
||||
max: 0,
|
||||
locked
|
||||
},
|
||||
|
|
@ -84,7 +75,7 @@ export default class Armor extends foundry.abstract.DataModel {
|
|||
name: game.i18n.localize('DAGGERHEART.EFFECTS.ChangeTypes.armor.newArmorEffect'),
|
||||
img: 'icons/equipment/chest/breastplate-helmet-metal.webp',
|
||||
system: {
|
||||
changes: [Armor.getInitialValue(true)]
|
||||
changes: [ArmorChange.getInitialValue(true)]
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue