Class Action
An action is something that a PersonLike does. An action is always derived from an underlying ActionType that contains various action settings. Actions can be queued up for a person (ActionQueue) or currently active (CurrentActions). To create a more complex action, it is best to extend MultiAction. You can find a multitude of action-related events in PersonLike, like OnActionsCompleted.
[DataContract]
public abstract class Action : JsonTypeSafeGenericDataHolder, IGenericDataHolder
- Inheritance
-
JsonTypeSafeGenericDataHolderAction
- Implements
-
IGenericDataHolder
- Derived
- Inherited Members
-
JsonTypeSafeGenericDataHolder.GetDataKeys()
- Extension Methods
Constructors
Action(ActionInfo)
Creates a new typeless action with the given action information.
protected Action(ActionInfo info)
Parameters
infoActionInfoThe information for this action.
Action(ActionType, ActionInfo)
Creates a new action with the given action information.
protected Action(ActionType type, ActionInfo info)
Parameters
typeActionTypeThe type for this action.
infoActionInfoThe information for this action.
Fields
Id
This action's unique id, which was randomly generated using NewGuid() when this action was constructed. An action's unique id can be used to reference this action in other places, and child actions can be retrieved using GetChildren(bool), GetChild<T>(Guid, bool) or through a Person using GetAction<T>(Guid, bool).
[DataMember]
public readonly Guid Id
Field Value
Info
The ActionInfo for this action that contains the clicked (or otherwise targeted) objects and more
[DataMember]
public readonly ActionInfo Info
Field Value
Migrations
The global set of action migrations, which will be applied to every loaded Action. To register migrations for specific action types only, use Migrations.
public static readonly List<Migration<Action>> Migrations
Field Value
Random
A Random instance that can be used by actions. This value has the default seed.
public static readonly Random Random
Field Value
Type
The ActionType that this action instance derives from
[DataMember]
public readonly ActionType Type
Field Value
Properties
ElapsedTime
The amount of in-game time that has elapsed since this action has started
[DataMember]
public TimeSpan ElapsedTime { get; protected set; }
Property Value
FullyInProgress
Returns whether this action is currently "properly" in progress. This is used by MultiAction and SocialAction and returns true only once the first actions are completed or the conversation has started, respectively. By default, this property always returns true, since regular actions immediately start their main part.
public virtual bool FullyInProgress { get; }
Property Value
- bool
Whether this action is fully in progress
InProgressTime
Represents the amount of time that this action has "properly" been in progress for. This is used by MultiAction and SocialAction and returns a time greater than Zero only once the first actions are completed or the conversation has started, respectively. By default, ElapsedTime is returned.
public virtual TimeSpan InProgressTime { get; }
Property Value
- TimeSpan
The amount of time that this action has properly been in progress for
Parent
The Action that created or otherwise owns this action, which also means this action will be part of the parent's GetChildren(bool). This is nonnull if this action is part of a UnderlyingActionHandler or MultiActionHandler.
public Action Parent { get; }
Property Value
Person
The Person that this action is being executed by
public PersonLike Person { get; }
Property Value
PlayerPromptOpen
A property that stores whether a player prompt is currently open. A prompt can be opened using OpenPlayerPrompt(string, Predicate<Panel>, Action<Panel>, bool, Action<CoveringGroup, Panel>, TextureRegion, float, bool). This property can be used to ensure that an action is not paused or canceled while a player prompt is open, as, based on the implementation of the action, there might be certain update frames that still occur while the prompt is open.
public bool PlayerPromptOpen { get; }
Property Value
StartedAutomatically
If this value is true, this action was started using PersonAi or through another action rather than by the player
[DataMember]
public bool StartedAutomatically { get; }
Property Value
Methods
CanActionInterrupt(Action)
Determines whether the given action can interrupt this action.
If this method returns true, it is usually followed by a call to Interrupt(CompletionType). To call this method effectively, use ActionInterruptAction(Action, Action, CompletionType, bool).
This method returns false by default, and MultiAction returns true only if the main action has not yet started.
public virtual bool CanActionInterrupt(Action action)
Parameters
actionActionThe action trying to interrupt this action.
Returns
- bool
Whether the action can interrupt this action.
CanEnqueueConversation(PersonLike, ActionType)
Returns true if the given person can (automatically) enqueue a social action with the Person that is executing this action.
Note that enqueueing a social action manually is still possible even if this method returns false.
By default, only TinyLife.Actions.SleepAction returns false on this method.
public virtual bool CanEnqueueConversation(PersonLike person, ActionType type)
Parameters
personPersonLikeThe person that wants to converse with us.
typeActionTypeThe type of action that should be enqueued. Might be null, in which case a generic or unknown action is querying this function.
Returns
- bool
Whether or not enqueueing a social action is possible.
CanGenericInterrupt(bool)
Determines whether this action can be interrupted by a generic interruption source. If this method returns true, it is usually followed by a call to Interrupt(CompletionType). To call this method effectively, use GenericInterruptAction(Action, bool, CompletionType, bool). This method returns true by default.
public virtual bool CanGenericInterrupt(bool isPlayer)
Parameters
isPlayerboolWhether the generic interruption source is the player.
Returns
- bool
Whether a generic interruption source can interrupt this action.
CanMultitask(Action)
Return true on this method if this action can be multi-tasked along with the passed Action. To actually check this property, CanMultitask(Action, Action) should be used as it compares both objects. A multi-tasking is an action that is currently active along with another action. By default, multi-tasking is disallowed for any action.
public virtual Action.CanMultitaskResult CanMultitask(Action other)
Parameters
otherActionThe action to multi-task with
Returns
- Action.CanMultitaskResult
Whether this action can be multi-tasked
CanMultitask(Action, Action)
A utility method that can be used whether the two Action instances can currently be invoked together. Internally, this checks if both actions return true on CanMultitask(Action).
public static bool CanMultitask(Action a1, Action a2)
Parameters
Returns
- bool
Whether the two actions can be multi-tasked
CanObjectInterrupt(MapObject, CanExecuteResult)
Determines whether the given source object can interrupt this action.
If this method returns true, it is usually followed by a call to Interrupt(CompletionType).
This method queries its Type's IgnoreObjectConditions by default, and returns true otherwise.
public virtual bool CanObjectInterrupt(MapObject source, CanExecuteResult reason)
Parameters
sourceMapObjectThe object trying to interrupt this action.
reasonCanExecuteResultThe reason the object is trying to interrupt this action for.
Returns
- bool
Whether the object can interrupt this action.
CanStartNow()
Return true on this method if this action can be started right now. This method is queried when this action moves from a person's ActionQueue to their CurrentActions. If this method returns false, it stays in the ActionQueue.
By default, MultiAction overrides this behavior to only allow the action to be started if the Person is not being held, and not currently occupying an action spot that has the Stay flag set.
public virtual bool CanStartNow()
Returns
- bool
Whether this action can start now.
CancelIfEmotional(params EmotionType[])
A helper method that returns Canceled if this action's Person has any of the given emotions, and Active otherwise.
public CompletionType CancelIfEmotional(params EmotionType[] emotions)
Parameters
emotionsEmotionType[]The emotions to cancel based on.
Returns
- CompletionType
A completion type based on whether any of the
emotionsare present.
Exceptions
- ArgumentOutOfRangeException
Thrown if the
emotionsarray has no entries.
CausesExtremelyFastSpeed()
Returns true if this action, while it is currently active, should cause the ExtremelyFast (or ExtremelyFastLimited) speed to be available. By default, this method returns false.
public virtual bool CausesExtremelyFastSpeed()
Returns
- bool
Whether the extremely fast speed should be available
CompleteIfNeedFull(NeedType, PersonLike)
public CompletionType CompleteIfNeedFull(NeedType type, PersonLike person = null)
Parameters
typeNeedTypeThe need that should be completed
personPersonLikeThe PersonLike whose need needs to be full, or null to use this action's Person.
Returns
- CompletionType
The appropriate completion type
CompleteIfTimeUp(TimeSpan, bool, SkillType, float, bool)
A helper method that returns Completed if the given time has passed.
This method makes use of GetEfficiencyModifier(float, ActionInfo, SkillType, float) to return true faster or slower based on the person's current mood and skill levels.
public CompletionType CompleteIfTimeUp(TimeSpan time, bool efficiencyMatters = false, SkillType skill = null, float levelModifier = 0.1, bool autoOnly = false)
Parameters
timeTimeSpanThe (total!) amount of time after which this action should be completed
efficiencyMattersboolWhether the person's efficiency modifier (GetEfficiencyModifier(float, ActionInfo, SkillType, float)) should be taken into account for the total time required
skillSkillTypeA skill that optionally influences the completion time
levelModifierfloatThe amount that each
skilllevel should influence the returned time by. Defaults to 0.1.autoOnlyboolWhether the action should only be completed in the given amount of time if it has been StartedAutomatically. If both this value and StartedAutomatically are true, this method always returns Active.
Returns
CompleteIfTimeUp(TimeSpan, TimeSpan, bool, SkillType, float, bool)
A helper method that returns Completed if a random time calculated using GetRandomCompletionTime(TimeSpan, TimeSpan), based on min and max, has passed.
This method makes use of GetEfficiencyModifier(float, ActionInfo, SkillType, float) to return true faster or slower based on the person's current mood and skill levels.
public CompletionType CompleteIfTimeUp(TimeSpan min, TimeSpan max, bool efficiencyMatters = false, SkillType skill = null, float levelModifier = 0.1, bool autoOnly = false)
Parameters
minTimeSpanThe minimum amount of time after which this action should be completed
maxTimeSpanThe maximum amount of time after which this action should be completed
efficiencyMattersboolWhether the person's efficiency modifier (GetEfficiencyModifier(float, ActionInfo, SkillType, float)) should be taken into account for the total time required
skillSkillTypeA skill that optionally influences the completion time
levelModifierfloatThe amount that each
skilllevel should influence the returned time by. Defaults to 0.1.autoOnlyboolWhether the action should only be completed in the given amount of time if it has been StartedAutomatically. If both this value and StartedAutomatically are true, this method always returns Active.
Returns
FindAllActionObjects(PersonLike, ActionType, Map, Vector2?, float?, float?, bool, bool)
Returns all ActionInfo objects that are available to the given Person for the given ActionType. The objects returned are the ones that would also be considered by the PersonAi when starting an action.
public static IEnumerable<ActionInfo> FindAllActionObjects(PersonLike person, ActionType type, Map map = null, Vector2? position = null, float? floor = null, float? radius = null, bool ignoreVisibility = false, bool allowOffLot = true)
Parameters
personPersonLikeThe person
typeActionTypeThe action to find valid action objects for, which is used for checking CanExecuteAction(ActionType, ActionInfo, bool) and related methods.
mapMapThe map to find objects on.
positionVector2?The position to focus around when finding action objects.
floorfloat?radiusfloat?ignoreVisibilityboolallowOffLotbool
Returns
- IEnumerable<ActionInfo>
A set of action infos that the given action can be started with
FindAllFreeFurniture(PersonLike, ObjectCategory, FurnitureType, bool, Map, Vector2?, float?, float?, bool, bool, Func<Furniture, bool>)
A helper method to find a set of all Furniture instances that are currently valid for interaction with the passed Person, ordered by their priority, where the first entry is the best possible Furniture object.
public static IEnumerable<Furniture> FindAllFreeFurniture(PersonLike person, ObjectCategory categories = null, FurnitureType objectSpotType = null, bool needsFreeActionSpot = true, Map map = null, Vector2? position = null, float? floor = null, float? radius = null, bool ignoreVisibility = false, bool allowOffLot = false, Func<Furniture, bool> predicate = null)
Parameters
personPersonLikeThe person that wants to start the action
categoriesObjectCategoryThe categories that the furniture should have
objectSpotTypeFurnitureTypeThe type of item that an object spot should be available for, or null if this is not required
needsFreeActionSpotboolWhether or not the furniture returned needs a non-occupied ActionSpot
mapMapThe map to find furniture on.
positionVector2?The position that we should find people around, or null to use the passed person's position
floorfloat?The floor to find furniture on.
radiusfloat?The radius that should be searched for people in, or 32 by default
ignoreVisibilityboolWhether the visibility (IsLotContentVisible(Lot, PersonLike, Map, Vector2?, bool)) of the object should be ignored. Defaults to false.
allowOffLotboolWhether objects that aren't on a lot should be considered for inclusion in the returned collection. If
ignoreVisibilityis true, this parameter is ignored, and objects that aren't on a lot are included.predicateFunc<Furniture, bool>A predicate that should be validated before the other conditions are checked. If this is a simple check, it will greatly speed up performance as the other checks can be skipped for invalid objects. If it is a complicated check, consider filtering the objects after they are returned from this method.
Returns
- IEnumerable<Furniture>
A set of valid furniture
FindAllFreeGround(PersonLike, Map, Vector2?, float?, float?, bool, bool)
A helper method to find a set of all positions on the ground that are currently valid for interaction
public static IEnumerable<TileInstance> FindAllFreeGround(PersonLike person, Map map = null, Vector2? position = null, float? floor = null, float? radius = null, bool ignoreVisibility = false, bool allowOffLot = false)
Parameters
personPersonLikeThe person that wants to start the action
mapMapThe maps to find ground tiles on.
positionVector2?The position that the ground should be around, or null to use the
person's positionfloorfloat?The floor to find ground tiles on.
radiusfloat?The radius that should be searched for ground positions in, or 32 by default
ignoreVisibilityboolWhether the visibility (IsLotContentVisible(Lot, PersonLike, Map, Vector2?, bool)) of the object should be ignored. Defaults to false.
allowOffLotboolWhether objects that aren't on a lot should be considered for inclusion in the returned collection. If
ignoreVisibilityis true, this parameter is ignored, and objects that aren't on a lot are included.
Returns
- IEnumerable<TileInstance>
A set of valid locations
FindAllFreePeople(PersonLike, ActionType, Map, Vector2?, float?, float?, bool, bool, bool, bool, Func<PersonLike, bool>)
A helper method to find a set of all Person instances that are currently valid for interaction with the passed Person, ordered by their priority, where the first entry is the best possible Person.
public static IEnumerable<PersonLike> FindAllFreePeople(PersonLike person, ActionType type = null, Map map = null, Vector2? position = null, float? floor = null, float? radius = null, bool ignoreVisibility = false, bool allowOffLot = true, bool ignoreNeeds = false, bool needsFreeActionSpot = true, Func<PersonLike, bool> predicate = null)
Parameters
personPersonLikeThe person that wants to start the aciton
typeActionTypeThe type of action we want to start
mapMapThe map to find people on.
positionVector2?The position that we should find people around, or null to use the passed person's position
floorfloat?The floor to find people on.
radiusfloat?The radius that should be searched for people in, or 32 by default
ignoreVisibilityboolWhether the visibility (IsLotContentVisible(Lot, PersonLike, Map, Vector2?, bool)) of the object should be ignored. Defaults to false.
allowOffLotboolWhether objects that aren't on a lot should be considered for inclusion in the returned collection. If
ignoreVisibilityis true, this parameter is ignored, and objects that aren't on a lot are included.ignoreNeedsboolWhether the free people's needs should be ignored.
needsFreeActionSpotboolWhether a free action spot is required on the free people.
predicateFunc<PersonLike, bool>A predicate that should be validated before the other conditions are checked. If this is a simple check, it will greatly speed up performance as the other checks can be skipped for invalid objects. If it is a complicated check, consider filtering the objects after they are returned from this method.
Returns
- IEnumerable<PersonLike>
A set of valid interaction partners
FindAllFreeWalls<T>(PersonLike, Map, Vector2?, float?, float?, bool, bool)
A helper method to find a set of all WallLike instances that are currently valid for interaction with the passed Person
public static IEnumerable<T> FindAllFreeWalls<T>(PersonLike person, Map map = null, Vector2? position = null, float? floor = null, float? radius = null, bool ignoreVisibility = false, bool allowOffLot = false) where T : WallLike
Parameters
personPersonLikeThe person that wants to start the action
mapMapThe map to find walls on.
positionVector2?The position that the walls should be around, or null to use the
person's positionfloorfloat?The floor to find walsl on.
radiusfloat?The radius that should be searched for walls in, or 32 by default
ignoreVisibilityboolWhether the visibility (IsLotContentVisible(Lot, PersonLike, Map, Vector2?, bool)) of the object should be ignored. Defaults to false.
allowOffLotboolWhether objects that aren't on a lot should be considered for inclusion in the returned collection. If
ignoreVisibilityis true, this parameter is ignored, and objects that aren't on a lot are included.
Returns
- IEnumerable<T>
A set of valid walls
Type Parameters
T
FindFreeFurniture(PersonLike, ObjectCategory, FurnitureType, Map, Vector2?, float?, float?, bool, bool)
A helper method to find the best Furniture instance to interact with based on the given data. Note that this method always returns a ActionInfo related to the first result from FindAllFreeFurniture(PersonLike, ObjectCategory, FurnitureType, bool, Map, Vector2?, float?, float?, bool, bool, Func<Furniture, bool>).
public static ActionInfo FindFreeFurniture(PersonLike person, ObjectCategory categories, FurnitureType objectSpotType = null, Map map = null, Vector2? position = null, float? floor = null, float? radius = null, bool ignoreVisibility = false, bool allowOffLot = false)
Parameters
personPersonLikeThe person that wants to start the action
categoriesObjectCategoryThe categories that the furniture, as well as its action spots, should have
objectSpotTypeFurnitureTypeThe type of item that an object spot should be available for, or null if this is not required
mapMapThe map to find furniture on.
positionVector2?The position that we should find people around, or null to use the passed person's position
floorfloat?The floor to find furniture on.
radiusfloat?The radius that should be searched for people in, or 32 by default
ignoreVisibilityboolWhether the visibility (IsLotContentVisible(Lot, PersonLike, Map, Vector2?, bool)) of the object should be ignored. Defaults to false.
allowOffLotboolWhether objects that aren't on a lot should be considered for inclusion in the returned collection. If
ignoreVisibilityis true, this parameter is ignored, and objects that aren't on a lot are included.
Returns
- ActionInfo
An action info for the best furniture, or null if there is none
FindValidActionObjects(PersonLike, ActionType, bool, Map, Vector2?, float?, float?, bool, bool, bool, bool, bool)
Returns all ActionInfo objects that are available to the given Person for the given ActionType, and whose CanExecuteAction(ActionType, ActionInfo, bool) indicates that the actions are valid for execution. This method also checks IsInappropriateElsewhere.
public static IEnumerable<ActionInfo> FindValidActionObjects(PersonLike person, ActionType type, bool automatic, Map map = null, Vector2? position = null, float? floor = null, float? radius = null, bool ignoreVisibility = false, bool allowOffLot = true, bool allowInappropriate = false, bool allowInvalid = false, bool checkRecentlyFailed = true)
Parameters
personPersonLikeThe person.
typeActionTypeThe action to find valid action objects for, which is used for checking CanExecuteAction(ActionType, ActionInfo, bool) and related methods.
automaticboolWhether the action is considered to start automatically.
mapMapThe map to find objects on.
positionVector2?The position to focus around when finding action objects.
floorfloat?radiusfloat?ignoreVisibilityboolallowOffLotboolallowInappropriateboolWhether to ignore the IsInappropriateElsewhere flag.
allowInvalidboolWhether invalid objects should also be returned, ie objects for which CanExecuteAction(ActionType, ActionInfo, bool) returns false.
checkRecentlyFailedboolWhether potential action objects at which the given
typehas recently failed should be checked for and ignored (causing them to be skipped as part of the returned set of action infos)
Returns
- IEnumerable<ActionInfo>
A set of action infos that the given action can be started with.
GetChild<T>(Guid, bool)
Returns the first child action of this action with the given type T that has the given id id. Child actions are actions that have their Parent set to this action.
Optionally, grandchildren can be included in the search.
public T GetChild<T>(Guid id, bool regardGrandchildren = false) where T : Action
Parameters
idGuidThe Id of the action to find.
regardGrandchildrenboolWhether to include grandchildren, which are children of children, and so on.
Returns
- T
The found child action, or null if there is no child action that matches the given conditions.
Type Parameters
TThe type of child action to find.
GetChildren(bool)
Returns a set of actions that are child actions of this action, which are actions that have their Parent set to this action. Optionally, grandchildren can be included in the returned set.
public IEnumerable<Action> GetChildren(bool regardGrandchildren = false)
Parameters
regardGrandchildrenboolWhether to include grandchildren, which are children of children, and so on.
Returns
- IEnumerable<Action>
The child actions of this action.
GetDisplayName()
Returns a localized string that explains this action in short. By default, this method returns GetDisplayName(ActionInfo, bool).
public virtual string GetDisplayName()
Returns
- string
This action's display name
GetExtraIcon()
Returns an extra icon in the form of a MLEM.Textures.TextureRegion, which, if non-null, will be displayed in the top-right corner of the action in the action queue. By default, this method returns null, and MultiAction returns an interrupted icon if it has been interrupted and is still executing.
public virtual TextureRegion GetExtraIcon()
Returns
- TextureRegion
The extra icon to display in the action queue.
GetFreeChair(PersonLike, Furniture)
A helper method that returns an ActionInfo for a ActionSpot on a Furniture with the Chair category that is closest to the given object which is on a desk or table.
The furniture returned is the one that the person should Sit(Furniture, float, ActionSpot) on when interacting with the passed deskObject.
This method will return the deskObject's parent itself if it is a picnic-style table that has benches directly attached to it.
public static (Furniture Chair, ActionSpot Spot, Direction2 Direction) GetFreeChair(PersonLike person, Furniture deskObject)
Parameters
personPersonLikeThe person to get the free chair for
deskObjectFurnitureThe object that is sat on a desk
Returns
- (Furniture Chair, ActionSpot Spot, Direction2 Direction)
The corresponding chair, ActionSpot and the action spot's rotation, or default if there is none
GetFreeChairs(PersonLike, Furniture, Func<Direction2, bool>)
Returns a set of free chair furniture paired with an ActionSpot and accessible direction.
This method is used by GetFreeChair(PersonLike, Furniture).
This method will return the table itself if it is a picnic-style table that has benches directly attached to it.
public static IEnumerable<(Furniture Chair, ActionSpot Spot, Direction2 Direction)> GetFreeChairs(PersonLike person, Furniture table, Func<Direction2, bool> canSitThisWay = null)
Parameters
personPersonLikeThe person to get the free chairs for
tableFurnitureThe table that the chairs should be connected to
canSitThisWayFunc<Direction2, bool>A function that determines whether a person can sit the given way, or null to allow all seating directions
Returns
- IEnumerable<(Furniture Chair, ActionSpot Spot, Direction2 Direction)>
A set of chairs, their action spots and their seating directions
GetIconObject()
Returns the map object that is displayed in the action queue in the top left of the screen using DrawIcon(Element, GameTime, SpriteBatch). Note that this value is ignored if this action's type has a Texture. By default, the GetActionObject<T>(bool) is returned.
public virtual MapObject GetIconObject()
Returns
- MapObject
The icon object
GetNextAction(CompletionType)
Returns an action that should be queued up immediately after this action completes in any way, including after being interrupted using Interrupt(CompletionType). The queued up action is immediately started in the slot that this action occupied. Can be null, and is null by default.
public virtual Action GetNextAction(CompletionType completion)
Parameters
completionCompletionTypeThe type that this action completed with
Returns
- Action
The follow-up action
GetProgress()
Optionally returns the progress that this action's execution currently exhibits, in a range between 0 and 1. The returned progress will be displayed below the action icon in the top left as a green bar that is expected to fill up slowly as progress is made. Returning an empty value causes no progress bar to be displayed, and is also the default behavior.
public virtual float? GetProgress()
Returns
- float?
This action's progress.
GetRandomCompletionTime(TimeSpan, TimeSpan)
Generates a random completion time for this action based on the min and max times passed.
The returned value will be the same for the same action Id and the same min and max values, as it is generated using a MLEM.Maths.SeedSource with those parameteers.
public TimeSpan GetRandomCompletionTime(TimeSpan min, TimeSpan max)
Parameters
minTimeSpanThe minimum amount of time after which this action should be completed
maxTimeSpanThe maximum amount of time after which this action should be completed
Returns
- TimeSpan
The final amount of time after which this action should be completed.
GetRandomValidArguments(ActionType, ActionInfo, bool)
Attempts to find a random valid action variety from the type's PossibleArguments.
public static ActionArgument[] GetRandomValidArguments(ActionType type, ActionInfo info, bool automatic)
Parameters
typeActionTypeThe action type whose varieties to search.
infoActionInfoThe action info.
automaticboolWhether variety should be selected automatically.
Returns
- ActionArgument[]
A set of action arguments, based on the rules defined in the documentation of PossibleArguments.
GetSeatCategory(PersonLike)
Returns the ObjectCategory that an object needs to have for the given person to be able to sit on it.
This method returns BabySittable for babies, and Chair otherwise.
public static ObjectCategory GetSeatCategory(PersonLike person)
Parameters
personPersonLikeThe person who should sit.
Returns
- ObjectCategory
The object category for seats.
GetTableSpot(Furniture, ActionSpot)
A helper method that returns the ObjectSpot on the table or desk that the given chair is connected to. This is the object spot that should be used for interaction if a person sits on the given chair.
public static (Furniture Table, ObjectSpot Spot) GetTableSpot(Furniture chair, ActionSpot actionSpot = null)
Parameters
chairFurnitureThe chair to get the table spot for
actionSpotActionSpotThe action spot on the
chairto get the table spot for
Returns
- (Furniture Table, ObjectSpot Spot)
The table spot, or null if there is none
Initialize()
This method is called when the action is first started by a Person. Note that it is not called when the action gets added to the ActionQueue, but when it is moved to CurrentActions.
public virtual void Initialize()
Interrupt(CompletionType)
Causes this action to be interrupted due to the given CompletionType. An interrupted action may continue executing under certain conditions, in which case its IsCompleted() method may not yet return the passed completion type. When canceling actions from outside the action itself, GenericInterruptAction(Action, bool, CompletionType, bool) and ActionInterruptAction(Action, Action, CompletionType, bool) should be used instead, as they handle additional cases and query CanGenericInterrupt(bool) and CanActionInterrupt(Action) automatically by default. Additionally, note that this method may be called in certain situations even when CanActionInterrupt(Action), CanGenericInterrupt(bool) and CanObjectInterrupt(MapObject, CanExecuteResult) all return false, which should be taken into account by implementors.
public virtual void Interrupt(CompletionType completion)
Parameters
completionCompletionTypeThe completion type to interrupt the action with.
InvokeForBoth(PersonLike, PersonLike, Action<PersonLike, PersonLike>)
Invokes the given action for two people while passing both of them, first as the main, and then as the second, parameter to the given action.
public static void InvokeForBoth(PersonLike person, PersonLike other, Action<PersonLike, PersonLike> action)
Parameters
personPersonLikeThe first person.
otherPersonLikeThe second person.
actionAction<PersonLike, PersonLike>The action to invoke for both people passed.
IsCompleted()
This method is called every update frame by a Person if this action is currently active to check if it should be stopped. If this returns a result other than Completed, OnCompleted(CompletionType) will be called and the action is stopped. By default, only the default behavior of Interrupt(CompletionType) modifies the completion type, otherwise Active is returned.
public virtual CompletionType IsCompleted()
Returns
- CompletionType
The current completion type of this action
IsInappropriate(ActionType, ActionInfo)
Checks whether the given action type is inappropriate for execution using the given info.
The return value is based on IsInappropriateElsewhere and the Lot.
public static bool IsInappropriate(ActionType type, ActionInfo info)
Parameters
typeActionTypeThe action type to execute.
infoActionInfoThe action info.
Returns
- bool
Whether the action is inappropriate here.
IsLotContentVisible(Lot, PersonLike, Map, Vector2?, bool)
Returns whether the given content of the given lot is currently visible to the given person.
If the lot is null, then comparisons are made to the lot at the given position.
public static bool IsLotContentVisible(Lot lot, PersonLike person, Map map = null, Vector2? position = null, bool allowOffLot = false)
Parameters
lotLotThe lot to query; can be null.
personPersonLikeThe person.
mapMapThe map to use to query the Lot that the
positionis on. If this is null, theperson's map is used.positionVector2?An additional position that should be query if
lotis null. If this is null, theperson's Position is used instead.allowOffLotboolWhether objects that aren't on a lot should be considered visible.
Returns
- bool
Whether the lot content on the
lotor at thepositionis visible.
OnChildCompleted(Action, CompletionType, bool)
This method is invoked automatically when an action completes that is marked as this action's child. A child action is one started through a MultiActionHandler or UnderlyingActionHandler. By default, this method calls OnChildCompleted(Action, CompletionType, bool) on this action's Parent, if there is one.
protected virtual void OnChildCompleted(Action child, CompletionType type, bool grandchild)
Parameters
childActionThe child that completed.
typeCompletionTypeThe child's completion type.
grandchildboolWhether the given child is a grandchild, rather than a direct child.
OnCompleted(CompletionType)
This method is called when this action IsCompleted(), or if it is canceled from an outside source. Note that, if this method is called as a result of IsCompleted(), the CompletionType passed will be the same. By default, only OnActionCompleted(Action, CompletionType, bool) is called.
public virtual void OnCompleted(CompletionType type)
Parameters
typeCompletionTypeThe type that this action completed with
OpenChoicePrompt(ChoicePromptInfo)
Opens a text prompt (OpenTextPrompt(string, Action<string>, Predicate<string>, Rule, string, bool, int?, TextureRegion, Action<CoveringGroup, Panel>)) that uses the ChoicePromptInfo system to display a set of options to the player, one of which is randomly chosen to be "correct", causing a positive effect to happen.
public CoveringGroup OpenChoicePrompt(ChoicePromptInfo info)
Parameters
infoChoicePromptInfoThe choice prompt information to display.
Returns
- CoveringGroup
The CoveringGroup that contains the choice prompt.
OpenPlayerPrompt(string, Predicate<Panel>, Action<Panel>, bool, Action<CoveringGroup, Panel>, TextureRegion, float, bool)
Opens a prompt for the player with the given elements, also pausing the game. This behavior is used for things like the QuitJob action, where a confirmation panel pops up. To check whether a player prompt is currently opened, see PlayerPromptOpen. For additional action information that can be selected not just by players, but also by the AI, see ActionArgument. Note that, if this action's Person is not part of the CurrentHousehold, no player prompt is opened and null is returned.
public CoveringGroup OpenPlayerPrompt(string title, Predicate<Panel> canFinish, Action<Panel> onFinished, bool canExit, Action<CoveringGroup, Panel> addChildren, TextureRegion portrait = null, float panelWidth = 100, bool scrollOverflow = true)
Parameters
titlestringThe title that should be displayed in the box, has to be localized if required
canFinishPredicate<Panel>A function that determines whether the Okay button can be pressed. If the function is null, no button is displayed.
onFinishedAction<Panel>A function that is called once the Okay button is pressed. Can be null.
canExitboolWhether the user can exit the window without making a decision by clicking the background
addChildrenAction<CoveringGroup, Panel>A function that should be used to add elements that should be displayed in this prompt, along with the title and possibly the Okay button if
canFinishis used.portraitTextureRegionThe portrait to display. If this is null, the Person's portrait is used.
panelWidthfloatThe width of the displayed panel. Defaults to 100.
scrollOverflowbool
Returns
- CoveringGroup
The opened player prompt's CoveringGroup, or null if this action's Person is not part of the CurrentHousehold.
OpenStackableItemSelectionPrompt<T>(string, IEnumerable<Stackable<T>>, Predicate<List<Stackable<T>>>, Action<List<Stackable<T>>>, bool, Func<Stackable<T>, string>, Func<Stackable<T>, TextureRegion>, TextureRegion, Action<CoveringGroup, Panel, List<Stackable<T>>>)
public CoveringGroup OpenStackableItemSelectionPrompt<T>(string title, IEnumerable<Stackable<T>> items, Predicate<List<Stackable<T>>> canFinish, Action<List<Stackable<T>>> onFinished, bool canExit, Func<Stackable<T>, string> itemDisplayName, Func<Stackable<T>, TextureRegion> itemTexture = null, TextureRegion portrait = null, Action<CoveringGroup, Panel, List<Stackable<T>>> addChildren = null)
Parameters
titlestringitemsIEnumerable<Stackable<T>>canFinishPredicate<List<Stackable<T>>>onFinishedAction<List<Stackable<T>>>canExitboolitemDisplayNameFunc<Stackable<T>, string>itemTextureFunc<Stackable<T>, TextureRegion>portraitTextureRegionaddChildrenAction<CoveringGroup, Panel, List<Stackable<T>>>
Returns
Type Parameters
T
OpenTextPrompt(string, Action<string>, Predicate<string>, Rule, string, bool, int?, TextureRegion, Action<CoveringGroup, Panel>)
Opens a prompt with a text box that allows the player to input a string. To check whether a player prompt is currently opened, see PlayerPromptOpen. For additional action information that can be selected not just by players, but also by the AI, see ActionArgument. Note that, if this action's Person is not part of the CurrentHousehold, no player prompt is opened and null is returned.
public CoveringGroup OpenTextPrompt(string title, Action<string> onFinished, Predicate<string> isNameValid, TextField.Rule rule = null, string defaultText = null, bool multiline = false, int? maxCharacters = null, TextureRegion portrait = null, Action<CoveringGroup, Panel> addChildren = null)
Parameters
titlestringThe text to display in the prompt
onFinishedAction<string>An action that is executed when the okay button is pressed, which contains the string that was input into the text box
isNameValidPredicate<string>A function that determines whether the give name, which may be an empty string, is valid.
ruleTextField.RuleA rule to use for the MLEM.Ui.Elements.TextField
defaultTextstringThe text that should be displayed in the text field by default, or null to display no default text
multilineboolWhether the text box should be multiline rather than a single line. Multiline input allows newline characters to be included, and makes the box bigger.
maxCharactersint?The maximum amount of characters that can be input into the text box.
portraitTextureRegionThe portrait to display. If this is null, the Person's portrait is used.
addChildrenAction<CoveringGroup, Panel>A function that should be used to add additional elements that should be displayed in this prompt.
Returns
- CoveringGroup
The opened player prompt's CoveringGroup, or null if this action's Person is not part of the CurrentHousehold.
OpenYesNoPrompt(string, Action, Action, TextureRegion, Action<CoveringGroup, Panel>)
Opens a prompt for the player that contains a yes and a no button along with some text. This prompt can be used to ensure that a player selected the right option in an important decision. To check whether a player prompt is currently opened, see PlayerPromptOpen. For additional action information that can be selected not just by players, but also by the AI, see ActionArgument. Note that, if this action's Person is not part of the CurrentHousehold, no player prompt is opened and null is returned.
public CoveringGroup OpenYesNoPrompt(string title, Action onYes, Action onNo = null, TextureRegion portrait = null, Action<CoveringGroup, Panel> addChildren = null)
Parameters
titlestringThe text to display in the prompt
onYesActionThe action that should be executed when the yes button is pressed
onNoActionThe action that should be executed when the no button is pressed
portraitTextureRegionThe portrait to display. If this is null, the Person's portrait is used.
addChildrenAction<CoveringGroup, Panel>A function that should be used to add additional elements that should be displayed in this prompt.
Returns
- CoveringGroup
The opened player prompt's CoveringGroup, or null if this action's Person is not part of the CurrentHousehold.
PickUpAndGoTo(ActionInfo, Func<Furniture, bool>, Func<Furniture, bool>, bool, int?, IEnumerable<ActionType>)
A helper method that returns a set of actions which cause the info's Person to set up a holdable item on an expected parent object in such a way that interacting with it is possible afterwards. This utility method is used for actions like Eat, where it is desired that a person picks up a food item from a counter and brings it to a table, if required.
ActionType.CanPickUpOrIsHoldingForTarget(TinyLife.Actions.ActionInfo,TinyLife.Objects.ObjectCategory,System.Func<TinyLife.Objects.Furniture,bool>,System.Nullable<TinyLife.Actions.CanExecuteResult>,bool,bool) provides a ActionType.CanExecuteDelegate equivalent to this method.
public static IEnumerable<Action> PickUpAndGoTo(ActionInfo info, Func<Furniture, bool> isParentValid, Func<Furniture, bool> isItemValid, bool putDown = true, int? radius = null, IEnumerable<ActionType> checkRecentlyFailedActions = null)
Parameters
infoActionInfoThe action info.
isParentValidFunc<Furniture, bool>A predicate that determines whether the given furniture item is a valid parent.
isItemValidFunc<Furniture, bool>A predicate that determines whether the given furniture item is a valid holdable and carryable item for this purpose.
putDownboolWhether the holdable item should be put down. If this is false, the person will only go to the goal location, but not put the item down on it.
radiusint?The radius that should be searched for applicable destinations in, or 32 by default
checkRecentlyFailedActionsIEnumerable<ActionType>An optional set of action types for which to check Person.HasRecentlyFailed on potential parent objects to find.
Returns
- IEnumerable<Action>
The actions to execute to cause this behavior.
PickUpAndGoTo(ActionInfo, ObjectCategory, ObjectCategory, bool, int?, IEnumerable<ActionType>)
A helper method that returns a set of actions which cause the info's Person to set up a holdable item on an expected parent object in such a way that interacting with it is possible afterwards. This utility method is used for actions like Eat, where it is desired that a person picks up a food item from a counter and brings it to a table, if required.
ActionType.CanPickUpOrIsHoldingForTarget(TinyLife.Actions.ActionInfo,TinyLife.Objects.ObjectCategory,System.Func<TinyLife.Objects.Furniture,bool>,System.Nullable<TinyLife.Actions.CanExecuteResult>,bool,bool) provides a ActionType.CanExecuteDelegate equivalent to this method.
public static IEnumerable<Action> PickUpAndGoTo(ActionInfo info, ObjectCategory expectedParent, ObjectCategory expectedItem, bool putDown = true, int? radius = null, IEnumerable<ActionType> checkRecentlyFailedActions = null)
Parameters
infoActionInfoThe action info.
expectedParentObjectCategoryA set of object categories that the goal parent is expected to have.
expectedItemObjectCategoryA set of object categories that the item to hold and carry is expected to have.
putDownboolWhether the
expectedItemshould be put down. If this is false, the person will only go to the goal location, but not put the item down on it.radiusint?The radius that should be searched for applicable destinations in, or 32 by default
checkRecentlyFailedActionsIEnumerable<ActionType>An optional set of action types for which to check Person.HasRecentlyFailed on potential parent objects to find.
Returns
- IEnumerable<Action>
The actions to execute to cause this behavior.
ResetSpeech()
Resets speech for this action's Person, including causing them to stop speaking and emoting, and resetting the timer used by SpeakAlone(GameTime, float, EmoteChoices?, SpeakStyle, int, float, float, float, float, EmoteBubbleType?), SpeakInConversation(PersonLike, GameTime, float, EmoteChoices?, SpeakStyle, EmoteChoices?, SpeakStyle?, int, float, float, float, float, EmoteBubbleType?, EmoteBubbleType?) and ThinkAlone(GameTime, float, EmoteChoices, float, float, float, float, int, EmoteBubbleType?).
public void ResetSpeech()
Sit(Furniture, float, ActionSpot)
A helper method that causes the Person to sit on the given object. This method causes the action spot to be occupied and the person's CurrentPose to be changed to Sitting. Additionally, the Energy need is restored a little bit. Note that this method has to be called every Update(GameTime, TimeSpan, float) frame for the person to stay sat down.
public bool Sit(Furniture chair, float speedMultiplier, ActionSpot spot = null)
Parameters
chairFurnitureThe chair to sit on
speedMultiplierfloatThe game speed multiplier, which represents how fast things should happen, which is usually determined by Speed
spotActionSpotThe action spot to sit on, or null to select one automatically
Returns
- bool
Whether or not the chair can be sat on
SpeakAlone(GameTime, float, EmoteChoices?, SpeakStyle, int, float, float, float, float, EmoteBubbleType?)
Displays emotes for this action's Person with the given settings as if they were talking to themselves out loud. This is used by actions like PracticeJokes and PracticeSpeech.
public bool SpeakAlone(GameTime time, float speedMultiplier, EmoteChoices? emoteChoices, SpeakStyle speakStyles, int totalAmount = 2147483647, float minimumSeconds = 1, float maximumSeconds = 3, float minimumBreakSeconds = -0.5, float maximumBreakSeconds = 1, EmoteBubbleType? type = null)
Parameters
timeGameTimeThe game's current time
speedMultiplierfloatThe game speed multiplier, which represents how fast things should happen, which is usually determined by Speed
emoteChoicesEmoteChoices?The emotes to pick from when displaying emotes
speakStylesSpeakStyleThe speak styles to use for speech sounds, can be a combined flag
totalAmountintThe total amount of emotes to display, defaults to an infinite amount (MaxValue)
minimumSecondsfloatThe minimum amount of seconds that a speech segment should last.
maximumSecondsfloatThe maximum amount of seconds that a speech segment should last.
minimumBreakSecondsfloatThe minimum amount of seconds of break to take between speech segments.
maximumBreakSecondsfloatThe maximum amount of seconds of break to take between speech segments.
typeEmoteBubbleType?The emote bubble type to use. If this is null, the bubble is a speech bubble if
speakStylesis supplied, and a thought bubble otherwise.
Returns
- bool
Whether all emotes were successfully displayed. This method only returns true if
totalAmountis less than the default value
SpeakInConversation(PersonLike, GameTime, float, EmoteChoices?, SpeakStyle, EmoteChoices?, SpeakStyle?, int, float, float, float, float, EmoteBubbleType?, EmoteBubbleType?)
Helper method to display emotes over each conversation partner in a back and forth fashion to make it seem like they are conversing. When used in SocialAction, only the action that IsMain should call this method.
public bool SpeakInConversation(PersonLike partner, GameTime time, float speedMultiplier, EmoteChoices? emoteChoices, SpeakStyle speakStyles, EmoteChoices? partnerEmoteChoices = null, SpeakStyle? partnerSpeakStyles = null, int totalAmount = 2147483647, float minimumSeconds = 1, float maximumSeconds = 3, float minimumBreakSeconds = -0.5, float maximumBreakSeconds = 1, EmoteBubbleType? type = null, EmoteBubbleType? partnerType = null)
Parameters
partnerPersonLikeThe partner to speak in conversation with.
timeGameTimeThe current game time
speedMultiplierfloatThe game speed multiplier, which represents how fast things should happen, which is usually determined by Speed
emoteChoicesEmoteChoices?The emotes to pick from when displaying emotes
speakStylesSpeakStyleThe speak styles to use for speech sounds, can be a combined flag
partnerEmoteChoicesEmoteChoices?The emotes to pick from when displaying emotes for the
partnerto use, or null to useemoteChoicespartnerSpeakStylesSpeakStyle?The speak styles for the interaction partner to use, or null to use
speakStylestotalAmountintThe total amount of emotes that should be shown (not per person, but in total)
minimumSecondsfloatThe minimum amount of seconds that a speech segment should last.
maximumSecondsfloatThe maximum amount of seconds that a speech segment should last.
minimumBreakSecondsfloatThe minimum amount of seconds of break to take between speech segments.
maximumBreakSecondsfloatThe maximum amount of seconds of break to take between speech segments.
typeEmoteBubbleType?The emote bubble type to use. If this is null, the bubble is a speech bubble if
speakStylesis supplied, and a thought bubble otherwise.partnerTypeEmoteBubbleType?The emote bubble type to use for the
partner. If this is null, the bubble is a speech bubble ifpartnerSpeakStylesis supplied, and a thought bubble otherwise.
Returns
- bool
If
totalAmountis set, true is returned if the emote back-and-forth is completed
ThinkAlone(GameTime, float, EmoteChoices, float, float, float, float, int, EmoteBubbleType?)
Displays thought bubbles for this action's Person with the given settings as if they were thinking to themselves. This is used by actions like Sleep.
public bool ThinkAlone(GameTime time, float speedMultiplier, EmoteChoices emoteChoices, float minimumSeconds = 1, float maximumSeconds = 3, float minimumBreakSeconds = 0.5, float maximumBreakSeconds = 2, int totalAmount = 2147483647, EmoteBubbleType? type = null)
Parameters
timeGameTimeThe game's current time
speedMultiplierfloatThe game speed multiplier, which represents how fast things should happen, which is usually determined by Speed
emoteChoicesEmoteChoicesThe emotes to pick from when displaying emotes
minimumSecondsfloatThe minimum amount of seconds that a speech segment should last.
maximumSecondsfloatThe maximum amount of seconds that a speech segment should last.
minimumBreakSecondsfloatThe minimum amount of seconds of break to take between speech segments.
maximumBreakSecondsfloatThe maximum amount of seconds of break to take between speech segments.
totalAmountintThe total amount of emotes to display, defaults to an infinite amount (MaxValue)
typeEmoteBubbleType?The emote bubble type to use. If this is null, the bubble is a thought bubble.
Returns
- bool
Whether all emotes were successfully displayed. This method only returns true if
totalAmountis less than the default value
Update(GameTime, TimeSpan, float)
This method is called every update frame if this action is currently active. By default, only the ElapsedTime is modified in this method and ActionUpdate(Action, GameTime, TimeSpan, float, bool) is called.
public virtual void Update(GameTime time, TimeSpan passedInGame, float speedMultiplier)
Parameters
timeGameTimeThe current game time
passedInGameTimeSpanThe amount of time that has passed, in game time
speedMultiplierfloatThe game speed multiplier, which represents how fast things should happen, which is usually determined by Speed
Validate(PersonLike, AppliedMigrations)
Validates this action's data. This is called when a map is loaded from disk. When returning false on this method, the action is removed from the Person.
public virtual bool Validate(PersonLike person, AppliedMigrations appliedMigrations)
Parameters
personPersonLikeThe person that this action belongs to
appliedMigrationsAppliedMigrationsThe migrations that have been applied so far
Returns
- bool
Whether or not the action is still valid (or if it has invalid data)
Events
OnActionTypeConstructed
An event that is invoked when an ActionType instance is constructed using the private constructor invoked in Register(TypeSettings). This event can be used to modify the ActionType.TypeSettings of the Action type before they are made readonly.
public static event Action.ActionTypeConstructedDelegate OnActionTypeConstructed