Skip to content

Commit fcf70a3

Browse files
authored
Merge pull request #11 from fmasa/fix-hardy
Fix Hardy revert for pre-3.3.0 Characters
2 parents ed5c274 + ad56697 commit fcf70a3

File tree

4 files changed

+104
-5
lines changed

4 files changed

+104
-5
lines changed

common/src/commonMain/kotlin/cz/frantisekmasa/wfrp_master/common/character/effects/EffectFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class EffectFactory {
1616
val name = item.talent.name.trim()
1717

1818
listOfNotNull(
19-
HardyWoundsModification.fromTalentOrNull(name, item.talent.taken.toUInt()),
19+
HardyWoundsModification.fromTalentOrNull(name, item.talent.taken),
2020
CharacteristicChange.fromTalentNameOrNull(name),
2121
)
2222
}

common/src/commonMain/kotlin/cz/frantisekmasa/wfrp_master/common/character/effects/HardyWoundsModification.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ package cz.frantisekmasa.wfrp_master.common.character.effects
22

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

5-
class HardyWoundsModification(private val timesTaken: UInt): CharacterEffect {
5+
class HardyWoundsModification(private val timesTaken: Int): CharacterEffect {
6+
init {
7+
require(timesTaken > 0)
8+
}
9+
610
override fun apply(character: Character, otherEffects: List<CharacterEffect>): Character {
711
val modifiers = character.woundsModifiers
812

@@ -19,13 +23,13 @@ class HardyWoundsModification(private val timesTaken: UInt): CharacterEffect {
1923
return character.modifyWounds(
2024
modifiers.copy(
2125
extraToughnessBonusMultiplier = (modifiers.extraToughnessBonusMultiplier - timesTaken)
22-
.coerceAtLeast(0.toUInt()),
26+
.coerceAtLeast(0),
2327
)
2428
)
2529
}
2630

2731
companion object {
28-
fun fromTalentOrNull(name: String, timesTaken: UInt): HardyWoundsModification? {
32+
fun fromTalentOrNull(name: String, timesTaken: Int): HardyWoundsModification? {
2933
if (name.equals("hardy", ignoreCase = true)) {
3034
return HardyWoundsModification(timesTaken)
3135
}

common/src/commonMain/kotlin/cz/frantisekmasa/wfrp_master/common/core/domain/character/WoundsModifiers.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import kotlinx.serialization.Serializable
1010
@Immutable
1111
data class WoundsModifiers(
1212
val afterMultiplier: UInt = 1.toUInt(),
13-
val extraToughnessBonusMultiplier: UInt = 0.toUInt(),
13+
val extraToughnessBonusMultiplier: Int = 0,
1414
) : Parcelable {
1515
init {
16+
require(extraToughnessBonusMultiplier >= 0)
1617
require(afterMultiplier >= 1.toUInt())
1718
}
1819
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package cz.frantisekmasa.wfrp_master.common.core.domain.character.effects
2+
3+
import com.benasher44.uuid.uuid4
4+
import cz.frantisekmasa.wfrp_master.common.character.effects.HardyWoundsModification
5+
import cz.frantisekmasa.wfrp_master.common.core.domain.Stats
6+
import cz.frantisekmasa.wfrp_master.common.core.domain.character.Character
7+
import cz.frantisekmasa.wfrp_master.common.core.domain.character.CharacterType
8+
import cz.frantisekmasa.wfrp_master.common.core.domain.character.Points
9+
import cz.frantisekmasa.wfrp_master.common.core.domain.character.Race
10+
import cz.frantisekmasa.wfrp_master.common.core.domain.character.SocialStatus
11+
import kotlin.test.Test
12+
import kotlin.test.assertEquals
13+
14+
class HardyWoundsModificationTest {
15+
16+
@Test
17+
fun `applying modification adds current TB to max Wounds`() {
18+
val character = character()
19+
assertEquals(6, character.wounds.max)
20+
21+
val updatedCharacter = HardyWoundsModification(1).apply(character, emptyList())
22+
23+
assertEquals(8, updatedCharacter.wounds.max)
24+
}
25+
26+
@Test
27+
fun `applying modification adds current TB multiple times to max Wounds when Hardy is taken multiple times`() {
28+
val character = character()
29+
assertEquals(6, character.wounds.max)
30+
31+
val updatedCharacter = HardyWoundsModification(2).apply(character, emptyList())
32+
33+
assertEquals(10, updatedCharacter.wounds.max)
34+
}
35+
36+
@Test
37+
fun `reverting more Hardy bonuses than Character has goes to zero`() {
38+
val character = HardyWoundsModification(2).apply(character(), emptyList())
39+
40+
val updatedCharacter = HardyWoundsModification(3).revert(character, emptyList())
41+
42+
assertEquals(6, updatedCharacter.wounds.max)
43+
}
44+
45+
@Test
46+
fun `reverting Hardy bonus subtracts correct amount of max Wounds`() {
47+
val character = HardyWoundsModification(3).apply(character(), emptyList())
48+
49+
val updatedCharacter = HardyWoundsModification(2).revert(character, emptyList())
50+
51+
assertEquals(8, updatedCharacter.wounds.max)
52+
}
53+
54+
private fun character(): Character {
55+
return Character(
56+
id = uuid4().toString(),
57+
type = CharacterType.NPC,
58+
name = "Bjorn Kveldulfson",
59+
userId = null,
60+
career = "Watchman",
61+
status = SocialStatus(SocialStatus.Tier.BRASS, 1),
62+
psychology = "",
63+
motivation = "",
64+
characteristicsBase = Stats(
65+
10,
66+
10,
67+
10,
68+
10,
69+
20,
70+
10,
71+
10,
72+
10,
73+
10,
74+
10,
75+
),
76+
characteristicsAdvances = Stats.ZERO,
77+
points = Points(
78+
corruption = 0,
79+
fate = 0,
80+
fortune = 0,
81+
maxWounds = null,
82+
wounds = 0,
83+
resilience = 0,
84+
resolve = 0,
85+
sin = 0,
86+
experience = 0,
87+
spentExperience = 0,
88+
hardyWoundsBonus = 0,
89+
),
90+
socialClass = "Warriors",
91+
race = Race.HUMAN,
92+
)
93+
}
94+
}

0 commit comments

Comments
 (0)