diff --git a/src/mudlib/combat/commands.py b/src/mudlib/combat/commands.py index 57190c4..8e8bcb7 100644 --- a/src/mudlib/combat/commands.py +++ b/src/mudlib/combat/commands.py @@ -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 = [] diff --git a/src/mudlib/combat/encounter.py b/src/mudlib/combat/encounter.py index 9743b30..52c206a 100644 --- a/src/mudlib/combat/encounter.py +++ b/src/mudlib/combat/encounter.py @@ -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 diff --git a/tests/test_combat_commands.py b/tests/test_combat_commands.py index 33ad69a..20c59c6 100644 --- a/tests/test_combat_commands.py +++ b/tests/test_combat_commands.py @@ -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 --- diff --git a/tests/test_combat_engine.py b/tests/test_combat_engine.py index a4e2f5f..8580fd0 100644 --- a/tests/test_combat_engine.py +++ b/tests/test_combat_engine.py @@ -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())