Consommer nourriture et boisson WIP
This commit is contained in:
		| @@ -257,6 +257,12 @@ export class RdDActorSheet extends ActorSheet { | ||||
|       const li = $(ev.currentTarget).parents(".item"); | ||||
|       RdDUtility.confirmerSuppression(this, li); | ||||
|     }); | ||||
|     html.find('.item-consommer').click(ev => { | ||||
|       const li = $(ev.currentTarget).parents(".item"); | ||||
|       const itemId = li.data("item-id"); | ||||
|       const item = this.actor.getObjet(itemId); | ||||
|       this.actor.consommer(item); | ||||
|     }); | ||||
|     html.find('.subacteur-delete').click(ev => { | ||||
|       const li = $(ev.currentTarget).parents(".item"); | ||||
|       RdDUtility.confirmerSuppressionSubacteur(this, li); | ||||
|   | ||||
| @@ -28,6 +28,7 @@ import { Draconique } from "./tmr/draconique.js"; | ||||
| import { RdDCarac } from "./rdd-carac.js"; | ||||
| import { Monnaie } from "./item-monnaie.js"; | ||||
| import { RdDHerbes } from "./rdd-herbes.js"; | ||||
| import { DialogConsommer } from "./dialog-consommer.js"; | ||||
|  | ||||
|  | ||||
| /* -------------------------------------------- */ | ||||
| @@ -355,6 +356,7 @@ export class RdDActor extends Actor { | ||||
|     await this.transformerStress(); | ||||
|     await this.retourSeuilDeReve(message); | ||||
|     this.bonusRecuperationPotion= 0; // Reset potion | ||||
|     await this.retourSust(message); | ||||
|     message.content = `A la fin Chateau Dormant, ${message.content}<br>Un nouveau jour se lève`; | ||||
|     ChatMessage.create(message); | ||||
|   } | ||||
| @@ -597,6 +599,26 @@ export class RdDActor extends Actor { | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   async retourSust(message) { | ||||
|     const tplData = Misc.templateData(this); | ||||
|     const sustNeeded = tplData.attributs.sust.value; | ||||
|     const sustConsomme = tplData.compteurs.sust.value; | ||||
|     const eauConsomme = tplData.compteurs.eau.value; | ||||
|     if (game.settings.get("foundryvtt-reve-de-dragon", "appliquer-famine-soif").includes('famine') && sustConsomme < sustNeeded) { | ||||
|       const perte = sustConsomme < Math.min(0.5, sustNeeded) ? 3 : (sustConsomme <= (sustNeeded / 2) ? 2 : 1); | ||||
|       message.content += `<br>Vous ne vous êtes sustenté que de ${sustConsomme} pour un appétit de ${sustNeeded}, vous avez faim! | ||||
|         La famine devrait vous faire ${perte} points d'endurance non récupérables, notez le cumul de côté et ajustez l'endurance`; | ||||
|     } | ||||
|  | ||||
|     if (game.settings.get("foundryvtt-reve-de-dragon", "appliquer-famine-soif").includes('soif') && eauConsomme < sustNeeded) { | ||||
|       const perte = eauConsomme < Math.min(0.5, sustNeeded) ? 12 : (eauConsomme <= (sustNeeded / 2) ? 6 : 3); | ||||
|       message.content += `<br>Vous n'avez bu que ${eauConsomme} doses de liquide pour une soif de ${sustNeeded}, vous avez soif! | ||||
|         La soif devrait vous faire ${perte} points d'endurance non récupérables, notez le cumul de côté et ajustez l'endurance`; | ||||
|     } | ||||
|     await this.updateCompteurValue('sust', 0); | ||||
|     await this.updateCompteurValue('eau', 0); | ||||
|   } | ||||
|  | ||||
|   /* -------------------------------------------- */ | ||||
|   async combattreReveDeDragon(force) { | ||||
|     let rollData = { | ||||
| @@ -1526,7 +1548,7 @@ export class RdDActor extends Actor { | ||||
|         ? "vous êtes libre de continuer à boire ou pas." | ||||
|         : "vous avez une envie irrépréssible de reprendre un verre."); | ||||
|  | ||||
|       msgText += `Vous avez échoué à votre jet d'éthylisme, vous êtes  | ||||
|       msgText += `Vous avez échoué à votre jet d'éthylisme, vous êtes    | ||||
|         maintenant ${RdDUtility.getNomEthylisme(ajustementEthylique)} (${ajustementEthylique}). | ||||
|         <br> ${RdDResolutionTable.explain(rollVolonte)} | ||||
|         <br>Qui a bu boira : ${quiABuBoira}`; | ||||
| @@ -1561,6 +1583,70 @@ export class RdDActor extends Actor { | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   /* -------------------------------------------- */ | ||||
|   async consommer(item) { | ||||
|     DialogConsommer.create(this, item, { | ||||
|       html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-consommer-nourriture.html', | ||||
|     }, []); | ||||
|   } | ||||
|  | ||||
|   async manger(sust) { | ||||
|     if (sust > 0) { | ||||
|       await this.updateCompteurValue('sust', Misc.templateData(this).compteurs.sust.value + sust); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   async boire(eau) { | ||||
|     if (eau > 0) { | ||||
|       await this.actor.updateCompteurValue('eau', Misc.templateData(this).eau.value + this.consommerData.data.desaltere); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   async alcool(forceAlcool) { | ||||
|     const actorTplData = Misc.templateData(this); | ||||
|     const etatGeneral = this.getEtatGeneral({ ethylisme: true }); | ||||
|     const nbDoses = -Number(actorTplData.compteurs.ethylisme.nb_doses || 0); | ||||
|     let rollData = { | ||||
|       vieValue: actorTplData.sante.vie.value, | ||||
|       forceAlcool: forceAlcool, | ||||
|       etat: etatGeneral, | ||||
|       diffNbDoses: nbDoses, | ||||
|       finalLevel: nbDoses + forceAlcool + etatGeneral, | ||||
|       diffConditions: 0, | ||||
|     }; | ||||
|     await this.performEthylisme(rollData); | ||||
|   } | ||||
|  | ||||
|   async apprecierCuisine(consommerData) { | ||||
|     const cuisine = Misc.data(this.getCompetence('cuisine')); | ||||
|     const qualite = consommerData.data.qualite; | ||||
|     if (cuisine && qualite > 0 && qualite > cuisine.data.niveau) { | ||||
|       const rolled = await this.rollCaracCompetence('gout', 'cuisine', qualite, { title: consommerData.data.boisson ? "apprécie la boisson" : "apprécie le plat" }); | ||||
|       if (rolled.isSuccess) { | ||||
|         await this.jetDeMoral('heureux'); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|    | ||||
|   async surmonterExotisme(consommerData) { | ||||
|     const qualite = consommerData.data.qualite; | ||||
|     if (qualite < 0) { | ||||
|       const rolled = await this.rollCaracCompetence('volonte', 'cuisine', qualite, { title: "tente de surmonter l'exotisme" }); | ||||
|       if (rolled.isEchec) { | ||||
|         if (!consommerData.data.seForcer) { | ||||
|           return false; | ||||
|         } | ||||
|         await this.actor.jetDeMoral('malheureux'); | ||||
|       } | ||||
|     } | ||||
|     return true; | ||||
|   } | ||||
|  | ||||
|   async jetGoutCuisine() { | ||||
|     console.info('Jet de Gout/Cuisine'); | ||||
|     return true; | ||||
|   } | ||||
|  | ||||
|   /* -------------------------------------------- */ | ||||
|   async transformerStress() { | ||||
|     const actorData = Misc.data(this); | ||||
| @@ -1974,7 +2060,7 @@ export class RdDActor extends Actor { | ||||
|     RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-general.html'); | ||||
|   } | ||||
|  | ||||
|   async rollCaracCompetence(caracName, compName, diff) { | ||||
|   async rollCaracCompetence(caracName, compName, diff, options = { title: "" }) { | ||||
|     const carac = this.getCaracByName(caracName); | ||||
|     if (!carac) { | ||||
|       ui.notifications.warn(`${this.name} n'a pas de caractéristique correspondant à ${caracName}`) | ||||
| @@ -1993,11 +2079,12 @@ export class RdDActor extends Actor { | ||||
|       finalLevel: (competence?.data.niveau ?? 0) + diff, | ||||
|       diffLibre: diff, | ||||
|       showDice: true, | ||||
|       show: { title: "Jets multiples" } | ||||
|       show: { title: options?.title ?? '' } | ||||
|     }; | ||||
|     await RdDResolutionTable.rollData(rollData); | ||||
|     this.appliquerExperience(rollData); | ||||
|     RdDResolutionTable.displayRollData(rollData, this) | ||||
|     return rollData.rolled; | ||||
|   } | ||||
|  | ||||
|   /* -------------------------------------------- */ | ||||
| @@ -3090,7 +3177,7 @@ export class RdDActor extends Actor { | ||||
|     return guerisonData; | ||||
|   }  | ||||
|  | ||||
|   /* -------------------------------------------- */ | ||||
|     /* -------------------------------------------- */ | ||||
|   async consommerPotionSoin(potionData) { | ||||
|     potionData.alias = this.name; | ||||
|  | ||||
|   | ||||
							
								
								
									
										124
									
								
								module/dialog-consommer.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										124
									
								
								module/dialog-consommer.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,124 @@ | ||||
| import { Grammar } from "./grammar.js"; | ||||
| import { Misc } from "./misc.js"; | ||||
|  | ||||
| export class DialogConsommer extends Dialog { | ||||
|  | ||||
|   static async create(actor, item, dialogConfig) { | ||||
|     let consommerData = DialogConsommer.prepareData(actor, item); | ||||
|     if (!consommerData) { | ||||
|       ui.notifications.warn(`Impossible de consommer un ${consommerData.name}, ce n'est pas de la nourriture, une boisson ou une potion`); | ||||
|       return; | ||||
|     } | ||||
|  | ||||
|     let conf = { | ||||
|       title: consommerData.title, | ||||
|       content: await renderTemplate(dialogConfig.html, consommerData), | ||||
|       default: consommerData.buttonName, | ||||
|     }; | ||||
|  | ||||
|  | ||||
|     let options = { classes: ["dialogconsommer"], width: 600, height: 500, 'z-index': 99999 }; | ||||
|     mergeObject(options, dialogConfig.options ?? {}, { overwrite: true }) | ||||
|  | ||||
|     console.log('consommer', actor, consommerData, conf, options); | ||||
|     const dialog = new DialogConsommer(actor, consommerData, conf, options); | ||||
|     dialog.render(true); | ||||
|     return dialog; | ||||
|   } | ||||
|  | ||||
|   static prepareData(actor, item) { | ||||
|     let consommerData = duplicate(Misc.data(item)); | ||||
|     switch (consommerData.type) { | ||||
|       default: | ||||
|         return undefined; | ||||
|       case 'nourritureboisson': | ||||
|         consommerData.doses = 1; | ||||
|         consommerData.title = consommerData.data.boisson ? `${consommerData.name}: boire une dose` : `${consommerData.name}: manger une portion`; | ||||
|         consommerData.buttonName = consommerData.data.boisson ? "Boire" : "Manger"; | ||||
|         break; | ||||
|       case 'potion': | ||||
|         buttonName.title = `${consommerData.name}: boire la potion`; | ||||
|         consommerData.buttonName = "Boire"; | ||||
|         consommerData.alchimie = Misc.data(actor.getCompetence('alchimie')); | ||||
|         break; | ||||
|     } | ||||
|     consommerData.cuisine = Misc.data(actor.getCompetence('cuisine')); | ||||
|     consommerData.seForcer = false; | ||||
|     return consommerData; | ||||
|   } | ||||
|  | ||||
|  | ||||
|   constructor(actor, consommerData, conf, options) { | ||||
|     conf.buttons = { | ||||
|       [consommerData.buttonName]: { | ||||
|         label: consommerData.buttonName, callback: it => { | ||||
|           this.consommer(); | ||||
|         } | ||||
|       } | ||||
|     }; | ||||
|  | ||||
|     super(conf, options); | ||||
|  | ||||
|     this.actor = actor; | ||||
|     this.consommerData = consommerData; | ||||
|   } | ||||
|  | ||||
|   activateListeners(html) { | ||||
|     super.activateListeners(html); | ||||
|  | ||||
|     function updateConsommerData(rollData) { | ||||
|  | ||||
|       rollData.finalLevel = Number(rollData.etat) + Number(rollData.forceAlcool) + rollData.diffNbDoses; | ||||
|  | ||||
|       // Mise à jour valeurs | ||||
|       $("#roll-param").text(rollData.vieValue + " / " + Misc.toSignedString(rollData.finalLevel)); | ||||
|       $(".table-resolution").remove(); | ||||
|       $("#resolutionTable").append(RdDResolutionTable.buildHTMLTableExtract(rollData.vieValue, rollData.finalLevel)); | ||||
|     } | ||||
|  | ||||
|     html.find(".consommer-doses").change(event => { | ||||
|       this.u | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   /* -------------------------------------------- */ | ||||
|   async consommer() { | ||||
|     switch (this.consommerData.type) { | ||||
|       default: | ||||
|         return undefined; | ||||
|       case 'nourritureboisson': | ||||
|         return await this.consommerNourritureBoisson(); | ||||
|       case 'potion': | ||||
|         return await this.consommerPotion(); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   async consommerNourritureBoisson() { | ||||
|     const surmonteExotisme = await this.actor.surmonterExotisme(this.consommerData); | ||||
|     if (!surmonteExotisme) { | ||||
|       return; | ||||
|     } | ||||
|     await this.actor.apprecierCuisine(this.consommerData); | ||||
|     if (this.isAlcool()) { | ||||
|       await this.actor.alcool(this.consommerData.data.force); | ||||
|     } | ||||
|     await this.actor.manger(this.consommerData.data.sust); | ||||
|     await this.actor.boire(this.consommerData.data.desaltere); | ||||
|   } | ||||
|  | ||||
|   isAlcool() { | ||||
|     return this.consommerData.data.boisson && this.consommerData.data.alcoolise; | ||||
|   } | ||||
|  | ||||
|   async apprecierCuisine(qualite) { | ||||
|     const jetGoutCuisine = await this.jetGoutCuisine(); | ||||
|     if (jetGoutCuisine) { | ||||
|       await this.actor.jetDeMoral('heureux'); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   async consommerPotion() { | ||||
|   } | ||||
|  | ||||
|  | ||||
| } | ||||
| @@ -117,6 +117,20 @@ Hooks.once("init", async function () { | ||||
|     default: true, | ||||
|     type: Boolean | ||||
|   });   | ||||
|   /* -------------------------------------------- */ | ||||
|   game.settings.register("foundryvtt-reve-de-dragon", "appliquer-famine-soif", { | ||||
|     name: "Notifier de la famine et la soif pour", | ||||
|     hint: "Indique si les cas de famine et de soif seront indiqués durant Château Dormant", | ||||
|     scope: "world", | ||||
|     config: true, | ||||
|     type: String, | ||||
|     choices: { | ||||
|       "aucun": "ni la famine, ni la soif", | ||||
|       "famine": "seulement la famine", | ||||
|       "famine-soif": "la famine et la soif", | ||||
|     }, | ||||
|     default: "aucun" | ||||
|   });   | ||||
|  | ||||
|   /* -------------------------------------------- */ | ||||
|   // Set an initiative formula for the system  | ||||
|   | ||||
| @@ -1,5 +1,3 @@ | ||||
| {{log 'calc' calc}} | ||||
|          | ||||
| <form class="{{cssClass}}" autocomplete="off"> | ||||
|  | ||||
|     {{!-- Sheet Header --}} | ||||
| @@ -765,6 +763,9 @@ | ||||
|                 <a class="item-control item-equip" title="Equiper">{{#if item.data.equipe}}<i class="fas fa-circle"></i>{{else}}<i class="fas fa-genderless"></i>{{/if}}</a> | ||||
|                 <a class="item-control item-edit" title="Editer"><i class="fas fa-edit"></i></a> | ||||
|                 <a class="item-control item-delete" title="Supprimer"><i class="fas fa-trash"></i></a> | ||||
|                 {{#if (and (eq item.type 'nourritureboisson') item.data.quantite)}} | ||||
|                 <a class="item-name item-consommer">Consommer</a> | ||||
|                 {{/if}} | ||||
|               </span> | ||||
|           </li> | ||||
|           {{/if}} | ||||
|   | ||||
							
								
								
									
										39
									
								
								templates/dialog-consommer-nourriture.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										39
									
								
								templates/dialog-consommer-nourriture.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,39 @@ | ||||
| <form class="rdddialog"> | ||||
|   <div class="form-group"> | ||||
|     <label>Quantité de {{name}} à {{#if data.boisson}}boire{{else}}manger{{/if}}</label> | ||||
|     <input class="attribute-value consommer-doses" type="text" name="doses" value="{{doses}}" data-dtype="Number" /> | ||||
|   </div> | ||||
|   <div> | ||||
|     {{#if data.sust}} | ||||
|     <p> | ||||
|       Cette {{#if data.boisson}}boisson{{else}}nourriture{{/if}} vous apportera {{data.sust}} de | ||||
|       sustantation. | ||||
|     </p> | ||||
|     {{/if}} | ||||
|     {{#if data.boisson}} | ||||
|     <p>{{#if data.alcoolise}} | ||||
|       C'est une boisson alcoolisée de force {{data.force}}, vous effectuerez un jet d'éthylisme. | ||||
|       {{/if}} | ||||
|       Cette boisson vous apportera {{data.desaltere}} unités d'eau. | ||||
|     </p> | ||||
|     {{/if}} | ||||
|     {{#if (gt data.qualite cuisine.data.niveau)}} | ||||
|     <p>La qualité du plat est telle qu'un jet de Goût/Cuisine à {{numberFormat data.qualite decimals=0 sign=true}} | ||||
|       vous permettra un jet de moral heureux.</p> | ||||
|     {{/if}} | ||||
|   </div> | ||||
|  | ||||
|   {{#if (lt data.qualite 0)}} | ||||
|   <div> | ||||
|     <p> | ||||
|       Pour surmonter l'exotisme, vous devez effectuer un jet de Volonté/Cuisine à  {{numberFormat data.qualite decimals=0 sign=true}}. | ||||
|     </p> | ||||
|     <p> | ||||
|       <label>En cas d'échec, voulez-vous vous forcer à manger (et subir un jet de moral en situation | ||||
|         malheureuse)?</label> | ||||
|       <input class="attribute-value" type="checkbox" name="se-forcer" /> | ||||
|     </p> | ||||
|   </div> | ||||
|   {{/if}} | ||||
|  | ||||
| </form> | ||||
		Reference in New Issue
	
	Block a user