54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
import { ROLL_TYPE } from "../config/system.mjs"
|
|
import LethalFantasyUtils from "../utils.mjs"
|
|
export default class LethalFantasyActor extends Actor {
|
|
|
|
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 === 'character') {
|
|
const skills = await LethalFantasyUtils.loadCompendium("fvtt-lethal-fantasy.lf-skills")
|
|
data.items = data.items || []
|
|
for (let skill of skills) {
|
|
if (skill.system.category === "layperson" || skill.system.category === "professional") {
|
|
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 === "character") {
|
|
Object.assign(prototypeToken, {
|
|
sight: { enabled: true },
|
|
actorLink: true,
|
|
disposition: CONST.TOKEN_DISPOSITIONS.FRIENDLY,
|
|
})
|
|
this.updateSource({ prototypeToken })
|
|
}
|
|
}
|
|
|
|
async rollResource(resource) {
|
|
if (this.type !== "character") return
|
|
await this.system.roll(ROLL_TYPE.RESOURCE, resource)
|
|
}
|
|
|
|
async rollSave(save, avantage) {
|
|
if (this.type !== "character") return
|
|
await this.system.roll(ROLL_TYPE.SAVE, save, avantage)
|
|
}
|
|
}
|