API

Programatic API for SMAPI modding (C#)

This is an experimental feature. It may be changed or removed in future.

NPC Adventures provides a SMAPI mod API. You can make use of the API as follows.

Create an interface for the API

Create the following interface in your project:

public interface INpcAdventureModApi
{
    bool CanRecruitCompanions();
    IEnumerable<NPC> GetPossibleCompanions();
    bool IsPossibleCompanion(string npc);
    bool IsPossibleCompanion(NPC npc);
    bool CanAskToFollow(NPC npc);
    bool CanRecruit(Farmer farmer, NPC npc);
    bool IsRecruited(NPC npc);
    bool IsAvailable(NPC npc);
    string GetNpcState(NPC npc);
    bool RecruitCompanion(Farmer farmer, NPC npc);
    string GetFriendSpecificDialogueText(Farmer farmer, NPC npc, string key);
    string LoadString(string path);
    string LoadString(string path, string substitution);
    string LoadString(string path, string[] substitutions);
}

Get the API

Any time after the GameLaunched event, create an instance of the API interface:

public static void GameLoop_GameLaunched(object sender, StardewModdingAPI.Events.GameLaunchedEventArgs e)
{
    if (Helper.ModRegistry.IsLoaded("purrplingcat.npcadventure"))
    {
        INpcAdventureModApi api = Helper.ModRegistry.GetApi<INpcAdventureModApi>("purrplingcat.npcadventure");
        if (api != null)
        {
            DoSomethingWithThe(api);
        }
    }
}

API Methods

The following methods are implemented in the API

MethodArg TypesReturn typeDescription
CanRecruitCompanionsnoneboolReturns true if player is eligible to recruit followers in general.
GetPossibleCompanionsnoneIEnumrable<string>Provides a list of possible companions.
IsPossibleCompanionstringboolReturns true if the named NPC is a possible companion.
IsPossibleCompanionNPCboolReturns true if the given NPC is a possible companion.
CanAskToFollow`NPCboolReturns true if the given NPC is ready to be asked to follow.
CanRecruitFarmer, `NPCboolReturns true if the given NPC can be recruited by the given farmer.
IsRecruitedNPCboolReturns true if the given NPC is currently recruited by the player.
IsAvailableNPCboolReturns true if the given NPC is currently available to be recruited by the player.
GetNpcStateNPCstringReturns a string describing the recruitment state for the NPC (RESET, AVAILABLE, RECRUITED, UNAVAILABLE) or null if error.
RecruitCompanionFarmer, `NPCboolRecruits the NPC and returns true if the given NPC was recruited successfully.
GetFriendSpecificDialogueTextFarmer, NPC, stringstringReturns a string from the mod's assets/Dialogue folder for the given NPC.
LoadStringstringstringReturns a string from the mod's assets/Strings/Strings.json file.
LoadStringstring, stringstringReturns a string from the mod's assets/Strings/Strings.json file with a single substitution for {0}.
LoadStringstring, string[]stringReturns a string from the mod's assets/Strings/Strings.json file with multiple {n} substitutions.

Future

Remember, this feature is experimental. In future the API may be changed, replaced or removed from the mod.