Skip to content

Commit

Permalink
normalize yaml extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jun 22, 2024
1 parent 205d692 commit c78de18
Show file tree
Hide file tree
Showing 22 changed files with 113 additions and 75 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,15 @@ TaleWeave AI has in-game actions for:

TaleWeave AI has game systems for:

| Core | Life Sim | RPG | Environment |
| -------- | --------------- | ------ | ----------- |
| Acting | Hunger & Thirst | Health | Humidity |
| Planning | Hygiene | Quests | Temperature |
| Summary | Mood | | Time of day |
| | Sleeping | | Weather |
| Core | Life Sim | RPG | Environment | Generic |
| -------- | --------------- | ------ | ----------- | ------- |
| Acting | Hunger & Thirst | Health | Humidity | Logic |
| Planning | Hygiene | Quests | Temperature | |
| Summary | Mood | | Time of day | |
| | Sleeping | | Weather | |

1. The core summary system provides character with a summary of actions taken by other characters in between turns.
2. The generic systems are driven by data files and can be used to implement new systems without writing any code.

All of the game systems are optional, including the core systems, so you can configure a world where characters only
plan and never act, or vice versa.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
9 changes: 5 additions & 4 deletions taleweave/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ def shutdown_threads():
logger.info(f"loading extra actions from {action_name}")
action_group, module_actions = load_plugin(action_name)
logger.info(
f"loaded extra actions to group '{action_group}': {[action.__name__ for action in module_actions]}"
f"added actions to group '{action_group}': {[action.__name__ for action in module_actions]}"
)

# set up the game systems
Expand All @@ -274,17 +274,18 @@ def shutdown_threads():

# load extra systems from plugins
for system_name in args.systems or []:
logger.info(f"loading extra systems from {system_name}")
logger.info(f"loading systems from {system_name}")
module_systems = load_plugin(system_name)
logger.info(f"loaded extra systems: {module_systems}")
logger.info(f"loaded game systems: {module_systems}")
systems.extend(module_systems)

# make sure the server system runs after any updates
if args.server:
from taleweave.server.websocket import server_system

systems.append(GameSystem(name="server", simulate=server_system))
systems.append(GameSystem(name="websocket_server", simulate=server_system))

logger.info(f"running with {len(systems)} game systems: {systems}")
set_game_systems(systems)

# load or generate the world
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
rules:
# wet/dry logic
- group: environment-moisture
- group: environment.moisture
match:
type: character
wet: true
chance: 0.1
set:
wet: false

- group: environment-moisture
- group: environment.moisture
match:
type: character
wet: true
Expand All @@ -17,20 +17,6 @@ rules:
set:
wet: false

- group: environment-temperature
match:
type: room
temperature: hot
chance: 0.2
trigger: [taleweave.systems.sim.environment_triggers:hot_room]

- group: environment-temperature
match:
type: room
temperature: cold
chance: 0.2
trigger: [taleweave.systems.sim.environment_triggers:cold_room]

labels:
- match:
type: character
Expand Down
26 changes: 4 additions & 22 deletions taleweave/systems/environment/temperature/logic.yaml
Original file line number Diff line number Diff line change
@@ -1,35 +1,17 @@
rules:
# wet/dry logic
- group: environment-moisture
match:
type: character
wet: true
chance: 0.1
set:
wet: false

- group: environment-moisture
match:
type: character
wet: true
temperature: hot
chance: 0.2
set:
wet: false

- group: environment-temperature
- group: environment.temperature
match:
type: room
temperature: hot
chance: 0.2
trigger: [taleweave.systems.sim.environment_triggers:hot_room]
trigger: [taleweave.systems.environment.temperature.triggers:hot_room]

- group: environment-temperature
- group: environment.temperature
match:
type: room
temperature: cold
chance: 0.2
trigger: [taleweave.systems.sim.environment_triggers:cold_room]
trigger: [taleweave.systems.environment.temperature.triggers:cold_room]

labels:
- match:
Expand Down
10 changes: 5 additions & 5 deletions taleweave/systems/environment/weather/logic.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
rules:
# weather logic
- group: weather
- group: environment.weather
match:
type: room
environment: outdoor
Expand All @@ -9,7 +9,7 @@ rules:
set:
weather: clouds

