Table of Contents

Class FoodType

Namespace
TinyLife.Skills
Assembly
Tiny Life.dll

A food type is a type of dish that can be cooked using GetIngredientsSingle. Food types store information such as their name and texture, but also the cooking level that is required to make them. Whether a food type has a custom Microsoft.Xna.Framework.Graphics.Texture is based on its FoodType.ContainerType, but most foods use the GetCustomFurnitureTextures(ModInfo) and are loaded as as "FoodName". Food types are registered using Register(FoodType).

[JsonConverter(typeof(MigratingStaticJsonConverter<FoodType>), new object[] { typeof(FoodType), "PrivateTypes", true })]
public class FoodType : GenericDataHolder, IGenericDataHolder, IEmotionSource
Inheritance
GenericDataHolder
FoodType
Implements
IGenericDataHolder
Inherited Members
GenericDataHolder.GetDataKeys()
Extension Methods

Constructors

FoodType(string, int, int, float, FoodRestriction, IngredientSource, Color?)

Creates a new food type with the given settings.

public FoodType(string name, int requiredSkillLevel, int price, float saturationModifier, FoodType.FoodRestriction restrictions, FoodType.IngredientSource source = null, Color? color = null)

Parameters

name string

The food type's name.

requiredSkillLevel int

The required skill level for the RequiredSkill.

price int

The price to prepare this food type.

saturationModifier float

A factor that determines how saturating this food type should be based on the default saturation value. As a reference, Mac and Cheese has a factor of 1, whereas Fish and Chips has a factor of 1.5.

restrictions FoodType.FoodRestriction

A set of FoodType.FoodRestriction flags that determine what things this food item contains that people might be intolerant to.

source FoodType.IngredientSource

The FoodType.IngredientSource that this food type can be created in, defaults to Fridge. Also causes RequiredSkilla nd Container to be set.

color Color?

The color that this food type should display with, or null to use Microsoft.Xna.Framework.Color.White.

Fields

AllRestrictions

All of the defined FoodType.FoodRestriction flag values.

public static readonly FoodType.FoodRestriction[] AllRestrictions

Field Value

FoodRestriction[]

Color

The color that this food type should display with.

public readonly Color Color

Field Value

Color

Name

This food type's name

public readonly string Name

Field Value

string

Price

The default price that creating this food type has. Use GetPrice(PersonLike, int, float, out float, out float?) to get the price for a given serving size as well as the modified, final price.

public readonly int Price

Field Value

int

RequiredSkillLevel

The level of the RequiredSkill that is required to prepare this dish

public readonly int RequiredSkillLevel

Field Value

int

Restrictions

A set of FoodType.FoodRestriction flags that determine what things this food item contains that people might be intolerant to.

public readonly FoodType.FoodRestriction Restrictions

Field Value

FoodType.FoodRestriction

SaturationModifier

A factor that determines how saturating this food type should be based on the default saturation value. As a reference, Mac and Cheese has a factor of 1, whereas Fish and Chips has a factor of 1.5.

public readonly float SaturationModifier

Field Value

float

Sources

A set of FoodType.IngredientSource objects that determine where this food type can be created.

public readonly ISet<FoodType.IngredientSource> Sources

Field Value

ISet<FoodType.IngredientSource>

Types

All of the FoodType instances that are registered by the game and mods

public static readonly ReadOnlyDictionary<string, FoodType> Types

Field Value

ReadOnlyDictionary<string, FoodType>

Properties

AdditionalObject

An object category that dictates an additional object that is required for this food type to be created. For default actions, the categories Stove and Oven are supported. If this is not set, a Fridge food will not be cooked or baked.

public ObjectCategory AdditionalObject { get; init; }

Property Value

ObjectCategory

CanCreateFunc

An optional ActionType.CanExecuteDelegate-style function that allows passing additional conditions to CanCreate(ActionInfo, bool, int, float, bool). If this is null, which is the default value, no additional checks are done in CanCreate(ActionInfo, bool, int, float, bool).

public Func<(ActionInfo Info, bool Automatic, int ServingSize, float PriceMarkup), CanExecuteResult> CanCreateFunc { get; init; }

Property Value

Func<(ActionInfo Info, bool Automatic, int ServingSize, float PriceMarkup), CanExecuteResult>

CanEatFunc

An optional ActionType.CanExecuteDelegate-style function that allows passing additional conditions to CanEat(PersonLike, FoodTypedItem, bool). If this is null, which is also the default value, no additional checks are done in CanEat(PersonLike, FoodTypedItem, bool).

public Func<(PersonLike Person, FoodTypedItem Food, bool Automatic), CanExecuteResult> CanEatFunc { get; init; }

Property Value

Func<(PersonLike Person, FoodTypedItem Food, bool Automatic), CanExecuteResult>

CanHaveCandle

A function that returns whether the given instance of this FoodType can have a candle added to it.

public Func<Food, bool> CanHaveCandle { get; init; }

Property Value

Func<Food, bool>

Container

The FoodType.ContainerType that this food type should be stored in.

