94 lines
2.9 KiB
Python
94 lines
2.9 KiB
Python
"""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.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pf1e_simulator.combat import CombatantState, CombatEngine
|
|
from pf1e_simulator.grid import Grid
|
|
from pf1e_simulator.map import MapSpec, TerrainType
|
|
from pf1e_simulator.models import (
|
|
AbilityScores,
|
|
ACProfile,
|
|
AttackSpec,
|
|
Combatant,
|
|
DamageComponent,
|
|
Saves,
|
|
)
|
|
from pf1e_simulator.rng import ScriptedRng
|
|
|
|
|
|
def make_combatant(
|
|
cid: str, *, attack_bonus: int = 2, weapon_name: str = "sword"
|
|
) -> Combatant:
|
|
attack = AttackSpec(
|
|
id=f"{cid}-w",
|
|
name=weapon_name,
|
|
kind="melee",
|
|
attack_bonus=attack_bonus,
|
|
damage=[DamageComponent(formula="1d4", types=["slashing"])],
|
|
)
|
|
return Combatant(
|
|
id=cid,
|
|
name=cid,
|
|
level=1,
|
|
size="Medium",
|
|
abilities=AbilityScores(
|
|
str_score=10, dex_score=10, con_score=10,
|
|
int_score=10, wis_score=10, cha_score=10,
|
|
),
|
|
hp_max=6,
|
|
ac=ACProfile(total=13, touch=13, flat_footed=13),
|
|
bab=attack_bonus,
|
|
initiative_mod=0,
|
|
speed_land_ft=30,
|
|
saves=Saves(fort=0, ref=0, will=0),
|
|
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)
|
|
|
|
|
|
def make_grid() -> Grid:
|
|
legend = {".": TerrainType(type="floor", move_cost=1)}
|
|
spec = MapSpec(name="test", terrain=tuple(["." * 8] * 8), legend=legend)
|
|
return Grid.from_spec(spec)
|
|
|
|
|
|
def make_engine(
|
|
queue: list[int], states: list[CombatantState]
|
|
) -> CombatEngine:
|
|
return CombatEngine(ScriptedRng(queue), make_grid(), states)
|
|
|
|
|
|
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))
|
|
hp_before = b.hp
|
|
engine = make_engine([12], [a, b])
|
|
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
|
|
|
|
|
|
def test_sunder_destroys_weapon_and_disarms() -> 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([12, 12, 12, 12, 12], [a, b])
|
|
for _ in range(5):
|
|
engine._execute_maneuver(a, b, "sunder")
|
|
assert b.hp == 6
|
|
assert "b-w" in b.weapon_broken
|
|
assert engine.weapon_for(b, a) is None
|
|
assert any(c.condition.name == "disarmed" for c in b.active_conditions)
|