- group: weather
- group: environment.weather
match:
type: room
environment: outdoor
Expand All @@ -18,7 +18,7 @@ rules:
set:
weather: rain

- group: weather
- group: environment.weather
match:
type: room
environment: outdoor
Expand All @@ -27,7 +27,7 @@ rules:
set:
weather: clear

- group: weather
- group: environment.weather
match:
type: room
environment: outdoor
Expand All @@ -37,7 +37,7 @@ rules:
weather: clear

# weather initial state
- group: weather
- group: environment.weather
match:
type: room
environment: outdoor
Expand Down
2 changes: 1 addition & 1 deletion taleweave/systems/generic/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def load_logic(filename: str, name_prefix: str = "logic") -> GameSystem:
)
logic_triggers[trigger] = get_plugin_function(function_name)

logger.info("initialized logic system")
logger.info("initialized logic system with %d rules", len(logic_rules.rules))
system_format = wraps(format_logic)(partial(format_logic, rules=logic_rules))
system_initialize = wraps(update_logic)(
partial(update_logic, turn=0, rules=logic_rules, triggers=logic_triggers)
Expand Down
2 changes: 2 additions & 0 deletions taleweave/systems/rpg/crafting/logic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rules: []
labels: []
Empty file.
33 changes: 33 additions & 0 deletions taleweave/systems/rpg/health/logic.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
rules:
- group: rpg.health
match:
type: character
rule: |
"health" in attributes and attributes&.health <= 0
set:
active: false
dead: true

- group: rpg.health
match:
type: character
rule: |
"bleeding" in attributes and attributes&.bleeding > 0
chance: 0.5
trigger: [taleweave.systems.rpg.health.triggers:character_bleeding]

labels:
- match:
type: character
dead: true
backstory: You are dead.
description: They are dead.
- match:
type: character
bleeding: true
backstory: You are bleeding.
description: They are bleeding.
- match:
type: room
bloody: true
description: The room is covered in blood.
Empty file.
33 changes: 33 additions & 0 deletions taleweave/systems/rpg/health/triggers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from logging import getLogger
from random import randint

from taleweave.context import get_current_world
from taleweave.models.entity import Character, WorldEntity
from taleweave.utils.attribute import subtract_attribute
from taleweave.utils.search import find_containing_room

logger = getLogger(__name__)


def character_bleeding(entity: WorldEntity) -> None:
world = get_current_world()
if not world:
raise ValueError("no world found")

if not isinstance(entity, Character):
raise ValueError("bleeding entity must be a character")

# remove bleeding from health, then reduce bleeding
amount = int(entity.attributes.get("bleeding", 0))
subtract_attribute(entity.attributes, "health", amount)

if amount > 0 and randint(0, 1):
subtract_attribute(entity.attributes, "bleeding", 1)

# leave blood in the room
room = find_containing_room(world, entity)
if room:
room.attributes["bloody"] = True
logger.info(f"{entity.name} bleeds in {room.name}")
else:
logger.warning(f"{entity.name} not found in any room")
2 changes: 1 addition & 1 deletion taleweave/systems/sim/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from taleweave.systems.generic.logic import load_logic

from .hunger.actions import action_cook, action_eat
from .hygiene.hygiene_actions import action_wash
from .hygiene.actions import action_wash
from .sleeping.actions import action_sleep


Expand Down
12 changes: 6 additions & 6 deletions taleweave/systems/sim/hunger/logic.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
rules:
# cooking logic
- group: cooking
- group: sim.cooking
match:
type: item
edible: true
Expand All @@ -9,7 +9,7 @@ rules:
set:
spoiled: true

- group: cooking
- group: sim.cooking
match:
type: item
edible: true
Expand All @@ -19,7 +19,7 @@ rules:
spoiled: true

# hunger logic
- group: hunger
- group: sim.hunger
match:
type: character
hunger: full
Expand All @@ -28,14 +28,14 @@ rules:
hunger: hungry

# hunger initialization
- group: hunger
- group: sim.hunger
rule: |
"hunger" not in attributes
set:
hunger: full

# thirst logic
- group: thirst
- group: sim.thirst
match:
type: character
thirst: hydrated
Expand All @@ -44,7 +44,7 @@ rules:
thirst: thirsty

# thirst initialization
- group: thirst
- group: sim.thirst
rule: |
"thirst" not in attributes
set:
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit c78de18

Please sign in to comment.