Add support of flat values in skills.
This commit is contained in:
parent
a0be0274f1
commit
7652a6a902
2 changed files with 36 additions and 15 deletions
|
|
@ -734,15 +734,7 @@ class DiceThrowUseCase @Inject constructor(
|
|||
val relatedStatBonus = diceThrow.statBonus(name = action)
|
||||
|
||||
// check for flat dice bonus (ex: healing potion 2d4 + 2)
|
||||
val flatBonus = diceThrow?.flat?.takeIf { it > 0 }?.let {
|
||||
allValue.add(it)
|
||||
listOf(
|
||||
NetworkThrow.Detail(
|
||||
title = application.getString(R.string.dice_roll_bonus_detail, action),
|
||||
result = "$it",
|
||||
)
|
||||
)
|
||||
} ?: emptyList()
|
||||
val relatedFlatBonus = diceThrow.flatBonus(name = action)
|
||||
|
||||
// compute the final roll result
|
||||
val rollResult = when {
|
||||
|
|
@ -781,7 +773,7 @@ class DiceThrowUseCase @Inject constructor(
|
|||
),
|
||||
result = "${result.value}",
|
||||
),
|
||||
) + diceAlterationBonus + flatAlterationBonus + relatedStatBonus + flatBonus,
|
||||
) + diceAlterationBonus + flatAlterationBonus + relatedStatBonus + relatedFlatBonus,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -844,6 +836,9 @@ class DiceThrowUseCase @Inject constructor(
|
|||
// fetch and build the associated characteristic
|
||||
val relatedStatBonus = spell?.effect.statBonus(name = spellName)
|
||||
|
||||
// fetch and build a list of flat bonus
|
||||
val relatedFlatBonus = spell?.effect?.flatBonus(name = spellName) ?: emptyList()
|
||||
|
||||
// compute the final roll result
|
||||
val rollResult = "${allValue.sum()}"
|
||||
|
||||
|
|
@ -873,7 +868,7 @@ class DiceThrowUseCase @Inject constructor(
|
|||
),
|
||||
result = "${result.value}",
|
||||
),
|
||||
) + levelBonus + relatedStatBonus,
|
||||
) + levelBonus + relatedStatBonus + relatedFlatBonus,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -912,6 +907,9 @@ class DiceThrowUseCase @Inject constructor(
|
|||
// fetch and build the associated characteristic, proficiency or level
|
||||
val relatedStatBonus = skill?.effect.statBonus(name = skill?.name)
|
||||
|
||||
// fetch and build a list of flat bonus
|
||||
val relatedFlatBonus = skill?.effect.flatBonus(name = skill?.name)
|
||||
|
||||
// compute the final roll result
|
||||
val rollResult = "${allValue.sum()}"
|
||||
|
||||
|
|
@ -941,7 +939,7 @@ class DiceThrowUseCase @Inject constructor(
|
|||
),
|
||||
result = "${result.value}",
|
||||
),
|
||||
) + diceAlterationBonus + flatAlterationBonus + relatedStatBonus,
|
||||
) + diceAlterationBonus + flatAlterationBonus + relatedStatBonus + relatedFlatBonus,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
@ -965,7 +963,14 @@ class DiceThrowUseCase @Inject constructor(
|
|||
return this?.modifier?.mapNotNull { it.statBonus(name = name) } ?: emptyList()
|
||||
}
|
||||
|
||||
fun Property.statBonus(name: String?): NetworkThrow.Detail? {
|
||||
/**
|
||||
* Fetch any flat bonus related to the throw.
|
||||
*/
|
||||
fun Throw?.flatBonus(name: String?): List<NetworkThrow.Detail> {
|
||||
return this?.flat?.flatBonus(name)?.let { listOf(it) } ?: emptyList()
|
||||
}
|
||||
|
||||
private fun Property.statBonus(name: String?): NetworkThrow.Detail? {
|
||||
return when (this) {
|
||||
Property.STRENGTH -> (character.strength + this@ThrowScope.status[this].sum).modifier
|
||||
Property.DEXTERITY -> (character.dexterity + this@ThrowScope.status[this].sum).modifier
|
||||
|
|
@ -1000,6 +1005,18 @@ class DiceThrowUseCase @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
private fun Int.flatBonus(name: String?): NetworkThrow.Detail? {
|
||||
allValue.add(this)
|
||||
return if (this != 0) {
|
||||
NetworkThrow.Detail(
|
||||
title = context.getString(R.string.dice_roll_bonus_detail, name),
|
||||
result = "$this",
|
||||
)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch any alteration related bonus and build a ThrowsCardUio.Detail for each.
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue