Table of Contents

Class SocialAction

Namespace
TinyLife.Actions
Assembly
Tiny Life.dll

A social action is an action that involves two Person instances. Before a social action "actually" starts, both parties have to have the action as their current action. For this to happen, the person that initiates the action follows the Partner until they reach them (or give up).

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

Constructors

SocialAction(ActionInfo)

Creates a new typeless action with the given action information.

protected SocialAction(ActionInfo info)

Parameters

info ActionInfo

The information for this action.

SocialAction(ActionType, ActionInfo)

Creates a new action with the given action information.

protected SocialAction(ActionType type, ActionInfo info)

Parameters

type ActionType

The type for this action.

info ActionInfo

The information for this action.

Properties

ConversationTime

The amount of time that the actual conversation has been going on for. This is the total amount of time (ElapsedTime) minus the amount of time it took for the IsMain Person to reach the Partner.

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

Property Value

TimeSpan

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

IsMain

Whether or not this is the action that started the social interaction The PartnerAction will always have the inverse value of this value.

[DataMember]
public bool IsMain { get; protected set; }

Property Value

bool

MainAction

The SocialAction that is the main action, which is either this or PartnerAction, based on whether this action IsMain.

public SocialAction MainAction { get; }

Property Value

SocialAction

Partner

The Person that we're interacting with, which is the first Person result from GetInvolvedObject<T>(ObjectCategory, bool, bool, Func<T, bool>) that isn't Person.

public Person Partner { get; }

Property Value

Person

PartnerAction

The SocialAction that the Partner of this action instantiated as part of the interaction

public SocialAction PartnerAction { get; }

Property Value

SocialAction

Methods

AndThenInitialize()

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

protected override sealed void AndThenInitialize()

AndThenIsCompleted()

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

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

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

Parameters

other Action

The action to multi-task with

Returns

bool

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

Returns

bool

Whether this action can start now.

CreateAskOffer(string, ObjectCategory, Type, CanExecuteDelegate, CanExecuteDelegate, AiSettings?, AiSettings?, CanExecuteResult?)

Creates and returns a set of ActionType.TypeSettings instances that contains an "Ask" action, as well as an "Offer" action, for a specific Action class. The returned ActionType.TypeSettings have an additional bool entry in their ConstructorArguments that determines whether the action was started from the offering party, rather than the asking party. It can be evaluated using IsHelper(bool) and related methods. The returned ActionType.TypeSettings also automatically include an ActionArgument evaluator that displays a list of potential action partners if no action partner was immediately selected through the context. This means that the constructedType's constructor should accept the usual ActionType and ActionInfo, but also the wasOffered bool and the (optional) Person passed from the ActionArgument.

public static IEnumerable<ActionType.TypeSettings> CreateAskOffer(string name, ObjectCategory context, Type constructedType, ActionType.CanExecuteDelegate canRecipientExecute, ActionType.CanExecuteDelegate canHelperExecute, ActionType.AiSettings? askAi = null, ActionType.AiSettings? offerAi = null, CanExecuteResult? noValidArgumentsResult = null)

Parameters

name string

The base action name, which has "Ask" and "Offer" appended to it automatically.

context ObjectCategory

The context.

constructedType Type

The constructed action type.

canRecipientExecute ActionType.CanExecuteDelegate

A ActionType.CanExecuteDelegate that determines whether the recipient of this action (the person that is offered help, or the person that asks for help) can execute it.

canHelperExecute ActionType.CanExecuteDelegate

A ActionType.CanExecuteDelegate that determines whether the helper of this action (the person that offers help, or the person that is asked for help) can execute it.

askAi ActionType.AiSettings?

The ActionType.AiSettings for the "Ask" version of this action.

offerAi ActionType.AiSettings?

The ActionType.AiSettings for the "Offer" version of this action.

noValidArgumentsResult CanExecuteResult?

A CanExecuteResult that is used when no free people are found.

Returns

IEnumerable<ActionType.TypeSettings>

The "Ask" and "Offer" action type settings.

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 override IEnumerable<Action> CreateFirstActions()

Returns

IEnumerable<Action>

A set of actions that should run before this action

EnqueuePartnerAction(ActionInfo)

