Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_AIPerformSmartHealing.c
Go to the documentation of this file.
1
class
SCR_AIPerformSmartHealing
:
AITaskScripted
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
;
16
protected
IEntity
m_targetEntity
,
m_item
;
17
protected
SCR_CharacterControllerComponent
m_targetContrComp
;
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
;
45
GetVariableIn
(
PORT_ITEM
,
m_item
);
46
47
IEntity
controlledEntity = owner.GetControlledEntity();
48
if
(!controlledEntity)
49
return
ENodeResult
.FAIL;
50
51
if
(!
GetVariableIn
(
PORT_TARGET_ENTITY
,
m_targetEntity
))
52
m_targetEntity
= controlledEntity;
53
54
m_sUserAction
= userActionString.ToType();
55
if
(
m_sUserAction
==
typename
.Empty)
56
return
ENodeResult
.FAIL;
57
58
ChimeraCharacter
character =
ChimeraCharacter
.Cast(
m_targetEntity
);
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());
67
if
(!
m_targetContrComp
)
68
return
ENodeResult
.FAIL;
69
70
array<BaseUserAction> outActions = {};
71
SCR_HealingUserAction
action;
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
81
if
(action.
GetUserActionGroup
() !=
GetTargetGroup
(
m_targetEntity
))
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
132
if
(
m_targetContrComp
)
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
//------------------------------------------------------------------------------------------------
143
void
OnItemUseBegan
(
IEntity
item,
ItemUseParameters
animParams)
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
168
ActionsManagerComponent
actionOnEntity =
ActionsManagerComponent
.Cast(targetEntity.
FindComponent
(
ActionsManagerComponent
));
169
170
if
(!actionOnEntity)
171
return
;
172
173
actionOnEntity.GetActionsList(outActions);
174
}
175
176
//------------------------------------------------------------------------------------------------
177
protected
ECharacterHitZoneGroup
GetTargetGroup
(
IEntity
targetEntity)
178
{
179
ChimeraCharacter
char
=
ChimeraCharacter
.Cast(targetEntity);
180
if
(!
char
)
181
return
0;
182
183
SCR_CharacterDamageManagerComponent
damageMan =
SCR_CharacterDamageManagerComponent
.Cast(
char
.
GetDamageManager
());
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
= {
198
PORT_USER_ACTION
,
199
PORT_TARGET_ENTITY
,
200
PORT_ITEM
201
};
202
203
//------------------------------------------------------------------------------------------------
204
override
TStringArray
GetVariablesIn
()
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
};
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
ECharacterHitZoneGroup
ECharacterHitZoneGroup
Definition
SCR_CharacterDamageManagerComponent.c:2
GetActions
array< ref SCR_MenuActionPreset > GetActions()
Definition
SCR_MenuActionsComponent.c:186
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition
SCR_RespawnBriefingComponent.c:17
GetDamageManager
SCR_VehicleDamageManagerComponent GetDamageManager()
Definition
VehicleControllerComponent.c:44
AITaskScripted
Definition
AITaskScripted.c:13
ActionsManagerComponent
Definition
ActionsManagerComponent.c:6
BaseUserAction
Definition
BaseUserAction.c:13
ChimeraCharacter
Definition
ChimeraCharacter.c:13
IEntity
Definition
IEntity.c:13
IEntity::FindComponent
proto external Managed FindComponent(typename typeName)
ItemUseParameters
Definition
ItemUseParameters.c:16
Node
Definition
Node.c:13
Node::GetVariableIn
proto bool GetVariableIn(string name, out void val)
SCR_AIPerformSmartHealing
Definition
SCR_AIPerformSmartHealing.c:2
SCR_AIPerformSmartHealing::CanReturnRunning
static override bool CanReturnRunning()
Definition
SCR_AIPerformSmartHealing.c:216
SCR_AIPerformSmartHealing::GetTargetGroup
ECharacterHitZoneGroup GetTargetGroup(IEntity targetEntity)
Definition
SCR_AIPerformSmartHealing.c:177
SCR_AIPerformSmartHealing::PORT_TARGET_ENTITY
const string PORT_TARGET_ENTITY
Definition
SCR_AIPerformSmartHealing.c:12
SCR_AIPerformSmartHealing::OnItemUseBegan
void OnItemUseBegan(IEntity item, ItemUseParameters animParams)
Definition
SCR_AIPerformSmartHealing.c:143
SCR_AIPerformSmartHealing::OnItemUseEnded
void OnItemUseEnded(IEntity item, bool actionCompleted, ItemUseParameters animParams)
Definition
SCR_AIPerformSmartHealing.c:151
SCR_AIPerformSmartHealing::PORT_USER_ACTION
const string PORT_USER_ACTION
Definition
SCR_AIPerformSmartHealing.c:11
SCR_AIPerformSmartHealing::m_targetEntity
IEntity m_targetEntity
Definition
SCR_AIPerformSmartHealing.c:16
SCR_AIPerformSmartHealing::s_aVarsIn
static ref TStringArray s_aVarsIn
Definition
SCR_AIPerformSmartHealing.c:197
SCR_AIPerformSmartHealing::EOnTaskSimulate
override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
Definition
SCR_AIPerformSmartHealing.c:34
SCR_AIPerformSmartHealing::GetOnHoverDescription
static override string GetOnHoverDescription()
Definition
SCR_AIPerformSmartHealing.c:219
SCR_AIPerformSmartHealing::TIME_OF_HEALING_MS
const float TIME_OF_HEALING_MS
Definition
SCR_AIPerformSmartHealing.c:10
SCR_AIPerformSmartHealing::m_sUserAction
m_sUserAction
Definition
SCR_AIPerformSmartHealing.c:15
SCR_AIPerformSmartHealing::OnAbort
override void OnAbort(AIAgent owner, Node nodeCausingAbort)
Definition
SCR_AIPerformSmartHealing.c:127
SCR_AIPerformSmartHealing::GetVariablesIn
override TStringArray GetVariablesIn()
Definition
SCR_AIPerformSmartHealing.c:204
SCR_AIPerformSmartHealing::PORT_ITEM
const string PORT_ITEM
Definition
SCR_AIPerformSmartHealing.c:13
SCR_AIPerformSmartHealing::VisibleInPalette
static override bool VisibleInPalette()
Definition
SCR_AIPerformSmartHealing.c:210
SCR_AIPerformSmartHealing::m_item
IEntity m_item
Definition
SCR_AIPerformSmartHealing.c:16
SCR_AIPerformSmartHealing::OnEnter
override void OnEnter(AIAgent owner)
Definition
SCR_AIPerformSmartHealing.c:26
SCR_AIPerformSmartHealing::m_bAborted
bool m_bAborted
Definition
SCR_AIPerformSmartHealing.c:18
SCR_AIPerformSmartHealing::m_targetContrComp
SCR_CharacterControllerComponent m_targetContrComp
Definition
SCR_AIPerformSmartHealing.c:17
SCR_AIPerformSmartHealing::GetActions
void GetActions(IEntity targetEntity, notnull out array< BaseUserAction > outActions)
Definition
SCR_AIPerformSmartHealing.c:163
SCR_AIPerformSmartHealing::m_userActionString
string m_userActionString
Definition
SCR_AIPerformSmartHealing.c:24
SCR_CharacterControllerComponent
Definition
SCR_CharacterControllerComponent.c:36
SCR_CharacterDamageManagerComponent
Definition
SCR_CharacterDamageManagerComponent.c:19
SCR_CharacterDamageManagerComponent::GetMostDOTHitZone
HitZone GetMostDOTHitZone(EDamageType damageType, bool includeVirtualHZs=false, array< EHitZoneGroup > allowedGroups=null)
Definition
SCR_CharacterDamageManagerComponent.c:1350
SCR_CharacterDamageManagerComponent::GetAllLimbs
static void GetAllLimbs(notnull out array< ECharacterHitZoneGroup > limbs)
Definition
SCR_CharacterDamageManagerComponent.c:1400
SCR_CharacterDamageManagerComponent::CanBeHealed
override bool CanBeHealed(bool ignoreHealingDOT=true)
Definition
SCR_CharacterDamageManagerComponent.c:633
SCR_HealingUserAction
Definition
SCR_HealingUserAction.c:2
SCR_HealingUserAction::GetUserActionGroup
ECharacterHitZoneGroup GetUserActionGroup()
Definition
SCR_HealingUserAction.c:152
SCR_HealingUserAction::PerformAction
override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
Definition
SCR_HealingUserAction.c:78
UIWidgets
Definition
attributes.c:40
ENodeResult
ENodeResult
Definition
ENodeResult.c:13
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
EDamageType
EDamageType
Definition
EDamageType.c:13
TStringArray
array< string > TStringArray
Definition
Types.c:385
scripts
Game
AI
ScriptedNodes
Soldier
SCR_AIPerformSmartHealing.c
Generated by
1.17.0