Skip to content

Commit

Permalink
Merge pull request #33 from fmasa/construct
Browse files Browse the repository at this point in the history
Use SB instead off WPB when determining max Wounds for Construct
  • Loading branch information
fmasa authored Nov 5, 2022
2 parents 88fa7da + cfd9b6f commit d7ec703
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cz.frantisekmasa.wfrp_master.common.character.effects

import cz.frantisekmasa.wfrp_master.common.core.domain.character.Character

class ConstructWoundsModification : CharacterEffect {
override fun apply(character: Character, otherEffects: List<CharacterEffect>): Character {
if (otherEffects.any { it is ConstructWoundsModification }) {
return character // This effect does not stack
}

return character.modifyWounds(
character.woundsModifiers.copy(isConstruct = true)
)
}

override fun revert(character: Character, otherEffects: List<CharacterEffect>): Character {
if (otherEffects.any { it is ConstructWoundsModification }) {
return character // This effect does not stack
}

return character.modifyWounds(
character.woundsModifiers.copy(isConstruct = false)
)
}

companion object {
fun fromTraitNameOrNull(name: String): ConstructWoundsModification? {
if (name.equals("construct", ignoreCase = true)) {
return ConstructWoundsModification()
}

return null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class EffectFactory {
SizeChange.fromTraitNameOrNull(name),
CharacteristicChange.fromTraitNameOrNull(name),
SwarmWoundsModification.fromTraitNameOrNull(name),
ConstructWoundsModification.fromTraitNameOrNull(name),
)
}
is EffectSource.Talent -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,24 +244,31 @@ data class Character(
characteristics: Stats,
): Int {
val manualMaxWounds = points.maxWounds
val tb = characteristics.toughnessBonus
val toughnessBonus = characteristics.toughnessBonus

if (manualMaxWounds != null) {
// TODO: Remove support for hasHardyTalent flag
if (hasHardyTalent) {
return manualMaxWounds + tb
return manualMaxWounds + toughnessBonus
}

return manualMaxWounds
}

val baseWounds = Wounds.calculateMax(size ?: Size.AVERAGE, characteristics)
val baseWounds = Wounds.calculateMax(
size = size ?: Size.AVERAGE,
toughnessBonus = toughnessBonus,
strengthBonus = characteristics.strengthBonus,
willPowerBonus = if (modifiers.isConstruct)
characteristics.strengthBonus
else characteristics.willPowerBonus
)
return (
baseWounds +
modifiers.extraToughnessBonusMultiplier.toInt() * tb +
(if (hasHardyTalent) tb else 0)
modifiers.extraToughnessBonusMultiplier * toughnessBonus +
(if (hasHardyTalent) toughnessBonus else 0)
) *
modifiers.afterMultiplier.toInt()
modifiers.afterMultiplier
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import kotlinx.serialization.Serializable
data class WoundsModifiers(
val afterMultiplier: Int = 1,
val extraToughnessBonusMultiplier: Int = 0,
val isConstruct: Boolean = false,
) : Parcelable {
init {
require(extraToughnessBonusMultiplier >= 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cz.frantisekmasa.wfrp_master.common.encounters.domain

import androidx.compose.runtime.Immutable
import cz.frantisekmasa.wfrp_master.common.core.domain.Size
import cz.frantisekmasa.wfrp_master.common.core.domain.Stats
import cz.frantisekmasa.wfrp_master.common.core.shared.Parcelable
import cz.frantisekmasa.wfrp_master.common.core.shared.Parcelize
import kotlinx.serialization.Serializable
Expand All @@ -23,8 +22,13 @@ data class Wounds(
fun fromMax(max: Int) = Wounds(max, max)

// See rulebook page 341
fun calculateMax(size: Size, characteristics: Stats): Int = with(characteristics) {
when (size) {
fun calculateMax(
size: Size,
toughnessBonus: Int,
strengthBonus: Int,
willPowerBonus: Int,
): Int {
return when (size) {
Size.TINY -> 1
Size.LITTLE -> toughnessBonus
Size.SMALL -> (2 * toughnessBonus) + willPowerBonus
Expand Down
9 changes: 7 additions & 2 deletions firebase/firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,14 @@ service cloud.firestore {
)
&& ! ("woundsModifiers" in character) || (
character.woundsModifiers is map &&
character.woundsModifiers.keys().toSet() == ["afterMultiplier", "extraToughnessBonusMultiplier"].toSet() &&
[
"afterMultiplier",
"extraToughnessBonusMultiplier",
"isConstruct"
].hasAll(character.woundsModifiers.keys()) &&
character.woundsModifiers.afterMultiplier is int &&
character.woundsModifiers.extraToughnessBonusMultiplier is int
character.woundsModifiers.extraToughnessBonusMultiplier is int &&
(! ("isConstruct" in character.woundsModifiers) || character.woundsModifiers.isConstruct is bool)
)
&& (! ("compendiumCareer" in character) || character.compendiumCareer == null || (
character.compendiumCareer is map &&
Expand Down

0 comments on commit d7ec703

Please sign in to comment.