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, 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
stringThe food type's name.
requiredSkillLevel
intThe required skill level for the RequiredSkill.
price
intThe price to prepare this food type.
saturationModifier
floatA 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.FoodRestrictionA set of FoodType.FoodRestriction flags that determine what things this food item contains that people might be intolerant to.
source
FoodType.IngredientSourceThe 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
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
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<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
info
ActionInfoThe action info.
automatic
boolWhether the action is invoked automatically.
servingSize
intThe serving size that is being created.
priceMarkup
floatA price markup that should be passed to GetPrice(PersonLike, int, float, out float, out float?).
onlyCheckPrice
boolWhether 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
PersonLikeThe person trying to eat this food item.
food
FoodTypedItemThe food item.
automatic
boolWhether 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
MapThe map
quality
QualityThe quality that the food should have, which also affects the FoodLeft
expirationTime
TimeSpanThe in-game time that the resulting food should expire at. This should be based on Time.
servingSize
intThe serving size
creator
PersonLikeAn optional id of a PersonLike that created this food item
id
Guid?An optional id to give to the Food instance returned
triggerGoals
boolWhether 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
FurnitureTypeThe FurnitureType that an instance of should be returned, has to construct a FoodTypedItem
map
MapThe map
expirationTime
TimeSpanThe in-game time that the resulting food should expire at. This should be based on Time.
servingSize
intThe serving size
creator
PersonLikeAn optional PersonLike that created this food item
id
Guid?An optional id to give to the Food instance returned
triggerGoals
boolWhether AutoGoalInfo goals should be triggered in SetCreator(PersonLike, bool)
Returns
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
stringThe food type's name.
requiredCookingLevel
intThe required skill level for the Cooking skill.
price
intThe price to prepare this food type.
saturationModifier
floatA 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.FoodRestrictionA set of FoodType.FoodRestriction flags that determine what things this food item contains that people might be intolerant to.
cake
boolWhether 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
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
boolWhether the container should hold multiple servings.
empty
boolWhether 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
intThe serving size the buyable variations should be assigned.
container
FoodType.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
person
PersonLikeThe person executing the actions.
servingSize
intThe serving size that should be served when using the variety
source
FoodType.IngredientSourceThe ingredient source to return actions for
priceMarkup
floatThe amount that the GetPrice(PersonLike, int, float, out float, out float?) should be multiplied by for display and condition checking.
requiredSkill
SkillTypeonlyCheckPrice
boolWhether 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
PersonLikeThe person to get the price for.
servingSize
intThe amount of servings to get the price for
markup
floatThe price markup multiplier.
originalPrice
floatThe 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
boolWhether 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
intThe 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
ActionInfoThe eat action's action info.
food
FoodTypedItemThe food item being eaten.
Register(FoodType)
Registers a new FoodType with the given settings.
public static FoodType Register(FoodType type)
Parameters
type
FoodTypeThe 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
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