Table of Contents

Class TimbnWorld

Namespace
Timbn.GraveyardKeeperTwo.Core.Framework
Assembly
Timbn.GraveyardKeeperTwo.Core.dll

Finds things in the loaded world, such as the walkable ground of a scene or the objects near a spot, and reads how the world is doing, such as the graveyard, church and town scores, the town's gratitude and the weather. A mod that uses the navigation graph needs its own reference to AstarPathfindingProject.dll from the game's Managed folder.

public static class TimbnWorld
Inheritance
TimbnWorld
Inherited Members

Properties

ChurchQuality

The church's quality score, the one the sermon window shows by the cross, or 0 at the main menu. A sermon draws no more parishioners than this.

public static float ChurchQuality { get; }

Property Value

float

Examples

if (TimbnWorld.ChurchQuality >= 100f)
    Logger.LogInfo("The church is looking fine.");

GraveyardBounds

The whole graveyard as seen from above, its paths and grass as well as the ground built on, as one rectangle of x and z. It stays the same however much is built. Empty at the main menu.

public static Rect GraveyardBounds { get; }

Property Value

Rect

Examples

var bounds = TimbnWorld.GraveyardBounds;
var spot = new Vector3(Random.Range(bounds.xMin, bounds.xMax), 0f, Random.Range(bounds.yMin, bounds.yMax));

GraveyardBuiltAreas

The graveyard's ground as seen from above, one rectangle of x and z for each graveyard module built, the area whose graves count toward GraveyardQuality. It grows as the graveyard does. Empty at the main menu.

public static IReadOnlyList<Rect> GraveyardBuiltAreas { get; }

Property Value

IReadOnlyList<Rect>

Examples

var inGraveyard = TimbnWorld.GraveyardBuiltAreas.Any(area => area.Contains(new Vector2(spot.x, spot.z)));

GraveyardQuality

The graveyard's quality score, the one the save slot and the graveyard's own info show, or 0 at the main menu.

public static float GraveyardQuality { get; }

Property Value

float

Examples

var visitors = Mathf.RoundToInt(TimbnWorld.GraveyardQuality / 25f);

IsRaining

Whether it is raining, in any of the game's rain weathers from a drizzle to a thunderstorm.

public static bool IsRaining { get; }

Property Value

bool

Examples

if (TimbnWorld.IsRaining)
    Logger.LogInfo("Bring an umbrella.");

Scenes

The scenes of the loaded world, each holding its world objects, zones, and the items on its ground. Empty at the main menu.

public static IReadOnlyList<GameSceneData> Scenes { get; }

Property Value

IReadOnlyList<GameSceneData>

TownGratitude

The town's gratitude, which selling to town vendors earns, or 0 at the main menu. A sermon draws as many parishioners as this or ChurchQuality, whichever is lower. Gains stop at TownQuality, but it is not lowered when the town's quality drops.

public static int TownGratitude { get; }

Property Value

int

Examples

var visitors = TimbnWorld.TownGratitude / 5;

TownQuality

The town's quality score, the number by the Town label and the most gratitude the town can have, or 0 at the main menu.

public static int TownQuality { get; }

Property Value

int

Examples

var full = TimbnWorld.TownGratitude >= TimbnWorld.TownQuality;

Weather

The weather right now, by the game's own name for it, such as CleanWeather, RainDayWeak or RainDayStorm, or empty at the main menu.

public static string Weather { get; }

Property Value

string

Examples

var stormy = TimbnWorld.Weather is "RainDayStorm" or "RainDayThunder";

Methods

Extensions(WgoData)

The world objects attached to a station, such as the ones built into its slots or a tool rack built next to it, read from the links the game keeps on the station and saves with it.

public static IReadOnlyList<WgoData> Extensions(WgoData station)

Parameters

station WgoData

The station.

Returns

IReadOnlyList<WgoData>

A copy of the list. Empty when nothing is attached or at the main menu.

Examples

var stands = TimbnWorld.Extensions(machine).Where(wgo => wgo.id == "timbn_infusion_stand").ToList();

FindAll(string)

Every world object of one definition in the loaded save, such as every sawhorse, in every scene, read from the game's own by id cache rather than by walking every scene.

public static IReadOnlyList<WgoData> FindAll(string definitionId)

Parameters

definitionId string

The definition's id from the balance, such as sawhorse, or an NPC's id from TimbnGameIds.Npcs.

Returns

IReadOnlyList<WgoData>

A copy of the list, so objects can be removed while looping it. Empty when there are none or at the main menu.

Examples

var hasSawhorse = TimbnWorld.FindAll("sawhorse").Count > 0;

FlatDistance(Vector3, Vector3)

The distance between two spots as seen from above, ignoring height.

public static float FlatDistance(Vector3 first, Vector3 second)

Parameters

first Vector3

One spot.

second Vector3

The other spot.

Returns

float

The flat distance in world units.

GravesWithBodies()

Every grave in the graveyard with a body buried in it, whether or not it has a stone or a fence. Open graves and graves left empty after an exhumation are not counted.

public static IEnumerable<WgoData> GravesWithBodies()

