For AI agents: the complete documentation index is available at /npc-mentality/zh/llms.txt, the full documentation bundle is available at /npc-mentality/zh/llms-full.txt, and this page is available as Markdown at /npc-mentality/zh/usage/rumor.md.
  • 简体中文
  • 谣言系统

    信息在 NPC 之间流传时内容逐渐变形。

    概述

    玩家击败了Boss
        ↓
    NPC1: "听说有人杀了一条龙?"
        ↓
    NPC2: "不对吧?据说是个魔法师。"
        ↓
    NPC3: "听说魔王死了。"

    组件

    RumorSystem — MonoBehaviour。

    字段类型默认值说明
    MutationChancefloat0.3f谣言变形概率(0~1)
    MutationSuffixesList<string>默认4个变形时附加的句子
    ActiveRumorsList<RumorData>—当前进行中的谣言列表

    API

    rumorSystem.SpreadRumor("有人杀了一条龙", sourceNpcId: "player");
    
    var rumor = rumorSystem.ActiveRumors[^1];
    rumorSystem.PassRumor(rumor, "npc_01");

    示例

    using NpcMentality;
    
    public class RumorDemo : MonoBehaviour
    {
        public RumorSystem rumorSystem;
        public string[] npcIds = { "blacksmith", "innkeeper", "farmer", "guard" };
    
        public void OnPlayerKillsDragon()
        {
            rumorSystem.SpreadRumor("有人杀了一条龙", "player");
            StartCoroutine(SpreadToVillage());
        }
    
        private System.Collections.IEnumerator SpreadToVillage()
        {
            var rumor = rumorSystem.ActiveRumors[^1];
            foreach (string npcId in npcIds)
            {
                yield return new WaitForSeconds(2f);
                rumorSystem.PassRumor(rumor, npcId);
            }
        }
    }

    提示

    • MutationChance = 0f — 不变形,只传播事实。
    • MutationChance = 1f — 每次传递都必定变形。
    • 与 RelationshipContagion 结合,同时传播谣言内容和情感。
    • 利用 HopCount 实现"这个谣言不可信"的 UI。