Class MultiAction
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
-
JsonTypeSafeGenericDataHolderMultiAction
- 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
infoActionInfoThe information for this action.
MultiAction(ActionType, ActionInfo)
Creates a new action with the given action information.
protected MultiAction(ActionType type, ActionInfo info)
Parameters
typeActionTypeThe type for this action.
infoActionInfoThe information for this action.
Fields
Handler
The MultiActionHandler that handles the actions created in CreateFirstActions()
[DataMember]
public readonly MultiActionHandler Handler
Field Value
Properties
CurrentStage
The MultiAction.Stage that this multi action is currently in. If this stage is FailedOrInterrupted, then StageBeforeFailureOrInterruption holds the stage that failed or was interrupted.
[DataMember]
protected MultiAction.Stage CurrentStage { get; }
Property Value
FailureOrInterruption
The reason that interrupted this action or caused it to fail. In the Update(GameTime, TimeSpan, float) call after this property is set (which occurs in Interrupt(CompletionType) or IsCompleted()), CurrentStage will be set to FailedOrInterrupted.
[DataMember(EmitDefaultValue = false)]
protected CompletionType? FailureOrInterruption { get; }
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 override 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 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
StageBeforeFailureOrInterruption
The MultiAction.Stage that this multi action was in before it failed or was interrupted. If CurrentStage is not FailedOrInterrupted, this property returns null.
[DataMember(EmitDefaultValue = false)]
protected MultiAction.Stage? StageBeforeFailureOrInterruption { get; }
Property Value
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
typeCompletionTypeThe 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
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
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 override bool CanActionInterrupt(Action action)
Parameters
actionActionThe action trying to interrupt this action.
Returns
- bool
Whether the action can interrupt this action.
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 override bool CanGenericInterrupt(bool isPlayer)
Parameters
isPlayerboolWhether the generic interruption source is the player.
Returns
- bool
Whether a generic interruption source 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 override bool CanStartNow()
Returns
- bool
Whether this action can start now.
CreateFailureInterruptionActions(CompletionType)
Returns a set of actions that should be executed after this multi-action is interrupted or has failed. This behavior can be used, for example, to ensure that a person always puts on clothes after an action that involves nudity, even if the action is canceled prematurely. Even if the yield statement is used, all actions will be collected into a list. If the returned set only contains null items, no failure/interruption actions will be executed, which is also this method's default behavior.
protected virtual IEnumerable<Action> CreateFailureInterruptionActions(CompletionType failureOrInterruption)
Parameters
failureOrInterruptionCompletionTypeThe reason for this action's failure or interruption.
Returns
- IEnumerable<Action>
A set of actions that should run after this action fails or is interrupted
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
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 override TextureRegion GetExtraIcon()
Returns
- TextureRegion
The extra icon to display in the action queue.
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()
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 override void Interrupt(CompletionType completion)
Parameters
completionCompletionTypeThe completion type to interrupt the action with.
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 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
typeCompletionTypeThe 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
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
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
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
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
typeCompletionTypeThe 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
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 override 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)