diff --git a/src/mudlib/commands/look.py b/src/mudlib/commands/look.py index 68eb58c..c184a22 100644 --- a/src/mudlib/commands/look.py +++ b/src/mudlib/commands/look.py @@ -102,6 +102,18 @@ async def cmd_look(player: Player, args: str) -> None: # Send to player player.writer.write("\r\n".join(output_lines) + "\r\n") + # Show entities (mobs, other players) at the player's position + entities_here = [ + obj + for obj in zone.contents_at(player.x, player.y) + if isinstance(obj, Entity) + and obj is not player + and (not hasattr(obj, "alive") or obj.alive) + ] + if entities_here: + names = ", ".join(e.name for e in entities_here) + player.writer.write(f"Here: {names}\r\n") + # Show items on the ground at player's position from mudlib.portal import Portal diff --git a/tests/test_commands.py b/tests/test_commands.py index 5c00a4a..9a609b9 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -432,6 +432,7 @@ async def test_look_ignores_items_at_other_positions(player, test_zone): output = "".join([call[0][0] for call in player.writer.write.call_args_list]) assert "far_rock" not in output.lower() +<<<<<<< HEAD @pytest.mark.asyncio @@ -470,3 +471,68 @@ async def test_quit_removes_player_from_zone(monkeypatch): await quit_mod.cmd_quit(p, "") assert p not in zone._contents assert "quitter" not in players + + +@pytest.mark.asyncio +async def test_look_shows_entities_here(player, test_zone): + """look lists mobs and other players at the player's position.""" + from mudlib.entity import Mob + from mudlib.player import players + + players.clear() + players[player.name] = player + + Mob(name="goblin", location=test_zone, x=5, y=5, description="a goblin") + other = Player( + name="Ally", + location=test_zone, + x=5, + y=5, + reader=MagicMock(), + writer=MagicMock(), + ) + players["Ally"] = other + + await look.cmd_look(player, "") + + output = "".join(c[0][0] for c in player.writer.write.call_args_list) + assert "Here: " in output + assert "goblin" in output + assert "Ally" in output + + +@pytest.mark.asyncio +async def test_look_hides_dead_mobs_from_here(player, test_zone): + """look omits dead mobs from the here line.""" + from mudlib.entity import Mob + from mudlib.player import players + + players.clear() + players[player.name] = player + + Mob( + name="corpse", + location=test_zone, + x=5, + y=5, + description="dead", + alive=False, + ) + await look.cmd_look(player, "") + + output = "".join(c[0][0] for c in player.writer.write.call_args_list) + assert "corpse" not in output + + +@pytest.mark.asyncio +async def test_look_no_here_line_when_alone(player, test_zone): + """look omits the here line when no other entities are present.""" + from mudlib.player import players + + players.clear() + players[player.name] = player + + await look.cmd_look(player, "") + + output = "".join(c[0][0] for c in player.writer.write.call_args_list) + assert "Here:" not in output