Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_UniversalInventoryStorageComponent.c
Go to the documentation of this file.
1 class SCR_UniversalInventoryStorageComponentClass : UniversalInventoryStorageComponentClass
2 {
3 }
4 
8 class SCR_UniversalInventoryStorageComponent : UniversalInventoryStorageComponent
9 {
10  [Attribute( "0", UIWidgets.EditBox, "How much weight it can carry")]
11  protected float m_fMaxWeight;
12 
13  [Attribute( "0", UIWidgets.EditBox, "The ID of slots the inserted items will be visible in")]
14  protected ref array<int> m_aSlotsToShow;
15 
16  [Attribute(desc: "Dictates how the entity gets other storage and sets them as linked storage or how it itself sets it as a linked storage of another storage. Do not use base class!")]
18 
20  protected ref array<BaseInventoryStorageComponent> m_aLinkedStorages;
21 
22  #ifndef DISABLE_INVENTORY
24  protected float m_fWeight;
25  protected SCR_InventoryStorageManagerComponent pInventoryManager;
26  protected static const int MIN_VOLUME_TO_SHOW_ITEM_IN_SLOT = 200000;
27 
28  //------------------------------------------------------------------------ USER METHODS ------------------------------------------------------------------------
29 
30  //------------------------------------------------------------------------------------------------
32  float GetMaxLoad()
33  {
34  return m_fMaxWeight;
35  }
36 
37  //------------------------------------------------------------------------------------------------
39  {
40  InventoryItemComponent pItemComp = GetItemComponent( item );
41  if( !pItemComp )
42  return null;
43 
44  return SCR_ItemAttributeCollection.Cast( pItemComp.GetAttributes() );
45  }
46 
47  //------------------------------------------------------------------------------------------------
48  protected InventoryItemComponent GetItemComponent( IEntity pItem )
49  {
50  return InventoryItemComponent.Cast( pItem.FindComponent( InventoryItemComponent ) );
51  }
52 
53  //------------------------------------------------------------------------------------------------
54  protected bool IsWeightOk( float fWeight )
55  {
56  if (!m_Attributes)
57  return false;
58 
59  fWeight += GetTotalWeight() - m_Attributes.GetWeight();
60 
61  return m_fMaxWeight >= fWeight;
62  }
63 
64  //------------------------------------------------------------------------------------------------
65  override bool CanStoreItem(IEntity item, int slotID)
66  {
67  if (!super.CanStoreItem(item, slotID))
68  return false;
69 
70  InventoryItemComponent pItemComp = GetItemComponent( item );
71  if( !pItemComp )
72  return false;
73 
74  bool bVolumeOK = PerformVolumeValidation( item );
75  if( !bVolumeOK )
76  {
77  if( pInventoryManager )
78  pInventoryManager.SetReturnCode( EInventoryRetCode.RETCODE_ITEM_TOO_BIG );
79  }
80 
81  bool bWeightOK = IsWeightOk( pItemComp.GetTotalWeight() );
82  if( !bWeightOK )
83  {
84  if( pInventoryManager )
85  pInventoryManager.SetReturnCode( EInventoryRetCode.RETCODE_ITEM_TOO_HEAVY );
86  }
87 
88  bool bDimensionsOK = PerformDimensionValidation(item);
89  return bVolumeOK && bWeightOK && bDimensionsOK;
90  }
91 
92  //------------------------------------------------------------------------------------------------
93  override bool CanStoreResource(ResourceName resourceName, int slotID)
94  {
95  if (!super.CanStoreResource(resourceName, slotID))
96  return false;
97 
98  bool bVolumeOK = PerformVolumeAndDimensionValidationForResource(resourceName, true);
99  if( !bVolumeOK )
100  {
101  if( pInventoryManager )
102  pInventoryManager.SetReturnCode( EInventoryRetCode.RETCODE_ITEM_TOO_BIG );
103  }
104 
105  float fWeight = GetWeightFromResource(resourceName);
106  bool bWeightOK = IsWeightOk( fWeight );
107  if( !bWeightOK )
108  {
109  if( pInventoryManager )
110  pInventoryManager.SetReturnCode( EInventoryRetCode.RETCODE_ITEM_TOO_HEAVY );
111  }
112 
113  return bVolumeOK && bWeightOK;
114  }
115 
116  //------------------------------------------------------------------------------------------------
117  override bool CanReplaceItem(IEntity nextItem, int slotID)
118  {
119  if (!super.CanReplaceItem(nextItem, slotID))
120  return false;
121 
122  if (!nextItem)
123  return false;
124 
125  IEntity item = Get(slotID);
126 
127  if (!item)
128  return false;
129 
130  // item is the item that is getting replaced by nextItem
131  // nextItem is the item that is replacing the item at slotID
132  // slotID is is the slot ID for the item that is getting replaced by nextItem
133 
134  InventoryItemComponent itemComp = GetItemComponent(item);
135  if(!itemComp)
136  return false;
137 
138  InventoryItemComponent nextItemComp = GetItemComponent(nextItem);
139  if(!nextItemComp)
140  return false;
141 
142  float itemVolume = itemComp.GetTotalVolume();
143  float nextItemVolume = nextItemComp.GetTotalVolume();
144  float occupiedVolumeWithoutItem = GetOccupiedSpace() - itemVolume;
145 
146  bool bVolumeOK = occupiedVolumeWithoutItem + nextItemVolume <= GetMaxVolumeCapacity();
147  if(!bVolumeOK && pInventoryManager)
148  {
149  pInventoryManager.SetReturnCode(EInventoryRetCode.RETCODE_ITEM_TOO_BIG);
150  }
151 
152  bool bWeightOK = IsWeightOk(nextItemComp.GetTotalWeight() - itemComp.GetTotalWeight());
153  if(!bWeightOK && pInventoryManager)
154  {
155  pInventoryManager.SetReturnCode(EInventoryRetCode.RETCODE_ITEM_TOO_HEAVY);
156  }
157 
158  bool bDimensionsOK = PerformDimensionValidation(nextItem);
159  return bVolumeOK && bWeightOK && bDimensionsOK;
160  }
161 
162  //------------------------------------------------------------------------------------------------
163  override void OnRemovedFromSlot(IEntity item, int slotID)
164  {
165  super.OnRemovedFromSlot(item, slotID);
166 
167  GenericEntity pGenComp = GenericEntity.Cast( item );
168  InventoryItemComponent pItemComponent = InventoryItemComponent.Cast(pGenComp.FindComponent(InventoryItemComponent));
169  pItemComponent.ShowOwner();
170  pItemComponent.EnablePhysics();
171 
172  m_fWeight -= pItemComponent.GetTotalWeight();
173  }
174 
175  //------------------------------------------------------------------------------------------------
176  protected override void OnAddedToSlot(IEntity item, int slotID)
177  {
178  super.OnAddedToSlot(item, slotID);
179 
180  GenericEntity pGenComp = GenericEntity.Cast( item );
181  InventoryItemComponent pItemComponent = InventoryItemComponent.Cast(pGenComp.FindComponent(InventoryItemComponent));
182  if( !pItemComponent )
183  return;
184 
185  float fVol = pItemComponent.GetTotalVolume();
186  if ( m_aSlotsToShow.Find( slotID ) != -1 )
187  {
188  pItemComponent.ShowOwner();
189  }
190  else
191  {
192  if ( fVol >= MIN_VOLUME_TO_SHOW_ITEM_IN_SLOT )
193  pItemComponent.ShowOwner();
194  }
195 
196  pItemComponent.DisablePhysics();
197  pItemComponent.ActivateOwner(false);
198 
199  m_fWeight += pItemComponent.GetTotalWeight();
200  }
201 
202  //------------------------------------------------------------------------ LINKED STORAGES ----------------------------------------------------------------------
203 
204  //------------------------------------------------------------------------------------------------
208  int GetLinkedStorages(notnull out array<BaseInventoryStorageComponent> linkedStorages)
209  {
210  if (!m_aLinkedStorages)
211  return 0;
212 
213  linkedStorages.Copy(m_aLinkedStorages);
214  return linkedStorages.Count();
215  }
216 
217  //------------------------------------------------------------------------------------------------
220  void AddLinkedStorage(BaseInventoryStorageComponent newLinkedStorage)
221  {
222  //~ Do not add self as linked storage
223  if (newLinkedStorage == this)
224  return;
225 
226  if (!m_aLinkedStorages)
227  m_aLinkedStorages = {};
228  //~ Already contains the storage
229  else if (m_aLinkedStorages.Contains(newLinkedStorage))
230  return;
231 
232  m_aLinkedStorages.Insert(newLinkedStorage);
233  }
234 
235  //------------------------------------------------------------------------------------------------
239  bool IsStorageALinkedChild(notnull BaseInventoryStorageComponent storage)
240  {
241  return m_aLinkedStorages.Contains(storage);
242  }
243 
244  //------------------------------------------------------------------------ COMMON METHODS ----------------------------------------------------------------------
245 
246  //------------------------------------------------------------------------------------------------
248  {
249  super.OnManagerChanged(manager);
250 
251  pInventoryManager = SCR_InventoryStorageManagerComponent.Cast( manager );
252  }
253 
254  //------------------------------------------------------------------------------------------------
255  // constructor
259  void SCR_UniversalInventoryStorageComponent( IEntityComponentSource src, IEntity ent, IEntity parent )
260  {
261  m_Attributes = SCR_ItemAttributeCollection.Cast(GetAttributes());
262  if (!m_Attributes)
263  return;
264 
265  m_fWeight = m_Attributes.GetWeight();
266 
268  m_LinkedStorageLogic.Init(this);
269  }
270  #else
271  private SCR_ItemAttributeCollection GetAttributeCollection( IEntity item );
272  protected InventoryItemComponent GetItemComponent( IEntity pItem );
273  protected bool IsVolumeOk( float fVolume );
274  protected bool IsWeightOk( float fWeight );
275  override bool CanStoreItem(IEntity item, int slotID);
276  override bool CanStoreResource(ResourceName resourceName, int slotID);
277  override bool CanRemoveItem(IEntity item);
278  override void OnRemovedFromSlot(IEntity item, int slotID);
279  protected override void OnAddedToSlot(IEntity item, int slotID);
280  override void OnManagerChanged(InventoryStorageManagerComponent manager);
281 // void SCR_UniversalInventoryStorageComponent( IEntityComponentSource src, IEntity ent, IEntity parent );
282 
283  #endif
284 }
pInventoryManager
protected SCR_InventoryStorageManagerComponent pInventoryManager
Definition: SCR_UniversalInventoryStorageComponent.c:25
PerformDimensionValidation
proto external bool PerformDimensionValidation(IEntity item)
performs dimension validation.
m_Attributes
private SCR_ItemAttributeCollection m_Attributes
Definition: SCR_UniversalInventoryStorageComponent.c:23
GetAttributeCollection
private SCR_ItemAttributeCollection GetAttributeCollection(IEntity item)
Definition: SCR_UniversalInventoryStorageComponent.c:38
Attribute
SCR_UniversalInventoryStorageComponentClass UniversalInventoryStorageComponentClass Attribute("0", UIWidgets.EditBox, "How much weight it can carry")] protected float m_fMaxWeight
m_fWeight
protected float m_fWeight
Definition: SCR_UniversalInventoryStorageComponent.c:24
OnRemovedFromSlot
override void OnRemovedFromSlot(IEntity item, int slotID)
Definition: SCR_UniversalInventoryStorageComponent.c:163
OnManagerChanged
override void OnManagerChanged(InventoryStorageManagerComponent manager)
Definition: SCR_UniversalInventoryStorageComponent.c:247
SCR_UniversalInventoryStorageComponent
void SCR_UniversalInventoryStorageComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_UniversalInventoryStorageComponent.c:259
CanStoreResource
override bool CanStoreResource(ResourceName resourceName, int slotID)
Definition: SCR_UniversalInventoryStorageComponent.c:93
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
IsWeightOk
protected bool IsWeightOk(float fWeight)
Definition: SCR_UniversalInventoryStorageComponent.c:54
CanRemoveItem
event bool CanRemoveItem(IEntity item)
Implemented logics for can remove here,.
Definition: BaseInventoryStorageComponent.c:128
SCR_UniversalInventoryStorageComponentClass
Definition: SCR_UniversalInventoryStorageComponent.c:1
InventoryStorageManagerComponent
Definition: InventoryStorageManagerComponent.c:12
OnAddedToSlot
protected override void OnAddedToSlot(IEntity item, int slotID)
Definition: SCR_UniversalInventoryStorageComponent.c:176
GetMaxLoad
float GetMaxLoad()
Returns how much weight the component can carry.
Definition: SCR_UniversalInventoryStorageComponent.c:32
m_aLinkedStorages
protected ref array< BaseInventoryStorageComponent > m_aLinkedStorages
Storages that will be automatically closed and opened when the parent (this) storage is closed or ope...
Definition: SCR_UniversalInventoryStorageComponent.c:20
GetLinkedStorages
int GetLinkedStorages(notnull out array< BaseInventoryStorageComponent > linkedStorages)
Definition: SCR_UniversalInventoryStorageComponent.c:208
m_LinkedStorageLogic
protected ref SCR_BaseLinkedStorageLogic m_LinkedStorageLogic
Definition: SCR_UniversalInventoryStorageComponent.c:17
CanStoreItem
override bool CanStoreItem(IEntity item, int slotID)
Definition: SCR_UniversalInventoryStorageComponent.c:65
GetItemComponent
protected InventoryItemComponent GetItemComponent(IEntity pItem)
Definition: SCR_UniversalInventoryStorageComponent.c:48
PerformVolumeValidation
proto external bool PerformVolumeValidation(IEntity item, bool includeDimensionValidation=true)
performs volume and item dimension validation.
InventoryItemComponent
Definition: InventoryItemComponent.c:12
m_aSlotsToShow
protected ref array< int > m_aSlotsToShow
Definition: SCR_UniversalInventoryStorageComponent.c:14
Get
proto external sealed IEntity Get(int slotID)
SCR_ItemAttributeCollection
Definition: SCR_ItemAttributeCollection.c:2
IsStorageALinkedChild
bool IsStorageALinkedChild(notnull BaseInventoryStorageComponent storage)
Definition: SCR_UniversalInventoryStorageComponent.c:239
CanReplaceItem
override bool CanReplaceItem(IEntity nextItem, int slotID)
Definition: SCR_UniversalInventoryStorageComponent.c:117
SCR_BaseLinkedStorageLogic
Definition: SCR_BaseLinkedStorageLogic.c:2
AddLinkedStorage
void AddLinkedStorage(BaseInventoryStorageComponent newLinkedStorage)
Definition: SCR_UniversalInventoryStorageComponent.c:220
PerformVolumeAndDimensionValidationForResource
proto external bool PerformVolumeAndDimensionValidationForResource(ResourceName resourceName, bool includeDimensionValidation=true)
performs volume and item dimension validation.
GetWeightFromResource
proto external float GetWeightFromResource(ResourceName resourceName)
get the weight of a prefab
GetOccupiedSpace
proto external float GetOccupiedSpace()
returns amount of space occupied by attached items
GetMaxVolumeCapacity
proto external float GetMaxVolumeCapacity()