import { VadentisUtility } from "./vadentis-utility.js"; /* -------------------------------------------- */ /** * Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system. * @extends {Actor} */ export class VadentisActor extends Actor { /* -------------------------------------------- */ /** * Override the create() function to provide additional SoS functionality. * * This overrided create() function adds initial items * Namely: Basic skills, money, * * @param {Object} data Barebones actor data which this function adds onto. * @param {Object} options (Unused) Additional options which customize the creation workflow. * */ 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; } /*data.items = []; let compendiumName = "foundryvtt-vadentis.competences"; if ( compendiumName ) { let skills = await SoSUtility.loadCompendium(compendiumName); data.items = data.items.concat( skills ); }*/ return super.create(data, options); } /* -------------------------------------------- */ async prepareData() { super.prepareData(); } /* -------------------------------------------- */ getCompetences() { return this.data.items.filter( item => item.type == 'competence'); } /* -------------------------------------------- */ getDonnees() { return this.data.items.filter( item => item.type == 'donnee'); } /* -------------------------------------------- */ async updateCompetence( name, field, value) { let competence = this.data.items.find( item => item.type == 'competence' && item.name == name); if (competence) { let dataPath = 'data.'+field; await this.updateOwnedItem( { _id: competence._id, [dataPath]:value }); } } /* -------------------------------------------- */ rollCompetence( competenceId ) { console.log("HERE !!!!", competenceId); let competence = this.data.items.find( item => item.type == 'competence' && item._id == competenceId); if ( competence) { let statValue = competence.data.base + competence.data.malus + competence.data.bonus; let formulaFull = `1d20+${competence.data.base}+${competence.data.malus}+${competence.data.bonus}`; let myRoll = new Roll("1d20+"+statValue); myRoll.evaluate(); myRoll.toMessage( { flavor: `Jet de compétence : ${competence.name} (${formulaFull})` } ); } } /* -------------------------------------------- */ rollCombat( combatName ) { let stat = this.data.data.combat[combatName]; let statValue = stat.base + stat.malus + stat.bonus; let formulaFull = `1d20+${stat.base}+${stat.malus}+${stat.bonus}`; let myRoll = new Roll("1d20+"+statValue); myRoll.evaluate(); myRoll.toMessage( { flavor: `Jet de ${stat.label} (${formulaFull})` } ); } }