From d7dbe8a0dae6dac1246020266863b2c5c39ac8f5 Mon Sep 17 00:00:00 2001 From: bridge Date: Sat, 22 Nov 2025 17:14:36 +0800 Subject: [PATCH] fix bug --- src/classes/long_term_objective.py | 16 ++++++------- static/templates/long_term_objective.txt | 2 +- static/templates/nickname.txt | 2 +- web/src/stores/world.ts | 29 ++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/classes/long_term_objective.py b/src/classes/long_term_objective.py index a3c44f4..fefd64f 100644 --- a/src/classes/long_term_objective.py +++ b/src/classes/long_term_objective.py @@ -1,6 +1,6 @@ """ 长期目标模块 -为角色生成和管理长期目标(3-5年) +为角色生成和管理长期目标(3-10年) """ from __future__ import annotations from dataclasses import dataclass @@ -35,8 +35,8 @@ def can_generate_long_term_objective(avatar: "Avatar") -> bool: 1. 已有用户设定的目标,永不自动生成 2. 无目标时,可以生成 3. 距离上次设定 <3年,不生成 - 4. 距离上次设定 ≥5年,必定生成 - 5. 距离上次设定 3-5年,按概率生成(渐进概率) + 4. 距离上次设定 ≥10年,必定生成 + 5. 距离上次设定 3-10年,按概率生成(渐进概率) Args: avatar: 要检查的角色 @@ -58,11 +58,11 @@ def can_generate_long_term_objective(avatar: "Avatar") -> bool: if years_passed < 3: return False - elif years_passed >= 5: + elif years_passed >= 10: return True - else: # 3-5年之间 - # 渐进概率:3年时10%,4年时50%,接近5年时接近100% - probability = (years_passed - 3) / 2 * 0.9 + 0.1 + else: # 3-10年之间 + # 渐进概率:3年时10%,随时间推移逐渐增加,接近10年时接近100% + probability = (years_passed - 3) / 7 * 0.9 + 0.1 return random.random() < probability @@ -93,7 +93,7 @@ async def generate_long_term_objective(avatar: "Avatar") -> Optional[LongTermObj } # 调用LLM并自动解析JSON(使用fast模型) - response_data = await call_llm_with_template(template_path, infos, LLMMode.FAST) + response_data = await call_llm_with_template(template_path, infos, LLMMode.NORMAL) content = response_data.get("long_term_objective", "").strip() diff --git a/static/templates/long_term_objective.txt b/static/templates/long_term_objective.txt index 6f854a5..04a6cc2 100644 --- a/static/templates/long_term_objective.txt +++ b/static/templates/long_term_objective.txt @@ -13,7 +13,7 @@ 返回JSON格式: {{ - "thinking": "思考。", + "thinking": "思考角色会有怎么样的长期目标,但也不用过度思考。", "long_term_objective": "目标内容,简洁清晰明快,15字以内。" }} diff --git a/static/templates/nickname.txt b/static/templates/nickname.txt index ff55598..9c50eba 100644 --- a/static/templates/nickname.txt +++ b/static/templates/nickname.txt @@ -13,7 +13,7 @@ 返回JSON格式: {{ - "thinking": "分析角色特点、主要事迹、性格特质,思考什么绰号最能体现这个人物...", + "thinking": "分析角色特点、主要事迹、性格特质,思考什么绰号最能体现这个人物...但也不用过度思考", "nickname": "绰号" }} diff --git a/web/src/stores/world.ts b/web/src/stores/world.ts index f77454c..c1baa22 100644 --- a/web/src/stores/world.ts +++ b/web/src/stores/world.ts @@ -81,6 +81,35 @@ export const useWorldStore = defineStore('world', () => { if (!isLoaded.value) return; setTime(payload.year, payload.month); + + // 检查并处理死亡事件,移除已死亡的角色 + if (payload.events && Array.isArray(payload.events)) { + const deathEvents = payload.events.filter((e: any) => { + const c = e.content || ''; + return c.includes('身亡') || c.includes('老死'); + }); + + if (deathEvents.length > 0) { + const next = new Map(avatars.value); + let changed = false; + + for (const de of deathEvents) { + if (de.related_avatar_ids && Array.isArray(de.related_avatar_ids)) { + for (const id of de.related_avatar_ids) { + if (next.has(id)) { + next.delete(id); + changed = true; + } + } + } + } + + if (changed) { + avatars.value = next; + } + } + } + if (payload.avatars) updateAvatars(payload.avatars); if (payload.events) addEvents(payload.events); }