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:
|
||||
|
||||
+60
-37
@@ -3,9 +3,9 @@
|
||||
L8 of the ``llm-policy-contract`` plan: ``Action`` gains a ``repair_weapon``
|
||||
kind (reusing the existing ``weapon_id`` field) so a policy can restore a
|
||||
weapon that a sunder maneuver broke. The weapon is removed from
|
||||
``state.weapon_broken``, its accumulated damage is reset, and the transient
|
||||
``disarmed`` condition originating from the sunder is removed so the repaired
|
||||
weapon is fully usable again via ``usable_attacks()``.
|
||||
``state.weapon_broken``, its accumulated damage is reset, and the weapon is
|
||||
fully usable again via ``usable_attacks()``. A weapon DESTROYED by a sunder
|
||||
(hp <= 0) cannot be repaired.
|
||||
|
||||
No default policy emits ``repair_weapon``; it is only accepted by ``_execute``
|
||||
(usage via custom policy / LLM).
|
||||
@@ -14,8 +14,6 @@ No default policy emits ``repair_weapon``; it is only accepted by ``_execute``
|
||||
from __future__ import annotations
|
||||
|
||||
from pf1e_simulator.combat import Action, CombatantState, CombatEngine
|
||||
from pf1e_simulator.conditions import Condition
|
||||
from pf1e_simulator.effects import ActiveCondition, StatModifier
|
||||
from pf1e_simulator.grid import Grid
|
||||
from pf1e_simulator.map import MapSpec, TerrainType
|
||||
from pf1e_simulator.models import (
|
||||
@@ -56,6 +54,37 @@ def make_combatant(cid: str, *, attack_bonus: int = 2) -> Combatant:
|
||||
)
|
||||
|
||||
|
||||
def _soft_sword_combatant(cid: str, *, attack_bonus: int = 2) -> Combatant:
|
||||
"""Combatant with a authored soft sword (hardness 0, 10 hp) so one
|
||||
scripted 1d4+3 sunder breaks it."""
|
||||
attack = AttackSpec(
|
||||
id=f"{cid}-w",
|
||||
name="sword",
|
||||
kind="melee",
|
||||
attack_bonus=attack_bonus,
|
||||
damage=[DamageComponent(formula="1d4", types=["slashing"])],
|
||||
hardness=0,
|
||||
hit_points=10,
|
||||
)
|
||||
return make_combatant(cid, attack_bonus=attack_bonus).model_copy(
|
||||
update={"attacks": [attack]}
|
||||
)
|
||||
|
||||
|
||||
def _heavy_striker(cid: str) -> Combatant:
|
||||
attack = AttackSpec(
|
||||
id=f"{cid}-w",
|
||||
name="sword",
|
||||
kind="melee",
|
||||
attack_bonus=2,
|
||||
damage=[DamageComponent(formula="1d4", types=["slashing"])],
|
||||
damage_bonus=3,
|
||||
)
|
||||
return make_combatant(cid, attack_bonus=2).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)
|
||||
|
||||
@@ -74,17 +103,6 @@ def _weapon_ids(state: CombatantState) -> list[str]:
|
||||
return [w.id for w in state.usable_attacks()]
|
||||
|
||||
|
||||
def _sunder_disarmed_condition() -> ActiveCondition:
|
||||
return ActiveCondition(
|
||||
condition=Condition(
|
||||
name="disarmed",
|
||||
modifiers=(StatModifier(target="attack", value=-4),),
|
||||
),
|
||||
rounds_left=1,
|
||||
source="maneuver: sunder",
|
||||
)
|
||||
|
||||
|
||||
# --- Test 1: repair restores a broken weapon ---------------------------------
|
||||
|
||||
def test_repair_restores_broken_weapon() -> None:
|
||||
@@ -94,16 +112,11 @@ def test_repair_restores_broken_weapon() -> None:
|
||||
b = make_state(b_spec, "monsters", (1, 2))
|
||||
b.weapon_damage = {"b-w": 10}
|
||||
b.weapon_broken = {"b-w"}
|
||||
b.active_conditions.append(_sunder_disarmed_condition())
|
||||
engine = make_engine([], [a, b])
|
||||
engine._execute(b, Action(kind="repair_weapon", weapon_id="b-w"))
|
||||
assert not b.weapon_broken
|
||||
assert not b.weapon_damage
|
||||
assert "b-w" in _weapon_ids(b)
|
||||
assert not any(
|
||||
c.condition.name == "disarmed" and c.source == "maneuver: sunder"
|
||||
for c in b.active_conditions
|
||||
)
|
||||
assert "repair b-w (restored)" in engine._transcript[-1]
|
||||
|
||||
|
||||
@@ -140,30 +153,40 @@ def test_repair_unknown_id_logs_nothing_to_repair() -> None:
|
||||
# --- Test 4: real sunder then repair restores the weapon ---------------------
|
||||
|
||||
def test_sunder_then_repair_restores_weapon() -> 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))
|
||||
engine = make_engine([1] + [12] * 5, [a, b])
|
||||
for _ in range(5):
|
||||
engine._execute(a, Action(kind="maneuver", target_id="b", maneuver="sunder"))
|
||||
# a's 1d4+3 (scripted 4+3=7) vs b's soft sword (hardness 0, 10 hp):
|
||||
# 3 hp left <= half -> broken (still usable at -2, CRB "Broken"); the
|
||||
# repair action resets the damage and clears the condition.
|
||||
a = make_state(_heavy_striker("a"), "players", (1, 1))
|
||||
b = make_state(_soft_sword_combatant("b"), "monsters", (1, 2))
|
||||
engine = make_engine([1, 12, 4], [a, b])
|
||||
engine._execute(a, Action(kind="maneuver", target_id="b", maneuver="sunder"))
|
||||
assert "b-w" in b.weapon_broken
|
||||
assert "b-w" not in _weapon_ids(b)
|
||||
assert any(
|
||||
c.condition.name == "disarmed" and c.source == "maneuver: sunder"
|
||||
for c in b.active_conditions
|
||||
)
|
||||
assert "b-w" in _weapon_ids(b)
|
||||
engine._execute(b, Action(kind="repair_weapon", weapon_id="b-w"))
|
||||
assert not b.weapon_broken
|
||||
assert not b.weapon_damage
|
||||
assert "b-w" in _weapon_ids(b)
|
||||
assert not any(
|
||||
c.condition.name == "disarmed" and c.source == "maneuver: sunder"
|
||||
for c in b.active_conditions
|
||||
)
|
||||
assert "repair b-w (restored)" in engine._transcript[-1]
|
||||
|
||||
|
||||
# --- Test 4b: a destroyed weapon cannot be repaired --------------------------
|
||||
|
||||
def test_repair_destroyed_weapon_is_refused() -> None:
|
||||
# CRB "Smashing an Object": hp <= 0 is "ruined" — repair_weapon is a
|
||||
# no-op on destroyed weapons.
|
||||
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))
|
||||
b.weapon_damage = {"b-w": 10}
|
||||
b.weapon_destroyed.add("b-w")
|
||||
engine = make_engine([], [a, b])
|
||||
engine._execute(b, Action(kind="repair_weapon", weapon_id="b-w"))
|
||||
assert "b-w" in b.weapon_destroyed
|
||||
assert b.weapon_damage == {"b-w": 10}
|
||||
assert "weapon destroyed" in engine._transcript[-1]
|
||||
|
||||
|
||||
# --- Test 5: determinism -----------------------------------------------------
|
||||
|
||||
def _run_with_repair() -> tuple[str, ...]:
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
|
||||
``attack`` and ``full_attack`` accept ``Action.weapon_id`` — the id of one of
|
||||
the attacker's weapons. With it the engine strikes with THAT weapon instead of
|
||||
the ``weapon_for`` auto-selection; a choice that is unknown, broken, stolen,
|
||||
or unable to strike the target (out of reach / no line of effect) is rejected
|
||||
with ``weapon_unavailable`` and no attack is made. Without it, the
|
||||
auto-selection and the full-attack mechanics are byte-identical to before.
|
||||
the ``weapon_for`` auto-selection; a choice that is unknown, destroyed,
|
||||
stolen, dropped, or unable to strike the target (out of reach / no line of
|
||||
effect) is rejected with ``weapon_unavailable`` and no attack is made (a
|
||||
BROKEN melee weapon stays selectable — CRB "Broken" makes it usable at -2).
|
||||
Without it, the auto-selection and the full-attack mechanics are
|
||||
byte-identical to before.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -133,15 +135,31 @@ def test_full_attack_without_choice_still_swings_all_melee_weapons() -> None:
|
||||
assert "shortsword vs foe d20=10+2=12" in joined
|
||||
|
||||
|
||||
# ── (b) broken weapon → weapon_unavailable ───────────────────────────────────
|
||||
# ── (b) broken / destroyed weapon selection ──────────────────────────────────
|
||||
|
||||
|
||||
def test_attack_with_broken_weapon_is_rejected() -> None:
|
||||
eng, hero, foe = _duel([]) # empty script: any roll would raise
|
||||
def test_attack_with_broken_weapon_is_usable() -> None:
|
||||
# CRB "Broken": a broken weapon is still usable — at -2 on attack and
|
||||
# damage. The explicit choice is accepted: d20 10 + 2 - 2 = 10 vs AC 10
|
||||
# -> HIT for 3 - 2 = 1 damage.
|
||||
eng, hero, foe = _duel([10, 3])
|
||||
hero.weapon_broken.add("hero-short")
|
||||
result = eng._execute(
|
||||
hero, Action(kind="attack", target_id="foe", weapon_id="hero-short")
|
||||
)
|
||||
assert result == ActionResult(kind="attack", ok=True, reason="ok")
|
||||
assert "shortsword vs foe d20=10+2=10 AC 10 -> HIT 1 damage" in eng._transcript[-1]
|
||||
assert foe.hp == 99
|
||||
|
||||
|
||||
def test_attack_with_destroyed_weapon_is_rejected() -> None:
|
||||
# A destroyed weapon (hp <= 0, CRB "Smashing an Object": "ruined") is
|
||||
# unusable: the explicit choice is rejected, no roll consumed.
|
||||
eng, hero, foe = _duel([]) # empty script: any roll would raise
|
||||
hero.weapon_destroyed.add("hero-short")
|
||||
result = eng._execute(
|
||||
hero, Action(kind="attack", target_id="foe", weapon_id="hero-short")
|
||||
)
|
||||
assert result == ActionResult(
|
||||
kind="attack", ok=False, reason="weapon_unavailable"
|
||||
)
|
||||
@@ -149,9 +167,9 @@ def test_attack_with_broken_weapon_is_rejected() -> None:
|
||||
assert foe.hp == 100
|
||||
|
||||
|
||||
def test_full_attack_with_broken_weapon_is_rejected() -> None:
|
||||
def test_full_attack_with_destroyed_weapon_is_rejected() -> None:
|
||||
eng, hero, foe = _duel([])
|
||||
hero.weapon_broken.add("hero-short")
|
||||
hero.weapon_destroyed.add("hero-short")
|
||||
result = eng._execute(
|
||||
hero, Action(kind="full_attack", target_id="foe", weapon_id="hero-short")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user