forked from public/foundryvtt-reve-de-dragon
		
	Lancer un sort avec RdDRoll
This commit is contained in:
		
							
								
								
									
										228
									
								
								module/actor.js
									
									
									
									
									
								
							
							
						
						
									
										228
									
								
								module/actor.js
									
									
									
									
									
								
							| @@ -91,7 +91,6 @@ export class RdDActor extends Actor { | |||||||
|     if (actorData.type === 'personnage') this._prepareCharacterData(actorData); |     if (actorData.type === 'personnage') this._prepareCharacterData(actorData); | ||||||
|     if (actorData.type === 'creature') this.computeEtatGeneral(actorData); |     if (actorData.type === 'creature') this.computeEtatGeneral(actorData); | ||||||
|     if (actorData.type === 'humanoide') this.computeEtatGeneral(actorData); |     if (actorData.type === 'humanoide') this.computeEtatGeneral(actorData); | ||||||
|  |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /* -------------------------------------------- */ |   /* -------------------------------------------- */ | ||||||
| @@ -142,14 +141,8 @@ export class RdDActor extends Actor { | |||||||
|  |  | ||||||
|   /* -------------------------------------------- */ |   /* -------------------------------------------- */ | ||||||
|   async performRoll(rollData, attacker = undefined) { |   async performRoll(rollData, attacker = undefined) { | ||||||
|  |  | ||||||
|     // Cas des bonus de cases pour les sorts |  | ||||||
|     let sortBonus = 0; |  | ||||||
|     if (rollData.selectedSort) {  |  | ||||||
|       sortBonus = RdDItemSort.getCaseBonus( rollData.selectedSort, rollData.coord ); |  | ||||||
|     } |  | ||||||
|     //  garder le résultat |     //  garder le résultat | ||||||
|     rollData.rolled = await RdDResolutionTable.roll(rollData.caracValue, rollData.finalLevel, sortBonus); |     rollData.rolled = await RdDResolutionTable.rollData(rollData); | ||||||
|  |  | ||||||
|     //console.log("performRoll", rollData) |     //console.log("performRoll", rollData) | ||||||
|     if ( !rollData.attackerRoll) {// Store in the registry if not a defense roll |     if ( !rollData.attackerRoll) {// Store in the registry if not a defense roll | ||||||
| @@ -303,12 +296,6 @@ export class RdDActor extends Actor { | |||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // Sort management |  | ||||||
|     if (rollData.selectedSort) { // Lancement de sort ! |  | ||||||
|       resumeCompetence = rollData.selectedDraconic.name + "/" + rollData.selectedSort.name; |  | ||||||
|       explications = await this._rollLancementDeSort(rollData, rolled); |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     // Save it for fight in the flags area |     // Save it for fight in the flags area | ||||||
|     game.system.rdd.rollDataHandler[this.data._id] = duplicate(rollData); |     game.system.rdd.rollDataHandler[this.data._id] = duplicate(rollData); | ||||||
|  |  | ||||||
| @@ -370,68 +357,6 @@ export class RdDActor extends Actor { | |||||||
|     return dmgArme + dmgPerso; |     return dmgArme + dmgPerso; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /* -------------------------------------------- */ |  | ||||||
|   async _rollLancementDeSort(rollData,  rolled) { |  | ||||||
|  |  | ||||||
|     let sort = duplicate(rollData.selectedSort); |  | ||||||
|  |  | ||||||
|     let closeTMR = true; |  | ||||||
|     let coutReve = sort.data.ptreve_reel; // toujours positionné par cas de sort à ptreve variables |  | ||||||
|  |  | ||||||
|     let explications = "<br>Lancement du sort <strong>" + sort.name + "</strong> : " + Misc.upperFirst(sort.data.draconic) |  | ||||||
|     + " pour " + coutReve + " points de Rêve" |  | ||||||
|       + "<br>Depuis la case " + rollData.coord + " (" + TMRUtility.getTMRDescription(rollData.coord).label + ")"; |  | ||||||
|        |  | ||||||
|       let myReve = duplicate(this.data.data.reve.reve); |  | ||||||
|       if (rolled.isSuccess) { // Réussite du sort ! |  | ||||||
|         sort.ptreve_reel = coutReve; |  | ||||||
|         if (rolled.isPart) { |  | ||||||
|           coutReve = Math.max(Math.ceil(coutReve / 2), 1); |  | ||||||
|         } |  | ||||||
|         // Incrémenter/gére le bonus de case |  | ||||||
|         RdDItemSort.incrementBonusCase(this, sort, rollData.coord); |  | ||||||
|  |  | ||||||
|         if (myReve.value > coutReve){ |  | ||||||
|           explications += "<br>Réussite du sort: " + coutReve + " points de Rêve sont dépensés (Bonus de case : +" + rolled.bonus + "%)"; |  | ||||||
|  |  | ||||||
|           if (rollData.isSortReserve) { |  | ||||||
|           // Mise en réserve |  | ||||||
|           myReve.value--; |  | ||||||
|           await this.sortMisEnReserve(rollData, sort); |  | ||||||
|           closeTMR = false; |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|       else { |  | ||||||
|          // Todo 0 pts de reve !!!! |  | ||||||
|          explications += "<br>Pas assez de rêve"; |  | ||||||
|          mergeObject(rollData, RdDResolutionTable.getResultat("echec")); |  | ||||||
|       }  |  | ||||||
|     } else { |  | ||||||
|       if (rolled.isETotal) { // Echec total ! |  | ||||||
|         coutReve *= 2; |  | ||||||
|         myReve.value = myReve.value - coutReve; |  | ||||||
|         explications += "<br><strong>Echec TOTAL</strong> du sort : " + coutReve + " Points de Rêve"; |  | ||||||
|       } else { |  | ||||||
|         coutReve = 0 |  | ||||||
|         explications += "<br>Echec du sort !"; |  | ||||||
|       } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     myReve.value = Math.max(myReve.value - coutReve, 0); |  | ||||||
|     await this.update({ "data.reve.reve": myReve }); |  | ||||||
|      |  | ||||||
|     if (myReve.value == 0) { // 0 points de reve |  | ||||||
|       ChatMessage.create({ content: this.name + " est réduit à 0 Points de Rêve, et tombe endormi !" }); |  | ||||||
|       closeTMR = true; |  | ||||||
|     } |  | ||||||
|     if (closeTMR) { |  | ||||||
|       this.currentTMR.close(); // Close TMR ! |  | ||||||
|     } else { |  | ||||||
|       this.currentTMR.maximize(); // Re-display TMR |  | ||||||
|     } |  | ||||||
|     return explications |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   /* -------------------------------------------- */ |   /* -------------------------------------------- */ | ||||||
|   async dormirChateauDormant() { |   async dormirChateauDormant() { | ||||||
|     let message = {  |     let message = {  | ||||||
| @@ -1324,38 +1249,6 @@ export class RdDActor extends Actor { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /* -------------------------------------------- */ |  | ||||||
|   async rollUnSort(coord) { |  | ||||||
|     let draconicList = this.getDraconicList(); |  | ||||||
|     let sortList = duplicate(this.getSortList()); // Duplication car les pts de reve sont modifiés dans le sort |  | ||||||
|      |  | ||||||
|     let rollData = {  |  | ||||||
|       selectedCarac: this.data.data.carac.reve, |  | ||||||
|       etat: this.data.data.compteurs.etat.value,  |  | ||||||
|       draconicList: draconicList, |  | ||||||
|       sortList: sortList, |  | ||||||
|       selectedDraconic: this.getBestDraconic(), |  | ||||||
|       selectedSort: sortList[0], |  | ||||||
|       coord: coord, |  | ||||||
|       coordLabel: TMRUtility.getTMRDescription( coord).label, |  | ||||||
|       finalLevel: 0, |  | ||||||
|       diffConditions: 0, |  | ||||||
|       diffLibre: sortList[0].data.difficulte, // Per default at startup |  | ||||||
|       coutreve: Array(20).fill().map((item, index) => 1 + index), |  | ||||||
|       ajustementsConditions: CONFIG.RDD.ajustementsConditions, |  | ||||||
|       difficultesLibres: CONFIG.RDD.difficultesLibres, |  | ||||||
|       malusArmureValue: 0, |  | ||||||
|       surencMalusFlag: false, // A ne pas utiliser pour les sorts |  | ||||||
|       surencMalusValue: 0, |  | ||||||
|       surencMalusApply: false, |  | ||||||
|       isNatation: false, |  | ||||||
|       useEncForNatation: false |  | ||||||
|     } |  | ||||||
|     if ( this.currentTMR) this.currentTMR.minimize(); // Hide |  | ||||||
|     let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-roll-sort.html', rollData); |  | ||||||
|     new RdDRollDialog("sort", html, rollData, this ).render(true); |  | ||||||
|   } |  | ||||||
|    |  | ||||||
|   /* -------------------------------------------- */   |   /* -------------------------------------------- */   | ||||||
|   _createCallbackExperience() { |   _createCallbackExperience() { | ||||||
|     return { |     return { | ||||||
| @@ -1374,6 +1267,125 @@ export class RdDActor extends Actor { | |||||||
|     ChatMessage.create(message); |     ChatMessage.create(message); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /* -------------------------------------------- */ | ||||||
|  |   async rollUnSort(coord) { | ||||||
|  |     let sortList = duplicate(this.getSortList()); // Duplication car les pts de reve sont modifiés dans le sort | ||||||
|  |     if (!sortList || sortList.length == 0) | ||||||
|  |     { | ||||||
|  |       ui.notifications.info("Aucun sort disponible!"); | ||||||
|  |       return; | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     let rollData = {  | ||||||
|  |       selectedCarac: this.data.data.carac.reve, | ||||||
|  |       draconicList: this.getDraconicList(), | ||||||
|  |       sortList: sortList, | ||||||
|  |       selectedDraconic: this.getBestDraconic(), | ||||||
|  |       selectedSort: sortList[0], | ||||||
|  |       coord: coord, | ||||||
|  |       coordLabel: TMRUtility.getTMRDescription( coord).label, | ||||||
|  |       diffLibre: sortList[0].data.difficulte, // Per default at startup | ||||||
|  |       coutreve: Array(20).fill().map((item, index) => 1 + index) | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     if ( this.currentTMR) this.currentTMR.minimize(); // Hide | ||||||
|  |     const dialog = await RdDRoll.create(this, rollData, | ||||||
|  |       {html: 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-sort.html'}, | ||||||
|  |       { | ||||||
|  |         name: 'lancer-un-sort', | ||||||
|  |         label: 'Lancer un sort', | ||||||
|  |         callbacks: [ | ||||||
|  |           this._createCallbackExperience(), | ||||||
|  |           { action: r => this._rollUnSortResult(r, false) } | ||||||
|  |         ] | ||||||
|  |       }, | ||||||
|  |       { | ||||||
|  |         name: 'mettre-en-reserve', | ||||||
|  |         label: 'Mettre un sort en réserve', | ||||||
|  |         callbacks: [ | ||||||
|  |           this._createCallbackExperience(), | ||||||
|  |           { action:  r => this._rollUnSortResult(r, true) } | ||||||
|  |         ] | ||||||
|  |       } | ||||||
|  |     ); | ||||||
|  |     dialog.render(true); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   async _rollUnSortResult(rollData, isSortReserve = false) { | ||||||
|  |     rollData.isSortReserve = isSortReserve; | ||||||
|  |     let rolled = rollData.rolled; | ||||||
|  |     let sort = rollData.selectedSort; | ||||||
|  |     let closeTMR = !rollData.isSortReserve; | ||||||
|  |      | ||||||
|  |     let explications = rollData.isSortReserve | ||||||
|  |     ? ("<br>Mise en réserve du sort en " + rollData.coordLabel + "(" + rollData.coord + ")<strong>") | ||||||
|  |     : "<br>Lancement du sort <strong>"; | ||||||
|  |     explications += sort.name + "</strong> : " + Misc.upperFirst(sort.data.draconic) | ||||||
|  |     + " pour " + sort.data.ptreve_reel + " points de Rêve" | ||||||
|  |     + "<br>Depuis la case " + rollData.coord + " (" + TMRUtility.getTMRDescription(rollData.coord).label + ")"; | ||||||
|  |      | ||||||
|  |     let depenseReve = sort.data.ptreve_reel; | ||||||
|  |     let myReve = duplicate(this.data.data.reve.reve); | ||||||
|  |     if (rolled.isSuccess) { // Réussite du sort ! | ||||||
|  |       //sort.ptreve_reel = coutReve; | ||||||
|  |       if (rolled.isPart) { | ||||||
|  |         depenseReve = Math.max(Math.floor(depenseReve / 2), 1); | ||||||
|  |       } | ||||||
|  |       if (rollData.isSortReserve) { | ||||||
|  |         depenseReve++; | ||||||
|  |       } | ||||||
|  |  | ||||||
|  |       if (myReve.value > depenseReve) { | ||||||
|  |         explications += "<br>Réussite du sort: " + depenseReve + " points de Rêve sont dépensés (Bonus de case en " + rollData.coord + ": +" + rolled.bonus + "%)"; | ||||||
|  |  | ||||||
|  |         // Incrémenter/gére le bonus de case | ||||||
|  |         RdDItemSort.incrementBonusCase(this, sort, rollData.coord); | ||||||
|  |  | ||||||
|  |         if (rollData.isSortReserve) { | ||||||
|  |           await this.sortMisEnReserve(rollData, sort); | ||||||
|  |           closeTMR = false; | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |       else { | ||||||
|  |         // Todo 0 pts de reve !!!! | ||||||
|  |         depenseReve = 0; | ||||||
|  |         explications += "<br>Pas assez de rêve"; | ||||||
|  |         mergeObject(rollData, RdDResolutionTable.getResultat("echec")); | ||||||
|  |       } | ||||||
|  |     } else { | ||||||
|  |       if (rolled.isETotal) { // Echec total ! | ||||||
|  |         depenseReve = Math.max(myReve.value, Math.floor(depenseReve * 1.5)) | ||||||
|  |         explications += "<br><strong>Echec TOTAL</strong> du sort : " + depenseReve + " Points de Rêve"; | ||||||
|  |         // TODO: mise en réserve d'un échec total... | ||||||
|  |       } else { | ||||||
|  |         depenseReve = 0 | ||||||
|  |         explications += "<br>Echec du sort !"; | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     myReve.value = Math.max(myReve.value - depenseReve, 0); | ||||||
|  |     await this.update({ "data.reve.reve": myReve }); | ||||||
|  |      | ||||||
|  |     if (myReve.value == 0) { // 0 points de reve | ||||||
|  |       ChatMessage.create({ content: this.name + " est réduit à 0 Points de Rêve, et tombe endormi !" }); | ||||||
|  |       closeTMR = true; | ||||||
|  |     } | ||||||
|  |     if (closeTMR) { | ||||||
|  |       this.currentTMR.close(); // Close TMR ! | ||||||
|  |     } else { | ||||||
|  |       this.currentTMR.maximize(); // Re-display TMR | ||||||
|  |     } | ||||||
|  |     // Final chat message | ||||||
|  |     let chatOptions = { | ||||||
|  |       content: "<strong>Test : " + rollData.selectedCarac.label + " / " + rollData.selectedDraconic.name + " / " + rollData.selectedSort.name + "</strong>" | ||||||
|  |       + "<br>Difficultés <strong>libre : " + rollData.diffLibre + "</strong> / conditions : " + Misc.toSignedString(rollData.diffConditions) +" / état : " + rollData.etat | ||||||
|  |       + RdDResolutionTable.explain(rolled) | ||||||
|  |       + explications | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     ChatUtility.chatWithRollMode(chatOptions, this.name) | ||||||
|  |   } | ||||||
|  |  | ||||||
|   /* -------------------------------------------- */   |   /* -------------------------------------------- */   | ||||||
|   async rollCarac( caracName ) { |   async rollCarac( caracName ) { | ||||||
|     let rollData = { |     let rollData = { | ||||||
|   | |||||||
| @@ -104,7 +104,7 @@ export class RdDResolutionTable { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   /* -------------------------------------------- */ |   /* -------------------------------------------- */ | ||||||
|   static async roll(caracValue, finalLevel, bonus = 0 ) { |   static async roll(caracValue, finalLevel, bonus = undefined ) { | ||||||
|     let chances = this.computeChances(caracValue, finalLevel); |     let chances = this.computeChances(caracValue, finalLevel); | ||||||
|     chances.showDice = true; |     chances.showDice = true; | ||||||
|     this.updateChancesWithBonus( chances, bonus); |     this.updateChancesWithBonus( chances, bonus); | ||||||
|   | |||||||
| @@ -75,6 +75,9 @@ export class RdDRoll extends Dialog { | |||||||
|  |  | ||||||
|   async onAction(action, html) { |   async onAction(action, html) { | ||||||
|     await RdDResolutionTable.rollData(this.rollData); |     await RdDResolutionTable.rollData(this.rollData); | ||||||
|  |  | ||||||
|  |     console.log("RdDRoll -=>", this.rollData, this.rollData.rolled); | ||||||
|  |  | ||||||
|     if (action.callbacks) |     if (action.callbacks) | ||||||
|       for (let callback of action.callbacks) { |       for (let callback of action.callbacks) { | ||||||
|         if (callback.condition == undefined || callback.condition(this.rollData)) { |         if (callback.condition == undefined || callback.condition(this.rollData)) { | ||||||
| @@ -102,6 +105,7 @@ export class RdDRoll extends Dialog { | |||||||
|  |  | ||||||
|       // Sort management |       // Sort management | ||||||
|       if (rollData.selectedSort) { |       if (rollData.selectedSort) { | ||||||
|  |         rollData.bonus = RdDItemSort.getCaseBonus( rollData.selectedSort, rollData.coord ), | ||||||
|         //console.log("Toggle show/hide", rollData.selectedSort); |         //console.log("Toggle show/hide", rollData.selectedSort); | ||||||
|         HtmlUtility._showControlWhen("#div-sort-difficulte", RdDItemSort.isDifficulteVariable(rollData.selectedSort)) |         HtmlUtility._showControlWhen("#div-sort-difficulte", RdDItemSort.isDifficulteVariable(rollData.selectedSort)) | ||||||
|         HtmlUtility._showControlWhen("#div-sort-ptreve", RdDItemSort.isCoutVariable(rollData.selectedSort)) |         HtmlUtility._showControlWhen("#div-sort-ptreve", RdDItemSort.isCoutVariable(rollData.selectedSort)) | ||||||
| @@ -154,6 +158,7 @@ export class RdDRoll extends Dialog { | |||||||
|     html.find('#sort').change((event) => { |     html.find('#sort').change((event) => { | ||||||
|       let sortKey = Misc.toInt(event.currentTarget.value); |       let sortKey = Misc.toInt(event.currentTarget.value); | ||||||
|       this.rollData.selectedSort = rollData.sortList[sortKey]; // Update the selectedCarac |       this.rollData.selectedSort = rollData.sortList[sortKey]; // Update the selectedCarac | ||||||
|  |       this.rollData.bonus =  RdDItemSort.getCaseBonus( rollData.selectedSort, rollData.coord ); | ||||||
|       RdDItemSort.setCoutReveReel(rollData.selectedSort); |       RdDItemSort.setCoutReveReel(rollData.selectedSort); | ||||||
|       //console.log("RdDRollSelectDialog - Sort selection", rollData.selectedSort); |       //console.log("RdDRollSelectDialog - Sort selection", rollData.selectedSort); | ||||||
|       updateRollResult(rollData); |       updateRollResult(rollData); | ||||||
|   | |||||||
| @@ -388,7 +388,7 @@ export class RdDTMRDialog extends Dialog { | |||||||
|       console.log("declencheSortEnReserve", sortReserve) |       console.log("declencheSortEnReserve", sortReserve) | ||||||
|       const declenchementSort = "Vous avez déclenché le sort <strong>" + sortReserve.sort.name |       const declenchementSort = "Vous avez déclenché le sort <strong>" + sortReserve.sort.name | ||||||
|         + "</strong> en réserve en " + sortReserve.coord + " (" + TMRUtility.getTMRDescription(sortReserve.coord).label |         + "</strong> en réserve en " + sortReserve.coord + " (" + TMRUtility.getTMRDescription(sortReserve.coord).label | ||||||
|         + ") avec " + sortReserve.sort.ptreve_reel + " points de Rêve"; |         + ") avec " + sortReserve.sort.data.ptreve_reel + " points de Rêve"; | ||||||
|       this._tellToGM(declenchementSort); |       this._tellToGM(declenchementSort); | ||||||
|       this.close(); |       this.close(); | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user