A method that is called to enqueue the action that the Partner should execute. By default, this causes a non-IsMain version of this action's Type to be enqueued using EnqueueAction<T>(ActionType, ActionInfo, bool, bool, bool, params ActionArgument[]).

protected virtual Action EnqueuePartnerAction(ActionInfo info)

Parameters

info ActionInfo

The action info to use.

Returns

Action

The action that was enqueued for the Partner.

GetDisplayName()

Returns a localized string that explains this action in short. By default, this method returns GetDisplayName(ActionInfo, bool).

public override string GetDisplayName()

Returns

string

This action's display name

GetHelper(bool)

Returns the helper party of this action, based on whether help was offered through this action. This should be used in conjunction with CreateAskOffer(string, ObjectCategory, Type, CanExecuteDelegate, CanExecuteDelegate, AiSettings?, AiSettings?, CanExecuteResult?).

protected Person GetHelper(bool wasOffered)

Parameters

wasOffered bool

Whether help was offered through this action.

Returns

Person

This action's helper party, which is either Person or Partner.

GetMaxWaitTime()

Returns the amount of time that the action Person should wait next to the person they want to talk to before the action is canceled. By default, this returns 30 minutes for an action that was StartedAutomatically, and 2 hours for a manual action.

protected virtual TimeSpan GetMaxWaitTime()

Returns

TimeSpan

The amount of time until this action is canceled.

GetPartnerArguments(ActionInfo)

A method that is called in EnqueuePartnerAction(ActionInfo) that determines what ActionArgument should be used. By default, null is returned.

protected virtual IEnumerable<ActionArgument> GetPartnerArguments(ActionInfo info)

Parameters

info ActionInfo

The action info to use.

Returns

IEnumerable<ActionArgument>

The ActionArgument to use for the partner action.

GetRecipientAction(bool)

Returns the recipient action of this action, based on whether help was offered through this action. This should be used in conjunction with CreateAskOffer(string, ObjectCategory, Type, CanExecuteDelegate, CanExecuteDelegate, AiSettings?, AiSettings?, CanExecuteResult?).

protected SocialAction GetRecipientAction(bool wasOffered)

Parameters

wasOffered bool

Whether help was offered through this action.

Returns

SocialAction

This action's recipient action, which is either PartnerAction or this.

InitializeConversation()

Initializes the conversation. This method is called for both partners in AndThenInitialize() by the partner who initializes this action last. By default, this method does nothing.

protected virtual void InitializeConversation()

InvokeForBoth(Action<Person, Person>)

Invokes the given action for both the Person and the Partner using InvokeForBoth(Person, Person, Action<Person, Person>).

public void InvokeForBoth(Action<Person, Person> action)

Parameters

action Action<Person, Person>

The action to invoke for both people of this conversation

IsConversationCompleted()

SocialAction version of IsCompleted(). This method returns whether or not the conversation should be marked as completed. Note that this method is only called for the IsMain part of the conversation.

protected virtual CompletionType IsConversationCompleted()

Returns

CompletionType

Whether or not this conversation is completed

IsHelper(bool)

Returns whether this action is the helper action, based on whether help was offered through this action. This should be used in conjunction with CreateAskOffer(string, ObjectCategory, Type, CanExecuteDelegate, CanExecuteDelegate, AiSettings?, AiSettings?, CanExecuteResult?).

protected bool IsHelper(bool wasOffered)

Parameters

wasOffered bool

Whether help was offered through this action.

Returns

bool

Whether this action is the helper action.

OnBothCompleted(CompletionType)

A method that is called when both actions (this action and the PartnerAction) have been completed. This method is called for both partners in AndThenOnCompleted(CompletionType) by the partner who completes this action last.

protected virtual void OnBothCompleted(CompletionType type)

Parameters

type CompletionType

The completion type.

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

UpdateConversation(GameTime, TimeSpan, float)

SocialAction version of Update(GameTime, TimeSpan, float). This method is called every update frame during an active conversation for both conversation partners. By default, this method only increases ConversationTime.

protected virtual void UpdateConversation(GameTime time, TimeSpan passedInGame, float speedMultiplier)

Parameters

time GameTime

The game's time

passedInGame TimeSpan

The amount of time passed in game time

speedMultiplier float

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