Example Breakdown: RestoredUnusedNPCs Architecture & Billy's 4-Act Storyline

This page and the next examine the source code of RestoredUnusedNPCs (RestoredUnusedNPCsMod.cs). Here we cover Billy's 4-act cross-day storyline, BarterOffer food sharing, Medbay wholesale fencing, and the Internal Affairs investigation.
1. State Machine & Auto-Dispatcher (billy)
Billy's arc is driven by two save keys:
billy_stage(0..5):0= Act 1 begging for food;1= Act 2 rookie guard buying gear;2= Act 3 first Medbay theft wholesale;3= Act 4 Internal Affairs investigation;4= arrested ending;5= permanent recurring wholesale supplier mode.billy_fed(0or1): records whether the player shared food with Billy in Act 1.
csharp
private static StoreClient CreateBillyByCurrentStage()
{
int stage = NpcFrameworkSdk.GetSaveInt("billy_stage", 0);
switch (stage)
{
case 0: return CreateBilly1();
case 1: return CreateBilly2();
case 2: return CreateBilly3Internal(false);
case 3: return CreateBillySecOfficer();
default: return CreateBilly3Internal(true);
}
}2. Act 1 (CreateBilly1): Begging for Food & Three-Way Choice
Billy visits with ClientIntent.BARTER (useClientBudget = false) requesting "FOOD":
- Branch 1 (
[Give him some food]): invokessc.barterOffer.InstanciateOffer()if"FOOD"is in the back inventory (or triggers a warm staff-meal fallback if out of stock), settingbilly_stage = 1, billy_fed = 1. - Branch 2 (
[Decline]): keepsbilly_stage = 0so Billy can try again on a later day. - Branch 3 (
[Tell him to get a job]): setsbilly_stage = 1, billy_fed = 0.
3. Act 2 (CreateBilly2), Act 3 (CreateBilly3Internal) & Act 4 (CreateBillySecOfficer)
- Act 2: Billy arrives in a Security uniform (
maleSec2) with180credits to buy a"TOOL","WEAPON", or"MELEE_WEAPON"(CHECK_RUST,CHECK_DENTED). Completing the sale setsbilly_stage = 2. - Act 3: Assigned to the Upper Level Pastel Medbay, Billy steals
large_purple_injector,pink_injector,hemostatic_bandage_item, andsmelling_salt, offering them as a 25%-off wholesale bundle (isOfferWholesale = true, wholesaleDiscount = -25). - Act 4: Internal Affairs questions the player. Reporting Billy awards
150credits, triggers the"Medbay Insider Arrested"newspaper headline, and setsbilly_stage = 4. Covering for Billy setsbilly_stage = 5, unlocking him as a permanent recurring wholesale supplier.