fix(rules): non-stacking types keep best bonus and worst penalty separately (CRB Common Terms - Stacking)

This commit is contained in:
2026-09-16 21:40:30 +02:00
parent fa63829385
commit 1c2663d21c
2 changed files with 51 additions and 17 deletions
+28 -5
View File
@@ -111,20 +111,42 @@ class TestNonStackingTypes:
class TestPenalties:
"""Given: penalties (negative values) with non-stacking types
When: resolve_modifiers is called
Then: least severe penalty is kept (max value)."""
Then: the worst penalty per type is kept, and a same-type bonus and
penalty apply together (CRB "Common Terms — Stacking")."""
def test_same_type_penalties_keep_least_severe(self) -> None:
def test_same_type_penalties_keep_most_severe(self) -> None:
mods = [
StatModifier("attack", -2, "morale"),
StatModifier("attack", -1, "morale"),
]
assert resolve_modifiers(mods) == -1
assert resolve_modifiers(mods) == -2
def test_same_type_bonus_and_penalty_keep_most_beneficial(self) -> None:
def test_morale_minus2_and_minus4_keep_worst(self) -> None:
mods = [
StatModifier("attack", -2, "morale"),
StatModifier("attack", -4, "morale"),
]
assert resolve_modifiers(mods) == -4
def test_same_type_bonus_and_penalty_both_apply(self) -> None:
mods = [
StatModifier("attack", 2, "morale"),
StatModifier("attack", -1, "morale"),
]
assert resolve_modifiers(mods) == 1
def test_morale_plus2_and_minus2_cancel(self) -> None:
mods = [
StatModifier("attack", 2, "morale"),
StatModifier("attack", -2, "morale"),
]
assert resolve_modifiers(mods) == 0
def test_morale_plus2_and_plus1_keep_highest(self) -> None:
mods = [
StatModifier("attack", 2, "morale"),
StatModifier("attack", 1, "morale"),
]
assert resolve_modifiers(mods) == 2
def test_untyped_penalties_stack(self) -> None:
@@ -167,7 +189,8 @@ class TestMixedStacking:
StatModifier("attack", -1),
StatModifier("attack", 1, "dodge"),
]
assert resolve_modifiers(mods) == 2 # 2 (max morale) + -1 (untyped) + 1 (dodge)
# 2 (max morale bonus) + -1 (morale penalty) + -1 (untyped) + 1 (dodge)
assert resolve_modifiers(mods) == 1
# ── Edge cases ────────────────────────────────────────────────────────────────