Show ground items in look command

After the viewport, look lists Things at the player's position
in a "On the ground: item1, item2" line. No output when empty.
This commit is contained in:
Jared Miller 2026-02-11 20:01:10 -05:00
parent e96fd50de5
commit 2e79255aec
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
2 changed files with 74 additions and 0 deletions

View file

@ -5,6 +5,7 @@ from mudlib.effects import get_effects_at
from mudlib.entity import Entity
from mudlib.player import Player
from mudlib.render.ansi import RESET, colorize_terrain
from mudlib.thing import Thing
from mudlib.zone import Zone
# Viewport dimensions
@ -99,6 +100,15 @@ async def cmd_look(player: Player, args: str) -> None:
# Send to player
player.writer.write("\r\n".join(output_lines) + "\r\n")
# Show items on the ground at player's position
ground_items = [
obj for obj in zone.contents_at(player.x, player.y) if isinstance(obj, Thing)
]
if ground_items:
names = ", ".join(item.name for item in ground_items)
player.writer.write(f"On the ground: {names}\r\n")
await player.writer.drain()

View file

@ -368,3 +368,67 @@ async def test_dispatch_allows_matching_mode(player):
await commands.dispatch(player, "strike")
assert called
@pytest.mark.asyncio
async def test_look_shows_ground_items(player, test_zone):
"""look shows things on the ground at the player's position."""
from mudlib.player import players
from mudlib.thing import Thing
players.clear()
players[player.name] = player
Thing(name="rock", location=test_zone, x=5, y=5)
await look.cmd_look(player, "")
output = "".join([call[0][0] for call in player.writer.write.call_args_list])
assert "rock" in output.lower()
@pytest.mark.asyncio
async def test_look_shows_multiple_ground_items(player, test_zone):
"""look shows all things at the player's position."""
from mudlib.player import players
from mudlib.thing import Thing
players.clear()
players[player.name] = player
Thing(name="rock", location=test_zone, x=5, y=5)
Thing(name="sword", location=test_zone, x=5, y=5)
await look.cmd_look(player, "")
output = "".join([call[0][0] for call in player.writer.write.call_args_list])
assert "rock" in output.lower()
assert "sword" in output.lower()
@pytest.mark.asyncio
async def test_look_no_ground_items_no_extra_output(player, test_zone):
"""look with no ground items doesn't mention items."""
from mudlib.player import players
players.clear()
players[player.name] = player
await look.cmd_look(player, "")
output = "".join([call[0][0] for call in player.writer.write.call_args_list])
assert "on the ground" not in output.lower()
@pytest.mark.asyncio
async def test_look_ignores_items_at_other_positions(player, test_zone):
"""look doesn't show items that are at different positions."""
from mudlib.player import players
from mudlib.thing import Thing
players.clear()
players[player.name] = player
Thing(name="far_rock", location=test_zone, x=9, y=9)
await look.cmd_look(player, "")
output = "".join([call[0][0] for call in player.writer.write.call_args_list])
assert "far_rock" not in output.lower()