- Removed world module-level variable from look.py - look.cmd_look() now uses player.location.get_viewport() instead of world.get_viewport() - look.cmd_look() uses zone.contents_near() to find nearby entities instead of iterating global players/mobs lists - Wrapping calculations use zone.width/height/toroidal instead of world properties - Added type check for player.location being a Zone instance - Removed look.world injection from server.py - Updated all tests to remove look.world injection - spawn_mob() and combat commands also migrated to use Zone (player.location) - Removed orphaned code from test_mob_ai.py and test_variant_prefix.py
29 lines
1,008 B
Python
29 lines
1,008 B
Python
"""Spawn command for creating mobs."""
|
|
|
|
from mudlib.commands import CommandDefinition, register
|
|
from mudlib.mobs import mob_templates, spawn_mob
|
|
from mudlib.player import Player
|
|
from mudlib.zone import Zone
|
|
|
|
|
|
async def cmd_spawn(player: Player, args: str) -> None:
|
|
"""Spawn a mob at the player's current position."""
|
|
name = args.strip().lower()
|
|
if not name:
|
|
await player.send("Usage: spawn <mob_type>\r\n")
|
|
return
|
|
|
|
if name not in mob_templates:
|
|
available = ", ".join(sorted(mob_templates.keys()))
|
|
await player.send(f"Unknown mob type: {name}\r\nAvailable: {available}\r\n")
|
|
return
|
|
|
|
if player.location is None or not isinstance(player.location, Zone):
|
|
await player.send("Cannot spawn mob: you are not in a zone.\r\n")
|
|
return
|
|
|
|
mob = spawn_mob(mob_templates[name], player.x, player.y, player.location)
|
|
await player.send(f"A {mob.name} appears!\r\n")
|
|
|
|
|
|
register(CommandDefinition("spawn", cmd_spawn, aliases=[], mode="normal"))
|