diff --git a/README.md b/README.md index c9f6064..e98f171 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/config.yml b/config.yaml similarity index 100% rename from config.yml rename to config.yaml diff --git a/prompts/discord-en-us.yml b/prompts/discord-en-us.yaml similarity index 100% rename from prompts/discord-en-us.yml rename to prompts/discord-en-us.yaml diff --git a/prompts/llama-base.yml b/prompts/llama-base.yaml similarity index 100% rename from prompts/llama-base.yml rename to prompts/llama-base.yaml diff --git a/prompts/llama-digest.yml b/prompts/llama-digest.yaml similarity index 100% rename from prompts/llama-digest.yml rename to prompts/llama-digest.yaml diff --git a/prompts/llama-quest.yml b/prompts/llama-quest.yaml similarity index 100% rename from prompts/llama-quest.yml rename to prompts/llama-quest.yaml diff --git a/taleweave/main.py b/taleweave/main.py index bfeb6aa..69e4f5f 100644 --- a/taleweave/main.py +++ b/taleweave/main.py @@ -264,7 +264,7 @@ def main(): 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 @@ -274,17 +274,18 @@ def main(): # 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 diff --git a/taleweave/systems/environment/humidity/logic.yaml b/taleweave/systems/environment/humidity/logic.yaml deleted file mode 100644 index d9cd032..0000000 --- a/taleweave/systems/environment/humidity/logic.yaml +++ /dev/null @@ -1,40 +0,0 @@ -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 - 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 - wet: true - backstory: You are soaking wet. - description: They are soaking wet and dripping water. - # false intentionally omitted \ No newline at end of file diff --git a/taleweave/systems/environment/moisture/logic.yaml b/taleweave/systems/environment/moisture/logic.yaml new file mode 100644 index 0000000..34d9c7e --- /dev/null +++ b/taleweave/systems/environment/moisture/logic.yaml @@ -0,0 +1,26 @@ +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 + +labels: + - match: + type: character + wet: true + backstory: You are soaking wet. + description: They are soaking wet and dripping water. + # false intentionally omitted \ No newline at end of file diff --git a/taleweave/systems/environment/temperature/logic.yaml b/taleweave/systems/environment/temperature/logic.yaml index d9cd032..340219d 100644 --- a/taleweave/systems/environment/temperature/logic.yaml +++ b/taleweave/systems/environment/temperature/logic.yaml @@ -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: diff --git a/taleweave/systems/environment/weather/logic.yaml b/taleweave/systems/environment/weather/logic.yaml index 1aa0cd5..6d27362 100644 --- a/taleweave/systems/environment/weather/logic.yaml +++ b/taleweave/systems/environment/weather/logic.yaml @@ -1,6 +1,6 @@ rules: # weather logic - - group: weather + - group: environment.weather match: type: room environment: outdoor @@ -9,7 +9,7 @@ rules: set: weather: clouds - - group: weather + - group: environment.weather match: type: room environment: outdoor @@ -18,7 +18,7 @@ rules: set: weather: rain - - group: weather + - group: environment.weather match: type: room environment: outdoor @@ -27,7 +27,7 @@ rules: set: weather: clear - - group: weather + - group: environment.weather match: type: room environment: outdoor @@ -37,7 +37,7 @@ rules: weather: clear # weather initial state - - group: weather + - group: environment.weather match: type: room environment: outdoor diff --git a/taleweave/systems/generic/logic.py b/taleweave/systems/generic/logic.py index 4e3ae0f..142d868 100644 --- a/taleweave/systems/generic/logic.py +++ b/taleweave/systems/generic/logic.py @@ -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) diff --git a/taleweave/systems/rpg/crafting/logic.yaml b/taleweave/systems/rpg/crafting/logic.yaml new file mode 100644 index 0000000..e0e1924 --- /dev/null +++ b/taleweave/systems/rpg/crafting/logic.yaml @@ -0,0 +1,2 @@ +rules: [] +labels: [] \ No newline at end of file diff --git a/taleweave/systems/rpg/crafting/logic.yml b/taleweave/systems/rpg/crafting/logic.yml deleted file mode 100644 index e69de29..0000000 diff --git a/taleweave/systems/rpg/health/logic.yaml b/taleweave/systems/rpg/health/logic.yaml new file mode 100644 index 0000000..17fd2b2 --- /dev/null +++ b/taleweave/systems/rpg/health/logic.yaml @@ -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. \ No newline at end of file diff --git a/taleweave/systems/rpg/health/logic.yml b/taleweave/systems/rpg/health/logic.yml deleted file mode 100644 index e69de29..0000000 diff --git a/taleweave/systems/rpg/health/triggers.py b/taleweave/systems/rpg/health/triggers.py index e69de29..0d9841f 100644 --- a/taleweave/systems/rpg/health/triggers.py +++ b/taleweave/systems/rpg/health/triggers.py @@ -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") diff --git a/taleweave/systems/sim/__init__.py b/taleweave/systems/sim/__init__.py index 85a6469..2260bb7 100644 --- a/taleweave/systems/sim/__init__.py +++ b/taleweave/systems/sim/__init__.py @@ -3,7 +3,7 @@ from os import path 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 diff --git a/taleweave/systems/sim/hunger/logic.yaml b/taleweave/systems/sim/hunger/logic.yaml index e9bbabe..5c0d507 100644 --- a/taleweave/systems/sim/hunger/logic.yaml +++ b/taleweave/systems/sim/hunger/logic.yaml @@ -1,6 +1,6 @@ rules: # cooking logic - - group: cooking + - group: sim.cooking match: type: item edible: true @@ -9,7 +9,7 @@ rules: set: spoiled: true - - group: cooking + - group: sim.cooking match: type: item edible: true @@ -19,7 +19,7 @@ rules: spoiled: true # hunger logic - - group: hunger + - group: sim.hunger match: type: character hunger: full @@ -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 @@ -44,7 +44,7 @@ rules: thirst: thirsty # thirst initialization - - group: thirst + - group: sim.thirst rule: | "thirst" not in attributes set: diff --git a/taleweave/systems/sim/hygiene/hygiene_actions.py b/taleweave/systems/sim/hygiene/actions.py similarity index 100% rename from taleweave/systems/sim/hygiene/hygiene_actions.py rename to taleweave/systems/sim/hygiene/actions.py diff --git a/taleweave/systems/sim/hygiene/hygiene_logic.yaml b/taleweave/systems/sim/hygiene/logic.yaml similarity index 100% rename from taleweave/systems/sim/hygiene/hygiene_logic.yaml rename to taleweave/systems/sim/hygiene/logic.yaml diff --git a/taleweave/systems/sim/mood/logic.yaml b/taleweave/systems/sim/mood/logic.yaml index da9633b..31eece5 100644 --- a/taleweave/systems/sim/mood/logic.yaml +++ b/taleweave/systems/sim/mood/logic.yaml @@ -1,6 +1,6 @@ rules: # mood logic - - group: mood + - group: sim.mood match: type: character mood: happy @@ -8,7 +8,7 @@ rules: set: mood: sad - - group: mood + - group: sim.mood match: type: character mood: happy @@ -16,7 +16,7 @@ rules: set: mood: neutral - - group: mood + - group: sim.mood match: type: character mood: angry @@ -24,7 +24,7 @@ rules: set: mood: neutral - - group: mood + - group: sim.mood match: type: character mood: neutral @@ -32,7 +32,7 @@ rules: set: mood: happy - - group: mood + - group: sim.mood match: type: character mood: neutral @@ -40,7 +40,7 @@ rules: set: mood: sad - - group: mood + - group: sim.mood match: type: character mood: sad @@ -48,7 +48,7 @@ rules: set: mood: angry - - group: mood + - group: sim.mood match: type: character mood: sad @@ -57,7 +57,7 @@ rules: mood: neutral # mood interactions with other systems - - group: mood + - group: sim.mood match: type: character mood: sad @@ -66,7 +66,7 @@ rules: set: sleep: tired - - group: mood + - group: sim.mood match: type: character hunger: hungry @@ -74,7 +74,7 @@ rules: set: mood: angry - - group: mood + - group: sim.mood match: type: character mood: angry @@ -83,7 +83,7 @@ rules: set: mood: neutral - - group: mood + - group: sim.mood match: type: character mood: neutral @@ -92,7 +92,7 @@ rules: set: mood: happy - - group: mood + - group: sim.mood match: type: character mood: happy @@ -101,7 +101,7 @@ rules: set: mood: neutral - - group: mood + - group: sim.mood match: type: character mood: neutral @@ -111,7 +111,7 @@ rules: mood: sad # mood initialization - - group: mood + - group: sim.mood rule: | "mood" not in attributes set: diff --git a/worlds.yml b/worlds.yaml similarity index 100% rename from worlds.yml rename to worlds.yaml