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) { 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,22 +2288,29 @@ 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;
data: { let tachesExistantes = this.filterItems(filterTacheLecture);
carac: 'intellect', if (tachesExistantes.length == 0) {
competence: 'Ecriture', const tache = {
difficulte: itemData.data.difficulte, name: nomTache, type: 'tache',
periodicite: "60 minutes", data: {
fatigue: 2, carac: 'intellect',
points_de_tache: itemData.data.points_de_tache, competence: 'Ecriture',
points_de_tache_courant: 0, difficulte: itemData.data.difficulte,
description: "Lecture du livre " + item.name + " - XP : " + itemData.data.xp + " - Compétences : " + itemData.data.competence periodicite: "60 minutes",
fatigue: 2,
points_de_tache: itemData.data.points_de_tache,
points_de_tache_courant: 0,
description: "Lecture du livre " + item.name + " - XP : " + itemData.data.xp + " - Compétences : " + itemData.data.competence
}
} }
await this.createEmbeddedDocuments('Item', [tache], options);
tachesExistantes = this.filterItems(filterTacheLecture);
} }
await this.createEmbeddedDocuments('Item', [tache], { renderSheet: true }); 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.`);