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)
|
val relatedStatBonus = diceThrow.statBonus(name = action)
|
||||||
|
|
||||||
// check for flat dice bonus (ex: healing potion 2d4 + 2)
|
// check for flat dice bonus (ex: healing potion 2d4 + 2)
|
||||||
val flatBonus = diceThrow?.flat?.takeIf { it > 0 }?.let {
|
val relatedFlatBonus = diceThrow.flatBonus(name = action)
|
||||||
allValue.add(it)
|
|
||||||
listOf(
|
|
||||||
NetworkThrow.Detail(
|
|
||||||
title = application.getString(R.string.dice_roll_bonus_detail, action),
|
|
||||||
result = "$it",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} ?: emptyList()
|
|
||||||
|
|
||||||
// compute the final roll result
|
// compute the final roll result
|
||||||
val rollResult = when {
|
val rollResult = when {
|
||||||
|
|
@ -781,7 +773,7 @@ class DiceThrowUseCase @Inject constructor(
|
||||||
),
|
),
|
||||||
result = "${result.value}",
|
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
|
// fetch and build the associated characteristic
|
||||||
val relatedStatBonus = spell?.effect.statBonus(name = spellName)
|
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
|
// compute the final roll result
|
||||||
val rollResult = "${allValue.sum()}"
|
val rollResult = "${allValue.sum()}"
|
||||||
|
|
||||||
|
|
@ -873,7 +868,7 @@ class DiceThrowUseCase @Inject constructor(
|
||||||
),
|
),
|
||||||
result = "${result.value}",
|
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
|
// fetch and build the associated characteristic, proficiency or level
|
||||||
val relatedStatBonus = skill?.effect.statBonus(name = skill?.name)
|
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
|
// compute the final roll result
|
||||||
val rollResult = "${allValue.sum()}"
|
val rollResult = "${allValue.sum()}"
|
||||||
|
|
||||||
|
|
@ -941,7 +939,7 @@ class DiceThrowUseCase @Inject constructor(
|
||||||
),
|
),
|
||||||
result = "${result.value}",
|
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()
|
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) {
|
return when (this) {
|
||||||
Property.STRENGTH -> (character.strength + this@ThrowScope.status[this].sum).modifier
|
Property.STRENGTH -> (character.strength + this@ThrowScope.status[this].sum).modifier
|
||||||
Property.DEXTERITY -> (character.dexterity + 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.
|
* Fetch any alteration related bonus and build a ThrowsCardUio.Detail for each.
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import com.pixelized.rplexicon.data.repository.character.DescriptionRepository
|
||||||
import com.pixelized.rplexicon.ui.screens.character.composable.actions.SkillItemUio
|
import com.pixelized.rplexicon.ui.screens.character.composable.actions.SkillItemUio
|
||||||
import com.pixelized.rplexicon.utilitary.extentions.icon
|
import com.pixelized.rplexicon.utilitary.extentions.icon
|
||||||
import com.pixelized.rplexicon.utilitary.extentions.modifier
|
import com.pixelized.rplexicon.utilitary.extentions.modifier
|
||||||
|
import com.pixelized.rplexicon.utilitary.extentions.toLabel
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class SkillFactoryUioFactory @Inject constructor(
|
class SkillFactoryUioFactory @Inject constructor(
|
||||||
|
|
@ -21,7 +22,7 @@ class SkillFactoryUioFactory @Inject constructor(
|
||||||
// Filter out passive skills, theses are display in the Proficiency Page.
|
// Filter out passive skills, theses are display in the Proficiency Page.
|
||||||
return skills.map { skill ->
|
return skills.map { skill ->
|
||||||
val description = descriptionRepository.find(name = skill.name)
|
val description = descriptionRepository.find(name = skill.name)
|
||||||
val modifier = skill.effect?.modifier?.sumOf {
|
val effectModifier = skill.effect?.modifier?.sumOf {
|
||||||
when (it) {
|
when (it) {
|
||||||
Property.LEVEL -> character?.level ?: 0
|
Property.LEVEL -> character?.level ?: 0
|
||||||
Property.PROFICIENCY -> character?.proficiency ?: 0
|
Property.PROFICIENCY -> character?.proficiency ?: 0
|
||||||
|
|
@ -34,6 +35,9 @@ class SkillFactoryUioFactory @Inject constructor(
|
||||||
else -> 0
|
else -> 0
|
||||||
}
|
}
|
||||||
} ?: 0
|
} ?: 0
|
||||||
|
val effectFlat = skill.effect?.flat ?: 0
|
||||||
|
val modifier = effectModifier + effectFlat
|
||||||
|
|
||||||
SkillItemUio(
|
SkillItemUio(
|
||||||
label = skill.name,
|
label = skill.name,
|
||||||
translate = description?.original,
|
translate = description?.original,
|
||||||
|
|
@ -42,7 +46,7 @@ class SkillFactoryUioFactory @Inject constructor(
|
||||||
effect = skill.effect?.let {
|
effect = skill.effect?.let {
|
||||||
SkillItemUio.Dice(
|
SkillItemUio.Dice(
|
||||||
icon = it.faces.icon,
|
icon = it.faces.icon,
|
||||||
label = "${skill.effect.amount}d${skill.effect.faces}${if (modifier > 0) "+$modifier" else ""}",
|
label = "${skill.effect.amount}d${skill.effect.faces}${if (modifier > 0) modifier.toLabel() else ""}",
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
value = fire?.skills?.get(skill.name) ?: 0,
|
value = fire?.skills?.get(skill.name) ?: 0,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue