Table of Contents

Class Action

Namespace
TinyLife.Actions
Assembly
Tiny Life.dll

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
JsonTypeSafeGenericDataHolder
Action
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

info ActionInfo

The information for this action.

Action(ActionType, ActionInfo)

Creates a new action with the given action information.

protected Action(ActionType type, ActionInfo info)

Parameters

type ActionType

The type for this action.

info ActionInfo

The information for this action.

Fields

ForceResult

This value can be set to a CompletionType to force IsCompleted() to return it. This is useful if there is an erroring calculation in your Update(GameTime, TimeSpan, float) code, for example.

protected CompletionType? ForceResult

Field Value

CompletionType?

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

Guid

Info

The ActionInfo for this action that contains the clicked (or otherwise targeted) objects and more

[DataMember]
public readonly ActionInfo Info

Field Value

ActionInfo

Random

A Random instance that can be used by actions. This value has the default seed.

public static readonly Random Random

Field Value

Random

Type

The ActionType that this action instance derives from

[DataMember]
public readonly ActionType Type

Field Value

ActionType

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

TimeSpan

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 is true if InProgressTime is greater than Zero.

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 true 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

Action

Person

The Person that this action is being executed by

public PersonLike Person { get; }

Property Value

PersonLike

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). 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

bool

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

bool

Methods

CanCancel(Action)

Returns whether or not this action can be canceled by the given outside source. Note that the outside source can be null, and if it is, it means that the player canceled the action manually. By default, actions can only be canceled if the cancelSource is null.

public virtual bool CanCancel(Action cancelSource)

Parameters

cancelSource Action

The source of the cancelation, or null if the player canceled it

Returns

bool

true if the action can be canceled

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 SleepAction returns false on this method.

public virtual bool CanEnqueueConversation(PersonLike person, ActionType type)

Parameters

person PersonLike

The person that wants to converse with us.

type ActionType

The 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.

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 bool CanMultitask(Action other)

Parameters

other Action

The action to multi-task with

Returns

bool

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

a1 Action

The first action

a2 Action

The second action

Returns

bool

Whether the two actions can be multi-tasked

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

emotions EmotionType[]

The emotions to cancel based on.

Returns

CompletionType

A completion type based on whether any of the emotions are present.

Exceptions

ArgumentOutOfRangeException

Thrown if the emotions array has no entries.

CausesExtremelyFastSpeed()

Returns true if this action, while it is currently active, should cause the ExtremelyFast 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)

A helper method that returns Completed if the given Need's value is at Max.

public CompletionType CompleteIfNeedFull(NeedType type, PersonLike person = null)

Parameters

type NeedType

The need that should be completed

person PersonLike

The 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

time TimeSpan

The (total!) amount of time after which this action should be completed

efficiencyMatters bool

Whether the person's efficiency modifier (GetEfficiencyModifier(float, ActionInfo, SkillType, float)) should be taken into account for the total time required

skill SkillType

A skill that optionally influences the completion time

levelModifier float

The amount that each skill level should influence the returned time by. Defaults to 0.1.

autoOnly bool

Whether 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

CompletionType

Completed if the time has passed, Active otherwise

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

min TimeSpan

The minimum amount of time after which this action should be completed

max TimeSpan

The maximum amount of time after which this action should be completed

efficiencyMatters bool

Whether the person's efficiency modifier (GetEfficiencyModifier(float, ActionInfo, SkillType, float)) should be taken into account for the total time required

skill SkillType

A skill that optionally influences the completion time

levelModifier float

The amount that each skill level should influence the returned time by. Defaults to 0.1.

autoOnly bool

Whether 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

CompletionType

Completed if the time has passed, Active otherwise

FindAllActionObjects(PersonLike, ActionType, Map, Vector2?)

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)

Parameters

person PersonLike

The person

type ActionType

The action to start

map Map

The map to find objects on.

position Vector2?

The position to focus around when finding action objects.

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)

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 allowBroken = false, bool ignoreVisibility = false)

Parameters

person PersonLike

The person that wants to start the action

categories ObjectCategory

The categories that the furniture should have

objectSpotType FurnitureType

The type of item that an object spot should be available for, or null if this is not required

needsFreeActionSpot bool

Whether or not the furniture returned needs a non-occupied ActionSpot

map Map

The map to find furniture on.

position Vector2?

The position that we should find people around, or null to use the passed person's position

floor float?

The floor to find furniture on.

radius float?

The radius that should be searched for people in, or 32 by default

allowBroken bool

Whether furniture that is Broken can be returned

