Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_AITakeGadgetInLeftHand.c
Go to the documentation of this file.
1 class SCR_AITakeGadgetInLeftHand : AITaskScripted
2 {
3  [Attribute("0", UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(ECommonItemType) )]
4  private ECommonItemType m_eItemType;
5 
6  [Attribute("0", UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EGadgetType) )]
7  private EGadgetType m_eGadgetType;
8 
9  protected const float TIMEOUT_S = 6.0;
10 
11  protected IEntity m_OwnerEntity;
12  protected CharacterControllerComponent m_CharacterController;
13  protected SCR_InventoryStorageManagerComponent m_InventoryMgr;
14  protected SCR_GadgetManagerComponent m_GadgetManager;
15 
16  protected IEntity m_ItemEntity; // Item which we have requested to equip
17  protected bool m_bWaiting; // When true, we are waiting for item to be equipped
18  protected float m_fTimer_s; // Timer how long we've been waiting
19 
20  protected static const string PORT_ITEM = "ItemOut";
21 
22  //------------------------------------------------------------------------------------------------
23  protected static ref TStringArray s_aVarsOut = {
24  PORT_ITEM
25  };
26 
27  //------------------------------------------------------------------------------------------------
28  override TStringArray GetVariablesOut()
29  {
30  return s_aVarsOut;
31  }
32 
33  // -----------------------------------------------------------------------------------------------
34  override void OnInit(AIAgent owner)
35  {
36  m_OwnerEntity = owner.GetControlledEntity();
37  m_CharacterController = CharacterControllerComponent.Cast(m_OwnerEntity.FindComponent(CharacterControllerComponent));
38  m_InventoryMgr = SCR_InventoryStorageManagerComponent.Cast(m_OwnerEntity.FindComponent(SCR_InventoryStorageManagerComponent));
40  }
41 
42  // -----------------------------------------------------------------------------------------------
43  override ENodeResult EOnTaskSimulate(AIAgent owner, float dt)
44  {
45  if (!m_CharacterController || !m_InventoryMgr)
46  return ENodeResult.FAIL;
47 
48  if (m_bWaiting)
49  {
50  if (IsItemEquipped(m_ItemEntity))
51  {
52  SetVariableOut(PORT_ITEM, m_ItemEntity);
53  Reset();
54  return ENodeResult.SUCCESS;
55  }
56  else if (m_fTimer_s > TIMEOUT_S)
57  {
58  ClearVariable(PORT_ITEM);
59  Reset();
60  return ENodeResult.FAIL;
61  }
62  else
63  {
64  m_fTimer_s += dt;
65  return ENodeResult.RUNNING;
66  }
67  }
68  else
69  {
70  IEntity item = FindItem();
71 
72  if (!item)
73  return ENodeResult.FAIL;
74  else
75  {
76  if (!m_CharacterController.CanEquipGadget(item))
77  return ENodeResult.RUNNING;
78  else
79  {
80  if (EquipInventoryItem(item))
81  {
82  m_ItemEntity = item;
83  m_fTimer_s = 0;
84  m_bWaiting = true;
85  return ENodeResult.RUNNING;
86  }
87  else
88  return ENodeResult.FAIL;
89  }
90  }
91  }
92  }
93 
94  //-----------------------------------------------------------------------------------------------
95  protected void Reset()
96  {
97  m_ItemEntity = null;
98  m_fTimer_s = 0;
99  m_bWaiting = false;
100  }
101 
102  //-----------------------------------------------------------------------------------------------
103  override void OnAbort(AIAgent owner, Node nodeCausingAbort)
104  {
105  Reset();
106  }
107 
108  //-----------------------------------------------------------------------------------------------
109  IEntity FindItem()
110  {
111  IEntity item;
112 
113  if (m_eItemType != 0)
114  {
115  SCR_HoldableItemPredicate predicate = new SCR_HoldableItemPredicate();
116  predicate.wanted = m_eItemType;
117  item = m_InventoryMgr.FindItem(predicate);
118  }
119  else
120  {
121  item = m_GadgetManager.GetGadgetByType(m_eGadgetType);
122  }
123 
124  return item;
125  }
126 
127  //-----------------------------------------------------------------------------------------------
128  bool EquipInventoryItem(IEntity item)
129  {
130  m_GadgetManager.SetGadgetMode(item, EGadgetMode.IN_HAND);
131  //m_CharacterController.TakeGadgetInLeftHand(item, 1);
132 
133  return true;
134  }
135 
136  //-----------------------------------------------------------------------------------------------
137  bool IsItemEquipped(IEntity item)
138  {
139  if (!item)
140  return false;
141 
142  IEntity itemAtSlot = m_CharacterController.GetAttachedGadgetAtLeftHandSlot();
143 
144  return itemAtSlot == item;
145  }
146 
147  //-----------------------------------------------------------------------------------------------
148  protected override string GetNodeMiddleText()
149  {
150  if (m_eItemType != 0)
151  return string.Format("Item type: %1", typename.EnumToString(ECommonItemType, m_eItemType));
152  else
153  return string.Format("Gadget type: %1", typename.EnumToString(EGadgetType, m_eGadgetType));
154  }
155 
156  // -----------------------------------------------------------------------------------------------
157  protected override bool VisibleInPalette()
158  {
159  return true;
160  }
161 
162  //-----------------------------------------------------------------------------------------------
163  protected override bool CanReturnRunning()
164  {
165  return true;
166  }
167 
168  //-----------------------------------------------------------------------------------------------
169  protected override string GetOnHoverDescription()
170  {
171  return "Equips inventory item, returns success when done and item ref.";
172  }
173 };
s_aVarsOut
SCR_AIPickupInventoryItemsBehavior s_aVarsOut
Definition: SCR_AIGetCombatMoveRequestParameters.c:149
SCR_GadgetManagerComponent
Definition: SCR_GadgetManagerComponent.c:138
ECommonItemType
ECommonItemType
Definition: InventoryConstants.c:30
m_CharacterController
SCR_CharacterPerceivableComponentClass m_CharacterController
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_GadgetManager
SCR_GadgetManagerComponent m_GadgetManager
Definition: SCR_GadgetManagerComponent.c:2
SCR_AITakeGadgetInLeftHand
Definition: SCR_AITakeGadgetInLeftHand.c:1
m_eItemType
protected SCR_EArsenalItemType m_eItemType
Definition: SCR_ArsenalItem.c:3
m_eGadgetType
protected EGadgetType m_eGadgetType
Definition: SCR_MapRTWBaseUI.c:36
m_OwnerEntity
SCR_AIUtilityComponentClass m_OwnerEntity