Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ArsenalInventoryStorageManagerComponent.c
Go to the documentation of this file.
4
5class 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 //------------------------------------------------------------------------------------------------
23 {
24 return m_ItemsInArsenal.Contains(item);
25 }
26
27 //------------------------------------------------------------------------------------------------
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
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
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
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 if (arsenalComponent.GetAvailablePrefabs(prefabs))
130 OnArsenalUpdated(prefabs);
131 else if (!SCR_EntityCatalogManagerComponent.GetInstance())
132 SCR_EntityCatalogManagerComponent.GetOnEntityCatalogInitialized().Insert(OnEntityCatalogInitialized);
133
134 //~ Subscribe to arsenal changes
135 arsenalComponent.GetOnArsenalUpdated().Insert(OnArsenalUpdated);
136 }
137
138 //------------------------------------------------------------------------------------------------
140 {
141 SCR_EntityCatalogManagerComponent.GetOnEntityCatalogInitialized().Remove(OnEntityCatalogInitialized);
142 SCR_ArsenalComponent arsenalComponent = SCR_ArsenalComponent.Cast(GetOwner().FindComponent(SCR_ArsenalComponent));
143 if (!arsenalComponent)
144 return;
145
146 array<ResourceName> prefabs = {};
147 if (!arsenalComponent.GetAvailablePrefabs(prefabs))
148 return;
149
150 OnArsenalUpdated(prefabs);
151 }
152
153 //------------------------------------------------------------------------------------------------
154 // destructor
156 {
157 SCR_ArsenalComponent arsenalComponent = SCR_ArsenalComponent.Cast(GetOwner().FindComponent(SCR_ArsenalComponent));
158 if (!arsenalComponent)
159 return;
160
161 arsenalComponent.GetOnArsenalUpdated().Remove(OnArsenalUpdated);
162 }
163}
ArmaReforgerScripted GetGame()
Definition game.c:1398
ref set< ResourceName > m_ItemsInArsenal
bool IsItemInArsenalStorage(notnull IEntity item)
void OnItemAdded(BaseInventoryStorageComponent storageOwner, IEntity item)
override void FillInitialPrefabsToStore(out array< ResourceName > prefabsToSpawn)
void OnItemRemoved(BaseInventoryStorageComponent storageOwner, IEntity item)
bool IsPrefabInArsenalStorage(ResourceName item)
void ~SCR_ArsenalInventoryStorageManagerComponent()
void OnArsenalUpdated(array< ResourceName > newArsenalContent)
void OnItemsAddedDelay(BaseInventoryStorageComponent storageOwner)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ref ScriptInvokerBase< ScriptInvokerEntityAndStorageMethod > m_OnItemRemovedInvoker
proto external Managed FindComponent(typename typeName)
proto external bool IsDeleted()
Main replication API.
Definition Replication.c:14
bool GetAvailablePrefabs(out notnull array< ResourceName > availablePrefabs)
ScriptInvokerArsenalUpdated GetOnArsenalUpdated()
static bool IsEditMode()
Definition Functions.c:1566
IEntity GetOwner()
Owner entity of the fuel tank.
SCR_FieldOfViewSettings Attribute
Tuple param1