Implementation:4thfever Cultivation world simulator StoryEventService
| Knowledge Sources | |
|---|---|
| Domains | Narrative_Generation, Event_System |
| Last Updated | 2026-10-22 14:00 GMT |
Overview
Concrete tool for probability-gated story event creation that decides whether to expand factual events into LLM-generated narrative, provided by the Cultivation World Simulator story event system.
Description
The StoryEventService class provides classmethods for the full story event lifecycle:
- is_enabled: checks the global `CONFIG.world.story.enabled` flag
- get_probability: returns the probability for a `StoryEventKind`; GATHERING is always 1.0, AUTONOMOUS_CREATION uses a separate config, others use `CONFIG.world.story.probabilities[kind]`
- should_trigger: rolls `random.random()` against the probability; GATHERING always returns True
- maybe_create_story: the main entry point — checks trigger, filters actors, enriches prompt with goldfinger, calls `StoryTeller.tell_story`, returns an `Event` with `is_story=True`
- maybe_create_gathering_story: specialized for gathering events — always triggers, uses `StoryTeller.tell_gathering_story`
The `StoryEventKind` enum defines 11 event kinds: COMBAT, RELATIONSHIP_MAJOR, CULTIVATION_MAJOR, CRAFTING, AUTONOMOUS_CREATION, DAILY_SOCIAL, SECT_MISSION, WORLD_FORTUNE, WORLD_MISFORTUNE, OPPORTUNITY, GATHERING.
Usage
Import and call these methods when:
- After any factual event: gameplay systems call `maybe_create_story` with the event's kind, text, actors, and related avatar IDs
- Gathering events: call `maybe_create_gathering_story` instead, which always triggers (100%)
- Testing: in test mode, the LLM call inside StoryTeller uses a rule-based fallback
Code Reference
Source Location
- Repository: cultivation-world-simulator
- File: src/classes/story_event_service.py
Signature
class StoryEventKind(StrEnum):
COMBAT = "combat"
RELATIONSHIP_MAJOR = "relationship_major"
CULTIVATION_MAJOR = "cultivation_major"
CRAFTING = "crafting"
AUTONOMOUS_CREATION = "autonomous_creation"
DAILY_SOCIAL = "daily_social"
SECT_MISSION = "sect_mission"
WORLD_FORTUNE = "world_fortune"
WORLD_MISFORTUNE = "world_misfortune"
OPPORTUNITY = "opportunity"
GATHERING = "gathering"
class StoryEventService:
@classmethod
def is_enabled(cls) -> bool: ...
@classmethod
def get_probability(cls, kind: StoryEventKind) -> float: ...
@classmethod
def should_trigger(cls, kind: StoryEventKind) -> bool: ...
@classmethod
async def maybe_create_story(
cls,
*,
kind: StoryEventKind,
month_stamp,
start_text: str,
result_text: str,
actors: list[Avatar | None],
related_avatar_ids: list[str] | None,
prompt: str = "",
allow_relation_changes: bool = False,
) -> Event | None: ...
@classmethod
async def maybe_create_gathering_story(
cls,
*,
month_stamp,
gathering_info: str,
events_text: str,
details_text: str,
related_avatars: list[Avatar],
prompt: str = "",
) -> Event | None: ...
Import
from src.classes.story_event_service import StoryEventService, StoryEventKind
I/O Contract
Inputs (maybe_create_story)
| Name | Type | Required | Description |
|---|---|---|---|
| kind | StoryEventKind | Yes | Event kind for probability lookup |
| month_stamp | MonthStamp | Yes | Current time |
| start_text | str | Yes | Factual event start text |
| result_text | str | Yes | Factual event result text |
| actors | None] | Yes | Participating actors (None filtered) |
| related_avatar_ids | None | Yes | Avatar IDs for the story event |
| prompt | str | No | Additional story prompt (default "") |
| allow_relation_changes | bool | No | Selects dual vs single template (default False) |
Outputs
| Name | Type | Description |
|---|---|---|
| return | None | Story event with is_story=True, or None if not triggered/no actors |
Usage Examples
Create Story for Combat Event
from src.classes.story_event_service import StoryEventService, StoryEventKind
story_event = await StoryEventService.maybe_create_story(
kind=StoryEventKind.COMBAT,
month_stamp=world.month_stamp,
start_text="张三 challenged 李四 to a duel.",
result_text="张三 emerged victorious after a fierce battle.",
actors=[avatar_a, avatar_b],
related_avatar_ids=[avatar_a.id, avatar_b.id],
allow_relation_changes=True,
)
if story_event:
world.event_manager.add_event(story_event)
Create Gathering Story (Always 100%)
gathering_story = await StoryEventService.maybe_create_gathering_story(
month_stamp=world.month_stamp,
gathering_info="The Annual Sword Conference at Heavenly Peak",
events_text="张三 won the sparring tournament. 李四 traded a rare herb.",
details_text="Participants: 5 cultivators from 3 sects.",
related_avatars=[avatar_a, avatar_b, avatar_c],
)