Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ArsenalInventoryStorageManagerComponent.c
Go to the documentation of this file.
2 {
3 }
4 
5 class SCR_ArsenalInventoryStorageManagerComponent : ScriptedInventoryStorageManagerComponent
6 {
7  [Attribute("1", desc: "If true it will negate the weight and volume of the items within the arsenal, if false the items within the arsenal will have weight and volume")]
8  protected bool m_bNegateItemWeightAndVolume;
9 
10  //~ Total weight of items that were added 1 frame OnBeforePossessed
11  protected float m_fTotalItemWeight;
12 
13  //~ If next frame the weight will be set when items are OnItemAdded
15 
16  protected ref set<ResourceName> m_ItemsInArsenal = new set<ResourceName>();
17 
18  //------------------------------------------------------------------------------------------------
22  bool IsPrefabInArsenalStorage(ResourceName item)
23  {
24  return m_ItemsInArsenal.Contains(item);
25  }
26 
27  //------------------------------------------------------------------------------------------------
31  bool IsItemInArsenalStorage(notnull IEntity item)
32  {
33  EntityPrefabData prefabData = item.GetPrefabData();
34 
35  if (!prefabData)
36  return false;
37 
38  return IsPrefabInArsenalStorage(prefabData.GetPrefabName());
39  }
40 
41  //------------------------------------------------------------------------------------------------
42  protected void OnArsenalUpdated(array<ResourceName> newArsenalContent)
43  {
44  m_ItemsInArsenal.Clear();
45  if (!newArsenalContent)
46  return;
47 
48  foreach (ResourceName prefab : newArsenalContent)
49  {
50  m_ItemsInArsenal.Insert(prefab);
51  }
52  }
53 
54  //------------------------------------------------------------------------------------------------
55  // Callback when item is added (will be performed locally after server completed the Insert/Move operation)
56  override protected void OnItemAdded(BaseInventoryStorageComponent storageOwner, IEntity item)
57  {
58  super.OnItemAdded(storageOwner, item);
59 
60  //~ Get the total weight and volume of all items added to negate that weight and volume the next frame
61  if (m_bNegateItemWeightAndVolume && Replication.IsServer())
62  {
63  if (storageOwner.GetParentSlot())
64  return;
65 
67  {
70 
71  //~ All items are added the same frame to negate the weight and volume the next frame
72  GetGame().GetCallqueue().CallLater(OnItemsAddedDelay, param1: storageOwner);
73  }
74 
75  InventoryItemComponent inventoryItem = InventoryItemComponent.Cast(item.FindComponent(InventoryItemComponent));
76  m_fTotalItemWeight += inventoryItem.GetTotalWeight();
77  inventoryItem.SetAdditionalVolume(-inventoryItem.GetTotalVolume());
78  }
79  }
80 
81  //------------------------------------------------------------------------------------------------
82  //~ Called one frame later after items were added to the arsenal. All items are added the same frame so the overal weight and volume of all those items added prev frame is removed to negate them
83  protected void OnItemsAddedDelay(BaseInventoryStorageComponent storageOwner)
84  {
86 
87  if (!storageOwner)
88  return;
89 
90  storageOwner.SetAdditionalWeight(-m_fTotalItemWeight);
91  }
92 
93  //------------------------------------------------------------------------------------------------
94  // Callback when item is removed (will be performed locally after server completed the Remove/Move operation)
95  override protected void OnItemRemoved(BaseInventoryStorageComponent storageOwner, IEntity item)
96  {
97  super.OnItemRemoved(storageOwner, item);
98 
99  if (m_OnItemRemovedInvoker && !item.IsDeleted())
100  m_OnItemRemovedInvoker.Invoke(item, storageOwner);
101 
102  //~ Clear any weight as the arsenal is being cleared
103  if (m_bNegateItemWeightAndVolume && !m_bItemAddCallQuequeCalled && Replication.IsServer())
104  {
105  if (storageOwner.GetAdditionalWeight() != 0)
106  storageOwner.SetAdditionalWeight(0);
107 
108  InventoryItemComponent inventoryItem = InventoryItemComponent.Cast(item.FindComponent(InventoryItemComponent));
109  if (!inventoryItem)
110  return;
111  if (inventoryItem.GetAdditionalVolume() != 0)
112  inventoryItem.SetAdditionalVolume(0);
113  }
114  }
115 
116  //------------------------------------------------------------------------------------------------
117  protected override void FillInitialPrefabsToStore(out array<ResourceName> prefabsToSpawn)
118  {
119  super.FillInitialPrefabsToStore(prefabsToSpawn);
120 
121  if (SCR_Global.IsEditMode())
122  return;
123 
124  SCR_ArsenalComponent arsenalComponent = SCR_ArsenalComponent.Cast(GetOwner().FindComponent(SCR_ArsenalComponent));
125  if (!arsenalComponent)
126  return;
127 
128  array<ResourceName> prefabs = {};
129  arsenalComponent.GetAvailablePrefabs(prefabs);
130  OnArsenalUpdated(prefabs);
131 
132  //~ Subscribe to arsenal changes
133  arsenalComponent.GetOnArsenalUpdated().Insert(OnArsenalUpdated);
134  }
135 
136  //------------------------------------------------------------------------------------------------
137  // destructor
139  {
140  SCR_ArsenalComponent arsenalComponent = SCR_ArsenalComponent.Cast(GetOwner().FindComponent(SCR_ArsenalComponent));
141  if (!arsenalComponent)
142  return;
143 
144  arsenalComponent.GetOnArsenalUpdated().Remove(OnArsenalUpdated);
145  }
146 }
FillInitialPrefabsToStore
protected override void FillInitialPrefabsToStore(out array< ResourceName > prefabsToSpawn)
Definition: SCR_ArsenalInventoryStorageManagerComponent.c:117
m_fTotalItemWeight
protected float m_fTotalItemWeight
Definition: SCR_ArsenalInventoryStorageManagerComponent.c:11
m_OnItemRemovedInvoker
ref ScriptInvokerBase< ScriptInvokerEntityAndStorageMethod > m_OnItemRemovedInvoker
Definition: ScriptedInventoryStorageManagerComponent.c:8
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
OnItemRemoved
override protected void OnItemRemoved(BaseInventoryStorageComponent storageOwner, IEntity item)
Definition: SCR_ArsenalInventoryStorageManagerComponent.c:95
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
OnItemAdded
override protected void OnItemAdded(BaseInventoryStorageComponent storageOwner, IEntity item)
Definition: SCR_ArsenalInventoryStorageManagerComponent.c:56
SCR_ArsenalInventoryStorageManagerComponentClass
Definition: SCR_ArsenalInventoryStorageManagerComponent.c:1
ScriptedInventoryStorageManagerComponentClass
Definition: ScriptedInventoryStorageManagerComponent.c:1
~SCR_ArsenalInventoryStorageManagerComponent
void ~SCR_ArsenalInventoryStorageManagerComponent()
Definition: SCR_ArsenalInventoryStorageManagerComponent.c:138
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
m_bItemAddCallQuequeCalled
protected bool m_bItemAddCallQuequeCalled
Definition: SCR_ArsenalInventoryStorageManagerComponent.c:14
InventoryItemComponent
Definition: InventoryItemComponent.c:12
SCR_Global
Definition: Functions.c:6
m_ItemsInArsenal
protected ref set< ResourceName > m_ItemsInArsenal
Definition: SCR_ArsenalInventoryStorageManagerComponent.c:16
OnArsenalUpdated
protected void OnArsenalUpdated(array< ResourceName > newArsenalContent)
Definition: SCR_ArsenalInventoryStorageManagerComponent.c:42
SCR_ArsenalComponent
Definition: SCR_ArsenalComponent.c:9
OnItemsAddedDelay
protected void OnItemsAddedDelay(BaseInventoryStorageComponent storageOwner)
Definition: SCR_ArsenalInventoryStorageManagerComponent.c:83
IsItemInArsenalStorage
bool IsItemInArsenalStorage(notnull IEntity item)
Definition: SCR_ArsenalInventoryStorageManagerComponent.c:31
Attribute
SCR_ArsenalInventoryStorageManagerComponentClass ScriptedInventoryStorageManagerComponentClass Attribute("1", desc:"If true it will negate the weight and volume of the items within the arsenal, if false the items within the arsenal will have weight and volume")] protected bool m_bNegateItemWeightAndVolume
IsPrefabInArsenalStorage
bool IsPrefabInArsenalStorage(ResourceName item)
Definition: SCR_ArsenalInventoryStorageManagerComponent.c:22