Fix variant defense mode and test cleanup
- Set variant defense registration to mode="*" (both attacks and defenses) - Strengthen telegraph switch test to verify new move's telegraph text - Remove unused punch parameter from four idle timeout tests - Use single time.monotonic() call in attack() method
This commit is contained in:
parent
1b3684dc65
commit
2de1ebd59e
4 changed files with 11 additions and 9 deletions
|
|
@ -213,7 +213,7 @@ def register_combat_commands(content_dir: Path) -> None:
|
|||
# Determine type from first variant
|
||||
first_variant = next(iter(variants.values()))
|
||||
handler_fn = do_attack if first_variant.move_type == "attack" else do_defend
|
||||
mode = "*" if first_variant.move_type == "attack" else "combat"
|
||||
mode = "*"
|
||||
|
||||
# Collect all variant aliases for the base command
|
||||
all_aliases = []
|
||||
|
|
|
|||
|
|
@ -56,6 +56,8 @@ class CombatEncounter:
|
|||
Args:
|
||||
move: The attack move to execute
|
||||
"""
|
||||
now = time.monotonic()
|
||||
|
||||
if self.state in (CombatState.TELEGRAPH, CombatState.WINDOW):
|
||||
# Switching — refund old cost, keep timer
|
||||
if self.current_move:
|
||||
|
|
@ -65,11 +67,11 @@ class CombatEncounter:
|
|||
)
|
||||
else:
|
||||
# First attack — start timer
|
||||
self.move_started_at = time.monotonic()
|
||||
self.move_started_at = now
|
||||
|
||||
self.current_move = move
|
||||
self.attacker.stamina -= move.stamina_cost
|
||||
self.last_action_at = time.monotonic()
|
||||
self.last_action_at = now
|
||||
if self.state == CombatState.IDLE:
|
||||
self.state = CombatState.TELEGRAPH
|
||||
|
||||
|
|
|
|||
|
|
@ -326,8 +326,8 @@ async def test_switch_attack_sends_new_telegraph(
|
|||
await combat_commands.do_attack(player, "", punch_left)
|
||||
|
||||
target_msgs = [call[0][0] for call in target.writer.write.call_args_list]
|
||||
# Defender should get a new telegraph
|
||||
assert len(target_msgs) > 0
|
||||
# Defender should get a new telegraph with the new move's text
|
||||
assert any("left hook" in msg.lower() for msg in target_msgs)
|
||||
|
||||
|
||||
# --- defense commitment tests ---
|
||||
|
|
|
|||
|
|
@ -334,7 +334,7 @@ async def test_process_combat_sends_messages_on_resolve(punch):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_idle_timeout_ends_encounter(punch):
|
||||
async def test_idle_timeout_ends_encounter():
|
||||
"""Test encounter times out after 30s of no actions."""
|
||||
w = _mock_writer
|
||||
attacker = Player(name="Goku", x=0, y=0, writer=w())
|
||||
|
|
@ -353,7 +353,7 @@ async def test_idle_timeout_ends_encounter(punch):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_idle_timeout_sends_message(punch):
|
||||
async def test_idle_timeout_sends_message():
|
||||
"""Test timeout sends fizzle message to both players."""
|
||||
atk_writer = _mock_writer()
|
||||
def_writer = _mock_writer()
|
||||
|
|
@ -374,7 +374,7 @@ async def test_idle_timeout_sends_message(punch):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_idle_timeout_pops_combat_mode(punch):
|
||||
async def test_idle_timeout_pops_combat_mode():
|
||||
"""Test timeout pops combat mode from both players."""
|
||||
w = _mock_writer
|
||||
attacker = Player(name="Goku", x=0, y=0, writer=w())
|
||||
|
|
@ -392,7 +392,7 @@ async def test_idle_timeout_pops_combat_mode(punch):
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_recent_action_prevents_timeout(punch):
|
||||
async def test_recent_action_prevents_timeout():
|
||||
"""Test recent action prevents idle timeout."""
|
||||
w = _mock_writer
|
||||
attacker = Player(name="Goku", x=0, y=0, writer=w())
|
||||
|
|
|
|||
Loading…
Reference in a new issue