Add item specific alteration
This commit is contained in:
parent
2c6fc19a2c
commit
3bda885411
10 changed files with 137 additions and 291 deletions
|
|
@ -20,6 +20,7 @@ import com.pixelized.rplexicon.ui.screens.rolls.composable.RollDiceUio
|
|||
import com.pixelized.rplexicon.ui.screens.rolls.composable.ThrowsCardUio
|
||||
import com.pixelized.rplexicon.utilitary.extentions.icon
|
||||
import com.pixelized.rplexicon.utilitary.extentions.local.advantage
|
||||
import com.pixelized.rplexicon.utilitary.extentions.local.critical
|
||||
import com.pixelized.rplexicon.utilitary.extentions.local.disadvantage
|
||||
import com.pixelized.rplexicon.utilitary.extentions.local.fail
|
||||
import com.pixelized.rplexicon.utilitary.extentions.local.isBrutalCritical
|
||||
|
|
@ -52,7 +53,6 @@ class DiceThrowUseCase @Inject constructor(
|
|||
val sheet = characterSheetRepository.find(name = diceThrow.character)
|
||||
val alterations = alterationRepository.getAlterations(character = diceThrow.character)
|
||||
.filter { alterationId.contains(it.name) }
|
||||
.toStatus()
|
||||
|
||||
return if (sheet != null) {
|
||||
when (diceThrow) {
|
||||
|
|
@ -349,12 +349,15 @@ 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,
|
||||
alterations = alterations + objectAlterations,
|
||||
ability = Property.PHYSICAL_MELEE_ATTACK,
|
||||
)
|
||||
}
|
||||
|
|
@ -364,12 +367,15 @@ 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,
|
||||
alterations = alterations + objectAlterations,
|
||||
ability = Property.PHYSICAL_MELEE_DAMAGE,
|
||||
)
|
||||
}
|
||||
|
|
@ -379,12 +385,15 @@ 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,
|
||||
alterations = alterations + objectAlterations,
|
||||
ability = Property.PHYSICAL_RANGE_ATTACK,
|
||||
)
|
||||
}
|
||||
|
|
@ -394,12 +403,15 @@ 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,
|
||||
alterations = alterations + objectAlterations,
|
||||
ability = Property.PHYSICAL_RANGE_DAMAGE,
|
||||
)
|
||||
}
|
||||
|
|
@ -414,7 +426,7 @@ class DiceThrowUseCase @Inject constructor(
|
|||
action = diceThrow.item,
|
||||
diceThrow = action?.effect,
|
||||
title = { getString(R.string.dice_roll_use_object, it) },
|
||||
alterations = emptyMap(),
|
||||
alterations = emptyList(),
|
||||
ability = null,
|
||||
)
|
||||
}
|
||||
|
|
@ -481,7 +493,7 @@ class DiceThrowUseCase @Inject constructor(
|
|||
|
||||
private fun abilityThrow(
|
||||
character: CharacterSheet,
|
||||
alterations: Map<Property, List<Alteration.Status>>,
|
||||
alterations: List<Alteration>,
|
||||
abilityLabel: Context.() -> String,
|
||||
relatedLabel: Context.() -> String?,
|
||||
ability: Property,
|
||||
|
|
@ -499,7 +511,7 @@ class DiceThrowUseCase @Inject constructor(
|
|||
|
||||
private fun savingThrow(
|
||||
character: CharacterSheet,
|
||||
alterations: Map<Property, List<Alteration.Status>>,
|
||||
alterations: List<Alteration>,
|
||||
abilityLabel: Context.() -> String,
|
||||
relatedLabel: Context.() -> String?,
|
||||
ability: Property,
|
||||
|
|
@ -517,7 +529,7 @@ class DiceThrowUseCase @Inject constructor(
|
|||
|
||||
private fun rollAbility(
|
||||
character: CharacterSheet,
|
||||
alterations: Map<Property, List<Alteration.Status>>,
|
||||
alterations: List<Alteration>,
|
||||
abilityTitle: Context.(label: String) -> String,
|
||||
abilityLabel: Context.() -> String,
|
||||
relatedTitle: Context.(label: String) -> String?,
|
||||
|
|
@ -531,27 +543,30 @@ class DiceThrowUseCase @Inject constructor(
|
|||
val abilityTitleString = abilityTitle(application, abilityLabelString)
|
||||
|
||||
// check if the roll is affected by some status.
|
||||
val advantage = alterations[ability].advantage
|
||||
val disadvantage = alterations[ability].disadvantage
|
||||
val fail = alterations[ability].fail
|
||||
|
||||
val advantage = status[ability].advantage
|
||||
val disadvantage = status[ability].disadvantage
|
||||
// main roll
|
||||
val result = roll(advantage = advantage, disadvantage = disadvantage, fail = fail)
|
||||
val result = roll(
|
||||
advantage = advantage,
|
||||
disadvantage = disadvantage,
|
||||
fail = status[ability].fail,
|
||||
critical = status[ability].critical,
|
||||
)
|
||||
|
||||
// fetch and build a list of dice roll base on alterations.
|
||||
val diceAlterationBonus = alterations[ability].alterationsBonus()
|
||||
val diceAlterationBonus = status[ability].alterationsBonus()
|
||||
|
||||
// fetch and build a list of flat bonus
|
||||
val flatAlterationBonus = alterations[ability].flatAlterationBonus()
|
||||
val flatAlterationBonus = status[ability].flatAlterationBonus()
|
||||
|
||||
// fetch and build the associated characteristic
|
||||
val relatedStatBonus = when (relatedStat) {
|
||||
Property.STRENGTH -> (character.strength + alterations[relatedStat].sum).modifier
|
||||
Property.DEXTERITY -> (character.dexterity + alterations[relatedStat].sum).modifier
|
||||
Property.CONSTITUTION -> (character.constitution + alterations[relatedStat].sum).modifier
|
||||
Property.INTELLIGENCE -> (character.intelligence + alterations[relatedStat].sum).modifier
|
||||
Property.WISDOM -> (character.wisdom + alterations[relatedStat].sum).modifier
|
||||
Property.CHARISMA -> (character.charisma + alterations[relatedStat].sum).modifier
|
||||
Property.STRENGTH -> (character.strength + status[relatedStat].sum).modifier
|
||||
Property.DEXTERITY -> (character.dexterity + status[relatedStat].sum).modifier
|
||||
Property.CONSTITUTION -> (character.constitution + status[relatedStat].sum).modifier
|
||||
Property.INTELLIGENCE -> (character.intelligence + status[relatedStat].sum).modifier
|
||||
Property.WISDOM -> (character.wisdom + status[relatedStat].sum).modifier
|
||||
Property.CHARISMA -> (character.charisma + status[relatedStat].sum).modifier
|
||||
Property.PROFICIENCY -> character.proficiency
|
||||
else -> null
|
||||
}?.let { value ->
|
||||
|
|
@ -657,7 +672,7 @@ class DiceThrowUseCase @Inject constructor(
|
|||
action: String,
|
||||
diceThrow: Throw?,
|
||||
title: Context.(action: String) -> String,
|
||||
alterations: Map<Property, List<Alteration.Status>>,
|
||||
alterations: List<Alteration>,
|
||||
ability: Property?,
|
||||
): DiceThrowResult {
|
||||
with(ThrowScope(context = application, character = character, alterations = alterations)) {
|
||||
|
|
@ -673,17 +688,16 @@ class DiceThrowUseCase @Inject constructor(
|
|||
}
|
||||
|
||||
// check if the roll is affected by some status.
|
||||
val advantage = alterations[ability].advantage
|
||||
val disadvantage = alterations[ability].disadvantage
|
||||
val fail = alterations[ability].fail
|
||||
val advantage = status[ability].advantage
|
||||
val disadvantage = status[ability].disadvantage
|
||||
|
||||
// compute the amount of main dice to throw.
|
||||
val amount = if (alterations.isCritical) {
|
||||
val amount = if (status.isCritical) {
|
||||
diceThrow?.amount?.times(2)?.let {
|
||||
if (ability == Property.PHYSICAL_MELEE_DAMAGE && alterations.isSavageAttacks)
|
||||
if (ability == Property.PHYSICAL_MELEE_DAMAGE && status.isSavageAttacks)
|
||||
it.plus(1) else it
|
||||
}?.let {
|
||||
if (ability == Property.PHYSICAL_MELEE_DAMAGE && alterations.isBrutalCritical)
|
||||
if (ability == Property.PHYSICAL_MELEE_DAMAGE && status.isBrutalCritical)
|
||||
it.plus(1) else it
|
||||
}
|
||||
} else {
|
||||
|
|
@ -695,14 +709,15 @@ class DiceThrowUseCase @Inject constructor(
|
|||
faces = diceThrow?.faces ?: 20,
|
||||
advantage = advantage,
|
||||
disadvantage = disadvantage,
|
||||
fail = fail,
|
||||
fail = status[ability].fail,
|
||||
critical = status[ability].critical,
|
||||
)
|
||||
|
||||
// fetch and build a list of dice roll base on alterations.
|
||||
val diceAlterationBonus = alterations[ability].alterationsBonus()
|
||||
val diceAlterationBonus = status[ability].alterationsBonus()
|
||||
|
||||
// fetch and build a list of flat bonus
|
||||
val flatAlterationBonus = alterations[ability].flatAlterationBonus()
|
||||
val flatAlterationBonus = status[ability].flatAlterationBonus()
|
||||
|
||||
// fetch and build the associated characteristic
|
||||
val relatedStatBonus = diceThrow.statBonus(name = action)
|
||||
|
|
@ -763,7 +778,7 @@ class DiceThrowUseCase @Inject constructor(
|
|||
character: CharacterSheet,
|
||||
spell: AssignedSpell?,
|
||||
level: Int,
|
||||
alterations: Map<Property, List<Alteration.Status>>,
|
||||
alterations: List<Alteration>,
|
||||
): DiceThrowResult {
|
||||
with(ThrowScope(context = application, character = character, alterations = alterations)) {
|
||||
// retrieve some wording.
|
||||
|
|
@ -833,7 +848,7 @@ class DiceThrowUseCase @Inject constructor(
|
|||
|
||||
private fun skillThrow(
|
||||
character: CharacterSheet,
|
||||
alterations: Map<Property, List<Alteration.Status>>,
|
||||
alterations: List<Alteration>,
|
||||
skill: Skill?,
|
||||
): DiceThrowResult {
|
||||
with(ThrowScope(context = application, character = character, alterations = alterations)) {
|
||||
|
|
@ -848,10 +863,10 @@ class DiceThrowUseCase @Inject constructor(
|
|||
)
|
||||
|
||||
// fetch and build a list of dice roll base on alterations.
|
||||
val diceAlterationBonus = alterations[Property.SKILL].alterationsBonus()
|
||||
val diceAlterationBonus = status[Property.SKILL].alterationsBonus()
|
||||
|
||||
// fetch and build a list of flat bonus
|
||||
val flatAlterationBonus = alterations[Property.SKILL].flatAlterationBonus()
|
||||
val flatAlterationBonus = status[Property.SKILL].flatAlterationBonus()
|
||||
|
||||
// fetch and build the associated characteristic, proficiency or level
|
||||
val relatedStatBonus = skill?.effect.statBonus(name = skill?.name)
|
||||
|
|
@ -894,8 +909,10 @@ class DiceThrowUseCase @Inject constructor(
|
|||
val context: Context,
|
||||
val allValue: MutableList<Int> = mutableListOf(),
|
||||
val character: CharacterSheet,
|
||||
val alterations: Map<Property, List<Alteration.Status>>,
|
||||
val alterations: List<Alteration>,
|
||||
) {
|
||||
val status = this.alterations.toStatus()
|
||||
|
||||
/**
|
||||
* Fetch any stats / proficiency / level related bonus and build a ThrowsCardUio.Detail for each.
|
||||
*/
|
||||
|
|
@ -905,12 +922,12 @@ class DiceThrowUseCase @Inject constructor(
|
|||
|
||||
fun Property.statBonus(name: String?): ThrowsCardUio.Detail? {
|
||||
return when (this) {
|
||||
Property.STRENGTH -> (character.strength + alterations[this].sum).modifier
|
||||
Property.DEXTERITY -> (character.dexterity + alterations[this].sum).modifier
|
||||
Property.CONSTITUTION -> (character.constitution + alterations[this].sum).modifier
|
||||
Property.INTELLIGENCE -> (character.intelligence + alterations[this].sum).modifier
|
||||
Property.WISDOM -> (character.wisdom + alterations[this].sum).modifier
|
||||
Property.CHARISMA -> (character.charisma + alterations[this].sum).modifier
|
||||
Property.STRENGTH -> (character.strength + this@ThrowScope.status[this].sum).modifier
|
||||
Property.DEXTERITY -> (character.dexterity + this@ThrowScope.status[this].sum).modifier
|
||||
Property.CONSTITUTION -> (character.constitution + this@ThrowScope.status[this].sum).modifier
|
||||
Property.INTELLIGENCE -> (character.intelligence + this@ThrowScope.status[this].sum).modifier
|
||||
Property.WISDOM -> (character.wisdom + this@ThrowScope.status[this].sum).modifier
|
||||
Property.CHARISMA -> (character.charisma + this@ThrowScope.status[this].sum).modifier
|
||||
Property.PROFICIENCY -> character.proficiency
|
||||
Property.LEVEL -> character.level
|
||||
else -> null
|
||||
|
|
@ -945,11 +962,12 @@ class DiceThrowUseCase @Inject constructor(
|
|||
return this?.flatMap { status ->
|
||||
status.dices.map { dice ->
|
||||
val localRoll = roll(
|
||||
amount = if (alterations.isCritical) dice.count * 2 else dice.count,
|
||||
amount = if (this@ThrowScope.status.isCritical) dice.count * 2 else dice.count,
|
||||
faces = dice.faces,
|
||||
advantage = dice.advantage,
|
||||
disadvantage = dice.disadvantage,
|
||||
fail = dice.fail
|
||||
fail = status.fail,
|
||||
critical = status.critical,
|
||||
)
|
||||
ThrowsCardUio.Detail(
|
||||
title = dice.title,
|
||||
|
|
@ -990,10 +1008,15 @@ class DiceThrowUseCase @Inject constructor(
|
|||
advantage: Boolean = false,
|
||||
disadvantage: Boolean = false,
|
||||
fail: Boolean = false,
|
||||
critical: Boolean = false,
|
||||
): DiceRollResult {
|
||||
val result = when {
|
||||
advantage && !disadvantage -> {
|
||||
val roll = List(amount) { random(faces, fail) to random(faces, fail) }
|
||||
val roll = List(amount) {
|
||||
val first = random(faces = faces, fail = fail, critical = critical)
|
||||
val second = random(faces = faces, fail = fail, critical = critical)
|
||||
first to second
|
||||
}
|
||||
DiceRollResult(
|
||||
label = roll.joinToString(" + ") { "${it.first}~${it.second}" },
|
||||
value = roll.sumOf { max(it.first, it.second) },
|
||||
|
|
@ -1001,7 +1024,11 @@ class DiceThrowUseCase @Inject constructor(
|
|||
}
|
||||
|
||||
disadvantage && !advantage -> {
|
||||
val roll = List(amount) { random(faces, fail) to random(faces, fail) }
|
||||
val roll = List(amount) {
|
||||
val first = random(faces = faces, fail = fail, critical = critical)
|
||||
val second = random(faces = faces, fail = fail, critical = critical)
|
||||
first to second
|
||||
}
|
||||
DiceRollResult(
|
||||
label = roll.joinToString(" + ") { "${it.first}~${it.second}" },
|
||||
value = roll.sumOf { min(it.first, it.second) },
|
||||
|
|
@ -1009,7 +1036,9 @@ class DiceThrowUseCase @Inject constructor(
|
|||
}
|
||||
|
||||
else -> {
|
||||
val roll = List(amount) { random(faces, fail) }
|
||||
val roll = List(amount) {
|
||||
random(faces = faces, fail = fail, critical = critical)
|
||||
}
|
||||
DiceRollResult(
|
||||
label = roll.toLabel(),
|
||||
value = roll.sum(),
|
||||
|
|
@ -1020,8 +1049,11 @@ class DiceThrowUseCase @Inject constructor(
|
|||
return result
|
||||
}
|
||||
|
||||
private fun random(faces: Int, fail: Boolean): Int =
|
||||
if (fail) 1 else (Math.random() * faces + 1).toInt()
|
||||
private fun random(faces: Int, fail: Boolean, critical: Boolean): Int = when {
|
||||
fail && !critical -> 1
|
||||
critical && !fail -> faces
|
||||
else -> (Math.random() * faces + 1).toInt()
|
||||
}
|
||||
}
|
||||
|
||||
private data class DiceRollResult(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue