diff --git a/module/actor.js b/module/actor.js index 4af2fc51..4718f936 100644 --- a/module/actor.js +++ b/module/actor.js @@ -53,7 +53,7 @@ import { PART_COMP } from "./roll/roll-part-comp.mjs"; import { PART_OEUVRE } from "./roll/roll-part-oeuvre.mjs"; import { PART_CUISINE } from "./roll/roll-part-cuisine.mjs"; import { RdDPossessionV2 } from "./rdd-possession-v2.mjs"; -import { MORAL, SITUATION_MORAL } from "./moral/apprecier.mjs"; +import { Apprecier, MORAL, SITUATION_MORAL } from "./moral/apprecier.mjs"; export const MAINS_DIRECTRICES = ['Droitier', 'Gaucher', 'Ambidextre'] @@ -1322,33 +1322,31 @@ export class RdDActor extends RdDBaseActorSang { } const item = this.getItem(itemId) if (!item.getUtilisationCuisine()) { - return; + return } if (choix.doses > item.system.quantite) { ui.notifications.warn(`Il n'y a pas assez de ${item.name} pour manger ${choix.doses}`) - return; + return } - if (!this._apprecierCuisine(item, choix.seForcer)) { - ui.notifications.info(`${this.name} ne n'arrive pas à manger de ${item.name}`) - return; - } - await this.manger(item, choix.doses, { diminuerQuantite: false }); - await this.boire(item, choix.doses, { diminuerQuantite: false }); - await item.diminuerQuantite(choix.doses, choix); - } - async _apprecierCuisine(item, seForcer) { - const surmonteExotisme = await this._surmonterExotisme(item, seForcer); - if (surmonteExotisme) { - await this.apprecier(CARACS.ODORATGOUT, 'cuisine', item.system.qualite, item.system.boisson ? "apprécie la boisson" : "apprécie le plat"); + const onManger = [ + async () => await this.manger(item, choix.doses, { diminuerQuantite: false }), + async () => await this.boire(item, choix.doses, { diminuerQuantite: false }), + async () => await item.diminuerQuantite(choix.doses, choix) + ] + + if (await this._surmonterExotisme(item)) { + const appreciation = item.system.appreciation; + new Apprecier(this, appreciation, item.system.qualite) + .apprecier(onManger) } - else if (seForcer) { - await this.jetDeMoral(MORAL.MALHEUREUX); + else if (choix.seForcer) { + await this.jetDeMoral(MORAL.MALHEUREUX) + await Promise.all(onManger.map(async callback => await callback())) } else { - return false; + ui.notifications.info(`${this.name} ne n'arrive pas à manger de ${item.name}`) } - return true; } /* -------------------------------------------- */ diff --git a/module/moral/apprecier.mjs b/module/moral/apprecier.mjs index 51e4d1f6..32761b3c 100644 --- a/module/moral/apprecier.mjs +++ b/module/moral/apprecier.mjs @@ -100,7 +100,7 @@ export class Apprecier { this.raisons = [] } - apprecier() { + apprecier(rollCallbacks = []) { if (this.qualite <= 0) { this.raisons.push(`la qualité ${this.qualite} est négative.`) } @@ -117,14 +117,14 @@ export class Apprecier { } if (this.appreciation.carac != "") { - this.rollAppreciation() + this.rollAppreciation(rollCallbacks) } else { this.rollMoral() } } - rollAppreciation() { + rollAppreciation(rollCallbacks = []) { const competence = (this.appreciation.jetComp && this.appreciation.competence) ? this.appreciation.competence : "" const rollData = { ids: { actorId: this.actor.id }, @@ -140,7 +140,12 @@ export class Apprecier { } } } - RollDialog.create(rollData, { callbacks: [async r => await this.onRollAppreciation(r)] }) + RollDialog.create(rollData, { + callbacks: [ + async r => await this.onRollAppreciation(r), + ...rollCallbacks + ] + }) } async onRollAppreciation(roll) {