diff --git a/modules/vadentis-actor-sheet.js b/modules/vadentis-actor-sheet.js index 9ae479a..8d10331 100644 --- a/modules/vadentis-actor-sheet.js +++ b/modules/vadentis-actor-sheet.js @@ -29,7 +29,8 @@ export class VadentisActorSheet extends ActorSheet { data.combat = this.actor.combat; data.magie = this.actor.magie; data.editScore = this.options.editScore; - console.log("Edit : ", data.editScore); + data.donnees = this.actor.getDonnees(); + data.competences = this.actor.getCompetences(); data.isGM = game.user.isGM; return data; @@ -63,27 +64,34 @@ export class VadentisActorSheet extends ActorSheet { // Delete Inventory Item html.find('.item-delete').click(ev => { const li = $(ev.currentTarget).parents(".item"); - SoSUtility.confirmDelete(this, li); + VadentisUtility.confirmDelete(this, li); }); - html.find('.stat-label a').click((event) => { - let statName = event.currentTarget.attributes.name.value; - this.actor.rollStat(statName); + html.find('.combat-label a').click((event) => { + let combatName = event.currentTarget.attributes.name.value; + this.actor.rollCombat(combatName); }); - html.find('.skill-label a').click((event) => { + html.find('.competence-label a').click((event) => { const li = $(event.currentTarget).parents(".item"); - const skill = this.actor.getOwnedItem(li.data("item-id")); - this.actor.rollSkill(skill); + const competenceId = li.data("item-id"); + this.actor.rollCompetence(competenceId); }); html.find('.weapon-label a').click((event) => { const li = $(event.currentTarget).parents(".item"); const weapon = this.actor.getOwnedItem(li.data("item-id")); this.actor.rollWeapon(weapon); }); - html.find('.skill-value').change((event) => { + html.find('.competence-base').change((event) => { let skillName = event.currentTarget.attributes.skillname.value; - //console.log("Competence changed :", skillName); - this.actor.updateSkill(skillName, parseInt(event.target.value)); + this.actor.updateCompetence(skillName, "base", parseInt(event.target.value)); + }); + html.find('.competence-bonus').change((event) => { + let skillName = event.currentTarget.attributes.skillname.value; + this.actor.updateCompetence(skillName, "bonus", parseInt(event.target.value)); + }); + html.find('.competence-malus').change((event) => { + let skillName = event.currentTarget.attributes.skillname.value; + this.actor.updateCompetence(skillName, "malus", parseInt(event.target.value)); }); html.find('.skill-xp').change((event) => { let skillName = event.currentTarget.attributes.skillname.value; diff --git a/modules/vadentis-actor.js b/modules/vadentis-actor.js index 9386439..610be34 100644 --- a/modules/vadentis-actor.js +++ b/modules/vadentis-actor.js @@ -45,8 +45,49 @@ export class VadentisActor extends Actor { /* -------------------------------------------- */ 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})` } ); + } + + } diff --git a/modules/vadentis-utility.js b/modules/vadentis-utility.js index 4235362..7ba1742 100644 --- a/modules/vadentis-utility.js +++ b/modules/vadentis-utility.js @@ -61,4 +61,33 @@ export class VadentisUtility extends Entity { return list; } + /* -------------------------------------------- */ + static async confirmDelete(actorSheet, li) { + let itemId = li.data("item-id"); + let objet = actorSheet.actor.items.find(item => item._id == itemId); + let msgTxt = "
Etes vous certain de souhaiter supprimer cet item ?"; + let buttons = { + delete: { + icon: '', + label: "Oui, à supprimer", + callback: () => { + actorSheet.actor.deleteOwnedItem(itemId); + li.slideUp(200, () => actorSheet.render(false)); + } + }, + cancel: { + icon: '', + label: "Annuler" + } + } + msgTxt += "
"; + let d = new Dialog({ + title: "Confirmer la suppression", + content: msgTxt, + buttons: buttons, + default: "cancel" + }); + d.render(true); + } + } \ No newline at end of file diff --git a/system.json b/system.json index 5ea86ac..eb13bcd 100644 --- a/system.json +++ b/system.json @@ -2,11 +2,11 @@ "name": "foundryvtt-vadentis", "title": "Vadentis", "description": "Système Vadentis pour FoundryVTT", - "version": "0.0.6", + "version": "0.0.7", "manifestPlusVersion": "1.0.0", "minimumCoreVersion": "0.7.5", "compatibleCoreVersion": "0.7.9", - "templateVersion": 5, + "templateVersion": 6, "author": "Uberwald", "esmodules": [ "modules/vadentis-main.js" ], "styles": ["styles/simple.css"], diff --git a/template.json b/template.json index 73220b7..8743bec 100644 --- a/template.json +++ b/template.json @@ -3,12 +3,14 @@ "types": ["personnage"], "templates": { "common": { - "stats": { + "experience": { "experience": { - "total": 0, - "disponibe": 0, - "label": "Expérience" - }, + "total": 0, + "disponibe": 0, + "label": "Expérience" + } + }, + "stats": { "pointsvie": { "value": 0, "max": 0, diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html index f51770a..1bfccc5 100644 --- a/templates/actor-sheet.html +++ b/templates/actor-sheet.html @@ -12,7 +12,7 @@ {{!-- Sheet Tab Navigation --}}