Table of Contents

Class TimbnBalance

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

Helpers for the game's balance tables. A plugin adds and edits definitions through its Balance property, and this class holds the static pieces around that, like checking whether the balance has loaded and swapping item icons.

public static class TimbnBalance
Inheritance
TimbnBalance
Inherited Members

Properties

Loaded

The balance if the game has loaded it, or null. Unlike GameBalance.Me it never forces a load.

public static GameBalance? Loaded { get; }

Property Value

GameBalance

Methods

Expression(string)

Builds a game expression from a formula the way the balance parses its own, for an expression field such as ItemDef.onUseExpressions, ExpressionGameRes.expression or CraftDef.onCraftEndExpressions. Unlike new LazyExpression(formula), a #perk or $resource reference in it works, so TimbnBalance.Expression("20+2*$food_eng_buff") reads the player's food buff.

public static LazyExpression Expression(string formula)

Parameters

formula string

The formula, for example AddPerk("buff_talent_blue_1") or 3+2*#perk_cook_2.

Returns

LazyExpression

The expression.

Exceptions

ArgumentException

The formula is empty.

GetIcon(ItemDef)

Reads an item's custom icon, or its iconId when it has none. Save it before SetIcon(ItemDef, string) to put the icon back later.

public static string GetIcon(ItemDef item)

Parameters

item ItemDef

The item.

Returns

string

The sprite name the item is drawn with.

SetIcon(ItemDef, string)

Changes an item's icon to any sprite the game has, or one added with the plugin's Sprites.AddPng. It sets the item's iconId and also its custom icon, so the two always match.

public static void SetIcon(ItemDef item, string iconId)

Parameters

item ItemDef

The item to change.

iconId string

The sprite name.

Examples

var original = "";
Balance.Edit<ItemDef>(
    "fish_roach",
    fish => { original = TimbnBalance.GetIcon(fish); TimbnBalance.SetIcon(fish, "timbn_roach"); },
    fish => TimbnBalance.SetIcon(fish, original));

TextExpression(string)

Builds a game expression that holds a plain text value, for a field that names an id but is typed as an expression, such as WGODef.replaceToWgoOnDie, WGODef.customAssetId or CraftDef.customCraftResultIcon. The game stores those as pure string values, and new LazyExpression("grave_top_stn_1") would try to evaluate the id as a formula and come out empty.

public static LazyExpression TextExpression(string value)

Parameters

value string

The text, usually an id.

Returns

LazyExpression

An expression that evaluates to the text.