2024-12-04 00:11:23 +01:00
|
|
|
import { SYSTEM } from "../config/system.mjs"
|
2024-12-17 09:25:02 +01:00
|
|
|
export default class CthulhuEternalSkill extends foundry.abstract.TypeDataModel {
|
2024-12-04 00:11:23 +01:00
|
|
|
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-04 00:11:23 +01:00
|
|
|
|
2024-12-22 23:04:15 +01:00
|
|
|
schema.base = new fields.StringField({ required: true, initial: "0" })
|
2024-12-04 00:11:23 +01:00
|
|
|
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 })
|
2024-12-04 00:11:23 +01:00
|
|
|
|
|
|
|
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-04 00:11:23 +01:00
|
|
|
}
|
|
|
|
|
2024-12-17 09:25:02 +01:00
|
|
|
computeScore() {
|
2024-12-04 00:11:23 +01:00
|
|
|
let actor = this.parent?.actor;
|
2025-01-05 23:48:43 +01:00
|
|
|
if ( isFinite(this.base) ) {
|
|
|
|
return Number(this.base) + Number(this.bonus);
|
2024-12-04 15:16:33 +01:00
|
|
|
}
|
2024-12-04 00:11:23 +01:00
|
|
|
if (!actor) {
|
2024-12-04 15:16:33 +01:00
|
|
|
return `${this.base} + ${ String(this.bonus)}`;
|
2024-12-04 00:11:23 +01:00
|
|
|
}
|
|
|
|
|
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 00:11:23 +01:00
|
|
|
}
|
2024-12-04 15:16:33 +01:00
|
|
|
let charValue = char.value;
|
|
|
|
return charValue + this.bonus
|
2024-12-04 00:11:23 +01:00
|
|
|
}
|
|
|
|
}
|