diff --git a/1.6/1.6/Assemblies/WulaFallenEmpire.dll b/1.6/1.6/Assemblies/WulaFallenEmpire.dll index b9f51d97..84c43473 100644 Binary files a/1.6/1.6/Assemblies/WulaFallenEmpire.dll and b/1.6/1.6/Assemblies/WulaFallenEmpire.dll differ diff --git a/1.6/1.6/Assemblies/WulaFallenEmpire.pdb b/1.6/1.6/Assemblies/WulaFallenEmpire.pdb index 648c6311..876b9c90 100644 Binary files a/1.6/1.6/Assemblies/WulaFallenEmpire.pdb and b/1.6/1.6/Assemblies/WulaFallenEmpire.pdb differ diff --git a/Source/WulaFallenEmpire/EventSystem/AI/AIAutoCommentary.cs b/Source/WulaFallenEmpire/EventSystem/AI/AIAutoCommentary.cs index 2528f1e2..50a7edda 100644 --- a/Source/WulaFallenEmpire/EventSystem/AI/AIAutoCommentary.cs +++ b/Source/WulaFallenEmpire/EventSystem/AI/AIAutoCommentary.cs @@ -17,32 +17,54 @@ namespace WulaFallenEmpire.EventSystem.AI public static void ProcessLetter(Letter letter) { - if (letter == null) return; + if (letter == null) + { + WulaLog.Debug("[AI Commentary] Letter is null, skipping."); + return; + } + + WulaLog.Debug($"[AI Commentary] Received letter: {letter.Label.Resolve()}"); // 检查设置 var settings = WulaFallenEmpireMod.settings; - if (settings == null || !settings.enableAIAutoCommentary) return; + if (settings == null) + { + WulaLog.Debug("[AI Commentary] Settings is null, skipping."); + return; + } + + if (!settings.enableAIAutoCommentary) + { + WulaLog.Debug("[AI Commentary] Auto commentary is disabled in settings, skipping."); + return; + } // 简单的冷却检查,避免刷屏 int currentTick = Find.TickManager?.TicksGame ?? 0; - if (currentTick - lastProcessedTick < MinTicksBetweenComments) return; + if (currentTick - lastProcessedTick < MinTicksBetweenComments) + { + WulaLog.Debug($"[AI Commentary] Cooldown active ({currentTick - lastProcessedTick} < {MinTicksBetweenComments}), skipping."); + return; + } lastProcessedTick = currentTick; // 获取 AI 核心 var aiCore = Find.World?.GetComponent(); if (aiCore == null) { - WulaLog.Debug("[AI Commentary] AIIntelligenceCore not found."); + WulaLog.Debug("[AI Commentary] AIIntelligenceCore not found on World."); return; } // 构建提示词 - 让 AI 自己决定是否需要回复 string prompt = BuildPrompt(letter); + WulaLog.Debug($"[AI Commentary] Sending to AI: {letter.Label.Resolve()}"); + // 直接发送到正常的 AI 对话流程(会经过完整的思考流程) aiCore.SendAutoCommentaryMessage(prompt); - WulaLog.Debug($"[AI Commentary] Sent letter to AI: {letter.Label.Resolve()}"); + WulaLog.Debug($"[AI Commentary] Successfully sent letter to AI: {letter.Label.Resolve()}"); } private static string BuildPrompt(Letter letter) @@ -53,16 +75,28 @@ namespace WulaFallenEmpire.EventSystem.AI string label = letter.Label.Resolve() ?? "Unknown"; string defName = letter.def?.defName ?? "Unknown"; - sb.AppendLine("[游戏事件通知]"); + // 获取事件描述(ChoiceLetter 才有 Text 属性) + string description = ""; + if (letter is ChoiceLetter choiceLetter) + { + description = choiceLetter.Text.Resolve() ?? ""; + } + + sb.AppendLine("[游戏事件通知 - 自动评论请求]"); sb.AppendLine($"事件标题: {label}"); sb.AppendLine($"事件类型: {defName}"); + if (!string.IsNullOrEmpty(description)) + { + sb.AppendLine($"事件描述: {description}"); + } sb.AppendLine(); sb.AppendLine("请根据这个事件决定是否需要向玩家发表简短评论。"); sb.AppendLine("- 如果是重要事件(如袭击、死亡),可以提供建议或警告"); sb.AppendLine("- 如果是有趣的事件,可以发表幽默评论"); - sb.AppendLine("- 如果事件不重要或不值得评论,什么都不说即可"); + sb.AppendLine("- 如果事件不重要或不值得评论,回复 [NO_COMMENT] 即可跳过"); sb.AppendLine(); sb.AppendLine("评论要简短(1-2句话),符合你作为帝国AI的人设。"); + sb.AppendLine("如果你决定不评论,只需回复: [NO_COMMENT]"); return sb.ToString(); } diff --git a/Source/WulaFallenEmpire/EventSystem/AI/AIIntelligenceCore.cs b/Source/WulaFallenEmpire/EventSystem/AI/AIIntelligenceCore.cs index 9ff4f0ab..d284bf6d 100644 --- a/Source/WulaFallenEmpire/EventSystem/AI/AIIntelligenceCore.cs +++ b/Source/WulaFallenEmpire/EventSystem/AI/AIIntelligenceCore.cs @@ -886,6 +886,14 @@ You are 'The Legion', a super AI of the Wula Empire. Your personality is authori return; } + // Check for NO_COMMENT marker (AI decided not to comment on auto-commentary events) + if (cleanedResponse.Contains("[NO_COMMENT]") || + cleanedResponse.Trim().Equals("[NO_COMMENT]", StringComparison.OrdinalIgnoreCase)) + { + WulaLog.Debug("[WulaAI] AI chose not to comment ([NO_COMMENT] received). Skipping message."); + return; + } + bool added = false; if (_history.Count == 0 || !string.Equals(_history[_history.Count - 1].role, "assistant", StringComparison.OrdinalIgnoreCase)) { diff --git a/Source/WulaFallenEmpire/EventSystem/AI/LetterInterceptor/Patch_LetterStack.cs b/Source/WulaFallenEmpire/EventSystem/AI/LetterInterceptor/Patch_LetterStack.cs index 622acd4f..e560cb1b 100644 --- a/Source/WulaFallenEmpire/EventSystem/AI/LetterInterceptor/Patch_LetterStack.cs +++ b/Source/WulaFallenEmpire/EventSystem/AI/LetterInterceptor/Patch_LetterStack.cs @@ -6,11 +6,15 @@ using WulaFallenEmpire.EventSystem.AI; namespace WulaFallenEmpire.EventSystem.AI.LetterInterceptor { - [HarmonyPatch(typeof(LetterStack), nameof(LetterStack.ReceiveLetter), new Type[] { typeof(Letter), typeof(string) })] + [HarmonyPatch(typeof(LetterStack), nameof(LetterStack.ReceiveLetter), + new Type[] { typeof(Letter), typeof(string), typeof(int), typeof(bool) })] public static class Patch_LetterStack_ReceiveLetter { - public static void Postfix(Letter let, string debugInfo) + public static void Postfix(Letter let, string debugInfo, int delayTicks, bool playSound) { + // Only process if not delayed (delayTicks == 0 or already arrived) + if (delayTicks > 0) return; + var settings = WulaFallenEmpireMod.settings; if (settings == null || !settings.enableAIAutoCommentary) { diff --git a/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs b/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs index 45dca809..7ce60d28 100644 --- a/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs +++ b/Source/WulaFallenEmpire/EventSystem/AI/UI/Dialog_AIConversation.cs @@ -322,6 +322,8 @@ namespace WulaFallenEmpire.EventSystem.AI.UI string messageText = entry.role == "assistant" ? ParseResponseForDisplay(entry.message) : AIIntelligenceCore.StripContextInfo(entry.message); if (entry.role == "tool" || entry.role == "system" || entry.role == "toolcall") continue; + // Hide auto-commentary system messages (user-side) from display + if (entry.role == "user" && entry.message.Contains("[AUTO_COMMENTARY]")) continue; if (string.IsNullOrEmpty(messageText) || (entry.role == "user" && messageText.StartsWith("[Tool Results]"))) continue; bool isLastMessage = i == history.Count - 1; diff --git a/Source/WulaFallenEmpire/EventSystem/AI/UI/Overlay_WulaLink.cs b/Source/WulaFallenEmpire/EventSystem/AI/UI/Overlay_WulaLink.cs index 176ae700..10bf970b 100644 --- a/Source/WulaFallenEmpire/EventSystem/AI/UI/Overlay_WulaLink.cs +++ b/Source/WulaFallenEmpire/EventSystem/AI/UI/Overlay_WulaLink.cs @@ -380,6 +380,9 @@ namespace WulaFallenEmpire.EventSystem.AI.UI if (msg.role == "tool" || msg.role == "toolcall") continue; if (msg.role == "system" && !Prefs.DevMode) continue; + // Hide auto-commentary system messages (user-side) from display + if (msg.role == "user" && msg.message.Contains("[AUTO_COMMENTARY]")) continue; + string displayText = msg.message; if (msg.role == "assistant") { diff --git a/Source/WulaFallenEmpire/EventSystem/AI/UI/Overlay_WulaLink_Notification.cs b/Source/WulaFallenEmpire/EventSystem/AI/UI/Overlay_WulaLink_Notification.cs index 5581f122..af96ab5c 100644 --- a/Source/WulaFallenEmpire/EventSystem/AI/UI/Overlay_WulaLink_Notification.cs +++ b/Source/WulaFallenEmpire/EventSystem/AI/UI/Overlay_WulaLink_Notification.cs @@ -10,7 +10,7 @@ namespace WulaFallenEmpire.EventSystem.AI.UI { private string _message; private int _tickCreated; - private const int DisplayTicks = 180; // 3 seconds + private const int DisplayTicks = 600; // 10 seconds private Vector2 _size = new Vector2(320f, 65f); public override Vector2 InitialSize => _size;