1
0
Fork 0
taleweave-ai/adventure/systems/rpg/language_actions.py

22 lines
662 B
Python
Raw Normal View History

from adventure.context import action_context, broadcast
from adventure.utils.search import find_item_in_actor
2024-05-19 20:27:56 +00:00
def action_read(item: str) -> str:
"""
Read an item like a book or a sign.
Args:
2024-05-19 20:27:56 +00:00
item: The name of the item to read.
"""
with action_context() as (_, action_actor):
2024-05-19 20:27:56 +00:00
action_item = find_item_in_actor(action_actor, item)
if not action_item:
return f"You do not have a {item} to read."
2024-05-19 20:27:56 +00:00
if "text" in action_item.attributes:
broadcast(f"{action_actor.name} reads {item}")
return str(action_item.attributes["text"])
2024-05-19 20:27:56 +00:00
return f"The {item} has nothing to read."