Class TimbnCraftBuilder
Describes a craft for the plugin's Crafts.Add, with where it runs, what it takes in and what it makes. The craft is copied from one of the game's own, the woodworking bench's wooden plank unless BasedOn(string) names another, so it starts with everything the game expects and the builder changes only what differs. What is not set stays the template's, so a craft that only calls Needs(string, int) and Makes(string, int) keeps the template's station, work time and energy. The exceptions are the unlock, since a craft is open from the start whatever the template did unless NeedsUnlock() or UnlockedBy(string) is called, and the template's rewards. A copy gives no tech points unless TechPoints(int, int, int) sets them, and leaves out the template's linked perks and what it does when it finishes, such as berry_pie unlocking its next tech.
public sealed class TimbnCraftBuilder
- Inheritance
-
TimbnCraftBuilder
- Inherited Members
Examples
Four sticks from a board at the Stick Box, and a plank from sticks that needs the pillar next to it.
Crafts.Add("timbn_stick_box_sticks", "Sticks from a Board", "Split one board into 4 sticks.", craft => craft
.In(box)
.Needs("flitch")
.Makes("stick", 4));
Crafts.Add("timbn_stick_box_magic_plank", "Plank from Sticks", "The red pillar binds 4 sticks back into a plank.", craft => craft
.In(box)
.NeedsExtension("timbn_red_magic")
.Needs("stick", 4)
.Makes("wooden_plank"));
Methods
AutoFinish()
Lets a craft at a station that runs itself finish on its own, dropping what it made next to the station and starting the next craft in the queue. Without it the station waits for the player to take the result, the way the kitchen oven does.
public TimbnCraftBuilder AutoFinish()
Returns
BasedOn(string)
The game craft the new one is copied from, "wooden_plank" by default. Pick a craft from the station the new one runs at to inherit its work time, energy and tab, for example "cook_baked_fish" for a smoked fish at an oven like station.
public TimbnCraftBuilder BasedOn(string craftId)
Parameters
craftIdstringThe game craft's id.
Returns
DurationTicks(int)
How long the craft takes in work ticks, swings of the tool at a bench worked by hand or the station's own tick at one that runs itself (10 seconds each at the kitchen oven). The template's otherwise, 4 for the wooden plank.
public TimbnCraftBuilder DurationTicks(int ticks)
Parameters
ticksintThe number of ticks.
Returns
Edit(Action<CraftDef>)
Changes anything else on the craft's definition after Core has filled it in, for example its tabId.
public TimbnCraftBuilder Edit(Action<CraftDef> edit)
Parameters
editAction<CraftDef>Runs on the copy each time the balance loads.
Returns
EnergyPerTick(int)
How much energy each work tick costs the player. The template's otherwise, 2 for the wooden plank.
public TimbnCraftBuilder EnergyPerTick(int energy)
Parameters
energyintEnergy per tick.
Returns
Hidden()
Leaves the craft out of the station's craft window and draws no progress over the station while it runs, for a craft only code starts with Crafts.Start.
public TimbnCraftBuilder Hidden()
Returns
Icon(string)
The icon the craft window shows for the craft, instead of the icon of what it makes. Any sprite the game has, or one added with the plugin's Sprites.AddEmbeddedPng.
public TimbnCraftBuilder Icon(string spriteId)
Parameters
spriteIdstringThe sprite name.
Returns
In(string)
A station the craft runs at, the game's own such as "kitchen_oven" or "woodworking_workbench_1", or one added with Stations.Add. Call it once per station. The first call replaces the template's stations. Whether the craft runs on its own follows the station, so a craft at the kitchen oven cooks by itself and one at a bench is worked by hand.
public TimbnCraftBuilder In(string stationId)
Parameters
stationIdstringThe station's world object id.
Returns
In(TimbnStation)
A station added with Stations.Add that the craft runs at. See In(string).
public TimbnCraftBuilder In(TimbnStation station)
Parameters
stationTimbnStationThe station.
Returns
Makes(string, int)
What the craft makes. Call it once per item. The first call replaces the template's output.
public TimbnCraftBuilder Makes(string itemId, int count = 1)
Parameters
Returns
Makes(string, string)
What the craft makes, with its count as one of the game's expressions, for example "3+2*#perk_cook_2" for a perk that adds two.
public TimbnCraftBuilder Makes(string itemId, string count)
Parameters
Returns
Mastery(int)
The mastery level the player or zombie needs in the station's talent to work the craft, which the player gets from the tool on their belt. The template's otherwise, 2 for the wooden plank, so Mastery(1) lets any tool work it.
public TimbnCraftBuilder Mastery(int level)
Parameters
levelintThe level, 1 or more.
Returns
Needs(string, int)
An item the craft takes in. Call it once per item. The first call replaces the template's items.
public TimbnCraftBuilder Needs(string itemId, int count = 1)
Parameters
Returns
Needs(string, string)
An item the craft takes in, with its count as one of the game's expressions, for example "10-5*#perk_heat_saver" for firewood that a perk saves on. A count that doesn't parse fails here, when the plugin loads.
public TimbnCraftBuilder Needs(string itemId, string count)
Parameters
Returns
Needs(params (string Item, int Count)[])
Several items the craft takes in at once, for example ("fillet_fish_river", 1), ("firewood", 1).
public TimbnCraftBuilder Needs(params (string Item, int Count)[] items)
Parameters
Returns
NeedsExtension(string)
Makes the craft run only while this bench extension is attached to the station, the game's "tool_rack" or one added with Stations.AddExtension. The craft window shows it in that extension's row.
public TimbnCraftBuilder NeedsExtension(string extensionId)
Parameters
extensionIdstringThe extension's world object id.
Returns
NeedsUnlock()
Keeps the craft hidden until the save unlocks it, by a tech that lists it in craftsAfterUnlock or by TimbnPlayer.UnlockCraft. A craft is open from the start otherwise.
public TimbnCraftBuilder NeedsUnlock()
Returns
OnFinished(Action<TimbnCraftEvent>)
Runs the handler each time the craft finishes at a station, as the game finishes it, once per unit of a craft with a count above one. A craft that fails while finishing doesn't raise it. The handler is undone when the plugin unloads, and one that throws is logged without stopping the craft.
public TimbnCraftBuilder OnFinished(Action<TimbnCraftEvent> handler)
Parameters
handlerAction<TimbnCraftEvent>Told the station and the craft's id.
Returns
Examples
Pay a tech point to every seated zombie when the teaching craft ends.
Crafts.Add("timbn_teach", "Teach", "Teaches every seated zombie.", craft => craft
.In(machine)
.OnFinished(done => PayZombies(done.Station)));
OnStarted(Action<TimbnCraftEvent>)
Runs the handler each time the craft starts at a station, which is when its ingredients are taken, for a timed craft as well as an instant one. A craft with a count above one starts once per unit. The handler is undone when the plugin unloads, and one that throws is logged without stopping the craft.
public TimbnCraftBuilder OnStarted(Action<TimbnCraftEvent> handler)
Parameters
handlerAction<TimbnCraftEvent>Told the station and the craft's id.
Returns
Requires(Func<WgoData, bool>)
Lets the craft start at a station only while the check passes for that station, for a condition the game has no field for. Until it passes the craft window's Start button stays gray and a queued craft waits, the way they do for a missing ingredient, and a craft already running carries on. The game asks again whenever it looks at the craft, so keep the check quick. A second call adds another check that must pass too. A check that throws is logged once and counts as passing. The check is undone when the plugin unloads.
public TimbnCraftBuilder Requires(Func<WgoData, bool> check)
Parameters
Returns
Examples
A lesson that only starts while a stand in the machine's slots holds a zombie.
Crafts.Add("timbn_lesson", "Lesson", "Teaches the zombies on the stands.", craft => craft
.In(machine)
.Requires(station => TimbnWorld.Extensions(station).Any(stand => TimbnZombies.AtStation(stand) != null)));
Exceptions
- ArgumentNullException
The check is null.
TechPoints(int, int, int)
The tech points the craft pays when it finishes, none otherwise whatever the template paid.
public TimbnCraftBuilder TechPoints(int red, int green, int blue)
Parameters
Returns
UnlockedBy(string)
Has a technology grant the craft, the way "cooking_pastries" grants the muffin and the croissant. The tech's tooltip lists the craft, researching the tech unlocks it, and a save that already has the tech gets it as soon as it loads. The craft stays hidden until then, so this includes NeedsUnlock(). The tech is put back when the plugin unloads, and a tech the game doesn't have is logged.
public TimbnCraftBuilder UnlockedBy(string techId)
Parameters
techIdstringThe technology's id.