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:
parent
833c0efa3a
commit
bea3c98124
2 changed files with 77 additions and 0 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -432,3 +432,68 @@ 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()
|
||||
|
||||
|
||||
@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
|
||||
|
|
|
|||
Loading…
Reference in a new issue