#36 Gestion des taches et création à partir d'un livre

This commit is contained in:
sladecraven 2020-12-15 21:28:55 +01:00
parent dc67c36b0a
commit e64c350632
8 changed files with 77 additions and 21 deletions

View File

@ -196,8 +196,7 @@ export class RdDActorSheet extends ActorSheet {
/* -------------------------------------------- */ /* -------------------------------------------- */
async createEmptyTache( ) { async createEmptyTache( ) {
let emptyTache = await Item.create( { name: 'Nouvelle tache', type: 'tache'} ); await this.actor.createOwnedItem( { name: 'Nouvelle tache', type: 'tache'}, { renderSheet: true } );
await this.actor.createOwnedItem( emptyTache.data, { renderSheet: true } );
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -1494,6 +1494,25 @@ export class RdDActor extends Actor {
dialog.render(true); 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 ) { getTache ( id ) {
return this.data.items.find( item => item._id == 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, label: 'Jet de Tâche ' + tache.name,
callbacks: [ callbacks: [
this.createCallbackExperience(), this.createCallbackExperience(),
{ action: this._tacheResult } { action: r => this._tacheResult(r) }
] ]
} ); } );
dialog.render(true); dialog.render(true);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
_tacheResult(rollData) { _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({ ChatUtility.chatWithRollMode({
content: "<strong>Test de Tache : " + rollData.tache.name + " - " + rollData.selectedCarac.label + " / " + rollData.competence.name + "</strong>" content: "<strong>Test de Tache : " + rollData.tache.name + " - " + rollData.selectedCarac.label + " / " + rollData.competence.name + "</strong>"
+ "<br>Difficultés <strong>libre : " + rollData.diffLibre + "</strong> / conditions : " + Misc.toSignedString(rollData.diffConditions) +" / état : " + rollData.etat + "<br>Difficultés <strong>libre : " + rollData.diffLibre + "</strong> / conditions : " + Misc.toSignedString(rollData.diffConditions) +" / état : " + rollData.etat
+ RdDResolutionTable.explain(rollData.rolled) + "<br>" + RdDResolutionTable.explain(rollData.rolled)
+ "<br>Points de taches : " + rollData.rolled.ptTache + ", ajustement qualité: " + rollData.rolled.ptQualite + "<br>Points de taches : " + rollData.rolled.ptTache + ", ajustement qualité: " + rollData.rolled.ptQualite
}, this.name); }, this.name);
// Message spécifique de la tâche
rollData.tache.data.points_de_tache_courant += rollData.rolled.ptTache; ChatUtility.chatWithRollMode({
rollData.actor.updateEmbeddedEntity( "OwnedItem", rollData.tache); content: "Votre tâche <strong>" + rollData.tache.name + "</strong> a duré " + rollData.tache.data.periodicite + "."
+ "<br>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 + "."
+ "<br>Et vous vous êtes fatigué de " + rollData.tache.data.fatigue + " cases."
}, this.name);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -1,4 +1,5 @@
import { RdDItemSort } from "./item-sort.js"; import { RdDItemSort } from "./item-sort.js";
import { RdDUtility } from "./rdd-utility.js";
/** /**
* Extend the basic ItemSheet with some very simple modifications * Extend the basic ItemSheet with some very simple modifications
@ -29,13 +30,16 @@ export class RdDItemSheet extends ItemSheet {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
getData() { async getData() {
let data = super.getData(); let data = super.getData();
if ( data.item.type == 'tache') { if ( data.item.type == 'tache' || data.item.type == 'livre') {
//console.log("****", data, this); data.caracList = duplicate(game.system.model.Actor.personnage.carac);
data.caracList = duplicate(this.actor.data.data.carac), data.competenceList = await RdDUtility.getCompetenceList( 'foundryvtt-reve-de-dragon.competences' );
data.competenceList = this.actor.getCompetenceList() }
if ( this.actor ) {
data.isOwned = true;
data.actorId = this.actor._id;
} }
data.bonusCaseList = RdDItemSort.getBonusCaseList(data, true); data.bonusCaseList = RdDItemSort.getBonusCaseList(data, true);
data.isGM = game.user.isGM; // Pour vérouiller certaines éditions data.isGM = game.user.isGM; // Pour vérouiller certaines éditions
@ -44,7 +48,6 @@ export class RdDItemSheet extends ItemSheet {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
/** @override */ /** @override */
activateListeners(html) { activateListeners(html) {
super.activateListeners(html); super.activateListeners(html);
@ -54,10 +57,15 @@ export class RdDItemSheet extends ItemSheet {
// Select competence categorie // Select competence categorie
html.find("#categorie").on("click", this._onClickSelectCategorie.bind(this) ); 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) { async _onClickSelectCategorie(event) {
event.preventDefault(); event.preventDefault();

View File

@ -638,6 +638,14 @@ export class RdDUtility {
return compList.find(item => item.name.toLowerCase() == compName && (item.type =="competence" || item.type == "competencecreature")) 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 ) static buildDefenseChatCard( attacker, target, rollData )
{ {

View File

@ -2,10 +2,10 @@
"name": "foundryvtt-reve-de-dragon", "name": "foundryvtt-reve-de-dragon",
"title": "Rêve de Dragon", "title": "Rêve de Dragon",
"description": "Rêve de Dragon RPG for FoundryVTT", "description": "Rêve de Dragon RPG for FoundryVTT",
"version": "1.1.9", "version": "1.1.10",
"minimumCoreVersion": "0.7.5", "minimumCoreVersion": "0.7.5",
"compatibleCoreVersion": "0.7.8", "compatibleCoreVersion": "0.7.8",
"templateVersion": 68, "templateVersion": 69,
"author": "LeRatierBretonnien", "author": "LeRatierBretonnien",
"esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ], "esmodules": [ "module/rdd-main.js", "module/hook-renderChatLog.js" ],
"styles": ["styles/simple.css"], "styles": ["styles/simple.css"],

View File

@ -652,6 +652,7 @@
}, },
"livre": { "livre": {
"description": "", "description": "",
"competence": "",
"auteur": "", "auteur": "",
"quantite": 1, "quantite": 1,
"difficulte": 0, "difficulte": 0,

View File

@ -675,6 +675,7 @@
</li> </li>
{{/each}} {{/each}}
</ul> </ul>
<hr>
</article> </article>
<article class="flexcol"> <article class="flexcol">

View File

@ -14,7 +14,13 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="xp">Compétence</label> <label for="xp">Compétence</label>
<input class="attribute-value" type="text" name="data.competence" value="{{data.competence}}" data-dtype="String"/> <select name="data.competence" id="competenceselect" data-dtype="String">
{{#select item.data.competence}}
{{#each competenceList as |competence key|}}
<option value="{{competence.name}}">{{competence.name}}</option>
{{/each}}
{{/select}}
</select>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="xp">Difficulté</label> <label for="xp">Difficulté</label>
@ -40,6 +46,11 @@
<label for="xp">Prix (sols) </label> <label for="xp">Prix (sols) </label>
<input class="attribute-value" type="text" name="data.cout" value="{{data.cout}}" data-dtype="Number"/> <input class="attribute-value" type="text" name="data.cout" value="{{data.cout}}" data-dtype="Number"/>
</div> </div>
{{#if isOwned}}
<div class="form-group">
<span for="xp"><a id="creer-tache-livre" data-actor-id="{{actorId}}">Créer une tâche de lecture</a></span>
</div>
{{/if}}
<div class="flexcol"> <div class="flexcol">
<span><label>Description : </label></span> <span><label>Description : </label></span>
<div class="form-group editor"> <div class="form-group editor">