import { ReglesOptionnelles } from "../settings/regles-optionnelles.js" import { DIFF, ROLL_TYPE_TACHE } from "./roll-constants.mjs" import { PART_TACHE } from "./roll-part-tache.mjs" import { RollType } from "./roll-type.mjs" export class RollTypeTache extends RollType { get code() { return ROLL_TYPE_TACHE } get name() { return `Travailler à une tâche` } visible(rollData) { return rollData.active.actor.isPersonnage() } title(rollData) { const current = rollData.current[PART_TACHE] const tache = current?.tache return tache ? `travaille à sa tâche: ${tache.name}` : `n'a pas de tâches à travailler` } onSelect(rollData) { this.setDiffType(rollData, DIFF.AUCUN) } callbacks(rollOptions) { return [async r => await RollTypeTache.$onRollTache(r)] } static async $onRollTache(rollData) { const actor = rollData.active.actor const tache = rollData.current[PART_TACHE].tache rollData.current[PART_TACHE].tache = await tache.update({ 'system.points_de_tache_courant': tache.system.points_de_tache_courant + rollData.rolled.ptTache, 'system.nb_jet_succes': tache.system.nb_jet_succes + (rollData.rolled.isSuccess ? 1 : 0), 'system.nb_jet_echec': tache.system.nb_jet_echec + (rollData.rolled.isSuccess ? 0 : 1), 'system.difficulte': tache.system.difficulte - (rollData.rolled.isETotal ? 1 : 0), }, { render: true }) if (ReglesOptionnelles.isUsing("appliquer-fatigue")) { await actor.santeIncDec("fatigue", tache.system.fatigue) } } }