Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_TourniquetStorageComponent.c
Go to the documentation of this file.
2 {
3 }
4 
5 class SCR_TourniquetMovedCallback : ScriptedInventoryOperationCallback
6 {
7  SCR_CharacterInventoryStorageComponent m_CharInventoryStorageComp;
8  IEntity m_Tourniquet;
9  int m_iSlotId;
10  BaseInventoryStorageComponent m_Storage;
11  bool m_bRemove;
12  ref ScriptInvoker<int> m_OnTourniquetMoved;
13 
14  //------------------------------------------------------------------------------------------------
15  override protected void OnComplete()
16  {
17  if (m_bRemove)
18  m_CharInventoryStorageComp.RemoveItemFromQuickSlot(m_Tourniquet);
19 
20  SCR_InventoryMenuUI menu = SCR_InventoryMenuUI.Cast(GetGame().GetMenuManager().FindMenuByPreset(ChimeraMenuPreset.Inventory20Menu));
21  if (menu)
22  {
24  if (itemComp && itemComp.GetParentSlot())
25  {
26  BaseInventoryStorageComponent tqStorage = itemComp.GetParentSlot().GetStorage();
27  if (tqStorage)
28  {
29  SCR_InventoryStorageBaseUI storageUI = menu.GetStorageUIByBaseStorageComponent(tqStorage);
30  if (storageUI)
31  storageUI.Refresh();
32  }
33  }
34 
35  if (m_Storage)
36  {
37  SCR_InventoryStorageBaseUI storageUI = menu.GetStorageUIByBaseStorageComponent(m_Storage);
38  if (storageUI)
39  storageUI.Refresh();
40  }
41  }
42 
45  }
46 }
47 
48 class SCR_TourniquetStorageComponent : SCR_EquipmentStorageComponent
49 {
50  protected ref SCR_TourniquetMovedCallback m_TourniquetMovedCallback = new SCR_TourniquetMovedCallback();
51 
52  //------------------------------------------------------------------------------------------------
57  void AddTourniquetToSlot(IEntity target, ECharacterHitZoneGroup eHitZoneGroup, IEntity tourniquet)
58  {
59  SCR_TourniquetStorageComponent tourniquetStorageComp = SCR_TourniquetStorageComponent.Cast(target.FindComponent(SCR_TourniquetStorageComponent));
60  if (!tourniquetStorageComp)
61  return;
62 
63  SCR_InventoryStorageManagerComponent storageMan = SCR_InventoryStorageManagerComponent.Cast(GetOwner().FindComponent(SCR_InventoryStorageManagerComponent));
64  if (!storageMan)
65  return;
66 
67  if (!tourniquet)
68  return;
69 
70  SCR_TourniquetStorageSlot tqTargetSlot;
71  for (int i, count = tourniquetStorageComp.GetSlotsCount(); i < count; i++)
72  {
73  tqTargetSlot = SCR_TourniquetStorageSlot.Cast(tourniquetStorageComp.GetSlot(i));
74  if (!tqTargetSlot)
75  continue;
76 
77  if (tqTargetSlot.GetAssociatedHZGroup() != eHitZoneGroup)
78  continue;
79 
80  //Return if slot already contains this particular tourniquet. Likely function got called twice harmlessly
81  if (tqTargetSlot.GetItem(i) == tourniquet)
82  return;
83 
84  if (tqTargetSlot.GetItem(i))
85  {
86  Print("TourniquetSlot already contained another item", LogLevel.WARNING);
87  return;
88  }
89 
90  break;
91  }
92 
93  SCR_CharacterInventoryStorageComponent charInventoryStorageComp = SCR_CharacterInventoryStorageComponent.Cast(GetOwner().FindComponent(SCR_CharacterInventoryStorageComponent));
94  if (!charInventoryStorageComp)
95  return;
96 
97  m_TourniquetMovedCallback.m_Tourniquet = tourniquet;
98  m_TourniquetMovedCallback.m_CharInventoryStorageComp = charInventoryStorageComp;
99  m_TourniquetMovedCallback.m_iSlotId = eHitZoneGroup;
100 
101  InventoryItemComponent itemComp = InventoryItemComponent.Cast(tourniquet.FindComponent(InventoryItemComponent));
102  if (itemComp.GetParentSlot())
103  m_TourniquetMovedCallback.m_Storage = itemComp.GetParentSlot().GetStorage();
104  else
105  m_TourniquetMovedCallback.m_Storage = null;
106 
107  m_TourniquetMovedCallback.m_bRemove = true;
108 
109  if (storageMan.TryMoveItemToStorage(tourniquet, tourniquetStorageComp, tqTargetSlot.GetID(), m_TourniquetMovedCallback))
110  return;
111 
112  InventoryItemComponent invComp = InventoryItemComponent.Cast(tourniquet.FindComponent(InventoryItemComponent));
113  if (!invComp)
114  return;
115 
116  if (!invComp.GetParentSlot())
117  {
118  if (storageMan.TryInsertItemInStorage(tourniquet, tourniquetStorageComp, tqTargetSlot.GetID(), m_TourniquetMovedCallback))
119  return;
120  }
121  }
122 
123  //------------------------------------------------------------------------------------------------
128  bool RemoveTourniquetFromSlot(ECharacterHitZoneGroup eHitZoneGroup, IEntity retrievingCharacter = null)
129  {
130  ChimeraCharacter character = ChimeraCharacter.Cast(GetOwner());
131  if (!character)
132  return false;
133 
134  SCR_CharacterDamageManagerComponent damageMgr = SCR_CharacterDamageManagerComponent.Cast(character.GetDamageManager());
135  if (!damageMgr)
136  return false;
137 
139  if (!tourniquetStorageComp)
140  return false;
141 
142  if (!retrievingCharacter)
143  retrievingCharacter = GetOwner();
144 
145  SCR_InventoryStorageManagerComponent storageMan = SCR_InventoryStorageManagerComponent.Cast(retrievingCharacter.FindComponent(SCR_InventoryStorageManagerComponent));
146  if (!storageMan)
147  return false;
148 
149  IEntity targetTourniquet;
150  SCR_TourniquetStorageSlot tqTargetSlot;
151  for (int i, count = tourniquetStorageComp.GetSlotsCount(); i < count; i++)
152  {
153  tqTargetSlot = SCR_TourniquetStorageSlot.Cast(tourniquetStorageComp.GetSlot(i));
154  if (!tqTargetSlot)
155  continue;
156 
157  if (tqTargetSlot.GetAssociatedHZGroup() != eHitZoneGroup)
158  continue;
159 
160  targetTourniquet = tqTargetSlot.GetItem(i);
161  break;
162  }
163 
164  BaseInventoryStorageComponent targetStorage = storageMan.FindStorageForItem(targetTourniquet, EStoragePurpose.PURPOSE_DEPOSIT);
165  m_TourniquetMovedCallback.m_Storage = targetStorage;
166  m_TourniquetMovedCallback.m_bRemove = false;
167 
168  if (storageMan.TryMoveItemToStorage(targetTourniquet, targetStorage, tqTargetSlot.GetID(), m_TourniquetMovedCallback))
169  return true;
170 
171  InventoryItemComponent invComp = InventoryItemComponent.Cast(targetTourniquet.FindComponent(InventoryItemComponent));
172  if (!invComp)
173  return false;
174 
175  if (!invComp.GetParentSlot())
176  {
177  if (storageMan.TryInsertItemInStorage(targetTourniquet, targetStorage, tqTargetSlot.GetID(), m_TourniquetMovedCallback))
178  return true;
179  }
180  else
181  {
182  if (storageMan.TryMoveItemToStorage(targetTourniquet, targetStorage, tqTargetSlot.GetID(), m_TourniquetMovedCallback))
183  return true;
184  }
185 
186  return false;
187  }
188 
189  //------------------------------------------------------------------------------------------------
190  override void OnAddedToSlot(IEntity item, int slotID)
191  {
192  ChimeraCharacter char = ChimeraCharacter.Cast(GetOwner());
193  if (!char)
194  return;
195 
197  if (!tqSlot)
198  return;
199 
201  if (!damageMgr)
202  return;
203 
204  damageMgr.SetTourniquettedGroup(tqSlot.GetAssociatedHZGroup(), true);
205  }
206 
207  //------------------------------------------------------------------------------------------------
208  override void OnRemovedFromSlot(IEntity item, int slotID)
209  {
210  ChimeraCharacter char = ChimeraCharacter.Cast(GetOwner());
211  if (!char)
212  return;
213 
215  if (!tqSlot)
216  return;
217 
219  if (!damageMgr)
220  return;
221 
222  damageMgr.SetTourniquettedGroup(tqSlot.GetAssociatedHZGroup(), false);
223  }
224 
225  //------------------------------------------------------------------------------------------------
227  ScriptInvoker GetOnTourniquetMoved()
228  {
229  if (!m_TourniquetMovedCallback.m_OnTourniquetMoved)
230  m_TourniquetMovedCallback.m_OnTourniquetMoved = new ScriptInvoker();
231 
232  return m_TourniquetMovedCallback.m_OnTourniquetMoved;
233  }
234 }
ECharacterHitZoneGroup
ECharacterHitZoneGroup
Definition: SCR_CharacterDamageManagerComponent.c:1
SCR_TourniquetStorageComponentClass
Definition: SCR_TourniquetStorageComponent.c:1
m_OnTourniquetMoved
ref ScriptInvoker< int > m_OnTourniquetMoved
Definition: SCR_TourniquetStorageComponent.c:12
SCR_TourniquetStorageComponent
Definition: SCR_TourniquetStorageComponent.c:48
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_iSlotId
int m_iSlotId
Definition: SCR_TourniquetStorageComponent.c:9
m_Tourniquet
IEntity m_Tourniquet
Definition: SCR_TourniquetStorageComponent.c:8
SCR_TourniquetStorageSlot
Definition: SCR_TourniquetStorageSlot.c:1
m_CharInventoryStorageComp
SCR_TourniquetStorageComponentClass m_CharInventoryStorageComp
GetSlot
IEntity GetSlot(IEntity occupant)
Definition: SCR_CompositionSlotManagerComponent.c:100
SCR_InventoryStorageBaseUI
Definition: SCR_InventoryStorageBaseUI.c:6
m_bRemove
bool m_bRemove
Definition: SCR_TourniquetStorageComponent.c:11
SCR_EquipmentStorageComponentClass
Definition: SCR_EquipmentStorageComponent.c:1
ScriptedInventoryOperationCallback
Definition: ScriptedInventoryOperationCallback.c:12
OnComplete
override protected void OnComplete()
Definition: SCR_TourniquetStorageComponent.c:15
SCR_CharacterDamageManagerComponent
Definition: SCR_CharacterDamageManagerComponent.c:18
GetDamageManager
proto external SCR_DamageManagerComponent GetDamageManager()
Returns component which handles damage.
SCR_InventoryMenuUI
Definition: SCR_InventoryMenuUI.c:247
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
InventoryItemComponent
Definition: InventoryItemComponent.c:12
ChimeraMenuPreset
ChimeraMenuPreset
Menu presets.
Definition: ChimeraMenuBase.c:3
EStoragePurpose
EStoragePurpose
Definition: EStoragePurpose.c:12
m_Storage
BaseInventoryStorageComponent m_Storage
Definition: SCR_TourniquetStorageComponent.c:10