Returns

IEnumerable<WgoData>

The graves. Empty at the main menu or when nobody is buried yet.

Examples

var graves = TimbnWorld.GravesWithBodies().ToList();
npc.Face(graves[0].Position);

Near(Vector3, float, Func<WgoData, bool>?)

Lists the world objects in the player's scene within a flat distance of a spot, nearest first. World objects are everything placed in the world, such as chests, stations, graves, NPCs, and zombies.

public static List<WgoData> Near(Vector3 position, float radius, Func<WgoData, bool>? match = null)

Parameters

position Vector3

The spot to measure from.

radius float

How far to look, in world units, measured flat as seen from above.

match Func<WgoData, bool>

Which objects to keep. Leave it out to keep all of them.

Returns

List<WgoData>

The matching objects, nearest first. Empty at the main menu.

Examples

var chests = TimbnWorld.Near(TimbnPlayer.Position, 5f, wgo => wgo.Inventory != null);

Objects(Func<WgoData, bool>?)

Every world object in the loaded save, in every scene, loaded around the player or not. World objects are everything placed in the world, such as chests, stations, graves, NPCs, and zombies. It walks every scene, so use FindAll(string) when the definition id is known.

public static IEnumerable<WgoData> Objects(Func<WgoData, bool>? match = null)

Parameters

match Func<WgoData, bool>

Which objects to keep. Leave it out to keep all of them.

Returns

IEnumerable<WgoData>

The matching objects, scene by scene. Empty at the main menu.

Examples

foreach (var station in TimbnWorld.Objects(wgo => wgo.CraftComponent != null))
    station.CraftComponent.ResetCraftsFromBalanceCache();

Point(string)

A point the game placed in a scene, the spots its people walk to and stand at, such as donkey_04 on the road by the graveyard. A point has a position, a facing and an enabled flag, and its id is the same string the Npcs module takes. The ids are listed in info_dump's points catalog.

public static GDPointData? Point(string id)

Parameters

id string

The point's id.

Returns

GDPointData

The point, or null when no point has that id or at the main menu.

Examples

var road = TimbnWorld.Point("donkey_04")?.Position;

PointsWithTag(string)

Every point carrying a custom tag, for a set of spots the game marks the same way, such as the two seats each church pew adds with the tag parishioner_bench_point. Disabled points are included, so check Enabled when that matters.

public static GDPointData[] PointsWithTag(string customTag)

Parameters

customTag string

The tag, as the game spells it.

Returns

GDPointData[]

The points, empty when none carry the tag or at the main menu.

Examples

var seats = TimbnWorld.PointsWithTag("parishioner_bench_point").Where(seat => seat.Enabled);

RunningCraft(WgoData)

The id of the craft at the front of a station's queue, running or waiting to start, or null when it has none, for example to check whether a stand started with Crafts.Start is still on "timbn_infusion_stand_infusion".

public static string? RunningCraft(WgoData station)

Parameters

station WgoData

The station.

Returns

string

TryFindWalkable(Vector3, float, out Vector3)

Finds the nearest walkable ground to a spot in the player's scene, measured flat as seen from above, so a spot on a roof or under the floor still finds the ground below or above it.

public static bool TryFindWalkable(Vector3 point, float range, out Vector3 ground)

Parameters

point Vector3

The spot to search from.

range float

How far to look, in world units.

ground Vector3

The nearest walkable point, or point when none was found.

Returns

bool

True when walkable ground was found within range.

Examples

if (TimbnWorld.TryFindWalkable(TimbnPlayer.Position, 5f, out var ground))
    TimbnPlayer.TeleportTo(ground);

TryGetNavGraph(string?, out NavGraph)

Gets the navigation graph of a scene, which holds its walkable ground. The game calculates walking paths over it.

public static bool TryGetNavGraph(string? sceneId, out NavGraph graph)

Parameters

sceneId string

The scene's id, or null for the scene the player is in.

graph NavGraph

The scene's graph, or null when there is none.

Returns

bool

True when the scene has a graph.

ViewOf(WgoData)

The view of a world object, the GameObject that draws it, or null when its chunk is not loaded around the player. The view is what the game's windows and effects work with, such as opening a station's window.

public static Wgo? ViewOf(WgoData data)

Parameters

data WgoData

The world object.

Returns

Wgo

Its view, or null when it has none right now.

Examples

foreach (var zombie in TimbnZombies.All())
    TimbnWorld.ViewOf(zombie)?.DrawWidgets();

ZonesAt(Vector3, GameSceneData?)

The zones a spot lies in, smallest first, read from the scene's data so it works for a scene that is not loaded around the player. Zones can nest, so a spot in a room is also in the building around it.

public static List<WorldZoneData> ZonesAt(Vector3 position, GameSceneData? scene = null)

Parameters

position Vector3

The spot to look at.

scene GameSceneData

The scene to look in. Leave it out for the scene the player is in.

Returns

List<WorldZoneData>

The zones containing the spot, smallest first. Empty when it is in none or at the main menu.

Examples

var zone = TimbnWorld.ZonesAt(TimbnPlayer.Position).FirstOrDefault();