Skip to content

Example Breakdown: CyberpunkMercV 5-Stage Storyline & State Machine ​

CyberpunkMercV

This page and the next dissect the complete source code of CyberpunkMercV (CyberpunkMercVMod.cs). Here we examine the registration architecture, the 5-stage narrative state machine (v_stage), the auto-stage dispatcher, and the implementation of Acts 1 through 3.


1. State Machine Design & Registration Table ​

CyberpunkMercV tracks cross-day narrative progression with two save keys:

  • v_stage (0..5): 0 = Act 1 Relic malfunction; 1 = Act 2 convoy ambush firearm prep; 2 = Act 3 corporate vault heist wholesale loot; 3 = Act 4 Corporate Spec-Ops investigation; 4 = post-story recurring mode & holophone unlocked; 5 = arrested/betrayed ending.
  • v_trust (0..2): tracks trust built with V across the storyline.
csharp
private static StoreClient CreateVByCurrentStage()
{
    int stage = NpcFrameworkSdk.GetSaveInt("v_stage", 0);
    switch (stage)
    {
        case 0: return CreateVAct1Relic();
        case 1: return CreateVAct2GunOrder();
        case 2: return CreateVAct3Heist();
        case 3: return CreateCorpoSecInvestigator();
        default: return CreateVRecurringMercInternal();
    }
}

private static StoreClient CreateVRecurringMercOrCurrentStage()
{
    int stage = NpcFrameworkSdk.GetSaveInt("v_stage", 0);
    if (stage < 4)
        return CreateVByCurrentStage();
    return CreateVRecurringMercInternal();
}

2. Act 1 (CreateVAct1Relic): Biochip Overwrite & Smart-Glasses Easter Egg ​

In Act 1, V enters the shop as an unfamiliar mercenary ("Mercenary V") experiencing a 68% Relic biochip neural overwrite:

csharp
private static StoreClient CreateVAct1Relic()
{
    var sc = new StoreClient
    {
        identifier = "v_act1_relic",
        displayName = T("陌生佣兵 V", "Mercenary V"),
        spriteName = "v_normal",
        clientFaction = "FACTION_BLACK_MARKET",
        clientIntent = StoreClient.ClientIntent.BUY,
        buyPriceModifier = 40,
        CanExposeChem = true,
        staysAfterFailedBargain = true,
        noAcceptingContraband = false,
        AcceptingContrabandOverride = true
    };
    sc.SetBudget(380);

    sc.clientBuyingIdList.Add("black_injector");
    sc.clientBuyingIdList.Add("large_purple_injector");
    sc.clientBuyingIdList.Add("pink_injector");
    sc.clientBuyingIdList.Add("dream_dust");
    sc.clientBuyingTagList.Add("MEDICAL");
    sc.clientBuyingTagList.Add("NARCOTIC");
    sc.AddCheck("CHECK_EXPIRED");
  • Branch 1 ([Hand him an emergency neuro-sedative]): hands V an emergency sedative directly from dialogue, advancing v_stage = 1, v_trust = 2, and granting 120 credits (PlayerStore.Instance?.ModCash(120, true)).
  • Branch 2 ([Open Stock]): enters the standard buying interface; completing the sale advances v_stage = 1 inside acceptDealDialogue and allDoneDialogue.

3. Act 2 (CreateVAct2GunOrder): Convoy Ambush Firearm Preparation ​

When v_stage == 1, V returns with 520 credits and +30% markup to purchase "FIREARM", "WEAPON", "AMMUNITION", or "MUNITION" (enforcing CHECK_RUST and CHECK_DENTED) ahead of his raid on an Arasaka/Pastel neural-matrix convoy. Completing the deal sets v_stage = 2.


4. Act 3 (CreateVAct3Heist): Corporate Vault Heist 30%-Off Wholesale Lot ​

When v_stage == 2, V brings the high-tech spoils of the corporate vault raid (aug_chip, command_keycard, sci_keycard, energy_credit_hyp, and smg) and offers them as a 30%-off wholesale bundle (isOfferWholesale = true, wholesaleDiscount = -30):

csharp
cur.SetEndAction(() =>
{
    var ps = PlayerStore.Instance;
    if (ps == null) return;
    ps.AddDirectSellingItemToTable("aug_chip", false, false, false, 0);
    ps.AddDirectSellingItemToTable("command_keycard", false, false, false, 0);
    ps.AddDirectSellingItemToTable("sci_keycard", false, false, false, 0);
    ps.AddDirectSellingItemToTable("energy_credit_hyp", false, false, false, 0);
    ps.AddDirectSellingItemToTable("smg", false, false, false, 0);
});

Custom NPC Framework Documentation