Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SalineStorageComponent.c
Go to the documentation of this file.
2 {
3 }
4 
5 class SCR_SalineMovedCallback : ScriptedInventoryOperationCallback
6 {
7  SCR_CharacterInventoryStorageComponent m_CharInventoryStorageComp;
8  IEntity m_SalineBag;
10 
11  //------------------------------------------------------------------------------------------------
12  override protected void OnComplete()
13  {
14  m_CharInventoryStorageComp.RemoveItemFromQuickSlot(m_SalineBag);
15  //Destroy saline bag when the healing effect wears off
16  GetGame().GetCallqueue().CallLater(DestroySalineBag, m_fItemRegenerationDuration * 1000, false, m_SalineBag);
17  }
18 
19  //------------------------------------------------------------------------------------------------
20  protected void DestroySalineBag(IEntity item)
21  {
22  if (!item)
23  return;
24 
25  RplComponent.DeleteRplEntity(item, false);
26  }
27 }
28 
29 class SCR_SalineStorageComponent : SCR_EquipmentStorageComponent
30 {
31  ref SCR_SalineMovedCallback m_SalineMovedCallback = new SCR_SalineMovedCallback();
32 
33  //------------------------------------------------------------------------------------------------
40  bool AddSalineBagToSlot(IEntity target, ECharacterHitZoneGroup eHitZoneGroup, IEntity salineBag, float itemRegenerationDuration)
41  {
42  if (!target || !salineBag)
43  return false;
44 
45  RplComponent rplComp = RplComponent.Cast(target.FindComponent(RplComponent));
46  if (rplComp && rplComp.IsProxy())
47  return false;
48 
49  SCR_SalineStorageComponent SalineStorageComp = SCR_SalineStorageComponent.Cast(target.FindComponent(SCR_SalineStorageComponent));
50  if (!SalineStorageComp)
51  return false;
52 
53  SCR_InventoryStorageManagerComponent storageMan = SCR_InventoryStorageManagerComponent.Cast(GetOwner().FindComponent(SCR_InventoryStorageManagerComponent));
54  if (!storageMan)
55  return false;
56 
57  SCR_SalineBagStorageSlot salineTargetSlot;
58  for (int i, count = SalineStorageComp.GetSlotsCount(); i < count; i++)
59  {
60  salineTargetSlot = SCR_SalineBagStorageSlot.Cast(SalineStorageComp.GetSlot(i));
61  if (!salineTargetSlot)
62  continue;
63 
64  if (salineTargetSlot.GetAssociatedHZGroup() != eHitZoneGroup)
65  continue;
66 
67  if (salineTargetSlot.GetItem(i) == salineBag)
68  return false;
69 
70  if (salineTargetSlot.GetItem(i))
71  {
72  Debug.Error("salineBagSlot already contained some item");
73  return false;
74  }
75 
76  break;
77  }
78 
79  if (!salineTargetSlot)
80  return false;
81 
82  SCR_CharacterInventoryStorageComponent charInventoryStorageComp = SCR_CharacterInventoryStorageComponent.Cast(GetOwner().FindComponent(SCR_CharacterInventoryStorageComponent));
83  if (!charInventoryStorageComp)
84  return false;
85 
86  m_SalineMovedCallback.m_SalineBag = salineBag;
87  m_SalineMovedCallback.m_CharInventoryStorageComp = charInventoryStorageComp;
88  m_SalineMovedCallback.m_fItemRegenerationDuration = itemRegenerationDuration;
89 
90  if (storageMan.TryMoveItemToStorage(salineBag, SalineStorageComp, salineTargetSlot.GetID(), m_SalineMovedCallback))
91  return true;
92 
93  InventoryItemComponent invComp = InventoryItemComponent.Cast(salineBag.FindComponent(InventoryItemComponent));
94  if (!invComp)
95  return false;
96 
97  if (!invComp.GetParentSlot())
98  {
99  if (storageMan.TryInsertItemInStorage(salineBag, SalineStorageComp, salineTargetSlot.GetID(), m_SalineMovedCallback))
100  return true;
101  }
102  else
103  {
104  if (storageMan.TryMoveItemToStorage(salineBag, SalineStorageComp, salineTargetSlot.GetID(), m_SalineMovedCallback))
105  return true;
106  }
107 
108  return false;
109  }
110 
111  //------------------------------------------------------------------------------------------------
112  override void OnAddedToSlot(IEntity item, int slotID)
113  {
114  ChimeraCharacter char = ChimeraCharacter.Cast(GetOwner());
115  if (!char)
116  return;
117 
118  SCR_SalineBagStorageSlot salineSlot = SCR_SalineBagStorageSlot.Cast(GetSlot(slotID));
119  if (!salineSlot)
120  return;
121 
123  if (!damageMgr)
124  return;
125 
126  damageMgr.SetSalineBaggedGroup(salineSlot.GetAssociatedHZGroup(), true);
127  }
128 
129  //------------------------------------------------------------------------------------------------
130  override void OnRemovedFromSlot(IEntity item, int slotID)
131  {
132  ChimeraCharacter char = ChimeraCharacter.Cast(GetOwner());
133  if (!char)
134  return;
135 
136  SCR_SalineBagStorageSlot salineSlot = SCR_SalineBagStorageSlot.Cast(GetSlot(slotID));
137  if (!salineSlot)
138  return;
139 
141  if (!damageMgr)
142  return;
143 
144  damageMgr.SetSalineBaggedGroup(salineSlot.GetAssociatedHZGroup(), false);
145  }
146 
147  //------------------------------------------------------------------------------------------------
148  override protected bool ShouldPreviewAttachedItems()
149  {
150  return true;
151  }
152 }
SCR_SalineStorageComponentClass
Definition: SCR_SalineStorageComponent.c:1
ECharacterHitZoneGroup
ECharacterHitZoneGroup
Definition: SCR_CharacterDamageManagerComponent.c:1
SCR_SalineBagStorageSlot
Definition: SCR_SalineBagStorageSlot.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_SalineBag
IEntity m_SalineBag
Definition: SCR_SalineStorageComponent.c:8
GetSlot
IEntity GetSlot(IEntity occupant)
Definition: SCR_CompositionSlotManagerComponent.c:100
SCR_EquipmentStorageComponentClass
Definition: SCR_EquipmentStorageComponent.c:1
m_fItemRegenerationDuration
float m_fItemRegenerationDuration
Definition: SCR_SalineStorageComponent.c:9
ScriptedInventoryOperationCallback
Definition: ScriptedInventoryOperationCallback.c:12
SCR_CharacterDamageManagerComponent
Definition: SCR_CharacterDamageManagerComponent.c:18
m_CharInventoryStorageComp
SCR_SalineStorageComponentClass m_CharInventoryStorageComp
DestroySalineBag
protected void DestroySalineBag(IEntity item)
Definition: SCR_SalineStorageComponent.c:20
GetDamageManager
proto external SCR_DamageManagerComponent GetDamageManager()
Returns component which handles damage.
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
InventoryItemComponent
Definition: InventoryItemComponent.c:12
SCR_SalineStorageComponent
Definition: SCR_SalineStorageComponent.c:29
OnComplete
override protected void OnComplete()
Definition: SCR_SalineStorageComponent.c:12