public FoodType.ContainerType Container { get; init; }

Property Value

FoodType.ContainerType

CustomTextureFunc

A function that can optionally return a custom texture to be used for the given serving size.

public Func<int, TextureRegion> CustomTextureFunc { get; init; }

Property Value

Func<int, TextureRegion>

DisplayName

This food type's Name, but localized using Food

public string DisplayName { get; }

Property Value

string

Icon

An icon that can optionally be displayed with the food type.

public TextureRegion Icon { get; init; }

Property Value

TextureRegion

OnEaten

An optional action that is invoked when this food object has been eaten. This method is called if the underlying Action is completed after a sufficient amount of time, so the food item has not necessarily been fully finished when this action is invoked. This action is invoked in InvokeOnEaten(ActionInfo, FoodTypedItem).

public Action<ActionInfo, FoodTypedItem> OnEaten { get; init; }

Property Value

Action<ActionInfo, FoodTypedItem>

RequiredSkill

The SkillType required for this food type, which is linked to the RequiredSkillLevel. This value defaults to the Cooking skill.

public SkillType RequiredSkill { get; init; }

Property Value

SkillType

SourceString

A (localized) string that is displayed when hovering over an EmotionModifier that has this source

public string SourceString { get; }

Property Value

string

Methods

CanCreate(ActionInfo, bool, int, float, bool)

Returns a CanExecuteResult indicating whether an item with this food type can be created in some way. This method also invokes CanCreateFunc, checks against GetPrice(PersonLike, int, float, out float, out float?) and checks for an object with the AdditionalObject category.

public CanExecuteResult CanCreate(ActionInfo info, bool automatic, int servingSize, float priceMarkup, bool onlyCheckPrice = false)

Parameters

info ActionInfo

The action info.

automatic bool

Whether the action is invoked automatically.

servingSize int

The serving size that is being created.

priceMarkup float

A price markup that should be passed to GetPrice(PersonLike, int, float, out float, out float?).

onlyCheckPrice bool

Whether only the price should be checked and additional conditions, like the AdditionalObject should be ignored.

Returns

CanExecuteResult

A CanExecuteResult indicating whether this food item can be created.

CanEat(PersonLike, FoodTypedItem, bool)

Returns a CanExecuteResult indicating whether a FoodTypedItem that has this food type can currently be eaten. This method also invokes CanEatFunc and checks for matching Restrictions.

public CanExecuteResult CanEat(PersonLike person, FoodTypedItem food, bool automatic)

Parameters

person PersonLike

The person trying to eat this food item.

food FoodTypedItem

The food item.

automatic bool

Whether the action is invoked automatically.

Returns

CanExecuteResult

A CanExecuteResult indicating whether this food item can be eaten.

Construct(Map, Quality, TimeSpan, int, PersonLike, Guid?, bool)

Constructs a new Food furniture instance based on this food type's FoodType.ContainerType. Note that the returned item won't be added to the map automatically.

public Food Construct(Map map, Quality quality, TimeSpan expirationTime, int servingSize, PersonLike creator = null, Guid? id = null, bool triggerGoals = true)

Parameters

map Map

The map

quality Quality

The quality that the food should have, which also affects the FoodLeft

expirationTime TimeSpan

The in-game time that the resulting food should expire at. This should be based on Time.

servingSize int

The serving size

creator PersonLike

An optional id of a PersonLike that created this food item

id Guid?

An optional id to give to the Food instance returned

triggerGoals bool

Whether AutoGoalInfo goals should be triggered in SetCreator(PersonLike, bool)

Returns

Food

A new food instance with the given settings

ConstructUnfinished(FurnitureType, Map, TimeSpan, int, PersonLike, Guid?, bool)

Constructs a new FoodTypedItem furniture instance based on the passed FurnitureType Note that the returned item won't be added to the map automatically.

public FoodTypedItem ConstructUnfinished(FurnitureType container, Map map, TimeSpan expirationTime, int servingSize, PersonLike creator = null, Guid? id = null, bool triggerGoals = false)

Parameters

container FurnitureType

The FurnitureType that an instance of should be returned, has to construct a FoodTypedItem

map Map

The map

expirationTime TimeSpan

The in-game time that the resulting food should expire at. This should be based on Time.

servingSize int

The serving size

creator PersonLike

An optional PersonLike that created this food item

id Guid?

An optional id to give to the Food instance returned

triggerGoals bool

Whether AutoGoalInfo goals should be triggered in SetCreator(PersonLike, bool)

Returns

FoodTypedItem

CreateBaked(string, int, int, float, FoodRestriction, bool, params IngredientSource[])

Helper method that creates a simple baked FoodType, which includes a set of sub-textures that are drawn when pieces or slices have been taken from it, as well as the ability to have a candle on it if it is a cake and no slices have been taken yet.

public static FoodType CreateBaked(string name, int requiredCookingLevel, int price, float saturationModifier, FoodType.FoodRestriction restrictions, bool cake = false, params FoodType.IngredientSource[] additionalSources)

Parameters

name string

The food type's name.

requiredCookingLevel int

