Class FoodType
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
-
GenericDataHolderFoodType
- Implements
-
IGenericDataHolder
- Inherited Members
-
GenericDataHolder.GetDataKeys()
- Extension Methods
Constructors
FoodType(string, int, int, float, FoodRestriction, FoodTime, 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.FoodTime preferredTimes, FoodType.IngredientSource source = null, Color? color = null)
Parameters
namestringThe food type's name.
requiredSkillLevelintThe required skill level for the RequiredSkill.
priceintThe price to prepare this food type.
saturationModifierfloatA 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.
restrictionsFoodType.FoodRestrictionA set of FoodType.FoodRestriction flags that determine what things this food item contains that people might be intolerant to.
preferredTimesFoodType.FoodTimeThe set of FoodType.FoodTime flags that determine when this food is generally eaten. This value is used by the AI to determine which foods should be created based on the time of day.
sourceFoodType.IngredientSourceThe FoodType.IngredientSource that this food type can be created in, defaults to Fridge. Also causes RequiredSkilla nd Container to be set.
colorColor?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
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
PreferredTimes
The set of FoodType.FoodTime flags that determine when this food is generally eaten. This value is used by the AI to determine which foods should be created based on the time of day.
public readonly FoodType.FoodTime PreferredTimes
Field Value
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
RequiredSkillLevel
The level of the RequiredSkill that is required to prepare this dish
public readonly int RequiredSkillLevel
Field Value
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
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
Sources
A set of FoodType.IngredientSource objects that determine where this food type can be created.
public readonly ISet<FoodType.IngredientSource> Sources
Field Value
Types
All of the FoodType instances that are registered by the game and mods
public static readonly ReadOnlyDictionary<string, FoodType> Types
Field Value
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
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
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
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
Container
The FoodType.ContainerType that this food type should be stored in.
public FoodType.ContainerType Container { get; init; }
Property Value
CustomTextureFunc
A function that can optionally return a custom texture to be used for the given serving size.
public Func<string, int, TextureRegion> CustomTextureFunc { get; init; }
Property Value
DisplayName
public string DisplayName { get; }
Property Value
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
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
SourceString
A (localized) string that is displayed when hovering over an EmotionModifier that has this source
public string SourceString { get; }
Property Value
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
infoActionInfoThe action info.
automaticboolWhether the action is invoked automatically.
servingSizeintThe serving size that is being created.
priceMarkupfloatA price markup that should be passed to GetPrice(PersonLike, int, float, out float, out float?).
onlyCheckPriceboolWhether 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
personPersonLikeThe person trying to eat this food item.
foodFoodTypedItemThe food item.
automaticboolWhether 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
mapMapThe map
qualityQualityThe quality that the food should have, which also affects the FoodLeft
expirationTimeTimeSpanThe in-game time that the resulting food should expire at. This should be based on Time.
servingSizeintThe serving size
creatorPersonLikeAn optional id of a PersonLike that created this food item
idGuid?An optional id to give to the Food instance returned
triggerGoalsboolWhether 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
containerFurnitureTypeThe FurnitureType that an instance of should be returned, has to construct a FoodTypedItem
mapMapThe map
expirationTimeTimeSpanThe in-game time that the resulting food should expire at. This should be based on Time.
servingSizeintThe serving size
creatorPersonLikeAn optional PersonLike that created this food item
idGuid?An optional id to give to the Food instance returned
triggerGoalsboolWhether AutoGoalInfo goals should be triggered in SetCreator(PersonLike, bool)
Returns
CreateBaked(string, int, int, float, FoodRestriction, FoodTime, 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 requiredBakingLevel, int price, float saturationModifier, FoodType.FoodRestriction restrictions, FoodType.FoodTime preferredTimes, bool cake = false, params FoodType.IngredientSource[] additionalSources)
Parameters
namestringThe food type's name.
requiredBakingLevelintThe required skill level for the Baking skill.
priceintThe price to prepare this food type.
saturationModifierfloatA 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.
restrictionsFoodType.FoodRestrictionA set of FoodType.FoodRestriction flags that determine what things this food item contains that people might be intolerant to.
preferredTimesFoodType.FoodTimeThe set of FoodType.FoodTime flags that determine when this food is generally eaten. This value is used by the AI to determine which foods should be created based on the time of day.
cakeboolWhether the item is a cake, which causes it to be able to have candles and slices.
additionalSourcesIngredientSource[]A set of additional values to add to the Sources collection.
Returns
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
multipleboolWhether the container should hold multiple servings.
emptyboolWhether 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
servingSizeintThe serving size the buyable variations should be assigned.
containerFoodType.ContainerTypeThe container that buyable variations should be returned for.
Returns
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
personPersonLikeThe person executing the actions.
servingSizeintThe serving size that should be served when using the variety
sourceFoodType.IngredientSourceThe ingredient source to return actions for
priceMarkupfloatThe amount that the GetPrice(PersonLike, int, float, out float, out float?) should be multiplied by for display and condition checking.
requiredSkillSkillTypeonlyCheckPriceboolWhether 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
personPersonLikeThe person to get the price for.
servingSizeintThe amount of servings to get the price for
markupfloatThe price markup multiplier.
originalPricefloatThe original price that should be used if
modifiedPriceis unset.modifiedPricefloat?The final price of the item, which is unset if the
originalPriceshould 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
includeIconboolWhether 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
servingSizeintThe 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
infoActionInfoThe eat action's action info.
foodFoodTypedItemThe food item being eaten.
PlatterTexture(string, int)
A helper method that can be used for CustomTextureFunc to return textures based on whether the food is a single item or a platter. This function expects texture regions to exist of the form "Food{name}Platter" and "Food{name}".
public static TextureRegion PlatterTexture(string name, int servingSize)
Parameters
Returns
- TextureRegion
The texture region to choose.
Register(FoodType)
Registers a new FoodType with the given settings.
public static FoodType Register(FoodType type)
Parameters
typeFoodTypeThe food type to register.
Returns
- FoodType
The passed
type, for chaining.
SlicedTexture(string, int)
A helper method that can be used for CustomTextureFunc to return textures based on whether the food is a single slice, a cut full item, or an uncut full item. This function expects texture regions to exist of the form "Food{name}Slice", "Food{name}Cut", and "Food{name}".
public static TextureRegion SlicedTexture(string name, int servingSize)
Parameters
Returns
- TextureRegion
The texture region to choose.
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
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