From 82e3a355128889dbfe8b263ef7a321603f91ef8e Mon Sep 17 00:00:00 2001 From: mcocdaa <2021137961@qq.com> Date: Sat, 7 Nov 2026 09:06:11 +0100 Subject: [PATCH 1/2] feat(release): prepare v2.0.0-rc.1 with Steam feedback fixes and BBCode About.xml feat(personality): add mute option and toggle for shaping vote popups Add a "Mute" option to the new-trait shaping vote popup that disables future popups, plus a checkbox in the personality profile dialog to re-enable them. This gives players a way to opt out of repeated vote prompts without losing the feature entirely. Also expand the About.xml description with full mod documentation and exclude dev config files from the release archive. --- .github/workflows/release.yml | 3 + About/About.xml | 66 ++++++++++++++++++- .../Keyed/RimMind_Personality.xml | 4 ++ .../English/Keyed/RimMind_Personality.xml | 4 ++ .../Personality/PersonalityThoughtMapper.cs | 19 +++++- Source/UI/Dialog_PersonalityProfile.cs | 22 ++++++- 6 files changed, 114 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1344fee..f941b16 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -171,6 +171,9 @@ jobs: --exclude='docs/' \ --exclude='*.csproj' \ --exclude='*.sln' \ + --exclude='.coderabbit.yaml' \ + --exclude='.pre-commit-config.yaml' \ + --exclude='INTRODUCTION.txt' \ --exclude='.gitignore' \ --exclude='.gitattributes' \ --exclude='*.md' \ diff --git a/About/About.xml b/About/About.xml index 8d9ca40..3b2b83a 100644 --- a/About/About.xml +++ b/About/About.xml @@ -8,7 +8,71 @@
  • 1.6
  • 1.7
  • - AI-driven personality system for colonists. Each day, an LLM evaluates colonist state and injects personality Thoughts that influence mood and behavior. [v2.0 BREAKING CHANGES] + [h1]RimMind - Personality (v2.0)[/h1] +Big-Five psychological profiling and probabilistic state-transition reflection system for RimWorld colonists. Endows every colonist with a persistent inner world, generating dynamic personality Thoughts and introspective soliloquies that influence mood, behavior, and advisor decisions. + +[b]v2.0 Clean Architecture & RimWorld 1.6 / 1.7 Dual-Version Support:[/b] +[list] +[*][b]RimWorld 1.6 & 1.7 (Waylith / .NET 10) Ready[/b]: Native multi-target compilation supporting both RimWorld 1.6 (.NET Framework 4.8) and RimWorld 1.7 (.NET 10 / Harmony 2.x & 3.x). +[*][b]v2.0 Big-Five Psychometric & Probabilistic State Engine[/b]: Replaces rigid timers with organic environmental triggers (06:00 Dawn Sunrise, Skygazing, Shared Recreation, Traumatic Mood Swings). Note: v1.x saves are not compatible with v2.0. +[*][b]Loose-Coupled Thought Event Bus[/b]: Broadcasts psychological shifts to [code]RimMind-Advisor[/code] and [code]RimMind-Core[/code] Zone 2 context without direct cross-mod coupling. +[/list] + +[h2]What Is RimMind[/h2] +RimMind is an enterprise-grade, AI-powered RimWorld mod suite. Integrated with Large Language Models (LLM), it transforms colonists into self-reflecting agents with distinct personalities, three-tier memories, natural spoken dialogues, autonomous mechanisms, and dynamic storytelling. + +[h2]Sub-mod List & Dependency Relationships[/h2] +[table] +[tr][th]Mod[/th][th]Responsibility[/th][th]Dependencies[/th][th]GitHub[/th][/tr] +[tr][td]RimMind-Core[/td][td]LLM runtime, 4-Zone context engine, async queue, ToolCall registry & F8 Hub[/td][td]Harmony[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Core]Link[/url][/td][/tr] +[tr][td]RimMind-Actions[/td][td]Composite ToolCall mechanisms, battlefield triage & autonomous construction[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Actions]Link[/url][/td][/tr] +[tr][td]RimMind-Advisor[/td][td]Colonist self-reflective advice cards, 5-domain autonomy & player approval[/td][td]Core, Actions[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Advisor]Link[/url][/td][/tr] +[tr][td]RimMind-Dialogue[/td][td]Contextual spoken dialogue via express_dialogue ToolCall & speech bubbles[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Dialogue]Link[/url][/td][/tr] +[tr][td]RimMind-Memory[/td][td]3-Tier cognitive memory hierarchy, work aggregation & temporal decay[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Memory]Link[/url][/td][/tr] +[tr][td][b]RimMind-Personality[/b][/td][td]Big-Five psychological profiles, dawn monologues & dynamic mood thoughts[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Personality]Link[/url][/td][/tr] +[tr][td]RimMind-Storyteller[/td][td]AI Story Director, dramatic tension curve, chained arcs & Storyteller Altar[/td][td]Core, Memory[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Storyteller]Link[/url][/td][/tr] +[tr][td]RimMind-Extension-ModelService[/td][td]Multi-provider routing, Anthropic KV cache, local gateways & load balancing[/td][td]Core[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Extension-ModelService]Link[/url][/td][/tr] +[tr][td]RimMind-Bridge-RimChat[/td][td]RimChat compatibility bridge: dialogue/action mutual exclusion & context sync[/td][td]Core, RimChat[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Bridge-RimChat]Link[/url][/td][/tr] +[tr][td]RimMind-Bridge-RimTalk[/td][td]RimTalk compatibility bridge: bubble harmonization & bidirectional context[/td][td]Core, RimTalk[/td][td][url=https://github.com/RimWorld-RimMind-Mod/RimWorld-RimMind-Mod-Bridge-RimTalk]Link[/url][/td][/tr] +[/table] +[code]Core ──┬── Actions ── Advisor + ├── Dialogue + ├── Memory ── Storyteller + ├── Personality + ├── Extension-ModelService + ├── Bridge-RimChat + └── Bridge-RimTalk[/code] + +[h2]Core Features[/h2] +[list] +[*][b]Big-Five Cognitive Profiling[/b] - Maps vanilla RimWorld traits (e.g., Bloodlust, Optimist, Neurotic) onto continuous psychometric axes ([i]Openness, Conscientiousness, Extraversion, Agreeableness, Neuroticism[/i]). +[*][b]Probabilistic State-Transition Reflections[/b] - Colonists reflect naturally during 06:00 Dawn Sunrise (30% chance), Skygazing/Solitude (40% chance), Shared Recreation (25% chance), and Traumatic Mood Swings (50% chance). +[*][b]Dynamic Mood Thought Injection[/b] - Generates 1 to 3 contextual Personality Thoughts (intensity -3 to +3, mapping to -10 to +10 mood offset) injected into independent mood slots without overwriting one another. +[*][b]Bio Personality Tab & Player Editing[/b] - View AI psychological narratives directly in the pawn Bio tab, customize personality descriptions, work preferences, and social tendencies, and use [b]Shape Voting[/b] to guide future AI evaluations. +[/list] + +[h2]Trigger Conditions & Mood Scaling[/h2] +[table] +[tr][th]Trigger Type[/th][th]Description[/th][/tr] +[tr][td]06:00 Dawn & Daily Cycle[/td][td]Morning reflection as daylight returns, with staggered offset to avoid simultaneous bursts[/td][/tr] +[tr][td]Injury & Illness[/td][td]Reacts to severe combat wounds or chronic health conditions[/td][/tr] +[tr][td]Skill Milestones[/td][td]Reflects on personal growth when skill levels advance[/td][/tr] +[tr][td]Major Colony Events & Bereavement[/td][td]Reacts to raids, harvests, or the loss of bonded companions[/td][/tr] +[/table] + +[table] +[tr][th]AI Intensity[/th][th]Mood Offset[/th][th]Psychological State[/th][/tr] +[tr][td]+3 / +2 / +1[/td][td]+10 / +3 / +1[/td][td]Inspired, hopeful, or quietly content[/td][/tr] +[tr][td]0[/td][td]0[/td][td]Emotionally balanced observation[/td][/tr] +[tr][td]-1 / -2 / -3[/td][td]-1 / -3 / -10[/td][td]Troubled, anxious, or deeply distressed[/td][/tr] +[/table] + +[h2]Frequently Asked Questions[/h2] +[b]Q: Can I customize a colonist's personality manually?[/b] +A: Yes! Open the Personality panel in the pawn's Bio tab to edit traits, work habits, and social tendencies, or upvote/downvote AI assessments via Shape Voting. + +[b]Q: How does Personality interact with Advisor and Dialogue?[/b] +A: Active Personality profiles and Thoughts are injected into Core's Zone 2 context and broadcast to [code]RimMind-Advisor[/code], ensuring dialogues and action proposals reflect each colonist's true inner state.
  • brrainz.harmony diff --git a/Languages/ChineseSimplified/Keyed/RimMind_Personality.xml b/Languages/ChineseSimplified/Keyed/RimMind_Personality.xml index 0e9e1ed..87b1ffd 100644 --- a/Languages/ChineseSimplified/Keyed/RimMind_Personality.xml +++ b/Languages/ChineseSimplified/Keyed/RimMind_Personality.xml @@ -50,6 +50,8 @@ 社交倾向 AI 近期叙事(只读,每日 AI 更新) (尚未评估——运行一段时间后 AI 会自动填写) + 启用人格塑造投票弹窗 + 取消勾选后,生成新人格特质时将不再在悬浮请求栏弹出投票提示。 保存 取消 [RimMind] {0} 的人格档案已保存。 @@ -73,6 +75,8 @@ 强化 抑制 忽略 + 不再弹出 + 关闭后续的人格塑造投票弹窗(可在人格设置或角色人格档案窗口中重新开启)。 [玩家塑造历史] 强化 diff --git a/Languages/English/Keyed/RimMind_Personality.xml b/Languages/English/Keyed/RimMind_Personality.xml index 79c4696..5b6b183 100644 --- a/Languages/English/Keyed/RimMind_Personality.xml +++ b/Languages/English/Keyed/RimMind_Personality.xml @@ -50,6 +50,8 @@ Social tendencies AI recent narrative (read-only, updated daily by AI) (Not yet evaluated - AI will fill in automatically after running for a while) + Enable personality shaping vote popups + When unchecked, new personality traits will not trigger shaping vote popups in the request overlay. Save Cancel [RimMind] {0}'s personality profile saved. @@ -73,6 +75,8 @@ Reinforce Suppress Ignore + Mute + Disable future personality shaping vote popups (can be re-enabled in Personality settings or the colonist's Personality window). [Player Shaping History] Reinforce diff --git a/Source/Personality/PersonalityThoughtMapper.cs b/Source/Personality/PersonalityThoughtMapper.cs index b7a615f..0f7bf21 100644 --- a/Source/Personality/PersonalityThoughtMapper.cs +++ b/Source/Personality/PersonalityThoughtMapper.cs @@ -88,6 +88,12 @@ private static void RegisterShapingVote(Pawn pawn, ThoughtEntryDto entry, AIPers string optIgnore = "RimMind.Personality.Shaping.Ignore".CanTranslate() ? "RimMind.Personality.Shaping.Ignore".Translate().ToString() : "Ignore"; + string optMuteVote = "RimMind.Personality.Shaping.MuteVote".CanTranslate() + ? "RimMind.Personality.Shaping.MuteVote".Translate().ToString() + : "Mute"; + string optMuteVoteTip = "RimMind.Personality.Shaping.MuteVote.Tip".CanTranslate() + ? "RimMind.Personality.Shaping.MuteVote.Tip".Translate().ToString() + : "Disable future personality shaping vote popups (can be re-enabled in Personality settings or the colonist's Personality window)."; string titleText = "RimMind.Personality.Shaping.NewTrait".CanTranslate() ? "RimMind.Personality.Shaping.NewTrait".Translate().ToString() : "New Personality Trait"; @@ -100,10 +106,21 @@ private static void RegisterShapingVote(Pawn pawn, ThoughtEntryDto entry, AIPers pawn = pawn, title = titleText, description = $"{capturedEntry.label}: {capturedEntry.description}", - options = new[] { optReinforce, optSuppress, optIgnore }, + options = new[] { optReinforce, optSuppress, optIgnore, optMuteVote }, + optionTooltips = new[] { string.Empty, string.Empty, string.Empty, optMuteVoteTip }, expireTicks = settings?.requestExpireTicks ?? 30000, callback = choice => { + if (choice == optMuteVote) + { + if (RimMindPersonalityMod.Settings != null) + { + RimMindPersonalityMod.Settings.enableShapingVote = false; + RimMindPersonalityMod.Settings.Write(); + } + return; + } + if (!RimMindPawnLookup.IsActiveSpawnedColonist(pawn)) return; var shapingAction = choice == optReinforce ? ShapingAction.Reinforce diff --git a/Source/UI/Dialog_PersonalityProfile.cs b/Source/UI/Dialog_PersonalityProfile.cs index bc4221c..3236996 100644 --- a/Source/UI/Dialog_PersonalityProfile.cs +++ b/Source/UI/Dialog_PersonalityProfile.cs @@ -26,7 +26,7 @@ public Dialog_PersonalityProfile(Pawn pawn) preventCameraMotion = false; } - public override Vector2 InitialSize => new Vector2(520f, 480f); + public override Vector2 InitialSize => new Vector2(520f, 510f); public override void PreOpen() { @@ -74,7 +74,25 @@ public override void DoWindowContents(Rect inRect) Widgets.Label(new Rect(0f, 0f, inRect.width - 16f, 9999f), narrative); GUI.color = Color.white; Widgets.EndScrollView(); - y += narrativeH + 6f; + y += narrativeH + 8f; + + if (RimMindPersonalityMod.Settings != null) + { + string voteToggleLabel = "RimMind.Personality.UI.EnableShapingVoteToggle".CanTranslate() + ? "RimMind.Personality.UI.EnableShapingVoteToggle".Translate().ToString() + : "Enable personality shaping vote popups"; + string voteToggleTip = "RimMind.Personality.UI.EnableShapingVoteToggle.Tip".CanTranslate() + ? "RimMind.Personality.UI.EnableShapingVoteToggle.Tip".Translate().ToString() + : "When unchecked, new personality traits will not trigger shaping vote popups in the request overlay."; + Rect toggleRect = new Rect(inRect.x, y, inRect.width, 24f); + bool prevVote = RimMindPersonalityMod.Settings.enableShapingVote; + Widgets.CheckboxLabeled(toggleRect, voteToggleLabel, ref RimMindPersonalityMod.Settings.enableShapingVote); + TooltipHandler.TipRegion(toggleRect, voteToggleTip); + if (RimMindPersonalityMod.Settings.enableShapingVote != prevVote) + { + RimMindPersonalityMod.Settings.Write(); + } + } float btnW = (inRect.width - 8f) / 2f; float btnY = inRect.yMax - 36f; From 6015bb198f2b7c7e10c1575197bda262bb2a883c Mon Sep 17 00:00:00 2001 From: mcocdaa Date: Mon, 16 Nov 2026 07:13:59 +0100 Subject: [PATCH 2/2] fix(personality): enforce active colonist lifecycle checks in comp attachment and evaluation fix: guard CompAIPersonality against non-Pawn parents and skip corpse defs Replace direct Pawn casts with safe `parent as Pawn` access and bail out early when the parent is not a Pawn, preventing null reference errors during state transition observation and event triggering. Also skip Corpse and non-Pawn ThingDefs in the humanlike comp injection patch to avoid attaching the personality comp to invalid defs. Remove stale comments and update the contract test to assert the current translation helper call. --- Source/Comps/CompAIPersonality.cs | 50 ++++++------------- Source/Patches/AddCompToHumanlikePatch.cs | 14 ++---- .../PersonalityEvaluationContracts.cs | 2 +- 3 files changed, 21 insertions(+), 45 deletions(-) diff --git a/Source/Comps/CompAIPersonality.cs b/Source/Comps/CompAIPersonality.cs index 99e9495..56a7991 100644 --- a/Source/Comps/CompAIPersonality.cs +++ b/Source/Comps/CompAIPersonality.cs @@ -14,10 +14,6 @@ public CompProperties_AIPersonality() } } - /// - /// 挂载于 Pawn 的 ThingComp,负责触发 AI 人格评估。 - /// 支持每日定时触发和事件驱动触发(外部 Patch 通过 TriggerEvent 注入)。 - /// public class CompAIPersonality : ThingComp { private bool _hasPendingRequest; @@ -34,13 +30,15 @@ public class CompAIPersonality : ThingComp private float _lastMood = -1f; private bool _wasAwake = true; - private Pawn Pawn => (Pawn)parent; + private Pawn? PawnOrNull => parent as Pawn; + private Pawn? Pawn => parent as Pawn; private AIPersonalitySettings Settings => RimMindPersonalityMod.Settings; private int GetDailyJitter() { + if (PawnOrNull is not Pawn pawn) return 0; if (_dailyJitter < 0) - _dailyJitter = new System.Random(Pawn.thingIDNumber ^ 0x3C3C3C3C).Next(-Settings.jitterRangeTicks, Settings.jitterRangeTicks + 1); + _dailyJitter = new System.Random(pawn.thingIDNumber ^ 0x3C3C3C3C).Next(-Settings.jitterRangeTicks, Settings.jitterRangeTicks + 1); return _dailyJitter; } @@ -119,14 +117,10 @@ public override void CompTick() }); } - /// - /// Detects natural behavioral transitions and queues probabilistic personality evaluations. - /// Colonist thoughts are not locked to 6:00 AM; they emerge dynamically at natural awakening (any hour), - /// dusk/sunset, idle wandering pulses, job shifts, and mood swings. - /// private void ObserveStateTransitions() { - Map? map = Pawn.Map; + if (PawnOrNull is not Pawn pawn) return; + Map? map = pawn.Map; if (map == null) return; int currentTick = Find.TickManager.TicksGame; @@ -134,14 +128,12 @@ private void ObserveStateTransitions() int effectiveCooldown = RimMind.Application.Common.Helpers.ActivityCooldownScaler.Scale(Settings.eventCooldownTicks, activityScale); bool canQueue = !_hasPendingRequest && (currentTick - _lastEventTick) >= effectiveCooldown && _pendingEventContext == null; - // Check A: Sunrise / Dawn transition (sampled every 250 ticks ≈ 4 seconds) - bool isAwake = Pawn.Awake(); + bool isAwake = pawn.Awake(); bool justWokeUp = !_wasAwake && isAwake; _wasAwake = isAwake; - float currentMood = Pawn.needs?.mood?.CurLevel ?? 0.5f; + float currentMood = pawn.needs?.mood?.CurLevel ?? 0.5f; - // Check A1: Natural Awakening transition at ANY hour of day or night if (justWokeUp && canQueue && Settings.enableSunriseTrigger) { float jitter = Rand.Range(0.85f, 1.15f); @@ -168,8 +160,7 @@ private void ObserveStateTransitions() } } - // Check A2: Dusk / Sunset transition (sampled every ~250 ticks ≈ 4 seconds) - if (Pawn.IsHashIntervalTick(250, 60)) + if (pawn.IsHashIntervalTick(250, 60)) { int currentHour = GenLocalDate.HourInteger(map); if (_lastHour != -1 && currentHour != _lastHour) @@ -189,10 +180,9 @@ private void ObserveStateTransitions() _lastHour = currentHour; } - // Check A3: Daytime Idle Wandering Contemplation Pulse (sampled every ~2500 ticks ≈ 40 seconds) - if (Pawn.IsHashIntervalTick(2500, 60) && canQueue && isAwake) + if (pawn.IsHashIntervalTick(2500, 60) && canQueue && isAwake) { - JobDef? activeJob = Pawn.CurJobDef; + JobDef? activeJob = pawn.CurJobDef; bool isIdle = activeJob == JobDefOf.Wait_Wander || activeJob == JobDefOf.GotoWander || activeJob == JobDefOf.Wait; if (isIdle) { @@ -209,15 +199,13 @@ private void ObserveStateTransitions() } } - // Check B: Job Transition (Recreation or Skygaze/Meditate) - JobDef? curJob = Pawn.CurJobDef; + JobDef? curJob = pawn.CurJobDef; string? curJobName = curJob?.defName; if (curJobName != _lastJobDefName) { if (curJob != null && curJobName != null) { float jitter = Rand.Range(0.85f, 1.15f); - // Skygazing / Meditating / Praying if (curJobName == "Skygaze" || curJobName == "Meditate" || curJobName == "Pray") { float dynamicChance = PersonalityTriggerPolicy.CalculateDynamicPersonalityChance(Settings.skygazeTriggerChance, currentMood, jitter, activityScale); @@ -232,7 +220,6 @@ private void ObserveStateTransitions() curJob.label ?? curJobName); } } - // Joy / Recreation else if (curJob.joyKind != null) { float dynamicChance = PersonalityTriggerPolicy.CalculateDynamicPersonalityChance(Settings.recreationTriggerChance, currentMood, jitter, activityScale); @@ -251,10 +238,9 @@ private void ObserveStateTransitions() _lastJobDefName = curJobName; } - // Check C: Mood Swing (sampled every ~500 ticks ≈ 8 seconds) - if (Pawn.IsHashIntervalTick(500, 60) && Pawn.needs?.mood != null) + if (pawn.IsHashIntervalTick(500, 60) && pawn.needs?.mood != null) { - float curMood = Pawn.needs.mood.CurLevel; + float curMood = pawn.needs.mood.CurLevel; if (_lastMood < 0f) { _lastMood = curMood; @@ -281,12 +267,9 @@ private void ObserveStateTransitions() } } - /// - /// 从外部 Patch(受伤、技能升级、事件等)触发一次人格评估。 - /// public void TriggerEvent(string context, TriggerEventType eventType = TriggerEventType.Incident) { - if (!Settings.enablePersonality) return; + if (PawnOrNull == null || !Settings.enablePersonality) return; if (!PersonalityTriggerPolicy.IsTriggerEnabled(eventType, Settings)) return; @@ -294,9 +277,8 @@ public void TriggerEvent(string context, TriggerEventType eventType = TriggerEve _pendingEventContext = context; } - private bool IsEligible() => PersonalityTriggerPolicy.IsEligible(Pawn); + private bool IsEligible() => PawnOrNull is Pawn pawn && PersonalityTriggerPolicy.IsEligible(pawn); - // Delegates to RimMindText.TrOr (guards key.CanTranslate() on the main thread). private static string TranslateOrFallback(string key, string fallback, params object[] args) => RimMindText.TrOr(key, fallback, args); diff --git a/Source/Patches/AddCompToHumanlikePatch.cs b/Source/Patches/AddCompToHumanlikePatch.cs index 8a36ba6..3e4339d 100644 --- a/Source/Patches/AddCompToHumanlikePatch.cs +++ b/Source/Patches/AddCompToHumanlikePatch.cs @@ -8,14 +8,8 @@ namespace RimMind.Personality.Patches { /// - /// 在所æœ?ThingDef 解析完继承关系(ResolveReferences)之后, - /// 动态为所有人形智能小人(å�?AlienRaces 外星种族)注å…?CompProperties_AIPersonalityã€? - /// - /// 为什么不ç”?XML PatchOperationï¼? - /// XML Patch 在继承解析前运行,raw XML 里没æœ?race/intelligence 字段(它们从父类继承而来), - /// 所ä»?XPath 过滤 race/intelligence="Humanlike" 匹配 0 个节点ã€? - /// Harmony Postfix 在解析后运行,可直接读取已解析的 race 字段ï¼? - /// 一次性覆盖原ç‰?Human + 所æœ?AlienRaces 种族 + 未来任何 mod 添加的人形种族ã€? + /// Dynamically injects CompProperties_AIPersonality into all humanlike Pawn ThingDefs + /// after ThingDef.ResolveReferences completes (excluding Corpse ThingDefs). /// [HarmonyPatch(typeof(ThingDef), nameof(ThingDef.ResolveReferences))] public static class AddCompToHumanlikePatch @@ -23,12 +17,12 @@ public static class AddCompToHumanlikePatch [HarmonyPostfix] public static void Postfix(ThingDef __instance) { - // 只处理人形智能种æ—? + if (__instance == null || __instance.IsCorpse) return; + if (__instance.thingClass == null || !typeof(Pawn).IsAssignableFrom(__instance.thingClass)) return; if (__instance.race?.intelligence != Intelligence.Humanlike) return; __instance.comps ??= new List(); - // 避免重复注入(热重载或多次调用场景) if (__instance.comps.Any(c => c is CompProperties_AIPersonality)) return; __instance.comps.Add(new CompProperties_AIPersonality()); diff --git a/Tests/Contracts/PersonalityEvaluationContracts.cs b/Tests/Contracts/PersonalityEvaluationContracts.cs index 584d291..74233dd 100644 --- a/Tests/Contracts/PersonalityEvaluationContracts.cs +++ b/Tests/Contracts/PersonalityEvaluationContracts.cs @@ -163,7 +163,7 @@ public void Evaluation_math_dto_and_context_policy_are_stable() { Assert.Contains(key, compSource, StringComparison.Ordinal); } - Assert.Contains("key.CanTranslate()", compSource, StringComparison.Ordinal); + Assert.Contains("RimMindText.TrOr(key, fallback, args)", compSource, StringComparison.Ordinal); })); }