The required skill level for the Cooking skill.

price int

The price to prepare this food type.

saturationModifier float

A factor that determines how saturating this food type should be based on the default saturation value. As a reference, Mac and Cheese has a factor of 1, whereas Fish and Chips has a factor of 1.5.

restrictions FoodType.FoodRestriction

A set of FoodType.FoodRestriction flags that determine what things this food item contains that people might be intolerant to.

cake bool

Whether the item is a cake, which causes it to be able to have candles and slices.

additionalSources IngredientSource[]

A set of additional values to add to the Sources collection.

Returns

FoodType

GetAllContainers(bool, bool)

Returns all of the FoodType.ContainerType furniture types that any registered food types will be stored in, based on the serving size. This method returns a distinct collection of FurnitureType instances representing the FoodType.ContainerType values of all Types.

public static IEnumerable<FurnitureType> GetAllContainers(bool multiple, bool empty = false)

Parameters

multiple bool

Whether the container should hold multiple servings.

empty bool

Whether to return all empty food containers, rather than all full food containers.

Returns

IEnumerable<FurnitureType>

All food containers for the given serving size

GetBuyableVariations(int, ContainerType)

Returns a set of buyable variations for the given servingSize and container, which can be used by furniture through the BuyableVariations field.

public static Action<Furniture>[] GetBuyableVariations(int servingSize, FoodType.ContainerType container)

Parameters

servingSize int

The serving size the buyable variations should be assigned.

container FoodType.ContainerType

The container that buyable variations should be returned for.

Returns

Action<Furniture>[]

The buyable variations of the given container.

GetPossibleArguments(PersonLike, int, IngredientSource, float, SkillType, bool)

Returns a set of action varieties for all FoodType objects that match the given predicate

public static IEnumerable<ActionArgument> GetPossibleArguments(PersonLike person, int servingSize, FoodType.IngredientSource source, float priceMarkup = 1, SkillType requiredSkill = null, bool onlyCheckPrice = false)

Parameters

person PersonLike

The person executing the actions.

servingSize int

The serving size that should be served when using the variety

source FoodType.IngredientSource

The ingredient source to return actions for

priceMarkup float

The amount that the GetPrice(PersonLike, int, float, out float, out float?) should be multiplied by for display and condition checking.

requiredSkill SkillType

The required skill, or null to use Cooking.

onlyCheckPrice bool

Whether only the price should be checked and additional conditions, like the AdditionalObject should be ignored.

Returns

IEnumerable<ActionArgument>

A set of action varieties representing food types

GetPrice(PersonLike, int, float, out float, out float?)

Returns the price of this food type, based on the amount of servings provided, as well as the OnGetPrice event.

public void GetPrice(PersonLike person, int servingSize, float markup, out float originalPrice, out float? modifiedPrice)

Parameters

person PersonLike

The person to get the price for.

servingSize int

The amount of servings to get the price for

markup float

The price markup multiplier.

originalPrice float

The original price that should be used if modifiedPrice is unset.

modifiedPrice float?

The final price of the item, which is unset if the originalPrice should be used.

GetRestrictionsDescription(bool)

Returns a set of strings that describe this food item's Restrictions. If this item has no restrictions, no strings are returned.

public IEnumerable<string> GetRestrictionsDescription(bool includeIcon = true)

Parameters

includeIcon bool

Whether the restrictions' icons should be included.

Returns

IEnumerable<string>

A set of strings that describe this food item's Restrictions.

GetTexture(int)

Returns the texture region that should be drawn for the given serving size. This method invokes the CustomTextureFunc and, by default, returns GetDefaultTexture(FoodType).

public TextureRegion GetTexture(int servingSize)

Parameters

servingSize int

The serving size to return a texture region for.

Returns

TextureRegion

The texture region to draw.

InvokeOnEaten(ActionInfo, FoodTypedItem)

Invokes this food type's OnEaten event, as well as this Sources' OnEaten events. This method should be called when a significant amount of this item is consumed, but is automatically called in Eat.

public void InvokeOnEaten(ActionInfo info, FoodTypedItem food)

Parameters

info ActionInfo

The eat action's action info.

food FoodTypedItem

The food item being eaten.

Register(FoodType)

Registers a new FoodType with the given settings.

public static FoodType Register(FoodType type)

Parameters

type FoodType

The food type to register.

Returns

FoodType

The passed type, for chaining.

Events

OnFoodEaten

An event that is invoked after a given FoodType's food type is eaten as part of the given Action. This event is invoked at the same time as OnEaten, but for any FoodType. This action is invoked in InvokeOnEaten(ActionInfo, FoodTypedItem).

public static event Action<ActionInfo, FoodTypedItem, FoodType> OnFoodEaten

Event Type

Action<ActionInfo, FoodTypedItem, FoodType>

OnGetPrice

An event that is invoked in GetPrice(PersonLike, int, float, out float, out float?), which can be used to modify the original and final price of a food type.

public static event FoodType.GetPriceDelegate OnGetPrice

Event Type

FoodType.GetPriceDelegate