MultiAction - Ellpeck/TinyLifeExampleMod Wiki

Tiny Life

TinyLife.Actions

MultiAction Class

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 Person to go somewhere to pick up an item etc.

public abstract class MultiAction : TinyLife.Actions.Action

Inheritance System.Object 🡒 MLEM.Misc.GenericDataHolder 🡒 Action 🡒 MultiAction

Derived
GetAndSitDownAction
GoHereAction
OutOfTownAction
SellAction
SinkAction
SitAction
WatchTvAction
WorkAtDeskObjectAction

Constructors

MultiAction.MultiAction(ActionType, ActionInfo) Constructor

Creates a new action from the given ActionType

public MultiAction(TinyLife.Actions.ActionType type, TinyLife.Actions.ActionInfo info);

Parameters

type ActionType
The type to create this action from

info ActionInfo
The information for this action

Properties

MultiAction.FirstActions Property

The actions that should be executed beore this action

public System.Collections.Generic.Queue<TinyLife.Actions.Action> FirstActions { get; set; }

Property Value

System.Collections.Generic.Queue<Action>

MultiAction.MainElapsedTime Property

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

public System.TimeSpan MainElapsedTime { get; set; }

Property Value

System.TimeSpan

MultiAction.NextActions Property

The actions that should be executed after this action

protected System.Collections.Generic.Queue<TinyLife.Actions.Action> NextActions { get; set; }

Property Value

System.Collections.Generic.Queue<Action>

Methods

MultiAction.AndThenInitialize() Method

Initializes the main action.
This method is called after FirstActions have all completed.

protected abstract void AndThenInitialize();

MultiAction.AndThenIsCompleted() Method

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

protected abstract TinyLife.Actions.Action.CompletionType AndThenIsCompleted();

Returns

CompletionType
Whether the main action is completed

MultiAction.AndThenOnCompleted(CompletionType) Method

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

protected virtual void AndThenOnCompleted(TinyLife.Actions.Action.CompletionType type);

Parameters

type CompletionType
The completion of the main action

MultiAction.AndThenUpdate(GameTime, TimeSpan, GameSpeed) Method

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

protected virtual void AndThenUpdate(Microsoft.Xna.Framework.GameTime time, System.TimeSpan passedInGame, TinyLife.GameSpeed speed);

Parameters

time Microsoft.Xna.Framework.GameTime
The current game time

passedInGame System.TimeSpan
The amount of time that has passed, in game time

speed GameSpeed
The game's speed

MultiAction.CanCancel(Action) Method

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(TinyLife.Actions.Action cancelSource);

Parameters

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

Returns

System.Boolean
true if the action can be canceled

MultiAction.CreateFirstActions() Method

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 a null action is returned as the first item, no first actions will be executed.

protected abstract System.Collections.Generic.IEnumerable<TinyLife.Actions.Action> CreateFirstActions();

Returns

System.Collections.Generic.IEnumerable<Action>
A set of actions that sohuld run before this action

MultiAction.CreateNextActions(CompletionType) Method

Return a set of actions that should be executed after this action.
Can be empty.

protected virtual System.Collections.Generic.IEnumerable<TinyLife.Actions.Action> CreateNextActions(TinyLife.Actions.Action.CompletionType type);

Parameters

type CompletionType
The completion of the main action

Returns

System.Collections.Generic.IEnumerable<Action>
A set of actions after this action

MultiAction.GetInProgressTime() Method

Returns 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 System.TimeSpan GetInProgressTime();

Returns

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

MultiAction.GoToActionLocation(ObjectCategory) Method

A helper method intended to be used with CreateFirstActions() that only returns an instance of TinyLife.Actions.ActionType.GoHere for a ToFreeActionSpot(ObjectCategory)

protected System.Collections.Generic.IEnumerable<TinyLife.Actions.Action> GoToActionLocation(TinyLife.Objects.ObjectCategory context=null);

Parameters

context ObjectCategory
The context that the action spot to go to needs to have. Defaults to Nothing.

Returns

System.Collections.Generic.IEnumerable<Action>
A set containinng a "go here" action if there is a free action spot, or an empty set if there is not

MultiAction.Initialize() Method

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

MultiAction.IsCompleted() Method

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 ForceFail modifies the completion type, otherwise Active is returned.

public sealed override TinyLife.Actions.Action.CompletionType IsCompleted();

Returns

CompletionType
The current completion type of this action

MultiAction.OnBetweenActions(GameTime, TimeSpan, GameSpeed, Action, CompletionType) Method

A method that is called after ShouldFail(Action, CompletionType) returns false and before the next action is started.
If this method returns true, the next action is not started yet, meaning that this action can fulfil tasks inbetween sub-actions.

protected virtual bool OnBetweenActions(Microsoft.Xna.Framework.GameTime time, System.TimeSpan passedInGame, TinyLife.GameSpeed speed, TinyLife.Actions.Action completedAction, TinyLife.Actions.Action.CompletionType completion);

Parameters

time Microsoft.Xna.Framework.GameTime
The current game time

passedInGame System.TimeSpan
The amount of time that has passed, in game time

speed GameSpeed
The game's current speed setting

completedAction Action
The action that has completed

completion CompletionType
The completion type of the action that has completed

Returns

System.Boolean
false to start the next sub-action (or the main action), true to wait

MultiAction.OnCompleted(CompletionType) Method

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.

public sealed override void OnCompleted(TinyLife.Actions.Action.CompletionType type);

Parameters

type CompletionType
The type that this action completed with

MultiAction.ShouldFail(Action, CompletionType) Method

A method that returns whether or not this main action should fail if the previous or next completedAction completed with the given completion.
By default, this method returns true only if completion is not Completed.

protected virtual bool ShouldFail(TinyLife.Actions.Action completedAction, TinyLife.Actions.Action.CompletionType completion);

Parameters

completedAction Action
The action that has completed

completion CompletionType
The completion type of the action

Returns

System.Boolean
true if we should fail due to this completion

MultiAction.Update(GameTime, TimeSpan, GameSpeed) Method

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, GameSpeed, bool) is called.

public sealed override void Update(Microsoft.Xna.Framework.GameTime time, System.TimeSpan passedInGame, TinyLife.GameSpeed speed);

Parameters

time Microsoft.Xna.Framework.GameTime
The current game time

passedInGame System.TimeSpan
The amount of time that has passed, in game time

speed GameSpeed
The game's current speed setting

MultiAction.Validate(Person) Method

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(TinyLife.Objects.Person person);

Parameters

person Person
The person that this action belongs to

Returns

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