ignoreVisibility bool

Whether the visibility (IsLotContentVisible(Lot, PersonLike, Map, Vector2?)) of the object should be ignored. Defaults to false.

Returns

IEnumerable<Furniture>

A set of valid furniture

FindAllFreeGround(PersonLike, Map, Vector2?, float?, float?, bool)

A helper method to find a set of all positions on the ground that are currently valid for interaction

public static IEnumerable<(Point Pos, int Floor, Tile Tile)> FindAllFreeGround(PersonLike person, Map map = null, Vector2? position = null, float? floor = null, float? radius = null, bool ignoreVisibility = false)

Parameters

person PersonLike

The person that wants to start the action

map Map

The maps to find ground tiles on.

position Vector2?

The position that the ground should be around, or null to use the person's position

floor float?

The floor to find ground tiles on.

radius float?

The radius that should be searched for ground positions in, or 32 by default

ignoreVisibility bool

Whether the visibility (IsLotContentVisible(Lot, PersonLike, Map, Vector2?)) of the object should be ignored. Defaults to false.

Returns

IEnumerable<(Point Pos, int Floor, Tile Tile)>

A set of valid locations

FindAllFreePeople(PersonLike, ActionType, Map, Vector2?, float?, float?, bool, bool, 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 ignoreNeeds = false, bool needsFreeActionSpot = true)

Parameters

person PersonLike

The person that wants to start the aciton

type ActionType

The type of action we want to start

map Map

The map to find people on.

position Vector2?

The position that we should find people around, or null to use the passed person's position

floor float?

The floor to find people on.

radius float?

The radius that should be searched for people in, or 32 by default

ignoreVisibility bool

Whether the visibility (IsLotContentVisible(Lot, PersonLike, Map, Vector2?)) of the object should be ignored. Defaults to false.

ignoreNeeds bool

Whether the free people's needs should be ignored.

needsFreeActionSpot bool

Whether a free action spot is required on the free people.

Returns

IEnumerable<PersonLike>

A set of valid interaction partners

FindAllFreeWalls<T>(PersonLike, Map, Vector2?, float?, float?, 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) where T : WallLike

Parameters

person PersonLike

The person that wants to start the action

map Map

The map to find walls on.

position Vector2?

The position that the walls should be around, or null to use the person's position

floor float?

The floor to find walsl on.

radius float?

The radius that should be searched for walls in, or 32 by default

ignoreVisibility bool

Whether the visibility (IsLotContentVisible(Lot, PersonLike, Map, Vector2?)) of the object should be ignored. Defaults to false.

Returns

IEnumerable<T>

A set of valid walls

Type Parameters

T

FindFreeFurniture(PersonLike, ObjectCategory, FurnitureType, Map, Vector2?, 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).

public static ActionInfo FindFreeFurniture(PersonLike person, ObjectCategory categories, FurnitureType objectSpotType = null, Map map = null, Vector2? position = null, bool allowBroken = false, bool ignoreVisibility = false)

Parameters

person PersonLike

The person that wants to start the action

categories ObjectCategory

The categories that the furniture, as well as its action spots, should have

objectSpotType FurnitureType

The type of item that an object spot should be available for, or null if this is not required

map Map

The map to find furniture on.

position Vector2?

The position that we should find people around, or null to use the passed person's position

allowBroken bool

Whether furniture that is Broken can be returned

ignoreVisibility bool

Whether the visibility (IsLotContentVisible(Lot, PersonLike, Map, Vector2?)) of the object should be ignored. Defaults to false.

Returns

ActionInfo

An action info for the best furniture, or null if there is none

FindValidActionObjects(PersonLike, ActionType, bool, Map, Vector2?, 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, bool allowInappropriate = false, bool allowInvalid = false)

Parameters

person PersonLike

The person.

type ActionType

The action to start.

automatic bool

Whether the action is considered to start automatically.

map Map

The map to find objects on.

position Vector2?

The position to focus around when finding action objects.

allowInappropriate bool

Whether to ignore the IsInappropriateElsewhere flag.

allowInvalid bool

Whether invalid objects should also be returned.

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

id Guid

The Id of the action to find.

regardGrandchildren bool

Whether 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

T

The 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

regardGrandchildren bool

Whether 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

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

person PersonLike

The person to get the free chair for

deskObject Furniture

The 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

person PersonLike

The person to get the free chairs for

table Furniture

The table that the chairs should be connected to

canSitThisWay Func<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. 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. 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

completion CompletionType

The 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.Misc.SeedSource with those parameteers.

