#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( ) {
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 } );
}
/* -------------------------------------------- */

View File

@ -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);
}
/* -------------------------------------------- */
_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: "<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
+ RdDResolutionTable.explain(rollData.rolled)
+ "<br>" + RdDResolutionTable.explain(rollData.rolled)
+ "<br>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 <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 { RdDUtility } from "./rdd-utility.js";
/**
* 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();
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
@ -44,7 +48,6 @@ export class RdDItemSheet extends ItemSheet {
}
/* -------------------------------------------- */
/** @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();

View File

@ -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 )
{

View File

@ -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"],

View File

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

View File

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

View File

@ -14,7 +14,13 @@
</div>
<div class="form-group">
<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 class="form-group">
<label for="xp">Difficulté</label>
@ -40,6 +46,11 @@
<label for="xp">Prix (sols) </label>
<input class="attribute-value" type="text" name="data.cout" value="{{data.cout}}" data-dtype="Number"/>
</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">
<span><label>Description : </label></span>
<div class="form-group editor">