Defenses now work outside combat mode with stamina cost, recovery lock (based on timing_window_ms), and broadcast to nearby players. Lock prevents spamming defenses — you commit to the move. Stamina deduction moved from encounter.defend() to do_defend command layer. Defense commands registered with mode="*" instead of "combat".
87 lines
2.3 KiB
Python
87 lines
2.3 KiB
Python
"""Tests for entity combat stats."""
|
|
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
|
|
import pytest
|
|
|
|
from mudlib.entity import Entity, Mob
|
|
from mudlib.player import Player
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_writer():
|
|
writer = MagicMock()
|
|
writer.write = MagicMock()
|
|
writer.drain = AsyncMock()
|
|
return writer
|
|
|
|
|
|
@pytest.fixture
|
|
def mock_reader():
|
|
return MagicMock()
|
|
|
|
|
|
def test_entity_has_combat_stats():
|
|
"""Test that Entity has PL and stamina stats."""
|
|
entity = Entity(name="Test", x=0, y=0)
|
|
assert entity.pl == 100.0
|
|
assert entity.stamina == 100.0
|
|
assert entity.max_stamina == 100.0
|
|
assert entity.defense_locked_until == 0.0
|
|
|
|
|
|
def test_entity_combat_stats_can_be_customized():
|
|
"""Test that combat stats can be set on initialization."""
|
|
entity = Entity(name="Weak", x=0, y=0, pl=50.0, stamina=30.0, max_stamina=30.0)
|
|
assert entity.pl == 50.0
|
|
assert entity.stamina == 30.0
|
|
assert entity.max_stamina == 30.0
|
|
|
|
|
|
def test_mob_inherits_combat_stats():
|
|
"""Test that Mob inherits combat stats from Entity."""
|
|
mob = Mob(name="Goku", x=10, y=10, description="A powerful fighter")
|
|
assert mob.pl == 100.0
|
|
assert mob.stamina == 100.0
|
|
assert mob.max_stamina == 100.0
|
|
|
|
|
|
def test_mob_combat_stats_can_be_customized():
|
|
"""Test that Mob can have custom combat stats."""
|
|
mob = Mob(
|
|
name="Boss",
|
|
x=5,
|
|
y=5,
|
|
description="Strong",
|
|
pl=200.0,
|
|
max_stamina=150.0,
|
|
stamina=150.0,
|
|
)
|
|
assert mob.pl == 200.0
|
|
assert mob.stamina == 150.0
|
|
assert mob.max_stamina == 150.0
|
|
|
|
|
|
def test_player_inherits_combat_stats(mock_reader, mock_writer):
|
|
"""Test that Player inherits combat stats from Entity."""
|
|
player = Player(name="Hero", x=0, y=0, reader=mock_reader, writer=mock_writer)
|
|
assert player.pl == 100.0
|
|
assert player.stamina == 100.0
|
|
assert player.max_stamina == 100.0
|
|
|
|
|
|
def test_player_combat_stats_can_be_customized(mock_reader, mock_writer):
|
|
"""Test that Player can have custom combat stats."""
|
|
player = Player(
|
|
name="Veteran",
|
|
x=0,
|
|
y=0,
|
|
reader=mock_reader,
|
|
writer=mock_writer,
|
|
pl=150.0,
|
|
stamina=120.0,
|
|
max_stamina=120.0,
|
|
)
|
|
assert player.pl == 150.0
|
|
assert player.stamina == 120.0
|
|
assert player.max_stamina == 120.0
|