Fix success/failure computation
All checks were successful
Release Creation / build (release) Successful in 58s

This commit is contained in:
2025-05-30 09:54:58 +02:00
parent 0ee42aef99
commit 10e668bc71
3 changed files with 51 additions and 43 deletions

View File

@@ -219,22 +219,32 @@ export default class HellbornRoll extends Roll {
} else if (this.total >= options.difficulty) {
resultType = "success"
}
// Compute the result quality
this.options.satanicSuccess = false
this.options.fiendishFailure = false
this.options.rollData = foundry.utils.duplicate(rollData)
if (resultType === "success") {
let nb6 = roll.terms[0].results.filter(r => r.result >= 4).length
nb6 += roll.terms[2].total <= 4 ? 1 : 0
this.options.satanicSuccess = nb6 >= 3
// Check if all results are equal
let workResults = foundry.utils.duplicate(roll.terms[0].results)
// Get the most common result of the roll
let commonResult = workResults.reduce((acc, r) => {
acc[r.result] = (acc[r.result] || 0) + 1
return acc
}, {})
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 (this.options.satanicSuccess) {
resultType = "success"
}
}
if (resultType === "failure") {
let nb1 = roll.terms[0].results.filter(r => r.result <= 3).length
nb1 += roll.terms[4].total <= 3 ? 1 : 0
this.options.fiendishFailure = nb1 >= 3
if (commonResult <= 3 && nbEqual >= 2) {
nbEqual += (options.nbDisadvantages > 0 && roll.terms[4].total === commonResult) ? 1 : 0
this.options.fiendishFailure = nbEqual >= 3
if (this.options.fiendishFailure) {
resultType = "failure"
}