feat(rules): sunder deals real weapon damage vs object hardness/hp; broken weapons usable at -2 with restricted crits
SRD Sunder + CRB 'Smashing an Object' / 'Conditions - Broken': weapons carry Table 7-12 object stats (AttackSpec.hardness/hit_points/enhancement, defaults by weapon class); a successful sunder deals the attacker's actual physical weapon damage minus the target weapon's hardness, subtracted from its hp. At <= half hp the weapon gains the broken condition - still usable at -2 attack/damage, crits only on a natural 20 at x2. At <= 0 it is destroyed (weapon_destroyed, unusable). The old flat str_mod+2 / durability 10 / synthetic 'disarmed' condition is gone. Firearm misfire carve-out kept (broken firearms stay unusable until Quick Clear - misfire escalation not modeled, documented).
This commit is contained in:
+159
-18
@@ -1,8 +1,11 @@
|
||||
"""Tests for combat maneuvers, focused on the sunder result.
|
||||
|
||||
A successful sunder damages the defender's WEAPON, never its HP. Repeated
|
||||
sunders can destroy the weapon, after which the defender can no longer use
|
||||
it (effectively disarmed). See the plan task-12.
|
||||
A successful sunder damages the defender's WEAPON as an OBJECT (SRD Sunder /
|
||||
CRB "Smashing an Object"): the attacker's weapon damage, less the object's
|
||||
Hardness, is subtracted from its hit points. At half hp or less the weapon
|
||||
gains the broken condition (still usable at -2 attack/damage, crits only on
|
||||
a natural 20 at x2 - CRB "Broken"); at 0 hp or less it is destroyed and
|
||||
unusable.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -53,6 +56,24 @@ def make_combatant(
|
||||
)
|
||||
|
||||
|
||||
def make_object_combatant(
|
||||
cid: str, *, hardness: int, hit_points: int, attack_bonus: int = 2
|
||||
) -> Combatant:
|
||||
"""Combatant whose sword carries authored object stats (Table 7-12
|
||||
overrides) so sunder outcomes are scripted exactly."""
|
||||
attack = AttackSpec(
|
||||
id=f"{cid}-w",
|
||||
name="sword",
|
||||
kind="melee",
|
||||
attack_bonus=attack_bonus,
|
||||
damage=[DamageComponent(formula="1d4", types=["slashing"])],
|
||||
hardness=hardness,
|
||||
hit_points=hit_points,
|
||||
)
|
||||
base = make_combatant(cid, attack_bonus=attack_bonus)
|
||||
return base.model_copy(update={"attacks": [attack]})
|
||||
|
||||
|
||||
def make_state(combatant: Combatant, side: str, pos: tuple[int, int]) -> CombatantState:
|
||||
return CombatantState(combatant=combatant, side=side, pos=pos, hp=combatant.hp_max)
|
||||
|
||||
@@ -72,32 +93,152 @@ def make_engine(
|
||||
return CombatEngine(ScriptedRng(queue), make_grid(), states)
|
||||
|
||||
|
||||
def test_object_stats_default_from_table_7_12() -> None:
|
||||
# CRB Table 7-12 defaults by weapon class (Medium, unenhanced): steel
|
||||
# blade 10/5 (one-handed) and 10/10 (two-handed); wooden hafted 5/5 and
|
||||
# 5/10; projectile weapon 5/5. Enhancement: +2 hardness and +10 hp per
|
||||
# +1 (footnotes 1 and 3).
|
||||
def _spec(**kw: object) -> AttackSpec:
|
||||
base: dict[str, object] = {
|
||||
"id": "w", "name": "sword", "kind": "melee", "attack_bonus": 0,
|
||||
"damage": [DamageComponent(formula="1d8", types=["slashing"])],
|
||||
}
|
||||
base.update(kw)
|
||||
return AttackSpec(**base)
|
||||
|
||||
assert _spec().object_stats() == (10, 5)
|
||||
assert _spec(two_handed=True).object_stats() == (10, 10)
|
||||
assert _spec(name="waraxe").object_stats() == (5, 5)
|
||||
assert _spec(name="waraxe", two_handed=True).object_stats() == (5, 10)
|
||||
assert _spec(name="short bow", kind="ranged").object_stats() == (5, 5)
|
||||
assert _spec(enhancement=2).object_stats() == (14, 25)
|
||||
# Authored overrides replace the class default.
|
||||
assert _spec(hardness=0, hit_points=4).object_stats() == (0, 4)
|
||||
|
||||
|
||||
def test_sunder_damages_weapon_not_hp() -> None:
|
||||
a_spec = make_combatant("a", attack_bonus=2)
|
||||
b_spec = make_combatant("b")
|
||||
a = make_state(a_spec, "players", (1, 1))
|
||||
b = make_state(b_spec, "monsters", (1, 2))
|
||||
# SRD Sunder / CRB "Smashing an Object": the sunder deals the attacker's
|
||||
# weapon damage (1d4 scripted to 4), reduced by the object's Hardness
|
||||
# (authored 2) -> 2 damage to the weapon's hit points, never to the
|
||||
# defender's HP.
|
||||
a = make_state(make_combatant("a", attack_bonus=2), "players", (1, 1))
|
||||
b = make_state(
|
||||
make_object_combatant("b", hardness=2, hit_points=10), "monsters", (1, 2)
|
||||
)
|
||||
hp_before = b.hp
|
||||
engine = make_engine([1, 12], [a, b])
|
||||
engine = make_engine([1, 12, 4], [a, b]) # AoO miss, CMB 12, 1d4 -> 4
|
||||
engine._execute_maneuver(a, b, "sunder")
|
||||
assert b.hp == hp_before
|
||||
assert b.weapon_damage["b-w"] == 2
|
||||
assert "b-w" not in b.weapon_broken
|
||||
assert "b-w" not in b.weapon_destroyed
|
||||
|
||||
|
||||
def test_sunder_destroys_weapon_and_disarms() -> None:
|
||||
a_spec = make_combatant("a", attack_bonus=2)
|
||||
b_spec = make_combatant("b")
|
||||
def test_sunder_hardness_absorbs_small_damage() -> None:
|
||||
# A plain steel blade is hardness 10 (Table 7-12): a 1d4 (max 4) sunder
|
||||
# cannot scratch it — 0 damage past hardness.
|
||||
a = make_state(make_combatant("a", attack_bonus=2), "players", (1, 1))
|
||||
b = make_state(make_combatant("b"), "monsters", (1, 2))
|
||||
engine = make_engine([1, 12, 4], [a, b])
|
||||
engine._execute_maneuver(a, b, "sunder")
|
||||
assert b.weapon_damage["b-w"] == 0
|
||||
assert "b-w" not in b.weapon_broken
|
||||
|
||||
|
||||
def test_sunder_breaks_weapon_at_half_hit_points() -> None:
|
||||
# SRD Sunder: "If an object has equal to or less than half its total hit
|
||||
# points remaining, it gains the broken condition." hardness 0, 10 hp;
|
||||
# 1d4+3 scripted to 4+3=7 -> 3 hp left <= 5 -> broken. The broken weapon
|
||||
# STAYS usable (CRB "Broken").
|
||||
a_spec = make_combatant("a", attack_bonus=2).model_copy(
|
||||
update={"attacks": [
|
||||
AttackSpec(
|
||||
id="a-w", name="sword", kind="melee", attack_bonus=2,
|
||||
damage=[DamageComponent(formula="1d4", types=["slashing"])],
|
||||
damage_bonus=3,
|
||||
)
|
||||
]}
|
||||
)
|
||||
a = make_state(a_spec, "players", (1, 1))
|
||||
b = make_state(b_spec, "monsters", (1, 2))
|
||||
# Only the first sunder provokes: b's per-round AoO allowance is spent.
|
||||
engine = make_engine([1, 12, 12, 12, 12, 12], [a, b])
|
||||
for _ in range(5):
|
||||
engine._execute_maneuver(a, b, "sunder")
|
||||
assert b.hp == 6
|
||||
b = make_state(
|
||||
make_object_combatant("b", hardness=0, hit_points=10), "monsters", (1, 2)
|
||||
)
|
||||
engine = make_engine([1, 12, 4], [a, b])
|
||||
engine._execute_maneuver(a, b, "sunder")
|
||||
assert "b-w" in b.weapon_broken
|
||||
assert "b-w" not in b.weapon_destroyed
|
||||
assert [w.id for w in b.usable_attacks()] == ["b-w"]
|
||||
assert engine.weapon_for(b, a) is not None
|
||||
assert "broken" in engine._transcript[-1]
|
||||
|
||||
|
||||
def test_sunder_destroys_weapon_at_zero_hit_points() -> None:
|
||||
# CRB "Smashing an Object": "When an object's hit points reach 0, it's
|
||||
# ruined." Two sunders of 7 (hardness 0, 10 hp): broken after the first,
|
||||
# destroyed after the second — then unusable.
|
||||
a_spec = make_combatant("a", attack_bonus=2).model_copy(
|
||||
update={"attacks": [
|
||||
AttackSpec(
|
||||
id="a-w", name="sword", kind="melee", attack_bonus=2,
|
||||
damage=[DamageComponent(formula="1d4", types=["slashing"])],
|
||||
damage_bonus=3,
|
||||
)
|
||||
]}
|
||||
)
|
||||
a = make_state(a_spec, "players", (1, 1))
|
||||
b = make_state(
|
||||
make_object_combatant("b", hardness=0, hit_points=10), "monsters", (1, 2)
|
||||
)
|
||||
engine = make_engine([1, 12, 4, 12, 4], [a, b])
|
||||
engine._execute_maneuver(a, b, "sunder") # first: AoO provokes (nat 1)
|
||||
assert "b-w" in b.weapon_broken
|
||||
engine._execute_maneuver(a, b, "sunder") # b's AoO allowance is spent
|
||||
assert "b-w" in b.weapon_destroyed
|
||||
assert "b-w" not in b.weapon_broken
|
||||
assert [w.id for w in b.usable_attacks()] == []
|
||||
assert engine.weapon_for(b, a) is None
|
||||
assert any(c.condition.name == "disarmed" for c in b.active_conditions)
|
||||
assert "weapon destroyed" in engine._transcript[-1]
|
||||
|
||||
|
||||
def test_broken_weapon_still_attacks_at_minus_two() -> None:
|
||||
# CRB "Broken": "any attacks made with the item suffer a -2 penalty on
|
||||
# attack and damage rolls."
|
||||
b = make_state(make_combatant("b"), "monsters", (1, 2))
|
||||
a = make_state(make_combatant("a", attack_bonus=2), "players", (1, 1))
|
||||
engine = make_engine([10], [a, b])
|
||||
result = engine.resolve_attack(a, b, a.combatant.attacks[0])
|
||||
assert result.total == 10 + 2 # intact baseline
|
||||
b.weapon_broken.add("b-w")
|
||||
engine2 = make_engine([10], [a, b])
|
||||
result2 = engine2.resolve_attack(b, a, b.combatant.attacks[0])
|
||||
assert result2.total == 10 + 2 - 2
|
||||
assert result2.hit is False # 10 vs AC 13: the -2 turns the hit into a miss
|
||||
|
||||
|
||||
def test_broken_weapon_crits_only_on_natural_twenty_at_x2() -> None:
|
||||
# CRB "Broken": "Such weapons only score a critical hit on a natural 20
|
||||
# and only deal x2 damage on a confirmed critical hit." The sword
|
||||
# threatens 19-20 at x3 when intact.
|
||||
sharp = AttackSpec(
|
||||
id="c-w", name="sword", kind="melee", attack_bonus=2,
|
||||
damage=[DamageComponent(formula="1d4", types=["slashing"])],
|
||||
crit_range=19, crit_mult=3,
|
||||
)
|
||||
c = make_state(
|
||||
make_combatant("c").model_copy(update={"attacks": [sharp]}), "players", (1, 1)
|
||||
)
|
||||
d = make_state(make_combatant("d"), "monsters", (1, 2))
|
||||
c.weapon_broken.add("c-w")
|
||||
# Natural 19: no threat at all with a broken weapon (no confirm roll).
|
||||
engine = make_engine([19, 4], [c, d])
|
||||
result = engine.resolve_attack(c, d, sharp)
|
||||
assert result.crit is False
|
||||
# Natural 20: threatens, auto-confirms (natural 20), x2 (not x3):
|
||||
# (1d4=4 - 2 broken) * 2 = 4.
|
||||
engine = make_engine([20, 20, 4], [c, d])
|
||||
result = engine.resolve_attack(c, d, sharp)
|
||||
assert result.crit is True
|
||||
assert result.damage == 4
|
||||
|
||||
|
||||
def test_escape_from_grapple_consumes_single_d20() -> None:
|
||||
|
||||
Reference in New Issue
Block a user