Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ScenarioFrameworkActionItemSafeguard.c
Go to the documentation of this file.
3{
4 [Attribute(desc: "Target entity (Optional if action is attached on Slot that spawns target entity)")]
5 ref SCR_ScenarioFrameworkGet m_Getter;
6
7 [Attribute(desc: "Actions that will be executed when target item is dropped", UIWidgets.Auto)]
8 ref array<ref SCR_ScenarioFrameworkActionBase> m_aActionsOnItemDropped;
9
10 [Attribute(desc: "Actions that will be executed when target item is possesed by someone/something", UIWidgets.Auto)]
11 ref array<ref SCR_ScenarioFrameworkActionBase> m_aActionsOnItemPossessed;
12
15
16 //------------------------------------------------------------------------------------------------
17 void OnItemPossessed(IEntity item, BaseInventoryStorageComponent pStorageOwner)
18 {
19 if(!item || item != m_ItemEntity)
20 return;
21
22 foreach (SCR_ScenarioFrameworkActionBase action : m_aActionsOnItemPossessed)
23 {
24 action.OnActivate(pStorageOwner.GetOwner());
25 }
26 }
27
28 //------------------------------------------------------------------------------------------------
29 void OnItemDropped(IEntity item, BaseInventoryStorageComponent pStorageOwner)
30 {
31 if(!item || item != m_ItemEntity)
32 return;
33
34 foreach (SCR_ScenarioFrameworkActionBase action : m_aActionsOnItemDropped)
35 {
36 action.OnActivate(pStorageOwner.GetOwner());
37 }
38 }
39
40 //------------------------------------------------------------------------------------------------
42 {
43 EventHandlerManagerComponent eventHandlerMgr;
44 InventoryItemComponent inventoryComponent;
45 IEntity owner;
46 IEntity rootOwner;
47 if (oldSlot)
48 {
49 owner = oldSlot.GetOwner();
50 rootOwner = owner.GetRootParent();
51
52 //Handles the case when for example item was inserted into the character inventory somewhere
53 eventHandlerMgr = EventHandlerManagerComponent.Cast(owner.FindComponent(EventHandlerManagerComponent));
54 if (eventHandlerMgr)
55 eventHandlerMgr.RemoveScriptHandler("OnDestroyed", this, OnDestroyed);
56
57 //Handles the case when for example item was inserted into a backpack that was already in a vehicle
58 if (owner != rootOwner)
59 {
60 eventHandlerMgr = EventHandlerManagerComponent.Cast(rootOwner.FindComponent(EventHandlerManagerComponent));
61 if (eventHandlerMgr)
62 eventHandlerMgr.RemoveScriptHandler("OnDestroyed", this, OnDestroyed);
63
64 //Handles possible revert of case prevention where GarbageSystem might delete root entity
66 {
67 HandleOldSlotGC(rootOwner);
68 }
69 }
70 else
71 {
72 HandleOldSlotGC(owner);
73 }
74
75 //Handles the case when for example item was inserted into a backpack and then this backpack was inserted into a vehicle
76 inventoryComponent = InventoryItemComponent.Cast(owner.FindComponent(InventoryItemComponent));
77 if (inventoryComponent)
78 inventoryComponent.m_OnParentSlotChangedInvoker.Remove(OnItemCarrierChanged);
79 }
80
81 if (newSlot)
82 {
83 owner = newSlot.GetOwner();
84 rootOwner = owner.GetRootParent();
85
86 //Handles the case when for example item is inserted into the character inventory somewhere
87 eventHandlerMgr = EventHandlerManagerComponent.Cast(owner.FindComponent(EventHandlerManagerComponent));
88 if (eventHandlerMgr)
89 eventHandlerMgr.RegisterScriptHandler("OnDestroyed", this, OnDestroyed);
90
91 //Handles the case when for example item is inserted into a backpack that is already in a vehicle
92 if (owner != rootOwner)
93 {
94 eventHandlerMgr = EventHandlerManagerComponent.Cast(rootOwner.FindComponent(EventHandlerManagerComponent));
95 if (eventHandlerMgr)
96 eventHandlerMgr.RegisterScriptHandler("OnDestroyed", this, OnDestroyed);
97
98 HandleNewSlotGC(rootOwner);
99 }
100 else
101 {
102 HandleNewSlotGC(owner);
103 }
104
105 //Handles the case when for example item is inserted into a backpack and then this backpack is inserted into a vehicle
106 inventoryComponent = InventoryItemComponent.Cast(owner.FindComponent(InventoryItemComponent));
107 if (inventoryComponent)
108 {
109 inventoryComponent.m_OnParentSlotChangedInvoker.Insert(OnItemCarrierChanged);
110 }
111 }
112 }
113
114 //------------------------------------------------------------------------------------------------
116 protected void HandleNewSlotGC(IEntity entity)
117 {
119 if (!garbageSystem)
120 return;
121
122 if (garbageSystem.IsInserted(entity))
124 else
126
127 garbageSystem.UpdateBlacklist(entity, true);
128 }
129
130 //------------------------------------------------------------------------------------------------
132 protected void HandleOldSlotGC(IEntity entity)
133 {
135 if (garbageSystem && m_eGarbageCollectionStatus == SCR_EScenarioFrameworkItemGCState.NOT_EXCLUDED)
136 {
137 garbageSystem.UpdateBlacklist(entity, false);
138 garbageSystem.Insert(entity);
139 }
140 }
141
142 //------------------------------------------------------------------------------------------------
144 protected void OnDestroyed(IEntity destroyedEntity)
145 {
146 if (!destroyedEntity)
147 return;
148
149 if (!m_ItemEntity)
150 return;
151
153 if (!invComp)
154 return;
155
156 InventoryStorageSlot parentSlot = invComp.GetParentSlot();
157 if (!parentSlot)
158 return;
159
161 if (!inventoryComponent)
162 return;
163
164 if (!inventoryComponent.Contains(m_ItemEntity))
165 return;
166
167 inventoryComponent.TryRemoveItemFromStorage(m_ItemEntity, parentSlot.GetStorage());
168
170 array<IEntity> excludedEntities = {};
171 excludedEntities.Insert(destroyedEntity);
172 excludedEntities.Insert(m_ItemEntity);
173
174 ChimeraCharacter character = ChimeraCharacter.Cast(destroyedEntity);
175 if (character && character.IsInVehicle())
176 {
177 CompartmentAccessComponent compartmentAccess = character.GetCompartmentAccessComponent();
178 if (compartmentAccess)
179 {
180 BaseCompartmentSlot compartmentSlot = compartmentAccess.GetCompartment();
181 if (compartmentSlot)
182 {
183 IEntity vehicle = compartmentSlot.GetOwner();
184 excludedEntities.Insert(vehicle);
185 }
186 }
187 }
188
189 SCR_TerrainHelper.SnapToGeometry(position, m_ItemEntity.GetOrigin(), excludedEntities, m_ItemEntity.GetWorld());
190
191 m_ItemEntity.SetOrigin(position);
192 m_ItemEntity.Update();
193 }
194
195 //------------------------------------------------------------------------------------------------
196 protected void OnDisconnected(int playerID)
197 {
198 IEntity player = GetGame().GetPlayerManager().GetPlayerControlledEntity(playerID);
199 if (!player)
200 return;
201
202 OnDestroyed(player);
203 }
204
205 //------------------------------------------------------------------------------------------------
206 protected void RegisterPlayer(int playerID, IEntity playerEntity)
207 {
208 IEntity player = GetGame().GetPlayerManager().GetPlayerControlledEntity(playerID);
209 if (!player)
210 return;
211
212 SCR_InventoryStorageManagerComponent inventoryComponent = SCR_InventoryStorageManagerComponent.Cast(player.FindComponent(SCR_InventoryStorageManagerComponent));
213 if (!inventoryComponent)
214 return;
215
216 inventoryComponent.m_OnItemAddedInvoker.Insert(OnItemPossessed);
217 inventoryComponent.m_OnItemRemovedInvoker.Insert(OnItemDropped);
218
219 EventHandlerManagerComponent eventHandlerMgr = EventHandlerManagerComponent.Cast(player.FindComponent(EventHandlerManagerComponent));
220 if (eventHandlerMgr)
221 eventHandlerMgr.RegisterScriptHandler("OnDestroyed", this, OnDestroyed);
222 }
223
224 //------------------------------------------------------------------------------------------------
225 override void OnActivate(IEntity object)
226 {
227 if (!CanActivate())
228 return;
229
230 if (!ValidateInputEntity(object, m_Getter, m_ItemEntity))
231 return;
232
234 if (!invComp)
235 return;
236
237 invComp.m_OnParentSlotChangedInvoker.Insert(OnItemCarrierChanged);
238
239 array<int> aPlayerIDs = {};
240 int iNrOfPlayersConnected = GetGame().GetPlayerManager().GetPlayers(aPlayerIDs);
241
242 foreach (int playerID : aPlayerIDs)
243 {
244 RegisterPlayer(playerID, null);
245 }
246
248 if (!gameMode)
249 return;
250
251 gameMode.GetOnPlayerSpawned().Insert(RegisterPlayer);
252 gameMode.GetOnPlayerDisconnected().Insert(OnDisconnected);
253 }
254
255 //------------------------------------------------------------------------------------------------
256 override array<ref SCR_ScenarioFrameworkActionBase> GetSubActions()
257 {
258 array<ref SCR_ScenarioFrameworkActionBase> m_aSubActions = {};
259 if (m_aActionsOnItemDropped)
260 {
261 foreach (SCR_ScenarioFrameworkActionBase action : m_aActionsOnItemDropped)
262 {
263 m_aSubActions.Insert(action);
264 }
265 }
266
267 if (m_aActionsOnItemPossessed)
268 {
269 foreach (SCR_ScenarioFrameworkActionBase action : m_aActionsOnItemPossessed)
270 {
271 m_aSubActions.Insert(action);
272 }
273 }
274
275 return m_aSubActions;
276 }
277}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
SCR_BaseGameMode GetGameMode()
vector position
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external Managed FindComponent(typename typeName)
proto external IEntity GetRootParent()
ScriptInvokerBase< SCR_BaseGameMode_OnPlayerDisconnected > GetOnPlayerDisconnected()
ScriptInvokerBase< SCR_BaseGameMode_PlayerIdAndEntity > GetOnPlayerSpawned()
Script entry for garbage system modding.
static SCR_GarbageSystem GetByEntityWorld(IEntity entity)
override array< ref SCR_ScenarioFrameworkActionBase > GetSubActions()
void HandleNewSlotGC(IEntity entity)
Handles the cases where GarbageSystem might delete new slot entity.
void OnDestroyed(IEntity destroyedEntity)
Used to remove task item from destroyed entity inventory and drop it to the ground.
void OnItemCarrierChanged(InventoryStorageSlot oldSlot, InventoryStorageSlot newSlot)
void OnItemPossessed(IEntity item, BaseInventoryStorageComponent pStorageOwner)
void HandleOldSlotGC(IEntity entity)
Handles possible revert of case prevention where GarbageSystem might delete root entity.
void OnItemDropped(IEntity item, BaseInventoryStorageComponent pStorageOwner)
static void SnapToGeometry(out vector newPosition, vector currentPosition, array< IEntity > excludedEntities, BaseWorld world=null, TraceParam traceParam=null, out vector surfaceNormal=vector.Zero)
SCR_FieldOfViewSettings Attribute