Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AISmartActionComponent.c
Go to the documentation of this file.
2 {
3 }
4 
5 void SCR_AIActionUserInvoker_Callback(AIAgent actionUser);
7 typedef ScriptInvokerBase<SCR_AIActionUserInvoker_Callback> SCR_AIActionUserInvoker;
8 
10 {
11  protected ref SCR_AIActionUserInvoker Event_EOnActionEnd;
12  protected ref SCR_AIActionUserInvoker Event_EOnActionFailed;
13  protected SCR_CharacterDamageManagerComponent m_pDamageManager;
14 
15  //------------------------------------------------------------------------------------------------
18  void ReserveAction(AIAgent owner)
19  {
20  // listen on death of the owner
21  IEntity ent = owner.GetControlledEntity();
22  if (!ent)
23  return;
24  m_pDamageManager = SCR_CharacterDamageManagerComponent.Cast(ent.FindComponent(SCR_CharacterDamageManagerComponent));
25  if (m_pDamageManager)
26  m_pDamageManager.GetOnDamageStateChanged().Insert(OnDamageStateChanged);
27  SetActionAccessible(false);
28  }
29 
30  //------------------------------------------------------------------------------------------------
32  void ReleaseAction()
33  {
34  if(m_pDamageManager)
35  {
36  m_pDamageManager.GetOnDamageStateChanged().Remove(OnDamageStateChanged);
37  m_pDamageManager = null;
38  }
39  SetActionAccessible(true);
40  }
41 
42  //------------------------------------------------------------------------------------------------
44  void OnDamageStateChanged(EDamageState state)
45  {
46  if (state == EDamageState.DESTROYED)
47  ReleaseAction();
48  }
49 
50  //------------------------------------------------------------------------------------------------
51  override void OnActionEnd(IEntity owner)
52  {
53  super.OnActionEnd(owner);
54  ReleaseAction();
55  if(Event_EOnActionEnd)
56  Event_EOnActionEnd.Invoke(GetUser());
57  }
58 
59  //------------------------------------------------------------------------------------------------
60  override void OnActionFailed(IEntity owner)
61  {
62  super.OnActionFailed(owner);
63  ReleaseAction();
64  if(Event_EOnActionEnd)
65  Event_EOnActionFailed.Invoke(GetUser());
66  }
67 
68  //------------------------------------------------------------------------------------------------
71  // Invokers for the completion of the smartaction to be used by the children //
72  SCR_AIActionUserInvoker GetOnActionEnd(bool createNew = true)
73  {
74  if (!Event_EOnActionEnd && createNew)
75  Event_EOnActionEnd = new SCR_AIActionUserInvoker();
76  return Event_EOnActionEnd;
77  }
78 
79  //------------------------------------------------------------------------------------------------
82  SCR_AIActionUserInvoker GetOnActionFailed(bool createNew = true)
83  {
84  if (!Event_EOnActionFailed && createNew)
85  Event_EOnActionFailed = new SCR_AIActionUserInvoker();
86  return Event_EOnActionFailed;
87  }
88 
89  //------------------------------------------------------------------------------------------------
90  override void OnDelete(IEntity owner)
91  {
92  if (m_pDamageManager)
93  m_pDamageManager.GetOnDamageStateChanged().Remove(OnDamageStateChanged);
94  }
95 }
AISmartActionComponentClass
Definition: AISmartActionComponent.c:12
SetActionAccessible
proto external void SetActionAccessible(bool accessible)
SCR_AISmartActionComponent
Definition: SCR_AISmartActionComponent.c:9
EDamageState
EDamageState
Definition: EDamageState.c:12
GetUser
proto external AIAgent GetUser()
func
func
Definition: SCR_AIThreatSystem.c:5
SCR_CharacterDamageManagerComponent
Definition: SCR_CharacterDamageManagerComponent.c:18
SCR_AIActionUserInvoker_Callback
func SCR_AIActionUserInvoker_Callback
Definition: SCR_AISmartActionComponent.c:6
SCR_AISmartActionComponentClass
Definition: SCR_AISmartActionComponent.c:1
AISmartActionComponent
void AISmartActionComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: AISmartActionComponent.c:19
SCR_AIActionUserInvoker
ScriptInvokerBase< SCR_AIActionUserInvoker_Callback > SCR_AIActionUserInvoker
Definition: SCR_AISmartActionComponent.c:7