Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AIToggleFlashlights.c
Go to the documentation of this file.
1 class SCR_AIToggleFlashlights : AITaskScripted
2 {
3  [Attribute("true", UIWidgets.CheckBox, "Set flashlights active or inactive?")]
4  protected bool m_bEnable;
5 
6  protected SCR_GadgetManagerComponent m_GadgetManager;
7 
8  //------------------------------------------------------------------------------------------------------
9  override static string GetOnHoverDescription()
10  {
11  return "Sets all flashlights attached to vest enabled or disabled. Returns failure if no suitable flashlight found.";
12  }
13 
14 
15  //------------------------------------------------------------------------------------------------------
16  override void OnInit(AIAgent owner)
17  {
18  m_GadgetManager = SCR_GadgetManagerComponent.GetGadgetManager(owner.GetControlledEntity());
19  }
20 
21  //------------------------------------------------------------------------------------------------------
22  protected override string GetNodeMiddleText()
23  {
24  return string.Format("Flashlights Enabled: %1", m_bEnable);
25  }
26 
27  //------------------------------------------------------------------------------------------------------
28  static ENodeResult ToggleFlashlights(notnull SCR_GadgetManagerComponent gadgetManager, bool newState)
29  {
30  array<SCR_GadgetComponent> gadgets = gadgetManager.GetGadgetsByType(EGadgetType.FLASHLIGHT);
31 
32  if (!gadgets)
33  return ENodeResult.FAIL;
34 
35  if (gadgets.IsEmpty())
36  return ENodeResult.FAIL;
37 
38  bool success = false;
39  foreach (SCR_GadgetComponent gadget : gadgets)
40  {
41  InventoryItemComponent invComp = InventoryItemComponent.Cast(gadget.GetOwner().FindComponent(InventoryItemComponent));
42 
43  if (!invComp)
44  continue;
45 
46  EquipmentStorageSlot slot = EquipmentStorageSlot.Cast(invComp.GetParentSlot());
47 
48  // Don't toggle gadgets not in slot
49  if (!slot)
50  continue;
51 
52  bool occluded = slot.IsOccluded();
53 
54  gadget.ToggleActive(newState && !occluded);
55  success |= true;
56  }
57 
58  if (success)
59  return ENodeResult.SUCCESS;
60  else
61  return ENodeResult.FAIL;
62  }
63 
64  //------------------------------------------------------------------------------------------------------
65  static protected override bool VisibleInPalette()
66  {
67  return false;
68  }
69 };
70 
71 
72 
74 {
75  //------------------------------------------------------------------------------------------------------
76  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
77  {
78  if (!m_GadgetManager)
79  return ENodeResult.FAIL;
80 
81  return ToggleFlashlights(m_GadgetManager, m_bEnable);
82  };
83 
84  //------------------------------------------------------------------------------------------------------
85  override static protected bool VisibleInPalette()
86  {
87  return true;
88  }
89 };
90 
91 
92 
94 {
95  //------------------------------------------------------------------------------------------------------
96  override void OnAbort(AIAgent owner, Node nodeCausingAbort)
97  {
98  if (!m_GadgetManager)
99  return;
100 
101  ToggleFlashlights(m_GadgetManager, m_bEnable);
102  }
103 
104  //------------------------------------------------------------------------------------------------------
105  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
106  {
107  return ENodeResult.RUNNING;
108  }
109 
110  //------------------------------------------------------------------------------------------------------
111  override static protected bool VisibleInPalette()
112  {
113  return true;
114  }
115 };
SCR_AIToggleFlashlightsOnSimulate
Definition: SCR_AIToggleFlashlights.c:73
SCR_GadgetManagerComponent
Definition: SCR_GadgetManagerComponent.c:138
EquipmentStorageSlot
Definition: EquipmentStorageSlot.c:7
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_GadgetManager
SCR_GadgetManagerComponent m_GadgetManager
Definition: SCR_GadgetManagerComponent.c:2
SCR_AIToggleFlashlights
Definition: SCR_AIToggleFlashlights.c:1
InventoryItemComponent
Definition: InventoryItemComponent.c:12
SCR_AIToggleFlashlightsOnAbort
Definition: SCR_AIToggleFlashlights.c:93