Lire un livre depuis l'équipement

This commit is contained in:
Vincent Vandemeulebrouck 2021-05-04 15:18:32 +02:00
parent 8f9346b31c
commit d1802e7496
2 changed files with 43 additions and 21 deletions

View File

@ -289,8 +289,18 @@ export class RdDActor extends Actor {
filterItemsData(filter) { filterItemsData(filter) {
return this.data.items.map(it => Misc.data(it)).filter(filter); return this.data.items.map(it => Misc.data(it)).filter(filter);
} }
filterItems(filter) {
return this.data.items.filter(it => filter(Misc.data(it)));
}
getItemOfType(id, type) { getItemOfType(id, type) {
return id ? this.data.items.find(it => it.id == id && Misc.data(it).type == type) : undefined; if (id && type) {
let itemById = this.data.items.find(it => it.id == id);
const itemData = Misc.data(itemById);
if (itemData.type == type) {
return itemById;
}
}
return undefined;
} }
getMonnaie(id) { getMonnaie(id) {
return this.getItemOfType(id, 'monnaie'); return this.getItemOfType(id, 'monnaie');
@ -1697,6 +1707,7 @@ export class RdDActor extends Actor {
switch (Misc.data(item).type) { switch (Misc.data(item).type) {
case 'nourritureboisson': return await this.actionNourritureboisson(item); case 'nourritureboisson': return await this.actionNourritureboisson(item);
case 'potion': return await this.actionPotion(item); case 'potion': return await this.actionPotion(item);
case 'livre': return await this.actionLire(item);
} }
} }
@ -1708,6 +1719,12 @@ export class RdDActor extends Actor {
async actionPotion(item) { async actionPotion(item) {
return await this.consommerPotion(item) return await this.consommerPotion(item)
} }
async actionLire(item) {
const tache = await this.creerTacheDepuisLivre(item, { renderSheet: false });
if (tache) {
await this.rollTache(tache.id);
}
}
/* -------------------------------------------- */ /* -------------------------------------------- */
async consommer(item, choix) { async consommer(item, choix) {
@ -2271,10 +2288,14 @@ export class RdDActor extends Actor {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async creerTacheDepuisLivre(item) { async creerTacheDepuisLivre(item, options = { renderSheet: true }) {
const itemData = Misc.data(item); const itemData = Misc.data(item);
let tache = { const nomTache = "Lire " + itemData.name;
name: "Lire " + item.name, type: 'tache', const filterTacheLecture = it => it.type == 'tache' && it.name == nomTache;
let tachesExistantes = this.filterItems(filterTacheLecture);
if (tachesExistantes.length == 0) {
const tache = {
name: nomTache, type: 'tache',
data: { data: {
carac: 'intellect', carac: 'intellect',
competence: 'Ecriture', competence: 'Ecriture',
@ -2286,7 +2307,10 @@ export class RdDActor extends Actor {
description: "Lecture du livre " + item.name + " - XP : " + itemData.data.xp + " - Compétences : " + itemData.data.competence description: "Lecture du livre " + item.name + " - XP : " + itemData.data.xp + " - Compétences : " + itemData.data.competence
} }
} }
await this.createEmbeddedDocuments('Item', [tache], { renderSheet: true }); await this.createEmbeddedDocuments('Item', [tache], options);
tachesExistantes = this.filterItems(filterTacheLecture);
}
return tachesExistantes.length > 0 ? tachesExistantes[0] : undefined;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
@ -2313,7 +2337,6 @@ export class RdDActor extends Actor {
callbacks: [ callbacks: [
this.createCallbackExperience(), this.createCallbackExperience(),
this.createCallbackAppelAuMoral(), this.createCallbackAppelAuMoral(),
{ condition: r => r.rolled.isETotal, action: r => this._tacheETotal(r) },
{ action: r => this._tacheResult(r) } { action: r => this._tacheResult(r) }
] ]
}); });
@ -2323,19 +2346,17 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */ /* -------------------------------------------- */
async _tacheResult(rollData) { async _tacheResult(rollData) {
// Mise à jour de la tache // Mise à jour de la tache
rollData.tache = duplicate(rollData.tache);
rollData.tache.data.points_de_tache_courant += rollData.rolled.ptTache; rollData.tache.data.points_de_tache_courant += rollData.rolled.ptTache;
if (rollData.rolled.isETotal){
rollData.tache.data.difficulte--;
}
this.updateEmbeddedDocuments('Item', [rollData.tache]); this.updateEmbeddedDocuments('Item', [rollData.tache]);
this.santeIncDec("fatigue", rollData.tache.data.fatigue); this.santeIncDec("fatigue", rollData.tache.data.fatigue);
RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-tache.html'); RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-tache.html');
} }
/* -------------------------------------------- */
_tacheETotal(rollData) {
rollData.tache.data.difficulte--;
this.updateEmbeddedDocuments('Item', [rollData.tache]);
}
/* -------------------------------------------- */ /* -------------------------------------------- */
async _rollArt(artData, selected, oeuvre, callBackResult = r => this._resultArt(r)) { async _rollArt(artData, selected, oeuvre, callBackResult = r => this._resultArt(r)) {
const actorData = Misc.data(this); const actorData = Misc.data(this);

View File

@ -95,6 +95,7 @@ export class RdDItem extends Item {
switch (itemData.type) { switch (itemData.type) {
case 'nourritureboisson': return itemData.data.boisson ? 'Boire' : 'Manger'; case 'nourritureboisson': return itemData.data.boisson ? 'Boire' : 'Manger';
case 'potion': return 'Boire'; case 'potion': return 'Boire';
case 'livre': return 'Lire';
} }
if (options.warnIfNot) { if (options.warnIfNot) {
ui.notifications.warn(`Impossible d'utilise un ${itemData.name}, aucune action associée définie.`); ui.notifications.warn(`Impossible d'utilise un ${itemData.name}, aucune action associée définie.`);