- Add StoryArc and StoryEventResult models - Create story_arcs.py with progress tracking logic - Implement two story arcs: civil_unrest and golden_age - Progress updates based on faction power balance - Trigger story events when progress reaches threshold - Add 3 tests for story arc system 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
from fastapi import FastAPI
|
|
from .models import StepRequest, StepResponse
|
|
from .state import load_state, save_state
|
|
from .engine import process_events, generate_actions, check_and_trigger_global_event
|
|
from .factions import check_and_trigger_faction_event
|
|
from .story_arcs import update_story_progress, check_and_trigger_story_event
|
|
|
|
app = FastAPI(title="AI Town Engine", version="0.1.0")
|
|
|
|
|
|
@app.post("/step", response_model=StepResponse)
|
|
def step(request: StepRequest) -> StepResponse:
|
|
"""执行一个模拟步骤"""
|
|
# 加载当前状态
|
|
state = load_state()
|
|
|
|
# 处理事件并更新状态
|
|
state = process_events(state, request.events)
|
|
|
|
# 检查并触发世界级事件
|
|
state, global_event_result = check_and_trigger_global_event(state)
|
|
|
|
# 检查并触发阵营事件
|
|
faction_event_result = check_and_trigger_faction_event(state)
|
|
|
|
# 更新剧情进度
|
|
update_story_progress(state)
|
|
|
|
# 检查并触发剧情事件
|
|
story_event_result = check_and_trigger_story_event(state)
|
|
|
|
# 生成 agent 行动
|
|
actions = generate_actions(state)
|
|
|
|
# 保存状态
|
|
save_state(state)
|
|
|
|
return StepResponse(
|
|
world_state=state,
|
|
actions=actions,
|
|
global_event=global_event_result,
|
|
triggered_faction_event=faction_event_result,
|
|
story_event=story_event_result
|
|
)
|
|
|
|
|
|
@app.get("/health")
|
|
def health():
|
|
"""健康检查"""
|
|
return {"status": "ok"}
|