From 96e02cdb7aa941aa8306eaca97561fa7b1d9042d Mon Sep 17 00:00:00 2001 From: sladecraven Date: Tue, 11 Jan 2022 18:19:13 +0100 Subject: [PATCH] Fix infinite loop + dices --- modules/yggdrasill-actor.js | 40 +++++++++++++------- modules/yggdrasill-utility.js | 61 +++++++++++++++++++++++------- system.json | 2 +- templates/chat-generic-result.html | 10 +++-- 4 files changed, 81 insertions(+), 32 deletions(-) diff --git a/modules/yggdrasill-actor.js b/modules/yggdrasill-actor.js index ab099ba..17593d8 100644 --- a/modules/yggdrasill-actor.js +++ b/modules/yggdrasill-actor.js @@ -197,8 +197,9 @@ export class YggdrasillActor extends Actor { if ( changed.data.caracsecondaire.pv.value < 0 ) changed.data.caracsecondaire.pv.value = 0; if ( changed.data.caracsecondaire.pv.value > this.data.data.caracsecondaire.pv.max ) - changed.data.caracsecondaire.pv.value = this.data.data.caracsecondaire.pv.max; + changed.data.caracsecondaire.pv.value = this.data.data.caracsecondaire.pv.max; } + if ( changed.data?.furor?.value ) { if ( changed.data.furor.value < 0 ) changed.data.furor.value = 0; @@ -303,8 +304,10 @@ export class YggdrasillActor extends Actor { /* -------------------------------------------- */ async setEpuise( ) { - await this.update({ 'data.status.epuise': true}); - this.data.data.status.epuise = true; + if (!this.data.data.status.epuise) { + await this.update({ 'data.status.epuise': true}); + this.data.data.status.epuise = true; + } /*let effect = this.getEffectByLabel('Epuisé'); if ( !effect ) { let effect = statusEffects.find( ef => ef.id == 'epuise'); @@ -313,8 +316,10 @@ export class YggdrasillActor extends Actor { } /* -------------------------------------------- */ async cleanEpuise() { - await this.update({ 'data.status.epuise': false}); - this.data.data.status.epuise = false; + if (this.data.data.status.epuise) { + await this.update({ 'data.status.epuise': false}); + this.data.data.status.epuise = false; + } /*let effect = this.getEffectByLabel('Epuisé'); if ( effect ) { await this.deleteEmbeddedDocuments("ActiveEffect", [ effect.id ]); @@ -335,9 +340,10 @@ export class YggdrasillActor extends Actor { /* -------------------------------------------- */ async setBlesse( ) { - await this.update({ 'data.status.blesse': true} ); - this.data.data.status.blesse = true; - console.log("BLESSSE !!!!"); + if (!this.data.data.status.blesse) { + await this.update({ 'data.status.blesse': true} ); + this.data.data.status.blesse = true; + } /*let effect = this.getEffectByLabel('Blessé'); if ( !effect ) { let effect = statusEffects.find( ef => ef.id == 'blesse'); @@ -346,8 +352,10 @@ export class YggdrasillActor extends Actor { } /* -------------------------------------------- */ async cleanBlesse() { - await this.update({ 'data.status.blesse': false} ); - this.data.data.status.blesse = false; + if (this.data.data.status.blesse) { + await this.update({ 'data.status.blesse': false} ); + this.data.data.status.blesse = false; + } /*let effect = this.getEffectByLabel('Blessé'); if ( effect ) { await this.deleteEmbeddedDocuments("ActiveEffect", [ effect.id ]); @@ -362,13 +370,17 @@ export class YggdrasillActor extends Actor { /* -------------------------------------------- */ async setMeurtri( ) { await this.setBlesse(); - await this.update({ 'data.status.meurtri': true}); - this.data.data.status.meurtri = true; + if (!this.data.data.status.meurtri) { + await this.update({ 'data.status.meurtri': true}); + this.data.data.status.meurtri = true; + } } /* -------------------------------------------- */ async cleanMeurtri() { - await this.update({ 'data.status.meurtri': false}); - this.data.data.status.meurtri = false; + if (this.data.data.status.meurtri) { + await this.update({ 'data.status.meurtri': false}); + this.data.data.status.meurtri = false; + } } /* -------------------------------------------- */ isMeurtri() { diff --git a/modules/yggdrasill-utility.js b/modules/yggdrasill-utility.js index aaf4739..0f50b9a 100644 --- a/modules/yggdrasill-utility.js +++ b/modules/yggdrasill-utility.js @@ -183,31 +183,66 @@ export class YggdrasillUtility { rollData.finalBM -= 3; } + rollData.rawDices = [] if (sumDice > nbDice) sumDice = nbDice; - let myRoll = new Roll(nbDice+"d10x10kh"+sumDice+"+"+rollData.furorUsage+"d10+"+niveauCompetence+"+"+rollData.finalBM).roll( { async: false} ); - await this.showDiceSoNice(myRoll, game.settings.get("core", "rollMode") ); - + let rolls = [] + let maxTab = [ {idx: 0, value: 0}, {idx: 0, value:0}] + for (let i=0; i maxTab[0].value) { + if ( maxTab[0].value > maxTab[1].value) { + maxTab[1].value = maxTab[0].value + maxTab[1].idx = maxTab[0].idx + } + maxTab[0].value = rolls[i].total + maxTab[0].idx = i + } else { + if ( rolls[i].total > maxTab[1].value) { + maxTab[1].value = rolls[i].total + maxTab[1].idx = i + } + } + } + let bonusRoll = new Roll(rollData.furorUsage+"d10x10+"+niveauCompetence+"+"+rollData.finalBM).roll( {async: false}) + if ( rollData.furorUsage > 0) { + this.showDiceSoNice(bonusRoll, game.settings.get("core", "rollMode") ); + } + rollData.finalTotal = (sumDice ==1) ? maxTab[0].value : maxTab[0].value + maxTab[1].value; + rollData.finalTotal += bonusRoll.total; + rollData.furorResult = (rollData.furorUsage >0 ) ? bonusRoll.dice[0].results[0].result : 0; + rollData.maxTab = maxTab + // Compute total SR rollData.srFinal = rollData.sr; if ( rollData.bonusdefense ) { rollData.srFinal += rollData.bonusdefense; - } + } + if ( rollData.srFinal > 0 ) { - isCritical = myRoll.total >= rollData.srFinal*2; - isSuccess = myRoll.total >= rollData.srFinal; - marge = myRoll.total - rollData.srFinal; + isCritical = myRoll.finalTotal >= rollData.srFinal*2; + isSuccess = myRoll.finalTotal >= rollData.srFinal; + marge = myRoll.finalTotal - rollData.srFinal; } - rollData.rawDices = duplicate(myRoll.dice[0].results); - if (nbDice == 1 && myRoll.dice[0].results[0].result == 1) { + if (nbDice == 1 && rolls[0].dice[0].results[0].result == 1) { isFailure = true; } - if (nbDice == 2 && myRoll.dice[0].results[0].result == 1 && myRoll.dice[0].results[1].result == 1) { + if (nbDice == 2 && rolls[0].dice[0].results[0].result == 1 && rolls[1].dice[0].results[0].result == 1) { isFailure = true; } if (nbDice >= 3 ) { - let nbOnes = myRoll.dice[0].results.filter( dice => dice.result == 1); - isFailure = nbOnes.length >= 3; + let nbOnes = 0 + for (let roll of rolls) { + if (roll.dice[0].results[0].result == 1 ) nbOnes++; + } + isFailure = nbOnes >= 3; } if ( rollData.furorUsage > 0 ) { let actor = game.actors.get(rollData.actorId); @@ -221,12 +256,12 @@ export class YggdrasillUtility { } // Stockage resultats + rollData.rolls = rolls rollData.sumDice = sumDice; rollData.isFailure = isFailure; rollData.isSuccess = isSuccess; rollData.isCritical = isCritical; rollData.marge = marge; - rollData.roll = myRoll // Specific GALDR if ( rollData.sort?.type == "sortgaldr" && rollData.isSuccess) { diff --git a/system.json b/system.json index 7b80b47..9f25122 100644 --- a/system.json +++ b/system.json @@ -2,7 +2,7 @@ "name": "fvtt-yggdrasill", "title": "Yggdrasill", "description": "Système non-officiel Yggdrasill (7ièm Cercle) pour FoundryVTT", - "version": "1.1.1", + "version": "1.1.2", "manifestPlusVersion": "1.0.0", "minimumCoreVersion": "0.8.0", "compatibleCoreVersion": "9", diff --git a/templates/chat-generic-result.html b/templates/chat-generic-result.html index ead6aab..36df9f4 100644 --- a/templates/chat-generic-result.html +++ b/templates/chat-generic-result.html @@ -43,21 +43,23 @@
  • Dés : - {{#each rawDices as |dice key|}} - {{dice.result}}  + {{#each rawDices as |roll key|}} + {{roll.result}}  {{/each}}
  • {{#if sumDice}}
  • Nombre de dés additionnés : {{sumDice}}
  • {{/if}} +
  • {{#if (eq mode "carac")}}Carac{{else}}Competence{{/if}} : {{niveauCompetence}}
  • Bonus/Malus Final : {{finalBM}}
  • {{#if sr}}
  • Seuil de Réussite final : {{srFinal}}
  • {{/if}} {{#if furorUsage}} -
  • Furor : {{furorUsage}}
  • +
  • Furor dépensée : {{furorUsage}}
  • +
  • Resultat de la Furor : {{furorResult}}
  • {{/if}} -
  • Total : {{roll.total}}

  • +
  • Total : {{finalTotal}}

{{#if dureeGaldrText}}