Skip to content

4.1 NpcFrameworkSdk 全量方法参考手册 ​

NpcFrameworkSdk 是扩展模组与底座框架 CustomNPCFramework 通信的唯一入口类。只需将单文件 NpcFrameworkSdk.cs 放入你的模组源码目录,即可零程序集引用调用以下全部静态属性与方法。


1. 语言本地化与辅助属性 ​

属性 / 方法签名返回类型详细说明
NpcFrameworkSdk.IsChinesebool读取 CustomNPCFramework 的语言设置(自动跟随游戏语言 LocHelper.GetCurrentLocaleCode() 或玩家手动指定的简中/英文),当前应显示中文时返回 true。
NpcFrameworkSdk.T(string zh, string en)string双语文本内联选择器,等价于 IsChinese ? zh : en。建议在所有 displayName、Dialogue 台词与 ModConfig 标签中使用。
NpcFrameworkSdk.ResolveSprite(string spriteName)string检查 spriteName 是否已在 SpriteDict.Instance.spriteDictionary 中注册;若未找到则查询内置回退映射("billy"→"trailer_scav1", "cul1"→"spy", "sha3"→"trailer_scav3")。

2. NPC 注册与即时召唤方法 ​

RegisterNpc ​

csharp
public static void RegisterNpc(
    string id,
    Func<string> displayNameGetter,
    int spawnPhase,
    int priority,
    int minDay,
    int cooldownDays,
    int spawnChancePercent,
    bool oncePerSave,
    Func<bool> canSpawnPredicate,
    Func<StoreClient> clientFactory,
    Action onSpawned = null,
    int maxDay = 9999,
    string requiredNotArrestedId = null)
  • 功能:注册自定义 NPC 条目。若框架尚未加载,自动进入 PendingQueue.v1 挂起队列等待框架消费;若框架已加载,立即写入 NpcFrameworkRegistry 并刷新开发者调试面板下拉菜单。

SummonNpcNow ​

csharp
public static bool SummonNpcNow(string id)
  • 功能:立即将 id 对应的 NPC 强制置顶到 clientStack[0]。
  • 返回值:若当前店铺处于营业状态(StoreState.OPEN)且成功置顶(当柜台前无人时还会自动触发 TryCallNextClient() 让其直接走进店门),返回 true;若当前处于主菜单或早晨尚未拉起卷帘门,则将其写入 PendingDebugSummonId 挂起槽(待卷帘门拉开时自动排在第一位进门),返回 false。

3. 跨日剧情存档状态机方法(Save State API) ​

所有键名均自动附加 "cnpcf_" 前缀并存入 PlayerStore.Instance.ModData():

csharp
// 整型状态读写与累加(最常用于管理剧情阶段 stage、好感度 trust、分支标记)
public static int GetSaveInt(string key, int defaultValue = 0);
public static void SetSaveInt(string key, int value);
public static int AddSaveInt(string key, int delta, int defaultValue = 0);

// 布尔状态读写
public static bool GetSaveBool(string key, bool defaultValue = false);
public static void SetSaveBool(string key, bool value);

// 字符串状态读写
public static string GetSaveString(string key, string defaultValue = "");
public static void SetSaveString(string key, string value);

4. 全息电话簿注册与同步方法 ​

csharp
public static void RegisterPhoneContact(
    long number,
    string dialogFuncId,
    Func<string> displayNameGetter,
    int cooldownDays,
    Func<bool> isUnlockedPredicate,
    Func<StorePhoneClient, Dialogue> callDialogFactory,
    params string[] clientAliases);

public static void SyncPhoneContacts();

5. 顾客塑造子系统扩展工具箱方法 ​

csharp
// 1. 声明式批量设置 StoreClient 的 46 项属性
public static void ApplyClientProfile(StoreClient client, Dictionary<string, object> profile);

// 2. 实体手写便条与打印纸张生成/投递
public static GameItem CreateHandnoteItem(string title, string body, string signature, int fontIndex = 0);
public static GameItem CreatePaperNoteItem(string title, string body);
public static bool SpawnItemOnCounterOrStore(GameItem item, bool isStolen = false, bool isContraband = false);
public static bool GiveHandnoteToPlayer(string title, string body, string signature, int fontIndex = 0);

// 3. 店铺电脑终端委托板悬赏激活
public static bool PostStoreRequest(
    string id, string title, string description, string requesterName,
    string factionId, string requiredItemId, int requiredCount = 1,
    int durationDays = 5, int creditReward = 200, int reputationReward = 10, bool force = true);

// 4. 期货预定委托单挂载
public static void AttachProcurementOffer(
    StoreClient client, string clientName, string offerDescription, string collectDescription,
    int dueInDays, int initialAdvanceCash, int finalRewardCash, Func<GameItem, bool> itemValidator);

// 5. 定制枪械改装订单构建
public static GunOrderData BuildCustomGunOrder(
    int tier, int baseReward, string dialogText, bool isBestOrder,
    IList<(string statTag, int minVal, int bonusReward, bool isMandatory)> requirements);

// 6. 隔日早报头条新闻激活
public static void TriggerNews(string id, string headline, string body, int durationDays = 1);

// 7. 夜间地点事件与钩子注册
public static bool RegisterAfterhourEvent(
    string id, string locationId, Func<string> titleGetter, Func<string> descriptionGetter,
    int durationDays = 2, float dailyChancePercent = 25f, bool closesLocation = false,
    Func<bool> canStartPredicate = null, Action onStart = null, Action onEnd = null);
public static void RegisterNightlyHook(Action hook);
public static void RegisterDumpingGroundWatcher(Action<GameInventory> watcher);

Custom NPC Framework Documentation