Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIPerformSmartHealing.c
Go to the documentation of this file.
2{
3 // instead of class-local enum :(
4 private const int USAGE_NONE = 0;
5 private const int USAGE_WAITING_TO_START = 1;
6 private const int USAGE_IN_PROGRESS = 2;
7 private const int USAGE_DONE_SUCCESS = 3;
8 private const int USAGE_DONE_FAILURE = 4;
9
10 protected const float TIME_OF_HEALING_MS = 12000.0; // how long the node waits before FAILS (time to trigger and execute healing action)
11 protected const string PORT_USER_ACTION = "UserAction";
12 protected const string PORT_TARGET_ENTITY = "TargetEntity";
13 protected const string PORT_ITEM = "ItemToUse";
14
15 protected typename m_sUserAction;
18 protected bool m_bAborted;
19
20 private int m_iItemUsageInProgress;
21 private float m_fTimeout_ms;
22
23 [Attribute( defvalue: "SCR_BandageUserAction", uiwidget: UIWidgets.EditBox, desc: "Insert UserAction class name" )]
24 protected string m_userActionString;
25
26 override void OnEnter(AIAgent owner)
27 {
28 m_fTimeout_ms = 0;
29 m_bAborted = false;
30 m_iItemUsageInProgress = USAGE_NONE;
31 }
32
33 //------------------------------------------------------------------------------------------------
34 override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
35 {
36 switch (m_iItemUsageInProgress)
37 {
38 case USAGE_NONE:
39 {
40
41 string userActionString;
42
43 if (!GetVariableIn(PORT_USER_ACTION, userActionString))
44 userActionString = m_userActionString;
46
47 IEntity controlledEntity = owner.GetControlledEntity();
48 if (!controlledEntity)
49 return ENodeResult.FAIL;
50
52 m_targetEntity = controlledEntity;
53
54 m_sUserAction = userActionString.ToType();
55 if (m_sUserAction == typename.Empty)
56 return ENodeResult.FAIL;
57
59 if (character)
60 {
61 SCR_CharacterDamageManagerComponent damageMan = SCR_CharacterDamageManagerComponent.Cast(character.GetDamageManager());
62 if (!damageMan && !damageMan.CanBeHealed())
63 return ENodeResult.FAIL;
64 }
65 character = ChimeraCharacter.Cast(controlledEntity);
66 m_targetContrComp = SCR_CharacterControllerComponent.Cast(character.GetCharacterController());
68 return ENodeResult.FAIL;
69
70 array<BaseUserAction> outActions = {};
72 GetActions(m_targetEntity, outActions);
73 foreach (BaseUserAction baseAction : outActions)
74 {
75 // Check if action is healing action type
76 action = SCR_HealingUserAction.Cast(baseAction);
77 if (!action)
78 continue;
79
80 // Find the healing action on the correct hitzone group
82 continue;
83
84 // If healing action is of the desired healing-type, and can be performed, PerformAction
85 if (action && m_sUserAction == action.Type() && action.CanBePerformedScript(controlledEntity))
86 {
87 m_targetContrComp.m_OnItemUseBeganInvoker.Insert(OnItemUseBegan);
88 m_targetContrComp.m_OnItemUseEndedInvoker.Insert(OnItemUseEnded);
89 m_iItemUsageInProgress = USAGE_WAITING_TO_START;
90 action.PerformAction(m_targetEntity, controlledEntity);
91 return ENodeResult.RUNNING;
92 }
93 }
94 return ENodeResult.FAIL;
95 };
96 case USAGE_WAITING_TO_START:
97 {
98 float worldTime = GetGame().GetWorld().GetWorldTime();
99 if (m_fTimeout_ms == 0)
100 m_fTimeout_ms = worldTime + TIME_OF_HEALING_MS;
101 //else if (worldTime > m_fTimeout_ms)
102 //return ENodeResult.FAIL;
103 return ENodeResult.RUNNING;
104 };
105 case USAGE_IN_PROGRESS:
106 {
107 float worldTime = GetGame().GetWorld().GetWorldTime();
108 if (m_fTimeout_ms == 0)
109 m_fTimeout_ms = worldTime + TIME_OF_HEALING_MS;
110 //else if (worldTime > m_fTimeout_ms)
111 //return ENodeResult.FAIL;
112 return ENodeResult.RUNNING;
113 };
114 case USAGE_DONE_SUCCESS:
115 {
116 return ENodeResult.SUCCESS;
117 };
118 case USAGE_DONE_FAILURE:
119 {
120 return ENodeResult.FAIL;
121 };
122 };
123 return ENodeResult.FAIL;
124 }
125
126 //------------------------------------------------------------------------------------------------
127 override void OnAbort(AIAgent owner, Node nodeCausingAbort)
128 {
129 if (m_bAborted)
130 return;
131
133 {
134 m_targetContrComp.m_OnItemUseBeganInvoker.Remove(OnItemUseBegan);
135 m_targetContrComp.m_OnItemUseEndedInvoker.Remove(OnItemUseEnded);
136 if (m_iItemUsageInProgress < USAGE_DONE_SUCCESS) // we are ending before the action has finished
137 m_targetContrComp.GetInputContext().SetCancelItemAction(true);
138 }
139 m_bAborted = true;
140 }
141
142 //------------------------------------------------------------------------------------------------
144 {
145 if (item != m_item)
146 return;
147 m_iItemUsageInProgress = USAGE_IN_PROGRESS;
148 }
149
150 //------------------------------------------------------------------------------------------------
151 void OnItemUseEnded(IEntity item, bool actionCompleted, ItemUseParameters animParams)
152 {
153 if (item != m_item)
154 return;
155
156 if (actionCompleted)
157 m_iItemUsageInProgress = USAGE_DONE_SUCCESS;
158 else
159 m_iItemUsageInProgress = USAGE_DONE_FAILURE;
160 }
161
162 //------------------------------------------------------------------------------------------------
163 protected void GetActions(IEntity targetEntity, notnull out array<BaseUserAction> outActions)
164 {
165 if (!targetEntity)
166 return;
167
169
170 if (!actionOnEntity)
171 return;
172
173 actionOnEntity.GetActionsList(outActions);
174 }
175
176 //------------------------------------------------------------------------------------------------
178 {
179 ChimeraCharacter char = ChimeraCharacter.Cast(targetEntity);
180 if (!char)
181 return 0;
182
184 if (!damageMan)
185 return 0;
186
187 array<ECharacterHitZoneGroup> limbs = {};
188 damageMan.GetAllLimbs(limbs);
189 SCR_CharacterHitZone charHitZone = SCR_CharacterHitZone.Cast(damageMan.GetMostDOTHitZone(EDamageType.BLEEDING, false, limbs));
190 if (!charHitZone)
191 return 0;
192
193 return charHitZone.GetHitZoneGroup();
194 }
195
196 //------------------------------------------------------------------------------------------------
197 protected static ref TStringArray s_aVarsIn = {
201 };
202
203 //------------------------------------------------------------------------------------------------
205 {
206 return s_aVarsIn;
207 }
208
209 //------------------------------------------------------------------------------------------------
210 protected static override bool VisibleInPalette()
211 {
212 return true;
213 }
214
215 //------------------------------------------------------------------------------------------------
216 static override bool CanReturnRunning() { return true; }
217
218 //------------------------------------------------------------------------------------------------
219 protected static override string GetOnHoverDescription()
220 {
221 return "Uses smart healing action and is running until it finishes.";
222 }
223};
ArmaReforgerScripted GetGame()
Definition game.c:1398
array< ref SCR_MenuActionPreset > GetActions()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_VehicleDamageManagerComponent GetDamageManager()
proto external Managed FindComponent(typename typeName)
Definition Node.c:13
proto bool GetVariableIn(string name, out void val)
static override bool CanReturnRunning()
ECharacterHitZoneGroup GetTargetGroup(IEntity targetEntity)
void OnItemUseBegan(IEntity item, ItemUseParameters animParams)
void OnItemUseEnded(IEntity item, bool actionCompleted, ItemUseParameters animParams)
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
static override string GetOnHoverDescription()
override void OnAbort(AIAgent owner, Node nodeCausingAbort)
override TStringArray GetVariablesIn()
static override bool VisibleInPalette()
override void OnEnter(AIAgent owner)
SCR_CharacterControllerComponent m_targetContrComp
void GetActions(IEntity targetEntity, notnull out array< BaseUserAction > outActions)
HitZone GetMostDOTHitZone(EDamageType damageType, bool includeVirtualHZs=false, array< EHitZoneGroup > allowedGroups=null)
static void GetAllLimbs(notnull out array< ECharacterHitZoneGroup > limbs)
override bool CanBeHealed(bool ignoreHealingDOT=true)
ECharacterHitZoneGroup GetUserActionGroup()
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
ENodeResult
Definition ENodeResult.c:13
SCR_FieldOfViewSettings Attribute
EDamageType
Definition EDamageType.c:13
array< string > TStringArray
Definition Types.c:385