flesh out sim systems
This commit is contained in:
parent
186edb6df2
commit
564be90d9f
|
@ -0,0 +1,28 @@
|
||||||
|
from .hunger_actions import action_cook, action_eat
|
||||||
|
from .hygiene_actions import action_wash
|
||||||
|
from .sleeping_actions import action_sleep
|
||||||
|
|
||||||
|
from adventure.logic import init_from_file
|
||||||
|
|
||||||
|
LOGIC_FILES = [
|
||||||
|
"./adventure/sim_systems/hunger_logic.yaml",
|
||||||
|
"./adventure/sim_systems/hygiene_logic.yaml",
|
||||||
|
"./adventure/sim_systems/mood_logic.yaml",
|
||||||
|
"./adventure/sim_systems/sleeping_logic.yaml",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def init_actions():
|
||||||
|
return [
|
||||||
|
# hunger
|
||||||
|
action_cook,
|
||||||
|
action_eat,
|
||||||
|
# hygiene
|
||||||
|
action_wash,
|
||||||
|
# sleeping
|
||||||
|
action_sleep,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def init_logic():
|
||||||
|
return [init_from_file(filename) for filename in LOGIC_FILES]
|
|
@ -15,16 +15,17 @@ def action_cook(item: str) -> str:
|
||||||
return "You don't have the item to cook."
|
return "You don't have the item to cook."
|
||||||
|
|
||||||
# Check if the item is edible
|
# Check if the item is edible
|
||||||
edible = target_item.attributes.get("edible", None)
|
edible = target_item.attributes.get("edible", False)
|
||||||
if not edible:
|
if not edible:
|
||||||
return "You can't cook that."
|
return "You can't cook that."
|
||||||
|
|
||||||
# Check if the item is raw
|
# Check if the item is raw
|
||||||
if edible == "cooked":
|
cooked = target_item.attributes.get("cooked", False)
|
||||||
|
if cooked:
|
||||||
return "That item is already cooked."
|
return "That item is already cooked."
|
||||||
|
|
||||||
# Cook the item
|
# Cook the item
|
||||||
target_item.attributes["edible"] = "cooked"
|
target_item.attributes["cooked"] = True
|
||||||
return f"You cook the {item}."
|
return f"You cook the {item}."
|
||||||
|
|
||||||
|
|
||||||
|
@ -42,16 +43,19 @@ def action_eat(item: str) -> str:
|
||||||
return "You don't have the item to eat."
|
return "You don't have the item to eat."
|
||||||
|
|
||||||
# Check if the item is edible
|
# Check if the item is edible
|
||||||
edible = target_item.attributes.get("edible", None)
|
edible = target_item.attributes.get("edible", False)
|
||||||
if not edible:
|
if not edible:
|
||||||
return "You can't eat that."
|
return "You can't eat that."
|
||||||
|
|
||||||
# Check if the item is cooked
|
# Check if the item is cooked
|
||||||
if edible == "raw":
|
cooked = target_item.attributes.get("cooked", False)
|
||||||
|
if not cooked:
|
||||||
return "You can't eat that raw."
|
return "You can't eat that raw."
|
||||||
|
|
||||||
if edible == "rotten":
|
# Check if the item is rotten
|
||||||
return "That item is rotten."
|
spoiled = target_item.attributes.get("spoiled", False)
|
||||||
|
if spoiled:
|
||||||
|
return "You can't eat that item, it is rotten."
|
||||||
|
|
||||||
# Check if the actor is hungry
|
# Check if the actor is hungry
|
||||||
hunger = action_actor.attributes.get("hunger", None)
|
hunger = action_actor.attributes.get("hunger", None)
|
||||||
|
|
|
@ -1,4 +1,21 @@
|
||||||
rules:
|
rules:
|
||||||
|
# cooking logic
|
||||||
|
- match:
|
||||||
|
type: item
|
||||||
|
edible: true
|
||||||
|
cooked: false
|
||||||
|
chance: 0.2
|
||||||
|
set:
|
||||||
|
spoiled: true
|
||||||
|
|
||||||
|
- match:
|
||||||
|
type: item
|
||||||
|
edible: true
|
||||||
|
cooked: true
|
||||||
|
chance: 0.1
|
||||||
|
set:
|
||||||
|
spoiled: true
|
||||||
|
|
||||||
# hunger logic
|
# hunger logic
|
||||||
- match:
|
- match:
|
||||||
type: actor
|
type: actor
|
||||||
|
@ -13,16 +30,53 @@ rules:
|
||||||
set:
|
set:
|
||||||
hunger: hungry
|
hunger: hungry
|
||||||
|
|
||||||
# cooking logic
|
# thirst logic
|
||||||
- match:
|
- match:
|
||||||
type: item
|
type: actor
|
||||||
edible: raw
|
thirst: hydrated
|
||||||
chance: 0.1
|
chance: 0.2
|
||||||
set:
|
set:
|
||||||
edible: cooked
|
thirst: thirsty
|
||||||
- match:
|
|
||||||
type: item
|
# thirst initialization
|
||||||
edible: cooked
|
- rule: |
|
||||||
chance: 0.1
|
"thirst" not in attributes
|
||||||
set:
|
set:
|
||||||
edible: rotten
|
thirst: hydrated
|
||||||
|
|
||||||
|
labels:
|
||||||
|
edible:
|
||||||
|
true:
|
||||||
|
backstory: You are edible.
|
||||||
|
description: This item is edible.
|
||||||
|
false:
|
||||||
|
backstory: You are not edible.
|
||||||
|
description: This item is not edible.
|
||||||
|
cooked:
|
||||||
|
true:
|
||||||
|
backstory: You are cooked.
|
||||||
|
description: This item is cooked.
|
||||||
|
false:
|
||||||
|
backstory: You are raw.
|
||||||
|
description: This item is raw.
|
||||||
|
spoiled:
|
||||||
|
true:
|
||||||
|
backstory: You are rotten and inedible.
|
||||||
|
description: This item is rotten and inedible.
|
||||||
|
false:
|
||||||
|
backstory: You are fresh and edible.
|
||||||
|
description: This item is fresh and edible.
|
||||||
|
hunger:
|
||||||
|
full:
|
||||||
|
backstory: You are have eaten recently and are full.
|
||||||
|
description: ~
|
||||||
|
hungry:
|
||||||
|
backstory: You are hungry and need to eat.
|
||||||
|
description: They look hungry.
|
||||||
|
thirst:
|
||||||
|
hydrated:
|
||||||
|
backstory: You are hydrated.
|
||||||
|
description: ~
|
||||||
|
thirsty:
|
||||||
|
backstory: You are thirsty and need to drink.
|
||||||
|
description: They look thirsty.
|
|
@ -0,0 +1,20 @@
|
||||||
|
from adventure.context import get_current_context, get_dungeon_master
|
||||||
|
|
||||||
|
|
||||||
|
def action_wash() -> str:
|
||||||
|
"""
|
||||||
|
Wash yourself.
|
||||||
|
"""
|
||||||
|
|
||||||
|
_, action_room, action_actor = get_current_context()
|
||||||
|
hygiene = action_actor.attributes.get("hygiene", "clean")
|
||||||
|
|
||||||
|
dungeon_master = get_dungeon_master()
|
||||||
|
outcome = dungeon_master(
|
||||||
|
f"{action_actor.name} washes themselves in the {action_room.name}. {action_room.description}. {action_actor.description}"
|
||||||
|
f"{action_actor.name} was {hygiene} to start with. How clean are they after washing? Respond with 'clean' or 'dirty'."
|
||||||
|
"If the room has a shower or running water, they should be cleaner. If the room is dirty, they should end up dirtier."
|
||||||
|
)
|
||||||
|
|
||||||
|
action_actor.attributes["clean"] = outcome.strip().lower()
|
||||||
|
return f"You wash yourself in the {action_room.name} and feel {outcome}"
|
|
@ -0,0 +1,26 @@
|
||||||
|
rules:
|
||||||
|
- match:
|
||||||
|
type: actor
|
||||||
|
hygiene: clean
|
||||||
|
chance: 0.2
|
||||||
|
set:
|
||||||
|
hygiene: dirty
|
||||||
|
|
||||||
|
- match:
|
||||||
|
type: actor
|
||||||
|
hygiene: dirty
|
||||||
|
chance: 0.2
|
||||||
|
set:
|
||||||
|
hygiene: filthy
|
||||||
|
|
||||||
|
labels:
|
||||||
|
hygiene:
|
||||||
|
clean:
|
||||||
|
backstory: You are clean and smell fresh.
|
||||||
|
description: They look freshly washed and smell clean.
|
||||||
|
dirty:
|
||||||
|
backstory: You are dirty and smell bad.
|
||||||
|
description: They look dirty and smell bad.
|
||||||
|
filthy:
|
||||||
|
backstory: You are filthy and smell terrible.
|
||||||
|
description: They look filthy and smell terrible.
|
|
@ -0,0 +1,131 @@
|
||||||
|
rules:
|
||||||
|
# mood logic
|
||||||
|
- group: mood
|
||||||
|
match:
|
||||||
|
type: actor
|
||||||
|
mood: happy
|
||||||
|
chance: 0.2
|
||||||
|
set:
|
||||||
|
mood: sad
|
||||||
|
|
||||||
|
- group: mood
|
||||||
|
match:
|
||||||
|
type: actor
|
||||||
|
mood: happy
|
||||||
|
chance: 0.2
|
||||||
|
set:
|
||||||
|
mood: neutral
|
||||||
|
|
||||||
|
- group: mood
|
||||||
|
match:
|
||||||
|
type: actor
|
||||||
|
mood: angry
|
||||||
|
chance: 0.2
|
||||||
|
set:
|
||||||
|
mood: neutral
|
||||||
|
|
||||||
|
- group: mood
|
||||||
|
match:
|
||||||
|
type: actor
|
||||||
|
mood: neutral
|
||||||
|
chance: 0.2
|
||||||
|
set:
|
||||||
|
mood: happy
|
||||||
|
|
||||||
|
- group: mood
|
||||||
|
match:
|
||||||
|
type: actor
|
||||||
|
mood: neutral
|
||||||
|
chance: 0.2
|
||||||
|
set:
|
||||||
|
mood: sad
|
||||||
|
|
||||||
|
- group: mood
|
||||||
|
match:
|
||||||
|
type: actor
|
||||||
|
mood: sad
|
||||||
|
chance: 0.2
|
||||||
|
set:
|
||||||
|
mood: angry
|
||||||
|
|
||||||
|
- group: mood
|
||||||
|
match:
|
||||||
|
type: actor
|
||||||
|
mood: sad
|
||||||
|
chance: 0.2
|
||||||
|
set:
|
||||||
|
mood: neutral
|
||||||
|
|
||||||
|
# mood interactions with other systems
|
||||||
|
- group: mood
|
||||||
|
match:
|
||||||
|
type: actor
|
||||||
|
mood: sad
|
||||||
|
sleep: rested
|
||||||
|
chance: 0.5
|
||||||
|
set:
|
||||||
|
sleep: tired
|
||||||
|
|
||||||
|
- group: mood
|
||||||
|
match:
|
||||||
|
type: actor
|
||||||
|
hunger: hungry
|
||||||
|
chance: 0.5
|
||||||
|
set:
|
||||||
|
mood: angry
|
||||||
|
|
||||||
|
- group: mood
|
||||||
|
match:
|
||||||
|
type: actor
|
||||||
|
mood: angry
|
||||||
|
hunger: full
|
||||||
|
chance: 0.5
|
||||||
|
set:
|
||||||
|
mood: neutral
|
||||||
|
|
||||||
|
- group: mood
|
||||||
|
match:
|
||||||
|
type: actor
|
||||||
|
mood: neutral
|
||||||
|
hunger: full
|
||||||
|
chance: 0.5
|
||||||
|
set:
|
||||||
|
mood: happy
|
||||||
|
|
||||||
|
- group: mood
|
||||||
|
match:
|
||||||
|
type: actor
|
||||||
|
mood: happy
|
||||||
|
hunger: hungry
|
||||||
|
chance: 0.5
|
||||||
|
set:
|
||||||
|
mood: neutral
|
||||||
|
|
||||||
|
- group: mood
|
||||||
|
match:
|
||||||
|
type: actor
|
||||||
|
mood: neutral
|
||||||
|
sleep: tired
|
||||||
|
chance: 0.5
|
||||||
|
set:
|
||||||
|
mood: sad
|
||||||
|
|
||||||
|
# mood initialization
|
||||||
|
- group: mood
|
||||||
|
rule: |
|
||||||
|
"mood" not in attributes
|
||||||
|
set:
|
||||||
|
mood: happy
|
||||||
|
|
||||||
|
labels:
|
||||||
|
mood:
|
||||||
|
happy:
|
||||||
|
backstory: You are feeling happy.
|
||||||
|
description: They look happy.
|
||||||
|
# neutral intentionally left out
|
||||||
|
sad:
|
||||||
|
backstory: You are feeling sad.
|
||||||
|
description: They look sad.
|
||||||
|
angry:
|
||||||
|
backstory: You are feeling angry.
|
||||||
|
description: They look angry.
|
|
@ -0,0 +1,18 @@
|
||||||
|
from adventure.context import get_current_context, get_dungeon_master
|
||||||
|
|
||||||
|
|
||||||
|
def action_sleep() -> str:
|
||||||
|
"""
|
||||||
|
Sleep until you are rested.
|
||||||
|
"""
|
||||||
|
|
||||||
|
_, action_room, action_actor = get_current_context()
|
||||||
|
|
||||||
|
dungeon_master = get_dungeon_master()
|
||||||
|
outcome = dungeon_master(
|
||||||
|
f"{action_actor.name} sleeps in the {action_room.name}. {action_room.description}. {action_actor.description}"
|
||||||
|
"How rested are they? Respond with 'rested' or 'tired'."
|
||||||
|
)
|
||||||
|
|
||||||
|
action_actor.attributes["rested"] = outcome
|
||||||
|
return f"You sleep in the {action_room.name} and wake up feeling {outcome}"
|
|
@ -0,0 +1,23 @@
|
||||||
|
rules:
|
||||||
|
# sleeping logic
|
||||||
|
- match:
|
||||||
|
type: actor
|
||||||
|
sleep: rested
|
||||||
|
chance: 0.2
|
||||||
|
set:
|
||||||
|
sleep: tired
|
||||||
|
|
||||||
|
# sleeping initialization
|
||||||
|
- rule: |
|
||||||
|
"sleep" not in attributes
|
||||||
|
set:
|
||||||
|
sleep: tired
|
||||||
|
|
||||||
|
labels:
|
||||||
|
sleep:
|
||||||
|
rested:
|
||||||
|
backstory: You are well-rested.
|
||||||
|
description: They look well-rested.
|
||||||
|
tired:
|
||||||
|
backstory: You are tired.
|
||||||
|
description: They look tired.
|
Loading…
Reference in New Issue