Show entities at player position beneath the map

Adds a "Here: goblin, Ally" line after the map grid listing mobs and
other players sharing the tile. Dead mobs are excluded.
This commit is contained in:
Jared Miller 2026-02-12 16:41:55 -05:00
parent 4cff1475c3
commit b63b054997
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C
2 changed files with 78 additions and 0 deletions

View file

@ -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

View file

@ -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