diff --git a/module/config.mjs b/module/config.mjs index 8c54f69c0d..52b39454bd 100644 --- a/module/config.mjs +++ b/module/config.mjs @@ -14,12 +14,20 @@ ______ ______ _____ _____ |___/ \\___/\\/___/ \\____/\\____/ _______________________________`; +/** + * Configuration data for abilities. + * + * @typedef {object} AbilityConfiguration + * @property {string} label Localized label. + * @property {string} abbreviation Localized abbreviation. + * @property {Object} defaults Default values for this ability based on actor type. + * If a string is used, the system will attempt to fetch the value of the + * specified ability. + */ + /** * The set of Ability Scores used within the system. - * @enum {{ - * label: string, - * abbreviation: string - * }} + * @enum {AbilityConfiguration} */ DND5E.abilities = { str: { @@ -36,23 +44,28 @@ DND5E.abilities = { }, int: { label: "DND5E.AbilityInt", - abbreviation: "DND5E.AbilityIntAbbr" + abbreviation: "DND5E.AbilityIntAbbr", + defaults: { vehicle: 0 } }, wis: { label: "DND5E.AbilityWis", - abbreviation: "DND5E.AbilityWisAbbr" + abbreviation: "DND5E.AbilityWisAbbr", + defaults: { vehicle: 0 } }, cha: { label: "DND5E.AbilityCha", - abbreviation: "DND5E.AbilityChaAbbr" + abbreviation: "DND5E.AbilityChaAbbr", + defaults: { vehicle: 0 } }, hon: { label: "DND5E.AbilityHon", - abbreviation: "DND5E.AbilityHonAbbr" + abbreviation: "DND5E.AbilityHonAbbr", + defaults: { npc: "cha", vehicle: 0 } }, san: { label: "DND5E.AbilitySan", - abbreviation: "DND5E.AbilitySanAbbr" + abbreviation: "DND5E.AbilitySanAbbr", + defaults: { npc: "wis", vehicle: 0 } } }; preLocalize("abilities", { keys: ["label", "abbreviation"] }); diff --git a/module/documents/actor/actor.mjs b/module/documents/actor/actor.mjs index 43ba2a8abf..3c19b28843 100644 --- a/module/documents/actor/actor.mjs +++ b/module/documents/actor/actor.mjs @@ -229,22 +229,16 @@ export default class Actor5e extends Actor { _prepareBaseAbilities() { if ( !("abilities" in this.system) ) return; const abilities = {}; - for ( const key of Object.keys(CONFIG.DND5E.abilities) ) { + for ( const [key, config] of Object.entries(CONFIG.DND5E.abilities) ) { abilities[key] = this.system.abilities[key]; if ( !abilities[key] ) { abilities[key] = foundry.utils.deepClone(game.system.template.Actor.templates.common.abilities.cha); - // Honor: Charisma for NPC, 0 for vehicles - if ( key === "hon" ) { - if ( this.type === "vehicle" ) abilities[key].value = 0; - else if ( this.type === "npc" ) abilities[key].value = this.system.abilities.cha?.value ?? 10; - } - - // Sanity: Wisdom for NPC, 0 for vehicles - else if ( key === "san" ) { - if ( this.type === "vehicle" ) abilities[key].value = 0; - else if ( this.type === "npc" ) abilities[key].value = this.system.abilities.wis?.value ?? 10; + let defaultValue = config.defaults?.[this.type] ?? 10; + if ( typeof defaultValue === "string" ) { + defaultValue = abilities[defaultValue].value ?? this.system.abilities[defaultValue] ?? 10; } + abilities[key].value = defaultValue; } } this.system.abilities = abilities;