1
0
Fork 0

add simulation systems

This commit is contained in:
Sean Sube 2024-05-05 15:50:51 -05:00
parent d6e8763914
commit 186edb6df2
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
2 changed files with 92 additions and 0 deletions

View File

@ -0,0 +1,64 @@
from adventure.context import get_current_context
def action_cook(item: str) -> str:
"""
Cook an item from your inventory.
Args:
item: The name of the item to cook.
"""
_, _, action_actor = get_current_context()
target_item = next((i for i in action_actor.items if i.name == item), None)
if target_item is None:
return "You don't have the item to cook."
# Check if the item is edible
edible = target_item.attributes.get("edible", None)
if not edible:
return "You can't cook that."
# Check if the item is raw
if edible == "cooked":
return "That item is already cooked."
# Cook the item
target_item.attributes["edible"] = "cooked"
return f"You cook the {item}."
def action_eat(item: str) -> str:
"""
Eat an item from your inventory.
Args:
item: The name of the item to eat.
"""
_, _, action_actor = get_current_context()
target_item = next((i for i in action_actor.items if i.name == item), None)
if target_item is None:
return "You don't have the item to eat."
# Check if the item is edible
edible = target_item.attributes.get("edible", None)
if not edible:
return "You can't eat that."
# Check if the item is cooked
if edible == "raw":
return "You can't eat that raw."
if edible == "rotten":
return "That item is rotten."
# Check if the actor is hungry
hunger = action_actor.attributes.get("hunger", None)
if hunger != "hungry":
return "You're not hungry."
# Eat the item
action_actor.items.remove(target_item)
action_actor.attributes["hunger"] = "full"
return f"You eat the {item}."

View File

@ -0,0 +1,28 @@
rules:
# hunger logic
- match:
type: actor
hunger: full
chance: 0.2
set:
hunger: hungry
# hunger initialization
- rule: |
"hunger" not in attributes
set:
hunger: hungry
# cooking logic
- match:
type: item
edible: raw
chance: 0.1
set:
edible: cooked
- match:
type: item
edible: cooked
chance: 0.1
set:
edible: rotten