From 151312b9940acebb8f68d527d7b6e534710382c5 Mon Sep 17 00:00:00 2001 From: LeRatierBretonnien Date: Fri, 30 May 2025 18:27:37 +0200 Subject: [PATCH] Fix success/failure computation --- module/documents/roll.mjs | 24 +++++++++++++++--------- templates/chat-message.hbs | 15 +++++++-------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/module/documents/roll.mjs b/module/documents/roll.mjs index e2ebbc0..d6a6e3d 100644 --- a/module/documents/roll.mjs +++ b/module/documents/roll.mjs @@ -199,7 +199,17 @@ export default class HellbornRoll extends Roll { options.nbAdvantages = Number(options.nbAdvantages) options.nbDisadvantages = Number(options.nbDisadvantages) - let diceFormula = `3D6 + ${options.nbAdvantages}D6kh - ${options.nbDisadvantages}D6kh + ${options.rollItem.value}` + let dice = 3; + let keep = "" + if ( options.nbAdvantages > 0 || options.nbDisadvantages > 0) { + dice = 4; + if ( options.nbAdvantages > options.nbDisadvantages) { + keep = "kh3" + } else { + keep = "kl3" + } + } + let diceFormula = `${dice}D6${keep} + ${options.rollItem.value}` const roll = new this(diceFormula, options.data, rollData) await roll.evaluate() console.log("Roll", rollData, roll) @@ -235,16 +245,14 @@ export default class HellbornRoll extends Roll { commonResult = Object.entries(commonResult).reduce((a, b) => (a[1] > b[1]) ? a : b)[0] let nbEqual = workResults.filter(r => Number(r.result) === Number(commonResult)).length - if (commonResult >= 4 && nbEqual >= 2) { - nbEqual += (options.nbAdvantages > 0 && roll.terms[2].total === commonResult) ? 1 : 0 - this.options.satanicSuccess = nbEqual >= 3 + if (commonResult >= 4 && nbEqual >= 3) { + this.options.satanicSuccess = true if (this.options.satanicSuccess) { resultType = "success" } } - if (commonResult <= 3 && nbEqual >= 2) { - nbEqual += (options.nbDisadvantages > 0 && roll.terms[4].total === commonResult) ? 1 : 0 - this.options.fiendishFailure = nbEqual >= 3 + if (commonResult <= 3 && nbEqual >= 3) { + this.options.fiendishFailure = true if (this.options.fiendishFailure) { resultType = "failure" } @@ -253,8 +261,6 @@ export default class HellbornRoll extends Roll { this.options.isSuccess = resultType === "success" this.options.isFailure = resultType === "failure" this.options.results = roll.terms[0].results - this.options.advantageResult = roll.terms[2].total - this.options.disadvantageResult = roll.terms[4].total } /** diff --git a/templates/chat-message.hbs b/templates/chat-message.hbs index ef0d202..631b187 100644 --- a/templates/chat-message.hbs +++ b/templates/chat-message.hbs @@ -21,20 +21,19 @@
  • {{localize "HELLBORN.Label.difficulty"}} : {{difficulty}}
  • + {{#if (gt nbAdvantages 0)}} +
  • With Advantage !
  • + {{/if}} + {{#if (gt nbDisadvantages 0)}} +
  • With Disadvantages !
  • + {{/if}} +
  • Results : {{#each results as |result|}} {{result.result}} {{/each}}
  • - {{#if (gt nbAdvantages 0)}} -
  • Advantages : {{nbAdvantages}}, result {{advantageResult}}
  • - {{/if}} - {{#if (gt nbDisadvantages 0)}} -
  • Disadvantages : {{nbDisadvantages}}, result {{disadvantageResult}}
  • - {{/if}} - - {{#if isSuccess}} {{#if satanicSuccess}}