#171 - Gestion des potions de repos
This commit is contained in:
		| @@ -310,6 +310,30 @@ export class RdDActor extends Actor { | |||||||
|   getDemiReve() { |   getDemiReve() { | ||||||
|     return Misc.templateData(this).reve.tmrpos.coord; |     return Misc.templateData(this).reve.tmrpos.coord; | ||||||
|   } |   } | ||||||
|  |    | ||||||
|  |   /* -------------------------------------------- */ | ||||||
|  |   async verifierPotionsEnchantees() { | ||||||
|  |     let potionsEnchantees = this.filterItemsData( it => it.type == 'potion' && it.data.categorie.toLowerCase().includes('enchante')); | ||||||
|  |     for ( let potion of potionsEnchantees) { | ||||||
|  |       if ( !potion.prpermanent) { | ||||||
|  |         console.log(potion); | ||||||
|  |         let newPr = (potion.data.pr > 0) ? potion.data.pr - 1 : 0; | ||||||
|  |         let update = { _id: potion._id, 'data.pr': newPr}; | ||||||
|  |         const updated = await this.updateEmbeddedDocuments('Item', [update]); // Updates one EmbeddedEntity   | ||||||
|  |  | ||||||
|  |         let messageData = { | ||||||
|  |           pr : newPr, | ||||||
|  |           alias : this.name, | ||||||
|  |           potionName : potion.name, | ||||||
|  |           potionImg : potion.img | ||||||
|  |         } | ||||||
|  |         ChatMessage.create({ | ||||||
|  |           whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), | ||||||
|  |           content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-potionenchantee-chateaudormant.html`, messageData) | ||||||
|  |         }); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|   /* -------------------------------------------- */ |   /* -------------------------------------------- */ | ||||||
|   async deleteSortReserve(sortReserve) { |   async deleteSortReserve(sortReserve) { | ||||||
| @@ -358,6 +382,7 @@ export class RdDActor extends Actor { | |||||||
|     await this.retourSeuilDeReve(message); |     await this.retourSeuilDeReve(message); | ||||||
|     this.bonusRecuperationPotion= 0; // Reset potion |     this.bonusRecuperationPotion= 0; // Reset potion | ||||||
|     await this.retourSust(message); |     await this.retourSust(message); | ||||||
|  |     await this.verifierPotionsEnchantees(); | ||||||
|     message.content = `A la fin Chateau Dormant, ${message.content}<br>Un nouveau jour se lève`; |     message.content = `A la fin Chateau Dormant, ${message.content}<br>Un nouveau jour se lève`; | ||||||
|     ChatMessage.create(message); |     ChatMessage.create(message); | ||||||
|   } |   } | ||||||
| @@ -3202,7 +3227,7 @@ export class RdDActor extends Actor { | |||||||
|     return guerisonData; |     return guerisonData; | ||||||
|   }  |   }  | ||||||
|  |  | ||||||
|     /* -------------------------------------------- */ |   /* -------------------------------------------- */ | ||||||
|   async consommerPotionSoin(potionData) { |   async consommerPotionSoin(potionData) { | ||||||
|     potionData.alias = this.name; |     potionData.alias = this.name; | ||||||
|  |  | ||||||
| @@ -3216,22 +3241,17 @@ export class RdDActor extends Actor { | |||||||
|       }); |       }); | ||||||
|       // Gestion de la résistance: |       // Gestion de la résistance: | ||||||
|       let rolled = await RdDResolutionTable.roll(this.getReveActuel(), -8 ); |       let rolled = await RdDResolutionTable.roll(this.getReveActuel(), -8 ); | ||||||
|  |       potionData.reussiteReve = false; | ||||||
|       if (!rolled.isSuccess) { |       if (!rolled.isSuccess) { | ||||||
|         await this.reveActuelIncDec(-1); |         await this.reveActuelIncDec(-1); | ||||||
|         potionData.guerisonData = await this.buildPotionGuerisonList(potionData.pointsGuerison); |         potionData.guerisonData = await this.buildPotionGuerisonList(potionData.pointsGuerison); | ||||||
|         potionData.guerisonMinutes = potionData.guerisonData.pointsConsommes * 5; |         potionData.guerisonMinutes = potionData.guerisonData.pointsConsommes * 5;         | ||||||
|         potionData.reussiteReve = true; |         potionData.reussiteReve = true; | ||||||
|         ChatMessage.create({ |  | ||||||
|           whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), |  | ||||||
|           content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-appliquer-potion-soin.html`, potionData ) |  | ||||||
|         });   |  | ||||||
|       } else { |  | ||||||
|         potionData.reussiteReve = false; |  | ||||||
|         ChatMessage.create({ |  | ||||||
|           whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), |  | ||||||
|           content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-appliquer-potion-soin.html`, potionData ) |  | ||||||
|         }); |  | ||||||
|       } |       } | ||||||
|  |       ChatMessage.create({ | ||||||
|  |         whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), | ||||||
|  |         content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-appliquer-potion-soin.html`, potionData ) | ||||||
|  |       });   | ||||||
|     } else { |     } else { | ||||||
|       potionData.enchanteTexte = ""; |       potionData.enchanteTexte = ""; | ||||||
|       potionData.isEnchante = false; |       potionData.isEnchante = false; | ||||||
| @@ -3243,17 +3263,64 @@ export class RdDActor extends Actor { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /* -------------------------------------------- */ | ||||||
|  |   async consommerPotionRepos(potionData) { | ||||||
|  |     potionData.alias = this.name; | ||||||
|  |  | ||||||
|  |     if (potionData.data.categorie.includes('Enchante')) { | ||||||
|  |       potionData.casesRepos = RdDHerbes.calculePointsRepos( potionData.data); | ||||||
|  |       potionData.enchanteTexte = "enchantée"; | ||||||
|  |       potionData.isEnchante = true; | ||||||
|  |       ChatMessage.create({ | ||||||
|  |         whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), | ||||||
|  |         content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-consommer-potion-repos.html`, potionData ) | ||||||
|  |       }); | ||||||
|  |       // Gestion de la résistance: | ||||||
|  |       let rolled = await RdDResolutionTable.roll(this.getReveActuel(), -8 ); | ||||||
|  |       potionData.reussiteReve = false; | ||||||
|  |       if (!rolled.isSuccess) { | ||||||
|  |         await this.reveActuelIncDec(-1); | ||||||
|  |         let fatigueActuelle = this.getFatigueActuelle(); | ||||||
|  |         potionData.caseFatigueReel = (fatigueActuelle >= potionData.casesRepos) ? potionData.casesRepos : fatigueActuelle; | ||||||
|  |         potionData.guerisonDureeUnite = (potionData.data.reposalchimique) ? "rounds" : "minutes"; | ||||||
|  |         potionData.guerisonDureeValue = (potionData.data.reposalchimique) ?  potionData.caseFatigueReel : potionData.caseFatigueReel*5; | ||||||
|  |         potionData.reussiteReve = true; | ||||||
|  |         potionData.aphasiePermanente = false; | ||||||
|  |         if ( potionData.data.reposalchimique ) { | ||||||
|  |           let chanceAphasie = new Roll("1d100").evaluate({async : false} ).total; | ||||||
|  |           if ( chanceAphasie <= potionData.data.pr ) { | ||||||
|  |             potionData.aphasiePermanente = true; | ||||||
|  |           } | ||||||
|  |         } | ||||||
|  |         await this.santeIncDec("fatigue", -potionData.caseFatigueReel); | ||||||
|  |       } | ||||||
|  |       ChatMessage.create({ | ||||||
|  |         whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), | ||||||
|  |         content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-appliquer-potion-repos.html`, potionData ) | ||||||
|  |       });   | ||||||
|  |     } else { | ||||||
|  |       potionData.enchanteTexte = ""; | ||||||
|  |       potionData.isEnchante = false; | ||||||
|  |       ChatMessage.create({ | ||||||
|  |         whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name), | ||||||
|  |         content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-appliquer-potion-repos.html`, potionData ) | ||||||
|  |       });   | ||||||
|  |       this.bonusRepos = potionData.data.herbeBonus; | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|   /* -------------------------------------------- */ |   /* -------------------------------------------- */ | ||||||
|   async consommerPotion( potion ) { |   async consommerPotion( potion ) { | ||||||
|     const potionData = Misc.data(potion); |     const potionData = Misc.data(potion); | ||||||
|  |  | ||||||
|     if ( potionData.data.categorie.includes('Soin')) { |     if ( potionData.data.categorie.includes('Soin')) { | ||||||
|       this.consommerPotionSoin( potionData); |       this.consommerPotionSoin( potionData); | ||||||
|     } else if( potion.data.categorie.includes('Repos')) { |     } else if( potionData.data.categorie.includes('Repos')) { | ||||||
|       //TODO |       this.consommerPotionRepos(potionData); | ||||||
|     } else { |     } else { | ||||||
|       //TODO |       //TODO | ||||||
|     } |     } | ||||||
|  |     await this.deleteEmbeddedDocuments('Item', [ potion._id ] ); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /* -------------------------------------------- */ |   /* -------------------------------------------- */ | ||||||
|   | |||||||
| @@ -60,6 +60,11 @@ export class RdDHerbes extends Item { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /* -------------------------------------------- */ | ||||||
|  |   static calculePointsRepos( data ) { | ||||||
|  |     return data.herbebonus * data.pr; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   /* -------------------------------------------- */ |   /* -------------------------------------------- */ | ||||||
|   static calculePointsGuerison( data ){ |   static calculePointsGuerison( data ){ | ||||||
|     return data.herbebonus * data.pr; |     return data.herbebonus * data.pr; | ||||||
|   | |||||||
| @@ -187,7 +187,8 @@ export class RdDUtility { | |||||||
|       'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-alchimie.html', |       'systems/foundryvtt-reve-de-dragon/templates/chat-resultat-alchimie.html', | ||||||
|       'systems/foundryvtt-reve-de-dragon/templates/chat-actor-turn-summary.html', |       'systems/foundryvtt-reve-de-dragon/templates/chat-actor-turn-summary.html', | ||||||
|       'systems/foundryvtt-reve-de-dragon/templates/chat-actor-competence-xp.html', |       'systems/foundryvtt-reve-de-dragon/templates/chat-actor-competence-xp.html', | ||||||
|       'systems/foundryvtt-reve-de-dragon/templates/chat-actor-carac-xp.html' |       'systems/foundryvtt-reve-de-dragon/templates/chat-actor-carac-xp.html', | ||||||
|  |       'systems/foundryvtt-reve-de-dragon/templates/chat-potionenchantee-chateaudormant.html' | ||||||
|     ]; |     ]; | ||||||
|  |  | ||||||
|     Handlebars.registerHelper('upperFirst', str => Misc.upperFirst(str ?? 'Null')); |     Handlebars.registerHelper('upperFirst', str => Misc.upperFirst(str ?? 'Null')); | ||||||
|   | |||||||
							
								
								
									
										22
									
								
								templates/chat-appliquer-potion-repos.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								templates/chat-appliquer-potion-repos.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,22 @@ | |||||||
|  | <img class="chat-icon" src="systems/foundryvtt-reve-de-dragon/icons/competence_botanique.png" alt="potion de repos" /> | ||||||
|  | <h4> | ||||||
|  |   {{#if reussiteReve}} | ||||||
|  |   {{alias}} a bu la potion et a échoué son Jet de Résistance (Rêve actuel à -8) : la potion fait effet ! | ||||||
|  |   {{else}} | ||||||
|  |   {{alias}} a bu la potion et a réussi son Jet de Résistance (Rêve actuel à -8) : la potion ne fait pas effet ! | ||||||
|  |   {{/if}} | ||||||
|  | </h4> | ||||||
|  | <hr> | ||||||
|  | <div> | ||||||
|  |   {{#if reussiteReve}} | ||||||
|  |   {{alias}} perd 1 point de rêve (déduit automatiquement) et s'endort pour {{guerisonDureeValue}} {{guerisonDureeUnite}} et | ||||||
|  |   se repose de {{caseFatigueReel}} cases de fatigue.<br> | ||||||
|  |     {{#if data.reposalchimique}} | ||||||
|  |     De plus, étant donné que la potion était alchimique, {{alias}} est en aphasie pendant cette durée. | ||||||
|  |       {{#if aphasiePermanente}} | ||||||
|  |       Et malheureusement, l'aphasie est permanente tant que {{alias}} ne réussit pas un jet de VOLONTE à 0 à Chateau Dormant (le moral compte). | ||||||
|  |       {{/if}} | ||||||
|  |     {{/if}} | ||||||
|  |   {{/if}} | ||||||
|  |   La potion a également été supprimée de l'équipement. | ||||||
|  | </div> | ||||||
| @@ -1,23 +1,21 @@ | |||||||
| <img class="chat-icon" src="systems/foundryvtt-reve-de-dragon/icons/competence_botanique.png" alt="potion de soin" /> | <img class="chat-icon" src="systems/foundryvtt-reve-de-dragon/icons/competence_botanique.png" alt="potion de soin" /> | ||||||
| <h4> | <h4> | ||||||
|   {{#if enchante}} |   {{#if reussiteReve}} | ||||||
|  |   {{alias}} a bu la potion et a échoué son Jet de Résistance (Rêve actuel à -8) : la potion fait effet ! | ||||||
|   {{else}} |   {{else}} | ||||||
|     {{#if reussiteReve}} |   {{alias}} a bu la potion et a réussi son Jet de Résistance (Rêve actuel à -8) : la potion ne fait pas effet ! | ||||||
|     {{alias}} a bu la potion et a échoué son Jet de Résistance (Rêve actuelà -8) : la potion fait effet ! |  | ||||||
|     {{else}} |  | ||||||
|     {{alias}} a bu la potion et a réussi son Jet de Résistance (Rêve actuelà -8) : la potion ne fait pas effet ! |  | ||||||
|     {{/if}} |  | ||||||
|   {{/if}} |   {{/if}} | ||||||
| </h4> | </h4> | ||||||
| <hr> | <hr> | ||||||
| {{#if reussiteReve}} |  | ||||||
| <div> | <div> | ||||||
|   {{alias}} perd 1 point de rêve (déduit autmatiquement) et s'endort pour {{guerisonMinutes}} minutes. A son réveil, les blessures suivantes seront guéries :  |   {{#if reussiteReve}} | ||||||
|  |   {{alias}} perd 1 point de rêve (déduit automatiquement) et s'endort pour {{guerisonMinutes}} minutes. A son réveil, les blessures suivantes seront guéries :  | ||||||
|   <ul> |   <ul> | ||||||
|     {{#each guerisonData.list as |guerison key|}} |     {{#each guerisonData.list as |guerison key|}} | ||||||
|     <li>{{guerison}}</li> |     <li>{{guerison}}</li> | ||||||
|     {{/each}} |     {{/each}} | ||||||
|   </ul> |   </ul> | ||||||
|  |   <br> | ||||||
|  |   {{/if}} | ||||||
|  |   La potion a également été supprimée de l'équipement. | ||||||
| </div> | </div> | ||||||
| {{/if}} |  | ||||||
|   | |||||||
							
								
								
									
										13
									
								
								templates/chat-consommer-potion-repos.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								templates/chat-consommer-potion-repos.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | <img class="chat-icon" src="systems/foundryvtt-reve-de-dragon/icons/competence_botanique.png" alt="potion de repos" /> | ||||||
|  | <h4> | ||||||
|  |   {{alias}} consomme sa Potion de Repos {{enchanteTexte}} de {{name}} ({{data.herbe}}, {{data.herbebrins}} brins). | ||||||
|  | </h4> | ||||||
|  | <hr> | ||||||
|  | <div> | ||||||
|  |   {{#if casesRepos}} | ||||||
|  |   Elle permet de récupérer jusqu'à {{casesRepos}} cases de repos. | ||||||
|  |   {{else}} | ||||||
|  |   Une fois consommée vers fin Lyre, elle vous octroie un bonus de {{data.herbebonus}} segments de fatigue récupérés en plus à la fin de Chateau Dormant (à gérer manuellement). | ||||||
|  |   <br>La potion a également été supprimée de l'équipement. | ||||||
|  |   {{/if}} | ||||||
|  | </div> | ||||||
| @@ -8,5 +8,6 @@ | |||||||
|   Elle permet de guérir {{pointsGuerison}} Points de Guérison. |   Elle permet de guérir {{pointsGuerison}} Points de Guérison. | ||||||
|   {{else}} |   {{else}} | ||||||
|   Lors de votre prochain jet de récupération à Chateau Dormant, vous bénéficierez d'un bonus de {{data.herbebonus}} (appliqué automatiquement). |   Lors de votre prochain jet de récupération à Chateau Dormant, vous bénéficierez d'un bonus de {{data.herbebonus}} (appliqué automatiquement). | ||||||
|  |   <br>La potion a également été supprimée de l'équipement. | ||||||
|   {{/if}} |   {{/if}} | ||||||
| </div> | </div> | ||||||
|   | |||||||
							
								
								
									
										9
									
								
								templates/chat-potionenchantee-chateaudormant.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								templates/chat-potionenchantee-chateaudormant.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | |||||||
|  | <img class="chat-icon" src="{{potionImg}}" alt="{{potionName}}" /> | ||||||
|  | <h4> | ||||||
|  |   La potion enchantée {{potionName}} de {{alias}} a perdu un Point de Rêve (nouveau total : {{pr}}).</h4> | ||||||
|  | <hr> | ||||||
|  | <div> | ||||||
|  |   {{#if (eq pr 0)}} | ||||||
|  |   Sa potion étant désormais à 0 Point de Rêve, elle est inutilisable et doit être jetée. | ||||||
|  |   {{/if}} | ||||||
|  | </div> | ||||||
		Reference in New Issue
	
	Block a user