48 lines
1.3 KiB
JavaScript
Raw Normal View History

2025-01-05 23:23:37 +01:00
import CthulhuEternalUtils from "../utils.mjs"
export default class CthulhuEternalActor extends Actor {
2024-12-18 18:45:47 +01:00
2025-01-05 23:23:37 +01:00
static async create(data, options) {
// Case of compendium global import
if (data instanceof Array) {
return super.create(data, options);
}
// If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic
if (data.items) {
let actor = super.create(data, options);
return actor;
}
if (data.type === 'protagonist') {
let era = game.settings.get("fvtt-cthulhu-eternal", "settings-era")
const skills = await CthulhuEternalUtils.loadCompendium("fvtt-cthulhu-eternal.skills")
data.items = data.items || []
for (let skill of skills) {
if (skill.system.settings === era ) {
data.items.push(skill.toObject())
}
}
}
return super.create(data, options);
}
async _preCreate(data, options, user) {
await super._preCreate(data, options, user)
// Configure prototype token settings
const prototypeToken = {}
if (this.type === "protagonist") {
Object.assign(prototypeToken, {
sight: { enabled: true },
actorLink: true,
disposition: CONST.TOKEN_DISPOSITIONS.FRIENDLY,
})
this.updateSource({ prototypeToken })
}
}
}