diff --git a/module/actor-sheet.js b/module/actor-sheet.js
index dce4e440..9efb56ac 100644
--- a/module/actor-sheet.js
+++ b/module/actor-sheet.js
@@ -196,8 +196,7 @@ export class RdDActorSheet extends ActorSheet {
/* -------------------------------------------- */
async createEmptyTache( ) {
- let emptyTache = await Item.create( { name: 'Nouvelle tache', type: 'tache'} );
- await this.actor.createOwnedItem( emptyTache.data, { renderSheet: true } );
+ await this.actor.createOwnedItem( { name: 'Nouvelle tache', type: 'tache'}, { renderSheet: true } );
}
/* -------------------------------------------- */
diff --git a/module/actor.js b/module/actor.js
index 85315ada..d91608ca 100644
--- a/module/actor.js
+++ b/module/actor.js
@@ -1494,6 +1494,25 @@ export class RdDActor extends Actor {
dialog.render(true);
}
+ /* -------------------------------------------- */
+ async creerTacheDepuisLivre( item ) {
+ console.log("FROM ITEM", item);
+ let tache = { name: "Lire " + item.name, type: 'tache',
+ data: {
+ carac: 'intellect',
+ competence: 'Ecriture',
+ difficulte: item.data.data.difficulte,
+ periodicite: "60 minutes",
+ fatigue: 2,
+ points_de_tache: item.data.data.points_de_tache,
+ points_de_tache_courant: 0,
+ description: "Lecture du livre " + item.name +
+ " - XP : " + item.data.data.xp + " - Compétences : " + item.data.data.competence
+ }
+ }
+ await this.createOwnedItem( tache, { renderSheet: true } );
+ }
+
/* -------------------------------------------- */
getTache ( id ) {
return this.data.items.find( item => item._id == id );
@@ -1523,24 +1542,33 @@ export class RdDActor extends Actor {
label: 'Jet de Tâche ' + tache.name,
callbacks: [
this.createCallbackExperience(),
- { action: this._tacheResult }
+ { action: r => this._tacheResult(r) }
]
} );
- dialog.render(true);
-
+ dialog.render(true);
}
/* -------------------------------------------- */
_tacheResult(rollData) {
+ // Mise à jour de la tache
+ rollData.tache.data.points_de_tache_courant += rollData.rolled.ptTache;
+ this.updateEmbeddedEntity( "OwnedItem", rollData.tache);
+ this.santeIncDec( "fatigue", -rollData.tache.data.fatigue);
+
+ // Message de résultat
ChatUtility.chatWithRollMode({
content: "Test de Tache : " + rollData.tache.name + " - " + rollData.selectedCarac.label + " / " + rollData.competence.name + ""
+ "
Difficultés libre : " + rollData.diffLibre + " / conditions : " + Misc.toSignedString(rollData.diffConditions) +" / état : " + rollData.etat
- + RdDResolutionTable.explain(rollData.rolled)
+ + "
" + RdDResolutionTable.explain(rollData.rolled)
+ "
Points de taches : " + rollData.rolled.ptTache + ", ajustement qualité: " + rollData.rolled.ptQualite
}, this.name);
-
- rollData.tache.data.points_de_tache_courant += rollData.rolled.ptTache;
- rollData.actor.updateEmbeddedEntity( "OwnedItem", rollData.tache);
+ // Message spécifique de la tâche
+ ChatUtility.chatWithRollMode({
+ content: "Votre tâche " + rollData.tache.name + " a duré " + rollData.tache.data.periodicite + "."
+ + "
Votre avancement est désormais de " + rollData.tache.data.points_de_tache_courant + " Points de Tache sur un objectif de "
+ + rollData.tache.data.points_de_tache + "."
+ + "
Et vous vous êtes fatigué de " + rollData.tache.data.fatigue + " cases."
+ }, this.name);
}
/* -------------------------------------------- */
diff --git a/module/item-sheet.js b/module/item-sheet.js
index 9893f88d..4b216f39 100644
--- a/module/item-sheet.js
+++ b/module/item-sheet.js
@@ -1,4 +1,5 @@
import { RdDItemSort } from "./item-sort.js";
+import { RdDUtility } from "./rdd-utility.js";
/**
* Extend the basic ItemSheet with some very simple modifications
@@ -29,22 +30,24 @@ export class RdDItemSheet extends ItemSheet {
}
/* -------------------------------------------- */
- getData() {
+ async getData() {
let data = super.getData();
- if ( data.item.type == 'tache') {
- //console.log("****", data, this);
- data.caracList = duplicate(this.actor.data.data.carac),
- data.competenceList = this.actor.getCompetenceList()
+ if ( data.item.type == 'tache' || data.item.type == 'livre') {
+ data.caracList = duplicate(game.system.model.Actor.personnage.carac);
+ data.competenceList = await RdDUtility.getCompetenceList( 'foundryvtt-reve-de-dragon.competences' );
+ }
+ if ( this.actor ) {
+ data.isOwned = true;
+ data.actorId = this.actor._id;
}
data.bonusCaseList = RdDItemSort.getBonusCaseList(data, true);
data.isGM = game.user.isGM; // Pour vérouiller certaines éditions
return data;
}
-
+
/* -------------------------------------------- */
-
/** @override */
activateListeners(html) {
super.activateListeners(html);
@@ -54,10 +57,15 @@ export class RdDItemSheet extends ItemSheet {
// Select competence categorie
html.find("#categorie").on("click", this._onClickSelectCategorie.bind(this) );
+
+ html.find('#creer-tache-livre').click((event) => {
+ let actorId = event.currentTarget.attributes['data-actor-id'].value;
+ let actor = game.actors.get( actorId );
+ actor.creerTacheDepuisLivre( this.item );
+ });
}
/* -------------------------------------------- */
-
async _onClickSelectCategorie(event) {
event.preventDefault();
diff --git a/module/rdd-utility.js b/module/rdd-utility.js
index aba15937..333b3d24 100644
--- a/module/rdd-utility.js
+++ b/module/rdd-utility.js
@@ -638,6 +638,14 @@ export class RdDUtility {
return compList.find(item => item.name.toLowerCase() == compName && (item.type =="competence" || item.type == "competencecreature"))
}
+ /* -------------------------------------------- */
+ static async getCompetenceList( compendium ) {
+ const pack = game.packs.get(compendium);
+ let competences;
+ await pack.getIndex().then(index => competences = index);
+ return competences;
+ }
+
/* -------------------------------------------- */
static buildDefenseChatCard( attacker, target, rollData )
{
diff --git a/system.json b/system.json
index a6c5f87b..84799848 100644
--- a/system.json
+++ b/system.json
@@ -2,10 +2,10 @@
"name": "foundryvtt-reve-de-dragon",
"title": "Rêve de Dragon",
"description": "Rêve de Dragon RPG for FoundryVTT",
- "version": "1.1.9",
+ "version": "1.1.10",
"minimumCoreVersion": "0.7.5",
"compatibleCoreVersion": "0.7.8",
- "templateVersion": 68,
+ "templateVersion": 69,
"author": "LeRatierBretonnien",
"esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ],
"styles": ["styles/simple.css"],
diff --git a/template.json b/template.json
index 521e4329..f3ed1b3a 100644
--- a/template.json
+++ b/template.json
@@ -652,6 +652,7 @@
},
"livre": {
"description": "",
+ "competence": "",
"auteur": "",
"quantite": 1,
"difficulte": 0,
diff --git a/templates/actor-sheet.html b/templates/actor-sheet.html
index b9d629d1..7770e99d 100644
--- a/templates/actor-sheet.html
+++ b/templates/actor-sheet.html
@@ -675,7 +675,8 @@
{{/each}}
-
+