From 28976d967243162279d13d06c790c278c333f6ff Mon Sep 17 00:00:00 2001 From: empty Date: Tue, 30 Dec 2025 12:10:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(engine):=20=E5=AE=9E=E7=8E=B0=E9=98=B5?= =?UTF-8?q?=E8=90=A5=E5=8D=9A=E5=BC=88=E6=9C=BA=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - FactionData 新增 threshold 和 skill 字段 - 修改能量累积逻辑:power 跨 tick 累积 - 阈值改为 10,达到后触发阵营技能 - festival 提升情绪,panic 降低情绪 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- engine-python/app/factions.py | 30 ++++++++++++++++-------------- engine-python/app/models.py | 2 ++ engine-python/app/state.py | 4 ++-- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/engine-python/app/factions.py b/engine-python/app/factions.py index e64e95a..877820b 100644 --- a/engine-python/app/factions.py +++ b/engine-python/app/factions.py @@ -10,7 +10,7 @@ OPTIMIST_THRESHOLD = 0.6 FEARFUL_THRESHOLD = 0.6 # 阵营技能触发阈值 -FACTION_POWER_THRESHOLD = 5 +FACTION_POWER_THRESHOLD = 10 # 阵营事件对情绪的影响 FACTION_EVENT_EFFECTS = { @@ -39,17 +39,18 @@ def update_factions(state: WorldState) -> None: """统计各派系并更新 world_state 流程: - 1. 清空 factions.members + 1. 清空 factions.members(但保留 power) 2. 遍历所有 agents,根据 emotion 分类 3. 更新 agent.faction 字段 4. 将 agent 加入对应 faction.members - 5. 每个 agent 为 faction 增加 power += 1 + 5. 每个 agent 为 faction 增加 power += 1(累积) """ - # 重置 factions - state.factions = Factions( - optimists=FactionData(power=0, members=[]), - fearful=FactionData(power=0, members=[]) - ) + # 保留现有 power,只清空 members + current_optimist_power = state.factions.optimists.power + current_fearful_power = state.factions.fearful.power + + state.factions.optimists.members = [] + state.factions.fearful.members = [] for agent_id, agent in state.agents.items(): faction = classify_faction(agent) @@ -57,11 +58,12 @@ def update_factions(state: WorldState) -> None: if faction == "optimists": state.factions.optimists.members.append(agent_id) - state.factions.optimists.power += 1 + state.factions.optimists.power = current_optimist_power + 1 + current_optimist_power = state.factions.optimists.power elif faction == "fearful": state.factions.fearful.members.append(agent_id) - state.factions.fearful.power += 1 - # neutral 不加入任何派系 + state.factions.fearful.power = current_fearful_power + 1 + current_fearful_power = state.factions.fearful.power def apply_faction_influence(state: WorldState) -> None: @@ -79,7 +81,7 @@ def check_and_trigger_faction_event(state: WorldState) -> FactionEventResult: """检查并触发阵营事件 规则: - - 当 faction.power >= 5 时,触发对应世界事件 + - 当 faction.power >= faction.threshold 时,触发对应技能 - optimists → festival(提升情绪) - fearful → panic(降低情绪) - 触发后该 faction.power 归零 @@ -87,13 +89,13 @@ def check_and_trigger_faction_event(state: WorldState) -> FactionEventResult: result = FactionEventResult(type=None, source_faction=None) # 检查乐观派 - if state.factions.optimists.power >= FACTION_POWER_THRESHOLD: + if state.factions.optimists.power >= state.factions.optimists.threshold: result = FactionEventResult(type="festival", source_faction="optimists") _apply_faction_event(state, "festival") state.factions.optimists.power = 0 # 检查恐惧派 - elif state.factions.fearful.power >= FACTION_POWER_THRESHOLD: + elif state.factions.fearful.power >= state.factions.fearful.threshold: result = FactionEventResult(type="panic", source_faction="fearful") _apply_faction_event(state, "panic") state.factions.fearful.power = 0 diff --git a/engine-python/app/models.py b/engine-python/app/models.py index 462ebc7..9db8d3b 100644 --- a/engine-python/app/models.py +++ b/engine-python/app/models.py @@ -47,6 +47,8 @@ class Stance(BaseModel): class FactionData(BaseModel): """单个派系的数据""" power: int = 0 + threshold: int = 10 + skill: str = "" members: List[str] = Field(default_factory=list) diff --git a/engine-python/app/state.py b/engine-python/app/state.py index 35ce3cb..4861be6 100644 --- a/engine-python/app/state.py +++ b/engine-python/app/state.py @@ -31,8 +31,8 @@ def get_default_state() -> WorldState: events=[], global_meter=GlobalMeter(value=0, threshold=100, cooldown=0), factions=Factions( - optimists=FactionData(power=0, members=[]), - fearful=FactionData(power=0, members=[]) + optimists=FactionData(power=0, threshold=10, skill="festival", members=[]), + fearful=FactionData(power=0, threshold=10, skill="panic", members=[]) ), story_arcs=get_default_story_arcs(), )