Skip to content

04. Barter & Begging (BarterOffer) ​

The barter subsystem (ClientIntent.BARTER) handles non-cash exchanges where a customer asks the player to hand over an item matching specific criteria (such as Billy begging for "FOOD" in Act 1 of RestoredUnusedNPCs).


Core Classes & Methods ​

Class / MemberTypeDescription
StoreClient.ClientIntent.BARTERClientIntentEnum value 6, marking the visit as a barter interaction.
sc.useClientBudgetboolSet to false to disable the credit budget bar.
sc.barterOfferBarterOfferBarter configuration attached to the client.
BarterOffer.getBarterResultFunc<BarterResult>Evaluates whether the player can fulfill the barter and returns BarterResult { isAccepted, response }.
sc.barterOffer.InstanciateOffer()voidOpens the vanilla item-handover UI when triggered from a dialogue choice.
EmporiumEntry.Instance.IsBackInvContainItemTag(string tag)boolChecks whether the player's inventory contains at least one item with tag.

Code Example: Food Barter with Stock Fallback ​

csharp
var sc = new StoreClient
{
    identifier = "billy1",
    displayName = NpcFrameworkSdk.T("比利", "Billy"),
    spriteName = "trailer_scav1",
    clientFaction = "FACTION_LOWER_LEVEL",
    clientIntent = StoreClient.ClientIntent.BARTER,
    useClientBudget = false
};
sc.clientBuyingTagList.Add("FOOD");

sc.barterOffer = new BarterOffer
{
    ownerClient = sc,
    barterTextBody = NpcFrameworkSdk.T("施舍一点食物?", "Spare Food?"),
    onInstance = () => { },
    getBarterResult = () =>
    {
        var res = new BarterResult();
        bool hasFood = EmporiumEntry.Instance != null && EmporiumEntry.Instance.IsBackInvContainItemTag("FOOD");
        res.isAccepted = hasFood;
        res.response = hasFood
            ? NpcFrameworkSdk.T("看起来太香了!", "That looks good!")
            : NpcFrameworkSdk.T("能分我一口吃的吗?", "Can you spare some food?");
        return res;
    }
};

Custom NPC Framework Documentation