Files
fvtt-prism-rpg/module/models/skill.mjs
T
2025-11-06 00:01:59 +01:00

135 lines
3.5 KiB
JavaScript

import { SYSTEM } from "../config/system.mjs"
/**
* Core Skill data model for Prism RPG
*
* Core Skills are skills in which the character is particularly proficient.
* - Basic skill checks: +5 modifier
* - Advanced skill checks: Only accessible with Core Skill
* - Core Skill Class: Gives access to a class based on archetype
* - Attribute Bonus: +2 to one of 3 associated attributes
*/
export default class PrismRPGSkill extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields
const schema = {}
const requiredInteger = { required: true, nullable: false, integer: true }
schema.description = new fields.HTMLField({
required: true,
textSearch: true,
initial: ""
})
// Core Skill type (from the 18 available Core Skills)
schema.coreSkill = new fields.StringField({
required: true,
initial: "acrobatics",
choices: Object.keys(SYSTEM.CORE_SKILLS || {}),
label: "Core Skill"
})
// Is this the character's chosen Core Skill?
schema.isCoreSkill = new fields.BooleanField({
required: true,
initial: false,
label: "Is Core Skill"
})
// If Core Skill, which attribute receives the +2 bonus?
schema.attributeBonus = new fields.StringField({
required: true,
initial: "",
label: "Attribute Bonus"
})
// Skill modifier (includes Core Skill bonus if applicable)
schema.modifier = new fields.NumberField({
...requiredInteger,
required: true,
initial: 0,
label: "Skill Modifier"
})
// Can perform advanced checks
schema.canAdvancedCheck = new fields.BooleanField({
required: true,
initial: false,
label: "Can Perform Advanced Checks"
})
// Associated Core Skill Class (if any)
schema.coreSkillClass = new fields.StringField({
required: true,
initial: "",
label: "Core Skill Class"
})
// Notes/Custom description
schema.notes = new fields.HTMLField({
required: true,
initial: "",
label: "Notes"
})
return schema
}
/** @override */
static LOCALIZATION_PREFIXES = ["PRISMRPG.Skill"]
/**
* Get the Core Skill definition from SYSTEM
*/
get coreSkillDefinition() {
return SYSTEM.CORE_SKILLS?.[this.coreSkill] || null
}
/**
* Get the localized Core Skill name
*/
get coreSkillLabel() {
const definition = this.coreSkillDefinition
return definition ? game.i18n.localize(definition.label) : this.coreSkill
}
/**
* Get the available attribute choices for this Core Skill
*/
get attributeChoices() {
const definition = this.coreSkillDefinition
return definition?.attributeChoices || []
}
/**
* Prepare derived data
*/
prepareDerivedData() {
super.prepareDerivedData()
// If this is the character's Core Skill, apply bonuses
if (this.isCoreSkill) {
this.modifier = SYSTEM.CORE_SKILL_BONUS?.basic || 5
this.canAdvancedCheck = true
} else {
this.modifier = 0
this.canAdvancedCheck = false
}
}
/**
* Calculate skill check bonus
* @param {string} attributeKey The attribute to use (str, dex, con, int, wis, cha)
* @returns {number} Total skill check bonus
*/
getSkillCheckBonus(attributeKey) {
let actor = this.parent?.actor
if (!actor) return this.modifier
const attribute = actor.system.characteristics?.[attributeKey]
const attributeMod = attribute?.mod || 0
return attributeMod + this.modifier
}
}