forked from public/fvtt-cthulhu-eternal
48 lines
1.6 KiB
JavaScript
48 lines
1.6 KiB
JavaScript
import { SYSTEM } from "../config/system.mjs"
|
|
export default class CthulhuEternalSkill 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 })
|
|
schema.settings = new fields.StringField({ required: true, initial: "common", choices: SYSTEM.AVAILABLE_SETTINGS })
|
|
|
|
schema.base = new fields.StringField({ required: true, initial: "WIS" })
|
|
schema.bonus = new fields.NumberField({ ...requiredInteger, required: true, initial: 0, min: 0 })
|
|
schema.diceEvolved = new fields.BooleanField({ required: true, initial: true })
|
|
schema.rollFailed = new fields.BooleanField({ required: true, initial: false })
|
|
|
|
return schema
|
|
}
|
|
|
|
/** @override */
|
|
static LOCALIZATION_PREFIXES = ["CTHULHUETERNAL.Skill"]
|
|
|
|
|
|
prepareDerivedData() {
|
|
super.prepareDerivedData();
|
|
this.skillTotal = this.computeScore();
|
|
}
|
|
|
|
computeScore() {
|
|
let actor = this.parent?.actor;
|
|
if (Number(this.base)) {
|
|
return Number(this.base) + this.bonus;
|
|
}
|
|
if (!actor) {
|
|
return `${this.base} + ${ String(this.bonus)}`;
|
|
}
|
|
|
|
// Split the base value per stat :
|
|
let base = this.base.toLowerCase();
|
|
let char = actor.system.characteristics[base];
|
|
if (!char) {
|
|
ui.notifications.error(`The characteristic ${base} is wrong for actor ${actor.name}`);
|
|
return `${this.base } + ${ String(this.bonus)}`;
|
|
}
|
|
let charValue = char.value;
|
|
return charValue + this.bonus
|
|
}
|
|
}
|