Class TimbnTalk<TSelf>
The steps every conversation shares, for talks added with the plugin's Dialog.AddTalk and for quest conversations. Each line is the text itself, and Core turns it into a localization key named after the talk or quest, numbered in the order written, so a lang file can translate it. Named(string) gives a line a name of its own instead, and Line(string, params object[]) leaves the text out of code and reads it from the plugin's lang files by name. The steps play in order, each waiting for the one before.
public abstract class TimbnTalk<TSelf> where TSelf : TimbnTalk<TSelf>
Type Parameters
TSelfThe conversation type, so each step chains on the same type.
- Inheritance
-
TimbnTalk<TSelf>
- Derived
- Inherited Members
Methods
Ask(Action<TimbnAsk>)
Shows answer choices over the player and waits for one. The picked answer's lines play, then the conversation carries on with whatever steps follow. An answer with needs or a cost is grayed out with the game's locks and prices until the player has them. The player cannot walk off, so when every answer has a need, a cost or a reward, Core adds the game's leave answer.
public TSelf Ask(Action<TimbnAsk> answers)
Parameters
Returns
- TSelf
This conversation, for chaining.
Examples
talk.Say("Got any boards?")
.Ask(ask => ask
.Answer("Here, take two.", then => then.Say("Thanks!"), cost: cost => cost.Item("flitch", 2), reward: reward => reward.Money(5))
.Answer("Not today."))
Cinematic()
Shows the game's black story bars until the conversation ends. Put it first to have them for the whole talk.
public TSelf Cinematic()
Returns
- TSelf
This conversation, for chaining.
Give(string, int)
Gives the player an item. Anything that does not fit drops in front of the player.
public TSelf Give(string itemId, int count = 1)
Parameters
Returns
- TSelf
This conversation, for chaining.
Line(string, params object[])
A line in the NPC's speech bubble with its text only in the plugin's lang files, under the talk or quest id plus this name, so Line("ask") in the offer of quest my_craving reads my_craving_offer_ask. Values fill %1, %2 and so on the same way as Say(string, params object[]). A name with no line in lang/en.txt fails when the talk or quest is added.
public TSelf Line(string name, params object[] values)
Parameters
namestringA short name of lowercase letters, digits and underscores, starting with a letter.
valuesobject[]The values for %1, %2 and so on.
Returns
- TSelf
This conversation, for chaining.
Examples
talk.Line("ask").Accept(then => then.Line("thanks")).Decline()
Named(string)
Names the line just before it, so its localization key is the talk or quest id plus this name rather than a number. Translators then see what the line is, and adding lines elsewhere never moves its key.
public TSelf Named(string name)
Parameters
namestringA short name of lowercase letters, digits and underscores, starting with a letter.
Returns
- TSelf
This conversation, for chaining.
Examples
talk.Say("Got any boards?").Named("ask")
PlayerSay(string, params object[])
A line in the player's speech bubble, with values filled in the same way as Say(string, params object[]).
public TSelf PlayerSay(string text, params object[] values)
Parameters
Returns
- TSelf
This conversation, for chaining.
RunCode(Action)
Runs your code at this point in the conversation. A throw is logged and ends the conversation.
public TSelf RunCode(Action action)
Parameters
actionActionThe code to run.
Returns
- TSelf
This conversation, for chaining.
RunExpression(string)
Runs one of the game's script expressions at this point in the conversation, such as AddRep("npc_larry", 5)
or $money += 50, the way the game's own conversations do. It runs against the NPC being talked to, so
@name reads a value on them. A typo fails when the talk or quest is added.
public TSelf RunExpression(string expression)
Parameters
expressionstringThe game expression.
Returns
- TSelf
This conversation, for chaining.
Say(string, params object[])
A line in the NPC's speech bubble. The text can hold the game's placeholders %1, %2 and so on, filled from
values in order. A value that is a Func<object> is worked out when the line
shows, so it can reflect what an earlier step changed.
public TSelf Say(string text, params object[] values)
Parameters
Returns
- TSelf
This conversation, for chaining.
Examples
Func<object> carried = () => TimbnItems.CountOnPlayer("flitch");
talk.Say("You have %1 boards.", carried);
SayAs(string, string)
A line spoken by another NPC, skipped with a warning when that NPC is not in the world.
public TSelf SayAs(string npcId, string text)
Parameters
npcIdstringThe other NPC, from TimbnGameIds.Npcs, such as TimbnGameIds.Npcs.Herm.
textstringThe line.
Returns
- TSelf
This conversation, for chaining.
Take(string, int)
Takes an item from the player's inventory and bags, as many as they have up to the count. Check first with When(Func<bool>, Action<TimbnLines>, Action<TimbnLines>?) and TimbnItems.CountOnPlayer when the player has to have enough.
public TSelf Take(string itemId, int count = 1)
Parameters
Returns
- TSelf
This conversation, for chaining.
WaitRealSeconds(float)
A pause before the next step, in real seconds.
public TSelf WaitRealSeconds(float seconds)
Parameters
secondsfloatHow long to pause.
Returns
- TSelf
This conversation, for chaining.
When(Func<bool>, Action<TimbnLines>, Action<TimbnLines>?)
Plays one set of lines or another, picked by the game's state when the conversation reaches it.
public TSelf When(Func<bool> condition, Action<TimbnLines> then, Action<TimbnLines>? otherwise = null)
Parameters
conditionFunc<bool>Whether
thenplays.thenAction<TimbnLines>The lines when the condition is true.
otherwiseAction<TimbnLines>The lines when it is false. Leave it out to play nothing.
Returns
- TSelf
This conversation, for chaining.
Examples
talk.When(() => TimbnClock.TimeOfDay > 0.75f,
then => then.Say("Bit late for visitors."),
otherwise => otherwise.Say("Lovely morning."))
When(string, Action<TimbnLines>, Action<TimbnLines>?)
Plays one set of lines or another, picked by one of the game's script expressions when the conversation
reaches it, such as $money >= 500. It runs against the NPC being talked to. See
When(Func<bool>, Action<TimbnLines>, Action<TimbnLines>?).
public TSelf When(string expression, Action<TimbnLines> then, Action<TimbnLines>? otherwise = null)
Parameters
expressionstringThe game expression, true for
then.thenAction<TimbnLines>The lines when it is true.
otherwiseAction<TimbnLines>The lines when it is false. Leave it out to play nothing.
Returns
- TSelf
This conversation, for chaining.