2024-05-27 13:10:24 +00:00
|
|
|
from taleweave.context import action_context, broadcast
|
|
|
|
from taleweave.utils.search import find_item_in_character
|
2024-05-18 21:20:47 +00:00
|
|
|
|
|
|
|
|
2024-05-19 20:27:56 +00:00
|
|
|
def action_read(item: str) -> str:
|
2024-05-18 21:20:47 +00:00
|
|
|
"""
|
|
|
|
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.
|
2024-05-18 21:20:47 +00:00
|
|
|
"""
|
2024-05-27 01:32:03 +00:00
|
|
|
with action_context() as (_, action_character):
|
|
|
|
action_item = find_item_in_character(action_character, item)
|
2024-05-19 20:27:56 +00:00
|
|
|
if not action_item:
|
|
|
|
return f"You do not have a {item} to read."
|
2024-05-18 21:20:47 +00:00
|
|
|
|
2024-05-19 20:27:56 +00:00
|
|
|
if "text" in action_item.attributes:
|
2024-05-27 01:32:03 +00:00
|
|
|
broadcast(f"{action_character.name} reads {item}")
|
2024-05-19 20:27:56 +00:00
|
|
|
return str(action_item.attributes["text"])
|
2024-05-18 21:20:47 +00:00
|
|
|
|
2024-05-19 20:27:56 +00:00
|
|
|
return f"The {item} has nothing to read."
|
2024-06-22 22:00:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
def action_write(item: str, text: str) -> str:
|
|
|
|
"""
|
|
|
|
Write on an item like a book or a sign.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
item: The name of the item to write on.
|
|
|
|
text: The text to write.
|
|
|
|
"""
|
|
|
|
with action_context() as (_, action_character):
|
|
|
|
action_item = find_item_in_character(action_character, item)
|
|
|
|
if not action_item:
|
|
|
|
return f"You do not have a {item} to write on."
|
|
|
|
|
|
|
|
action_item.attributes["text"] = text
|
|
|
|
broadcast(f"{action_character.name} writes on {item}")
|
|
|
|
return f"You write on the {item}."
|