mud/src/mudlib/verb_handlers.py
Jared Miller 6ce57ad970
Add key-based unlock as first verb interaction
Implements unlock_handler that checks for a key in player inventory
and unlocks containers. Tests cover error cases (non-container,
not locked, no key), success case, key aliasing, and state preservation.
2026-02-11 21:47:33 -05:00

38 lines
1,022 B
Python

"""Verb handlers for object interactions."""
async def unlock_handler(obj, player, args):
"""
Handle unlocking a container.
Args:
obj: The object being unlocked (should be a Container)
player: The player attempting to unlock
args: Additional arguments (unused)
"""
from mudlib.container import Container
if not isinstance(obj, Container):
await player.send("That can't be unlocked.\r\n")
return
if not obj.locked:
await player.send("That's not locked.\r\n")
return
# Check for key in player inventory
key = None
for item in player.contents:
if item.name.lower() == "key" or "key" in [
a.lower() for a in getattr(item, "aliases", [])
]:
key = item
break
if key is None:
await player.send("You don't have a key.\r\n")
return
obj.locked = False
obj.closed = False
await player.send(f"You unlock the {obj.name} with the {key.name}.\r\n")