Class TimbnPluginQuests
Adds quests to the game on behalf of a plugin, removed again when the plugin unloads. Reach it through the plugin's Quests property.
public sealed class TimbnPluginQuests
- Inheritance
-
TimbnPluginQuests
- Inherited Members
Methods
Add(string, Action<TimbnQuestBuilder>)
Adds a quest with its giver read from its run, like the Add that takes a name, with the name only in the plugin's lang files under the quest id. Pair it with Description(), Line(string, params object[]), and the Accept and Decline that take no text, so all of the quest's text lives in lang/en.txt and its translations.
public TimbnQuest Add(string id, Action<TimbnQuestBuilder> quest)
Parameters
idstringThe quest id. Keep it stable, since saves keep progress under it.
questAction<TimbnQuestBuilder>Describes the quest. It needs a Giver.
Returns
- TimbnQuest
The quest, for rolling and canceling runs.
Examples
var craving = Quests.Add("my_craving", quest => quest
.Repeatable()
.Setup(run => ...)
.Giver(run => run.NpcId("villager"))
.Description()
.Offer(talk => talk
.Line("ask")
.Accept(then => then.Line("thanks"))
.Decline())
.Cost((cost, run) => cost.Item(run.Item("dish")))
.Talk(talk => talk
.Accept(then => then.Line("thanks"))
.Decline()));
with lang/en.txt holding my_craving, quest_open_my_craving_d, my_craving_offer_ask, my_craving_accept, my_craving_accept_thanks, my_craving_decline, my_craving_talk_accept, my_craving_talk_accept_thanks and my_craving_talk_decline.
Add(string, string, Action<TimbnQuestBuilder>)
Adds a quest whose giver changes from one play to the next, read from its run with Giver(Func<TimbnQuestRun, string>). Everything else works the same as the Add that takes an NPC.
public TimbnQuest Add(string id, string name, Action<TimbnQuestBuilder> quest)
Parameters
idstringThe quest id. Keep it stable, since saves keep progress under it.
namestringThe quest's name in the quest tree.
questAction<TimbnQuestBuilder>Describes the quest. It needs a Giver.
Returns
- TimbnQuest
The quest, for rolling and canceling runs.
Examples
A villager asks for a dish about once a week, and pays its sale price for it.
var craving = Quests.Add("my_craving", "A Villager's Craving", quest => quest
.Repeatable()
.Setup(run =>
{
var villagers = TimbnNpcs.GroupMemberIds(TimbnGameIds.Groups.VillagersDayAll);
if (villagers.Count == 0)
return false;
run.Npc("villager", villagers[UnityEngine.Random.Range(0, villagers.Count)]).Item("dish", "cook_muffin");
return true;
})
.Giver(run => run.NpcId("villager"))
.Description("Bring {villager} {dish}.")
.Offer(talk => talk
.Say("Could you bring me {dish}?")
.Accept("I'll bring it.")
.Decline("Not now."))
.Cost((cost, run) => cost.Item(run.Item("dish")))
.Reward((reward, run) => reward.Money(TimbnItems.SalePrice(run.Item("dish"))))
.Talk(talk => talk
.Accept("Here you go.", then => then.Say("Thank you!"))
.Decline("Not yet.")));
Events.NewDayStarted(_ =>
{
if (UnityEngine.Random.Range(0, 7) == 0)
craving.NewRun();
});
Add(string, string, string, Action<TimbnQuestBuilder>)
Adds a quest. Core registers it in the quest tree, adds its text, shows a speech bubble on the NPC when there is something to say, runs the offer and talk conversations, and pays its rewards. See TimbnQuestBuilder for what a quest can hold. Call it in OnAwake.
public TimbnQuest Add(string id, string npcId, string name, Action<TimbnQuestBuilder> quest)
Parameters
idstringThe quest id. Keep it stable, since saves keep progress under it.
npcIdstringThe NPC who gives the quest, from TimbnGameIds.Npcs, such as TimbnGameIds.Npcs.Larry.
namestringThe quest's name in the quest tree.
questAction<TimbnQuestBuilder>Describes the quest.
Returns
- TimbnQuest
The quest, for starting it, marking it ready, or chaining another quest after it. It lives until the plugin unloads, since a quest in a loaded save should not vanish mid save. When another mod already adds a quest with the same id, this one is skipped and named in the main menu's load error popup.
Examples
var wine = Quests.Add("my_larry_wine", TimbnGameIds.Npcs.Larry, "Larry's Thirst", quest => quest
.Description("Larry wants 3 bottles of wine.")
.Offer(talk => talk
.Say("Could you fetch us 3 bottles of wine?")
.Accept("Fine."))
.Cost(cost => cost.Item("grape_wine:1", 3))
.Reward(reward => reward.Money(300))
.Talk(talk => talk.Accept("Here's your wine.", then => then.Say("Lovely."))));