Table of Contents

Class MultiAction

Namespace
TinyLife.Actions
Assembly
Tiny Life.dll

A multi action is an action that can have different actions executed before and/or after itself. This is quite useful if an action requires a PersonLike to go somewhere to pick up an item etc.

public abstract class MultiAction : Action, IGenericDataHolder
Inheritance
JsonTypeSafeGenericDataHolder
MultiAction
Implements
IGenericDataHolder
Derived
Inherited Members
JsonTypeSafeGenericDataHolder.GetDataKeys()
Extension Methods

Constructors

MultiAction(ActionInfo)

Creates a new typeless action with the given action information.

protected MultiAction(ActionInfo info)

Parameters

info ActionInfo

The information for this action.

MultiAction(ActionType, ActionInfo)

Creates a new action with the given action information.

protected MultiAction(ActionType type, ActionInfo info)

Parameters

type ActionType

The type for this action.

info ActionInfo

The information for this action.

Fields

Handler

The MultiActionHandler that handles the actions created in CreateFirstActions()

[DataMember]
public readonly MultiActionHandler Handler

Field Value

MultiActionHandler

Properties

CurrentStage

The MultiAction.Stage that this multi action is currently in.

[DataMember]
protected MultiAction.Stage CurrentStage { get; }

Property Value

MultiAction.Stage

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 override TimeSpan InProgressTime { get; }

Property Value

TimeSpan

The amount of time that this action has properly been in progress for

MainElapsedTime

The amount of time that has elapsed of this action, excluding the time that Handler took.

[DataMember]
public TimeSpan MainElapsedTime { get; protected set; }

Property Value

TimeSpan

Methods

AndThenInitialize()

Initializes the main action. This method is called after Handler has all completed.

protected virtual void AndThenInitialize()

AndThenIsCompleted()

MultiAction version of IsCompleted(). This method returns whether or not the main action is completed.

protected abstract CompletionType AndThenIsCompleted()

Returns

CompletionType

Whether the main action is completed

AndThenOnCompleted(CompletionType)

MultiAction version of OnCompleted(CompletionType). This method gets called when the main action completes.

protected virtual void AndThenOnCompleted(CompletionType type)

Parameters

type CompletionType

The completion of the main action

AndThenUpdate(GameTime, TimeSpan, float)

MultiAction version of Update(GameTime, TimeSpan, float). This method is called every update frame while the main action is active. By default, only MainElapsedTime is increased.

protected virtual void AndThenUpdate(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

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

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 override bool CanStartNow()

Returns

bool

Whether this action can start now.

CreateFirstActions()

Return a set of actions that should be executed before this action. Even if the yield statement is used, all actions will be collected into a list at the start of this action's invocation. If no action gets returned in this function, this action fails. If the returned set only contains null items, no first actions will be executed.

protected abstract IEnumerable<Action> CreateFirstActions()

Returns

IEnumerable<Action>

A set of actions that should run before this action

CreateLastActions()

Return a set of actions that should be executed after this action. Even if the yield statement is used, all actions will be collected into a list after the main action is finished. If no action gets returned in this function, this action fails. If the returned set only contains null items, no last actions will be executed, which is also this method's default behavior.

protected virtual IEnumerable<Action> CreateLastActions()

Returns

IEnumerable<Action>

A set of actions that should run after this action

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 override sealed void Initialize()

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 override sealed CompletionType IsCompleted()

Returns

CompletionType

The current completion type of this action

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 override sealed void OnCompleted(CompletionType type)

Parameters

type CompletionType

The type that this action completed with

OnFirstUpdate(GameTime, TimeSpan, float)

A method that is invoked in Update(GameTime, TimeSpan, float) every time one of the first actions of this multi action (CreateFirstActions()) is updated.

protected virtual void OnFirstUpdate(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

OnLastUpdate(GameTime, TimeSpan, float)

A method that is invoked in Update(GameTime, TimeSpan, float) every time one of the last actions of this multi action (CreateLastActions()) is updated.

protected virtual void OnLastUpdate(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

PreCompleted(CompletionType)

This method is called in OnCompleted(CompletionType) before AndThenOnCompleted(CompletionType) is called. It will also be called even if AndThenInitialize() has not yet been called.

protected virtual void PreCompleted(CompletionType type)

Parameters

type CompletionType

The completion type.

PreInitialize()

This method is called in Initialize() before CreateFirstActions() is called. By default, it does nothing.

protected virtual void PreInitialize()

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 override sealed 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, 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 override bool Validate(PersonLike person, AppliedMigrations appliedMigrations)

Parameters

person PersonLike

The person that this action belongs to

appliedMigrations AppliedMigrations

The migrations that have been applied so far

Returns

bool

Whether or not the action is still valid (or if it has invalid data)