From a0251cbeeec0c1ab6fd4edd49514956a97562bbd Mon Sep 17 00:00:00 2001 From: Thomas Andres Gomez Date: Tue, 10 Oct 2023 09:00:23 +0200 Subject: [PATCH] Fix critical roll damage. --- .../rplexicon/business/DiceThrowUseCase.kt | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/pixelized/rplexicon/business/DiceThrowUseCase.kt b/app/src/main/java/com/pixelized/rplexicon/business/DiceThrowUseCase.kt index 93fbfec..f8b183d 100644 --- a/app/src/main/java/com/pixelized/rplexicon/business/DiceThrowUseCase.kt +++ b/app/src/main/java/com/pixelized/rplexicon/business/DiceThrowUseCase.kt @@ -669,13 +669,13 @@ class DiceThrowUseCase @Inject constructor( // retrieve some wording. val titleString = title(application, action) - val canMakeCriticalRoll = - ability == Property.PHYSICAL_MELEE_ATTACK || ability == Property.PHYSICAL_RANGE_ATTACK || ability == Property.SPELL_ATTACK + // check if this throw can be a critical success of failure. + val canMakeCriticalRoll = when (ability) { + Property.PHYSICAL_MELEE_ATTACK, + Property.PHYSICAL_RANGE_ATTACK, + Property.SPELL_ATTACK -> true - var criticalDiceMultiplier = 2 - if (ability == Property.PHYSICAL_MELEE_DAMAGE) { - if (alterations.isSavageAttacks) criticalDiceMultiplier++ - if (alterations.isBrutalCritical) criticalDiceMultiplier++ + else -> false } // create a list destined to contain all the values (rolled + bonus) @@ -686,14 +686,25 @@ class DiceThrowUseCase @Inject constructor( val disadvantage = alterations[ability].disadvantage val fail = alterations[ability].fail + // compute the amount of main dice to throw. + val amount = if (alterations.isCritical) { + diceThrow?.amount?.times(2)?.let { + if (ability == Property.PHYSICAL_MELEE_DAMAGE && alterations.isSavageAttacks) + it.plus(1) else it + }?.let { + if (ability == Property.PHYSICAL_MELEE_DAMAGE && alterations.isBrutalCritical) + it.plus(1) else it + } + } else { + diceThrow?.amount + } ?: 1 // main roll val result = roll( - amount = diceThrow?.amount ?: 1, + amount = amount, faces = diceThrow?.faces ?: 20, advantage = advantage, disadvantage = disadvantage, fail = fail, - critical = if (alterations.isCritical) criticalDiceMultiplier else 1, ) allValue.add(result.value) @@ -701,7 +712,7 @@ class DiceThrowUseCase @Inject constructor( val diceAlterationBonus = alterations[ability]?.flatMap { status -> status.dices.map { dice -> val localRoll = roll( - amount = dice.count, + amount = if (alterations.isCritical) dice.count * 2 else dice.count, faces = dice.faces, advantage = dice.advantage, disadvantage = dice.disadvantage, @@ -995,11 +1006,10 @@ class DiceThrowUseCase @Inject constructor( advantage: Boolean = false, disadvantage: Boolean = false, fail: Boolean = false, - critical: Int = 1, ): DiceRollResult { return when { advantage && !disadvantage -> { - val roll = List(amount * critical) { random(faces, fail) to random(faces, fail) } + val roll = List(amount) { random(faces, fail) to random(faces, fail) } DiceRollResult( label = roll.joinToString(" + ") { "${it.first}~${it.second}" }, value = roll.sumOf { max(it.first, it.second) }, @@ -1007,7 +1017,7 @@ class DiceThrowUseCase @Inject constructor( } disadvantage && !advantage -> { - val roll = List(amount * critical) { random(faces, fail) to random(faces, fail) } + val roll = List(amount) { random(faces, fail) to random(faces, fail) } DiceRollResult( label = roll.joinToString(" + ") { "${it.first}~${it.second}" }, value = roll.sumOf { min(it.first, it.second) }, @@ -1015,7 +1025,7 @@ class DiceThrowUseCase @Inject constructor( } else -> { - val roll = List(amount * critical) { random(faces, fail) } + val roll = List(amount) { random(faces, fail) } DiceRollResult( label = roll.toLabel(), value = roll.sum(),