public TimeSpan GetRandomCompletionTime(TimeSpan min, TimeSpan max)

Parameters

min TimeSpan

The minimum amount of time after which this action should be completed

max TimeSpan

The 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

type ActionType

The action type whose varieties to search.

info ActionInfo

The action info.

automatic bool

Whether 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

person PersonLike

The 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

chair Furniture

The chair to get the table spot for

actionSpot ActionSpot

The action spot on the chair to 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()

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

person PersonLike

The first person.

other PersonLike

The second person.

action Action<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 ForceResult 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

type ActionType

The action type to execute.

info ActionInfo

The action info.

Returns

bool

Whether the action is inappropriate here.

IsLotContentVisible(Lot, PersonLike, Map, Vector2?)

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)

Parameters

lot Lot

The lot to query; can be null.

person PersonLike

The person.

map Map

The map to use to query the Lot that the position is on. If this is null, the person's map is used.

position Vector2?

An additional position that should be query if lot is null. If this is null, the person's Position is used instead.

Returns

bool

Whether the lot content on the lot or at the position is 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

child Action

The child that completed.

type CompletionType

The child's completion type.

grandchild bool

Whether 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

type CompletionType

The type that this action completed with

OpenChoicePrompt(ChoicePromptInfo)

Opens a text prompt (OpenTextPrompt(string, Action<string>, Predicate<string>, Rule, string, TextureRegion)) 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

info ChoicePromptInfo

The 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)

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.

public CoveringGroup OpenPlayerPrompt(string title, Predicate<Panel> canFinish, Action<Panel> onFinished, bool canExit, Action<CoveringGroup, Panel> addChildren, TextureRegion portrait = null, float panelWidth = 100)

Parameters

title string

The title that should be displayed in the box, has to be localized if required

canFinish Predicate<Panel>

A function that determines whether the Okay button can be pressed. If the function is null, no button is displayed.

onFinished Action<Panel>

A function that is called once the Okay button is pressed. Can be null.

canExit bool

Whether the user can exit the window without making a decision by clicking the background

addChildren Action<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 canFinish is used.

portrait TextureRegion

The portrait to display. If this is null, the Person's portrait is used.

panelWidth float

The width of the displayed panel. Defaults to 100.

Returns

CoveringGroup

Exceptions

InvalidOperationException

Thrown if this action's Person is not part of the CurrentHousehold.

OpenTextPrompt(string, Action<string>, Predicate<string>, Rule, string, TextureRegion)

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.

public CoveringGroup OpenTextPrompt(string title, Action<string> onFinished, Predicate<string> isNameValid = null, TextField.Rule rule = null, string defaultText = null, TextureRegion portrait = null)

Parameters

title string

The text to display in the prompt

onFinished Action<string>

An action that is executed when the okay button is pressed, which contains the string that was input into the text box

isNameValid Predicate<string>

A function that determines whether the name is valid. If this is null, all text inputs (except an empty string) will be valid.

rule TextField.Rule

A rule to use for the MLEM.Ui.Elements.TextField

defaultText string

The text that should be displayed in the text field by default, or null to display no default text

portrait TextureRegion

The portrait to display. If this is null, the Person's portrait is used.

Returns

CoveringGroup

OpenYesNoPrompt(string, Action, Action, TextureRegion)

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.

public CoveringGroup OpenYesNoPrompt(string title, Action onYes, Action onNo = null, TextureRegion portrait = null)

Parameters

title string

The text to display in the prompt

onYes Action

The action that should be executed when the yes button is pressed

onNo Action

The action that should be executed when the no button is pressed

portrait TextureRegion

The portrait to display. If this is null, the Person's portrait is used.

Returns

CoveringGroup

PickUpAndGoTo(ActionInfo, Func<Furniture, bool>, Func<Furniture, bool>, bool)

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. CanPickUpOrIsHoldingForTarget(ActionInfo, ObjectCategory, Func<Furniture, bool>, 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)

Parameters

info ActionInfo

The action info.

isParentValid Func<Furniture, bool>

A predicate that determines whether the given furniture item is a valid parent.

isItemValid Func<Furniture, bool>

A predicate that determines whether the given furniture item is a valid holdable and carryable item for this purpose.

putDown bool

Whether 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.

Returns

IEnumerable<Action>

The actions to execute to cause this behavior.

PickUpAndGoTo(ActionInfo, ObjectCategory, ObjectCategory, bool)

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. CanPickUpOrIsHoldingForTarget(ActionInfo, ObjectCategory, Func<Furniture, bool>, 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)

