diff --git a/assets/actions/cuisine.svg b/assets/actions/cuisine.svg new file mode 100644 index 00000000..2bb4ca88 --- /dev/null +++ b/assets/actions/cuisine.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/module/roll/roll-constants.mjs b/module/roll/roll-constants.mjs index f44f9bd5..cb36cf3c 100644 --- a/module/roll/roll-constants.mjs +++ b/module/roll/roll-constants.mjs @@ -4,6 +4,7 @@ export const ROLL_TYPE_COMP = 'comp' export const ROLL_TYPE_DEFENSE = 'defense' export const ROLL_TYPE_JEU = 'jeu' export const ROLL_TYPE_MEDITATION = 'meditation' +export const ROLL_TYPE_CUISINE = 'cuisine' export const ROLL_TYPE_OEUVRE = 'oeuvre' export const ROLL_TYPE_SORT = 'sort' export const ROLL_TYPE_TACHE = 'tache' diff --git a/module/roll/roll-dialog.mjs b/module/roll/roll-dialog.mjs index b00c4dae..82fcacc3 100644 --- a/module/roll/roll-dialog.mjs +++ b/module/roll/roll-dialog.mjs @@ -37,9 +37,11 @@ import { RollPartAttaque } from "./roll-part-attaque.mjs"; import { RollPartDefense } from "./roll-part-defense.mjs"; import { RollDialogAdapter } from "./roll-dialog-adapter.mjs"; import { ROLLDIALOG_SECTION } from "./roll-part.mjs"; -import { ROLL_TYPE_ATTAQUE, ROLL_TYPE_COMP } from "./roll-constants.mjs"; +import { ROLL_TYPE_COMP } from "./roll-constants.mjs"; import ChatRollResult from "./chat-roll-result.mjs"; import { renderTemplate } from "../constants.js"; +import { RollTypeCuisine } from "./roll-type-cuisine.mjs"; +import { RollPartCuisine } from "./roll-part-cuisine.mjs"; const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api @@ -52,6 +54,7 @@ const ALL_ROLL_TYPES = [ new RollTypeDefense(), new RollTypeSort(), new RollTypeMeditation(), + new RollTypeCuisine(), new RollTypeOeuvre(), new RollTypeJeu(), // new RollTypeResistance ?? @@ -71,6 +74,7 @@ const ROLL_PARTS = [ new RollPartMeditation(), new RollPartSort(), new RollPartTache(), + new RollPartCuisine(), new RollPartOeuvre(), new RollPartJeu(), diff --git a/module/roll/roll-part-cuisine.mjs b/module/roll/roll-part-cuisine.mjs new file mode 100644 index 00000000..fa60128d --- /dev/null +++ b/module/roll/roll-part-cuisine.mjs @@ -0,0 +1,76 @@ +import { ITEM_TYPES } from "../constants.js" +import { CARACS } from "../rdd-carac.js" +import { ROLL_TYPE_CUISINE } from "./roll-constants.mjs" +import { PART_CARAC } from "./roll-part-carac.mjs" +import { PART_COMP } from "./roll-part-comp.mjs" +import { RollPartSelect } from "./roll-part-select.mjs" +import { ROLLDIALOG_SECTION } from "./roll-part.mjs" + +export const PART_CUISINE = "cuisine" + +export class RollPartCuisine extends RollPartSelect { + onReady() { + foundry.applications.handlebars.loadTemplates({ 'roll-oeuvre-recettecuisine': `systems/foundryvtt-reve-de-dragon/templates/roll/roll-oeuvre-recettecuisine.hbs` }) + } + + get code() { return PART_CUISINE } + get section() { return ROLLDIALOG_SECTION.CHOIX } + + isValid(rollData) { return rollData.active.actor.isPersonnage() } + visible(rollData) { return this.isRollType(rollData, ROLL_TYPE_CUISINE) } + + loadRefs(rollData) { + const refs = this.getRefs(rollData) + refs.recettes = rollData.active.actor.items + .filter(it => it.type == ITEM_TYPES.recettecuisine) + .map(it => RollPartCuisine.$extractRecette(it, rollData.active.actor)) + if (refs.recettes.length > 0) { + this.$selectRecette(rollData) + } + } + + choices(refs) { return refs.recettes } + + static $extractRecette(recette, actor) { + return { + key: recette.id, + label: recette.name, + caracs: RollPartCuisine.getCaracs(recette), + qualite: recette.system.niveau, + value: -recette.system.niveau, + recette: recette, + comp: actor.getCompetence('Cuisine') + } + } + static getCaracs(recette){ + // TODO: permettre différentes caractéristiques pour la cuisine? + return [CARACS.ODORATGOUT, CARACS.EMPATHIE, CARACS.DEXTERITE] + } + + $selectRecette(rollData, key) { + this.selectByKey(rollData, key, 0) + } + + async _onRender(rollDialog, context, options) { + const selectRecette = rollDialog.element.querySelector(`roll-section[name="${this.code}"] select[name="select-recette"]`) + + selectRecette.addEventListener("change", e => { + const selectOptions = e.currentTarget.options + const index = selectOptions.selectedIndex + this.$selectRecette(rollDialog.rollData, selectOptions[index]?.value) + rollDialog.render() + }) + } + + impactOtherPart(part, rollData) { + if (this.visible(rollData)) { + const current = this.getCurrent(rollData) + switch (part.code) { + case PART_CARAC: return part.filterCaracs(rollData, current.caracs) + case PART_COMP: return part.filterComps(rollData, [current.comp?.name]) + } + } + return undefined + } + +} diff --git a/module/roll/roll-part-oeuvre.mjs b/module/roll/roll-part-oeuvre.mjs index d59dd63a..a8dd637a 100644 --- a/module/roll/roll-part-oeuvre.mjs +++ b/module/roll/roll-part-oeuvre.mjs @@ -11,6 +11,7 @@ export const PART_OEUVRE = "oeuvre" const ARTS = [ { type: ITEM_TYPES.oeuvre, action: "interpréte l'oeuvre", competence: it => it.system.competence, caracs: it => [it.system.default_carac] }, + { type: ITEM_TYPES.musique, action: "joue le morceau:", competence: it => 'Musique', caracs: it => [CARACS.OUIE] }, { type: ITEM_TYPES.chant, action: "chante", competence: it => 'Chant', caracs: it => [CARACS.OUIE] }, { type: ITEM_TYPES.danse, action: "danse:", competence: it => 'Danse', caracs: it => { @@ -20,8 +21,6 @@ const ARTS = [ return caracs } }, - { type: ITEM_TYPES.musique, action: "joue le morceau:", competence: it => 'Musique', caracs: it => [CARACS.OUIE] }, - { type: ITEM_TYPES.recettecuisine, action: "cuisine le plat:", competence: it => 'Cuisine', caracs: it => [CARACS.ODORATGOUT] }, ] export class RollPartOeuvre extends RollPartSelect { diff --git a/module/roll/roll-type-cuisine.mjs b/module/roll/roll-type-cuisine.mjs new file mode 100644 index 00000000..7ab82f6b --- /dev/null +++ b/module/roll/roll-type-cuisine.mjs @@ -0,0 +1,28 @@ +import { DIFF, ROLL_TYPE_CUISINE } from "./roll-constants.mjs" +import { PART_CUISINE } from "./roll-part-cuisine.mjs" +import { RollType } from "./roll-type.mjs" + +export class RollTypeCuisine extends RollType { + get code() { return ROLL_TYPE_CUISINE } + get name() { return `Interpréter une oeuvre` } + + visible(rollData) { return rollData.active.actor.isPersonnage() } + title(rollData) { + const current = rollData.current[PART_CUISINE] + return `prépare une recette: ${current.label}` + } + + onSelect(rollData) { + this.setDiffType(rollData, DIFF.AUCUN) + } + + getResult(rollData){ + const current = rollData.current[PART_CUISINE] + const qualite = rollData.rolled.isSuccess ? current.qualite : Math.min(current.qualite, current.comp.system.niveau) + return { + qualite: qualite + rollData.rolled.ptQualite + } + } + +} + diff --git a/templates/roll/result/chat-cuisine.hbs b/templates/roll/result/chat-cuisine.hbs new file mode 100644 index 00000000..3b17db80 --- /dev/null +++ b/templates/roll/result/chat-cuisine.hbs @@ -0,0 +1,29 @@ +
+
+ + +
+
+ {{active.name}} prépare une recette de niveau {{current.cuisine.recette.system.niveau}}: : {{current.cuisine.label}} ( +
+ +
+ {{current.carac.label}} / {{current.comp.label}} à {{current.diff.value}} +
{{> "systems/foundryvtt-reve-de-dragon/templates/chat-infojet.hbs"}} +
+ +
+

+ {{active.name}} + {{#if rolled.isSuccess}}réussit la recette avec + {{else}}manque d'inspiration, le plat a + {{/if}} + une qualité de {{result.qualite}}. +

+ {{> 'partial-info-appel-moral'}} + {{> "systems/foundryvtt-reve-de-dragon/templates/chat-description.hbs" current.cuisine.recette.system}} +
+
+ {{> 'partial-appel-chance'}} +
+
diff --git a/templates/roll/roll-oeuvre-recettecuisine.hbs b/templates/roll/roll-oeuvre-recettecuisine.hbs index d6ba4bc6..0822fb49 100644 --- a/templates/roll/roll-oeuvre-recettecuisine.hbs +++ b/templates/roll/roll-oeuvre-recettecuisine.hbs @@ -1,3 +1,4 @@ + -{{> "systems/foundryvtt-reve-de-dragon/templates/partial-description.hbs" current.oeuvre.system}} +{{> "systems/foundryvtt-reve-de-dragon/templates/partial-description.hbs" current.recette.system}} diff --git a/templates/roll/roll-part-cuisine.hbs b/templates/roll/roll-part-cuisine.hbs new file mode 100644 index 00000000..0f88df9a --- /dev/null +++ b/templates/roll/roll-part-cuisine.hbs @@ -0,0 +1,16 @@ + + + + + + + {{#if current.recette}} + {{plusMoins current.value}} + {{/if}} + + {{#if current.recette}} + {{> 'roll-oeuvre-recettecuisine'}} + {{/if}} + \ No newline at end of file