3 [
Attribute( defvalue:
"", uiwidget: UIWidgets.EditBox,
desc:
"Insert UserAction class name" )]
4 protected string m_sUserAction;
6 [
Attribute( defvalue:
"0", uiwidget: UIWidgets.CheckBox,
desc:
"Perform OnAbort? If false, performs action OnSimulate. If true OnSimulate returns RUNNING" )]
7 protected bool m_bPerformOnAbort;
9 protected bool m_bHasAborted;
11 static const string USER_ACTION_PORT =
"UserAction";
12 static const string TARGET_ENTITY_PORT =
"TargetEntity";
15 protected static ref TStringArray s_aVarsIn = {
21 override TStringArray GetVariablesIn()
27 override void OnInit(AIAgent owner)
29 m_bHasAborted =
false;
33 override ENodeResult EOnTaskSimulate(AIAgent owner,
float dt)
35 if (m_bPerformOnAbort)
36 return ENodeResult.RUNNING;
37 return PerformAction(owner,
true);
41 private ENodeResult PerformAction(AIAgent owner,
bool turnActionOn)
44 string userActionString;
46 GetVariableIn(TARGET_ENTITY_PORT, targetEntity);
47 if (!GetVariableIn(USER_ACTION_PORT, userActionString))
48 userActionString = m_sUserAction;
50 IEntity controlledEntity = owner.GetControlledEntity();
51 if (!controlledEntity)
52 return ENodeResult.FAIL;
55 return ENodeResult.FAIL;
57 userAction = userActionString.ToType();
59 return ENodeResult.FAIL;
61 array<BaseUserAction> outActions = {};
63 GetActions(targetEntity, outActions);
67 if (action && userAction == action.Type() && action.CanBePerformedScript(controlledEntity))
70 if (actionWithOccupancy)
72 if (turnActionOn && actionWithOccupancy.IsOccupied())
73 return ENodeResult.FAIL;
74 else if (!turnActionOn && !actionWithOccupancy.IsOccupied())
75 return ENodeResult.FAIL;
77 action.PerformAction(targetEntity, controlledEntity);
78 return ENodeResult.SUCCESS;
81 return ENodeResult.FAIL;
84 override void OnAbort(AIAgent owner, Node nodeCausingAbort)
86 if (m_bPerformOnAbort && !m_bHasAborted)
88 PerformAction(owner,
false);
94 private void GetActions(IEntity targetEntity, notnull out array<BaseUserAction> outActions)
99 ActionsManagerComponent actionOnEntity = ActionsManagerComponent.Cast(targetEntity.FindComponent(ActionsManagerComponent));
104 actionOnEntity.GetActionsList(outActions);
108 protected override bool VisibleInPalette()
114 protected override bool CanReturnRunning()
120 protected override string GetOnHoverDescription()
122 return "Performs specified smart action on target entity. Both must be specified. It can either perform it OnSimulate (default) or OnAbort.";