feat(combat): add repair_weapon action to fix broken weapons

This commit is contained in:
2026-09-06 10:05:55 +02:00
parent 8e957c9fac
commit fdcd103e8a
2 changed files with 221 additions and 1 deletions
+34 -1
View File
@@ -358,7 +358,7 @@ class Action:
"attack", "move", "wait", "swift", "free", "immediate", "full_round",
"full_attack", "charge", "withdraw", "5foot_step", "cast_spell",
"maneuver", "channel_energy", "hex", "deed", "spell_combat",
"inspire_courage", "retrieve_weapon",
"inspire_courage", "retrieve_weapon", "repair_weapon",
]
target_id: str | None = None
spell_name: str | None = None
@@ -1478,6 +1478,8 @@ class CombatEngine:
)
elif kind == "retrieve_weapon":
self._retrieve_weapon(state, action.weapon_id)
elif kind == "repair_weapon":
self._repair_weapon(state, action.weapon_id)
elif kind in ("channel_energy", "hex", "deed", "spell_combat", "inspire_courage"):
self._execute_class_ability(state, target, action)
elif kind == "charge":
@@ -1648,6 +1650,37 @@ class CombatEngine:
f"retrieve {weapon_id} (restored)"
)
def _repair_weapon(self, state: CombatantState, weapon_id: str | None) -> None:
"""Repair a broken weapon: remove it from ``weapon_broken`` and reset damage.
No-op (with a log line) when ``weapon_id`` is None or the weapon was never
damaged. Also removes the transient ``disarmed`` condition originating
from the sunder that broke the weapon, so the repaired weapon is fully
usable again.
"""
if weapon_id is None:
self._log(
f"round {self._current_round} {state.combatant.id}: "
f"repair: nothing to repair"
)
return
if weapon_id not in state.weapon_damage:
self._log(
f"round {self._current_round} {state.combatant.id}: "
f"repair {weapon_id}: nothing to repair"
)
return
state.weapon_damage.pop(weapon_id, None)
state.weapon_broken.discard(weapon_id)
state.active_conditions = [
c for c in state.active_conditions
if not (c.condition.name == "disarmed" and c.source == "maneuver: sunder")
]
self._log(
f"round {self._current_round} {state.combatant.id}: "
f"repair {weapon_id} (restored)"
)
def _maneuver_cmb(self, state: CombatantState) -> int:
return (
state.combatant.cmb