Gestion des signes draconiques #455

Closed
vincent.vandeme wants to merge 233 commits from v1.4-signes-draconiques into master
2 changed files with 43 additions and 21 deletions
Showing only changes of commit d1802e7496 - Show all commits

View File

@ -289,8 +289,18 @@ export class RdDActor extends Actor {
filterItemsData(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) {
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) {
return this.getItemOfType(id, 'monnaie');
@ -1697,6 +1707,7 @@ export class RdDActor extends Actor {
switch (Misc.data(item).type) {
case 'nourritureboisson': return await this.actionNourritureboisson(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) {
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) {
@ -2271,10 +2288,14 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
async creerTacheDepuisLivre(item) {
async creerTacheDepuisLivre(item, options = { renderSheet: true }) {
const itemData = Misc.data(item);
let tache = {
name: "Lire " + item.name, type: 'tache',
const nomTache = "Lire " + itemData.name;
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: {
carac: 'intellect',
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
}
}
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: [
this.createCallbackExperience(),
this.createCallbackAppelAuMoral(),
{ condition: r => r.rolled.isETotal, action: r => this._tacheETotal(r) },
{ action: r => this._tacheResult(r) }
]
});
@ -2323,19 +2346,17 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async _tacheResult(rollData) {
// Mise à jour de la tache
rollData.tache = duplicate(rollData.tache);
rollData.tache.data.points_de_tache_courant += rollData.rolled.ptTache;
if (rollData.rolled.isETotal){
rollData.tache.data.difficulte--;
}
this.updateEmbeddedDocuments('Item', [rollData.tache]);
this.santeIncDec("fatigue", rollData.tache.data.fatigue);
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)) {
const actorData = Misc.data(this);

View File

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