feat(engine): 实现行动点系统
- 扩展 AgentState 添加 action_points, max_action_points, last_action_tick 字段 - 新增 ActionFeedback 模型用于返回行动执行结果 - 创建 action_points.py 模块实现行动点消耗与恢复逻辑 - 行动消耗表: vote=1, trigger_skill=2, influence=2, comment/support/chaos=0 - 每 tick 恢复 1 点行动点(不超过 max) - 行动点不足时拒绝执行并返回失败反馈 - 新增 7 个测试用例,全部 37 个测试通过 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@ from __future__ import annotations
|
||||
from typing import List, Optional, Tuple
|
||||
from .models import (
|
||||
WorldState, AgentState, Event, Action, Emotion, Weather,
|
||||
GlobalEventResult, GlobalEventInfo, FactionEventResult
|
||||
GlobalEventResult, GlobalEventInfo, FactionEventResult, ActionFeedback
|
||||
)
|
||||
from .global_events import GLOBAL_EVENT_POOL, GlobalEvent
|
||||
from .opinions import generate_opinions
|
||||
@@ -12,6 +12,9 @@ from .factions import (
|
||||
)
|
||||
from .voting import process_votes, apply_votes_to_factions
|
||||
from .faction_skills import check_and_unlock_skills, apply_skill_effects
|
||||
from .action_points import (
|
||||
regenerate_action_points, process_event_with_ap, get_action_cost
|
||||
)
|
||||
|
||||
MAX_EVENTS = 20
|
||||
MAX_MEMORY_PER_AGENT = 3
|
||||
@@ -40,11 +43,16 @@ def update_world_effects(state: WorldState) -> None:
|
||||
state.world_effects = active_effects
|
||||
|
||||
|
||||
def process_events(state: WorldState, events: List[Event]) -> WorldState:
|
||||
"""处理事件并更新世界状态"""
|
||||
def process_events(
|
||||
state: WorldState, events: List[Event]
|
||||
) -> Tuple[WorldState, List[ActionFeedback]]:
|
||||
"""处理事件并更新世界状态,返回行动反馈列表"""
|
||||
# tick 递增
|
||||
state.tick += 1
|
||||
|
||||
# ★ 行动点恢复
|
||||
regenerate_action_points(state)
|
||||
|
||||
# ★ 在 tick 开始时:将上一轮投票累加到阵营能量
|
||||
apply_votes_to_factions(state)
|
||||
|
||||
@@ -58,7 +66,17 @@ def process_events(state: WorldState, events: List[Event]) -> WorldState:
|
||||
# ★ 处理投票事件(记录到 votes,下一 tick 生效)
|
||||
process_votes(state, events)
|
||||
|
||||
# 收集行动反馈
|
||||
action_feedbacks: List[ActionFeedback] = []
|
||||
|
||||
for event in events:
|
||||
# ★ 行动点检查
|
||||
allowed, feedback = process_event_with_ap(state, event)
|
||||
action_feedbacks.append(feedback)
|
||||
|
||||
if not allowed:
|
||||
continue # 行动点不足,跳过此事件
|
||||
|
||||
text = event.text
|
||||
|
||||
# 累计能量
|
||||
@@ -113,7 +131,7 @@ def process_events(state: WorldState, events: List[Event]) -> WorldState:
|
||||
# 应用已解锁技能效果
|
||||
apply_skill_effects(state)
|
||||
|
||||
return state
|
||||
return state, action_feedbacks
|
||||
|
||||
|
||||
def check_and_trigger_global_event(
|
||||
|
||||
Reference in New Issue
Block a user