49 lines
1.7 KiB
JavaScript
Raw Normal View History

import { SYSTEM } from "../config/system.mjs"
2024-12-17 09:25:02 +01:00
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 })
2024-12-22 23:04:15 +01:00
schema.settings = new fields.StringField({ required: true, initial: "modern", choices: SYSTEM.AVAILABLE_SETTINGS })
2024-12-22 23:04:15 +01:00
schema.base = new fields.StringField({ required: true, initial: "0" })
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 })
2025-01-04 22:24:39 +01:00
schema.isAdversary = new fields.BooleanField({ required: true, initial: false })
return schema
}
/** @override */
static LOCALIZATION_PREFIXES = ["CTHULHUETERNAL.Skill"]
prepareDerivedData() {
super.prepareDerivedData();
2024-12-17 09:25:02 +01:00
this.skillTotal = this.computeScore();
}
2024-12-17 09:25:02 +01:00
computeScore() {
let actor = this.parent?.actor;
2024-12-04 15:16:33 +01:00
if (Number(this.base)) {
return Number(this.base) + this.bonus;
}
if (!actor) {
2024-12-04 15:16:33 +01:00
return `${this.base} + ${ String(this.bonus)}`;
}
2024-12-18 18:45:47 +01:00
// Split the base value per stat :
2024-12-04 15:16:33 +01:00
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)}`;
}
2024-12-04 15:16:33 +01:00
let charValue = char.value;
return charValue + this.bonus
}
}