Parameters

info ActionInfo

The action info.

expectedParent ObjectCategory

A set of object categories that the goal parent is expected to have.

expectedItem ObjectCategory

A set of object categories that the item to hold and carry is expected to have.

putDown bool

Whether the expectedItem 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.

Returns

IEnumerable<Action>

The actions to execute to cause this behavior.

ResetSpeech()

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

chair Furniture

The chair to sit on

speedMultiplier float

The game speed multiplier, which represents how fast things should happen, which is usually determined by Speed

spot ActionSpot

The 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)

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)

Parameters

time GameTime

The game's current time

speedMultiplier float

The game speed multiplier, which represents how fast things should happen, which is usually determined by Speed

emoteChoices EmoteChoices

The emotes to pick from when displaying emotes

speakStyles SpeakStyle

The speak styles to use for speech sounds, can be a combined flag

totalAmount int

The total amount of emotes to display, defaults to an infinite amount (MaxValue)

minimumSeconds float

The minimum amount of seconds that a speech segment should last.

maximumSeconds float

The maximum amount of seconds that a speech segment should last.

minimumBreakSeconds float

The minimum amount of seconds of break to take between speech segments.

maximumBreakSeconds float

The maximum amount of seconds of break to take between speech segments.

Returns

bool

Whether all emotes were successfully displayed. This method only returns true if totalAmount is less than the default value

SpeakInConversation(PersonLike, GameTime, float, EmoteChoices, SpeakStyle, EmoteChoices?, SpeakStyle?, int, float, float, float, float)

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)

Parameters

partner PersonLike

The partner to speak in conversation with.

time GameTime

The current game time

speedMultiplier float

The game speed multiplier, which represents how fast things should happen, which is usually determined by Speed

emoteChoices EmoteChoices

The emotes to pick from when displaying emotes

speakStyles SpeakStyle

The speak styles to use for speech sounds, can be a combined flag

partnerEmoteChoices EmoteChoices?

The emotes to pick from when displaying emotes for the partner to use, or null to use emoteChoices

partnerSpeakStyles SpeakStyle?

The speak styles for the interaction partner to use, or null to use speakStyles

totalAmount int

The total amount of emotes that should be shown (not per person, but in total)

minimumSeconds float

The minimum amount of seconds that a speech segment should last.

maximumSeconds float

The maximum amount of seconds that a speech segment should last.

minimumBreakSeconds float

The minimum amount of seconds of break to take between speech segments.

maximumBreakSeconds float

The maximum amount of seconds of break to take between speech segments.

Returns

bool

If totalAmount is set, true is returned if the emote back-and-forth is completed

ThinkAlone(GameTime, float, EmoteChoices, float, float, float, float, int)

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)

Parameters

time GameTime

The game's current time

speedMultiplier float

The game speed multiplier, which represents how fast things should happen, which is usually determined by Speed

emoteChoices EmoteChoices

The emotes to pick from when displaying emotes

minimumSeconds float

The minimum amount of seconds that a speech segment should last.

maximumSeconds float

The maximum amount of seconds that a speech segment should last.

minimumBreakSeconds float

The minimum amount of seconds of break to take between speech segments.

maximumBreakSeconds float

The maximum amount of seconds of break to take between speech segments.

totalAmount int

The total amount of emotes to display, defaults to an infinite amount (MaxValue)

Returns

bool

Whether all emotes were successfully displayed. This method only returns true if totalAmount is less than the default value

TryForceResult(CompletionType, CanExecuteResult?, MapObject)

This is an external version of ForceResult which can be called from outside sources, like a BreakableFurniture object. A reason is provided that can be used to decide whether the external object can cause this action to fail. By default, this action sets ForceResult to true and returns true if IgnoreObjectConditions doesn't return true.

public virtual bool TryForceResult(CompletionType result, CanExecuteResult? reason = null, MapObject source = null)

Parameters

result CompletionType

The result to force.

reason CanExecuteResult?

The reason for this action to fail. Can be null.

source MapObject

The object that is trying to force this action to fail. Can be null.

Returns

bool

Whether this action was successfully forced to fail (if returning true, ForceResult should also be set to true).

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

time GameTime

The current game time

passedInGame TimeSpan

The amount of time that has passed, in game time

speedMultiplier float

The game speed multiplier, which represents how fast things should happen, which is usually determined by Speed

Validate(PersonLike)

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)

Parameters

person PersonLike

The person that this action belongs to

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

Event Type

Action.ActionTypeConstructedDelegate