Refactor the alteration system to be full flow.

This commit is contained in:
Andres Gomez, Thomas (ITDV RL) 2024-06-02 17:01:32 +02:00
parent 8841529b31
commit 6ea8f90903
41 changed files with 688 additions and 452 deletions

View file

@ -3,12 +3,12 @@ package com.pixelized.rplexicon.business
import android.app.Application
import android.content.Context
import com.pixelized.rplexicon.R
import com.pixelized.rplexicon.data.model.Alteration
import com.pixelized.rplexicon.data.model.AssignedSpell
import com.pixelized.rplexicon.data.model.CharacterSheet
import com.pixelized.rplexicon.data.model.DiceThrow
import com.pixelized.rplexicon.data.model.Property
import com.pixelized.rplexicon.data.model.Skill
import com.pixelized.rplexicon.data.model.alteration.Alteration
import com.pixelized.rplexicon.data.model.roll.Flat
import com.pixelized.rplexicon.data.model.roll.Throw
import com.pixelized.rplexicon.data.network.NetworkThrow
@ -20,7 +20,6 @@ import com.pixelized.rplexicon.data.repository.character.SkillRepository
import com.pixelized.rplexicon.data.repository.character.SpellRepository
import com.pixelized.rplexicon.ui.screens.rolls.composable.RollDiceUio
import com.pixelized.rplexicon.utilitary.extentions.icon
import com.pixelized.rplexicon.utilitary.extentions.toLabel
import com.pixelized.rplexicon.utilitary.extentions.local.advantage
import com.pixelized.rplexicon.utilitary.extentions.local.base
import com.pixelized.rplexicon.utilitary.extentions.local.critical
@ -36,6 +35,8 @@ import com.pixelized.rplexicon.utilitary.extentions.local.sum
import com.pixelized.rplexicon.utilitary.extentions.local.toStatus
import com.pixelized.rplexicon.utilitary.extentions.masteryMultiplier
import com.pixelized.rplexicon.utilitary.extentions.modifier
import com.pixelized.rplexicon.utilitary.extentions.toLabel
import kotlinx.coroutines.flow.firstOrNull
import javax.inject.Inject
import kotlin.math.abs
import kotlin.math.max
@ -57,14 +58,15 @@ class DiceThrowUseCase @Inject constructor(
private val skillRepository: SkillRepository,
private val alterationRepository: AlterationRepository,
) {
fun roll(
suspend fun roll(
diceThrow: DiceThrow,
isThrowHidden: Boolean,
alterationId: List<String>,
): DiceThrowResult? {
val sheet = characterSheetRepository.find(name = diceThrow.character)
val alterations = alterationRepository.getAlterations(character = diceThrow.character)
.filter { alterationId.contains(it.name) }
val alterations =
alterationRepository.getAssignedAlterations(diceThrow.character).firstOrNull()
?.filter { alterationId.contains(it.name) } ?: emptyList()
return if (sheet != null) {
when (diceThrow) {
@ -393,15 +395,12 @@ class DiceThrowUseCase @Inject constructor(
character = diceThrow.character,
action = diceThrow.weapon,
)
val objectAlterations = alterationRepository.getAlterations(
objects = action?.alterations,
)
actionThrow(
character = sheet,
action = diceThrow.weapon,
diceThrow = action?.hit,
title = { getString(R.string.dice_roll_attack_hit_title, it) },
alterations = alterations + objectAlterations,
alterations = alterations,
ability = Property.PHYSICAL_MELEE_ATTACK,
)
}
@ -411,15 +410,12 @@ class DiceThrowUseCase @Inject constructor(
character = diceThrow.character,
action = diceThrow.weapon,
)
val objectAlterations = alterationRepository.getAlterations(
objects = action?.alterations,
)
actionThrow(
character = sheet,
action = diceThrow.weapon,
diceThrow = action?.damage,
title = { getString(R.string.dice_roll_attack_damage_title, it) },
alterations = alterations + objectAlterations,
alterations = alterations,
ability = Property.PHYSICAL_MELEE_DAMAGE,
)
}
@ -429,15 +425,12 @@ class DiceThrowUseCase @Inject constructor(
character = diceThrow.character,
action = diceThrow.weapon,
)
val objectAlterations = alterationRepository.getAlterations(
objects = action?.alterations,
)
actionThrow(
character = sheet,
action = diceThrow.weapon,
diceThrow = action?.hit,
title = { getString(R.string.dice_roll_attack_hit_title, it) },
alterations = alterations + objectAlterations,
alterations = alterations,
ability = Property.PHYSICAL_RANGE_ATTACK,
)
}
@ -447,15 +440,12 @@ class DiceThrowUseCase @Inject constructor(
character = diceThrow.character,
action = diceThrow.weapon,
)
val objectAlterations = alterationRepository.getAlterations(
objects = action?.alterations,
)
actionThrow(
character = sheet,
action = diceThrow.weapon,
diceThrow = action?.damage,
title = { getString(R.string.dice_roll_attack_damage_title, it) },
alterations = alterations + objectAlterations,
alterations = alterations,
ability = Property.PHYSICAL_RANGE_DAMAGE,
)
}
@ -750,11 +740,13 @@ class DiceThrowUseCase @Inject constructor(
// compute the amount of main dice to throw.
val amount = if (status.isCritical) {
diceThrow?.dice?.count?.times(2)?.let {
if (ability == Property.PHYSICAL_MELEE_DAMAGE && status.isSavageAttacks)
it.plus(1) else it
if (ability == Property.PHYSICAL_MELEE_DAMAGE && status.isSavageAttacks) it.plus(
1
) else it
}?.let {
if (ability == Property.PHYSICAL_MELEE_DAMAGE && status.isBrutalCritical)
it.plus(1) else it
if (ability == Property.PHYSICAL_MELEE_DAMAGE && status.isBrutalCritical) it.plus(
1
) else it
}
} else {
diceThrow?.dice?.count