From ae6581219bd5d0a2cbe2d1a51d2c13aa887ca81b Mon Sep 17 00:00:00 2001 From: Thomas Andres Gomez Date: Sun, 17 Dec 2023 19:19:43 +0100 Subject: [PATCH] Add Object / Spell alterations. --- .../rplexicon/business/DiceThrowUseCase.kt | 30 ++++++++++++++++--- .../rplexicon/data/model/Property.kt | 2 ++ .../ui/screens/rolls/composable/ThrowsCard.kt | 4 +-- .../rolls/factory/AlterationFactory.kt | 4 +-- 4 files changed, 32 insertions(+), 8 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 9dd00c1..2fa3a79 100644 --- a/app/src/main/java/com/pixelized/rplexicon/business/DiceThrowUseCase.kt +++ b/app/src/main/java/com/pixelized/rplexicon/business/DiceThrowUseCase.kt @@ -426,8 +426,8 @@ class DiceThrowUseCase @Inject constructor( action = diceThrow.item, diceThrow = action?.effect, title = { getString(R.string.dice_roll_use_object, it) }, - alterations = emptyList(), - ability = null, + alterations = alterations, + ability = Property.OBJECT_EFFECT, ) } @@ -702,10 +702,10 @@ class DiceThrowUseCase @Inject constructor( } } else { diceThrow?.amount - } ?: 1 + } // main roll val result = roll( - amount = amount, + amount = amount ?: 1, faces = diceThrow?.faces ?: 20, advantage = advantage, disadvantage = disadvantage, @@ -785,10 +785,16 @@ class DiceThrowUseCase @Inject constructor( val spellName = spell?.spell?.name ?: "" val titleString = application.getString(R.string.dice_roll_spell_cast, spellName) + val advantage = status[Property.SPELL_EFFECT].advantage + val disadvantage = status[Property.SPELL_EFFECT].disadvantage // main roll val result = roll( amount = spell?.effect?.amount ?: 1, faces = spell?.effect?.faces ?: 4, + advantage = advantage, + disadvantage = disadvantage, + fail = status[Property.SPELL_EFFECT].fail, + critical = status[Property.SPELL_EFFECT].critical, ) // fetch and build a list of additionnal level effect. @@ -797,12 +803,18 @@ class DiceThrowUseCase @Inject constructor( val localRoll = roll( amount = spell.level.amount, faces = spell.level.faces, + advantage = advantage, + disadvantage = disadvantage, + fail = status[Property.SPELL_EFFECT].fail, + critical = status[Property.SPELL_EFFECT].critical, ) ThrowsCardUio.Detail( title = application.getString(R.string.spell_level_chooser_label, "$it"), throws = ThrowsCardUio.Throw( dice = spell.level.faces.icon, roll = "${spell.level.amount}d${spell.level.faces}", + advantage = advantage, + disadvantage = disadvantage, result = localRoll.label, ), result = "${localRoll.value}", @@ -836,6 +848,8 @@ class DiceThrowUseCase @Inject constructor( throws = ThrowsCardUio.Throw( dice = (spell?.effect?.faces ?: 4).icon, roll = "${spell?.effect?.amount ?: 1}d${spell?.effect?.faces ?: 4}", + advantage = advantage, + disadvantage = disadvantage, result = result.label, ), result = "${result.value}", @@ -856,10 +870,16 @@ class DiceThrowUseCase @Inject constructor( val spellName = skill?.name val titleString = application.getString(R.string.dice_roll_spell_cast, spellName) + val advantage = status[Property.SKILL].advantage + val disadvantage = status[Property.SKILL].disadvantage // main roll val result = roll( amount = skill?.effect?.amount ?: 1, faces = skill?.effect?.faces ?: 4, + advantage = advantage, + disadvantage = disadvantage, + fail = status[Property.SKILL].fail, + critical = status[Property.SKILL].critical, ) // fetch and build a list of dice roll base on alterations. @@ -892,6 +912,8 @@ class DiceThrowUseCase @Inject constructor( throws = ThrowsCardUio.Throw( dice = (skill?.effect?.faces ?: 4).icon, roll = "${skill?.effect?.amount ?: 1}d${skill?.effect?.faces ?: 4}", + advantage = advantage, + disadvantage = disadvantage, result = result.label, ), result = "${result.value}", diff --git a/app/src/main/java/com/pixelized/rplexicon/data/model/Property.kt b/app/src/main/java/com/pixelized/rplexicon/data/model/Property.kt index b926cc9..8056ddd 100644 --- a/app/src/main/java/com/pixelized/rplexicon/data/model/Property.kt +++ b/app/src/main/java/com/pixelized/rplexicon/data/model/Property.kt @@ -50,4 +50,6 @@ enum class Property(val key: String) { PHYSICAL_RANGE_DAMAGE("Dommage physique à distance"), SPELL_ATTACK("Attaque sortilège"), SPELL_DAMAGE("Dommage sortilège"), + SPELL_EFFECT("Effet des objects"), + OBJECT_EFFECT("Effet des sortilège") } \ No newline at end of file diff --git a/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/composable/ThrowsCard.kt b/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/composable/ThrowsCard.kt index d6460a5..7038549 100644 --- a/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/composable/ThrowsCard.kt +++ b/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/composable/ThrowsCard.kt @@ -225,8 +225,8 @@ private fun ThrowsRollDetail( .align(alignment = Alignment.Bottom) .padding(bottom = 2.dp), tint = when { - it.advantage -> MaterialTheme.colorScheme.primary - it.disadvantage -> Color.Red + it.advantage && !it.disadvantage -> MaterialTheme.colorScheme.primary + it.disadvantage && !it.advantage -> Color.Red else -> MaterialTheme.colorScheme.onSurface }, painter = painterResource(id = it.dice), diff --git a/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/factory/AlterationFactory.kt b/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/factory/AlterationFactory.kt index 7e6e988..1a76589 100644 --- a/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/factory/AlterationFactory.kt +++ b/app/src/main/java/com/pixelized/rplexicon/ui/screens/rolls/factory/AlterationFactory.kt @@ -117,7 +117,7 @@ class AlterationFactory @Inject constructor( character = diceThrow.character, spell = diceThrow.spell, ) - spell?.effect?.modifier ?: emptyList() + listOf(Property.SPELL_EFFECT) + (spell?.effect?.modifier ?: emptyList()) } is DiceThrow.Skill -> { @@ -128,7 +128,7 @@ class AlterationFactory @Inject constructor( listOf(Property.SKILL) + (skill?.effect?.modifier ?: emptyList()) } - is DiceThrow.Object -> emptyList() + is DiceThrow.Object -> listOf(Property.OBJECT_EFFECT) } return alterationRepository