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:
+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, ...]:
|
||||
|
||||
Reference in New Issue
Block a user