Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PlaceableInventoryItemComponent.c
Go to the documentation of this file.
5
8typedef ScriptInvokerBase<ScriptInvokerItemPlacedMethod> ScriptInvokerItemPlaced;
9
10class SCR_PlaceableInventoryItemComponent : SCR_BaseInventoryItemComponent
11{
12 protected vector m_vMat[4];
13 protected bool m_bUseTransform = false;
14 protected RplId m_ParentRplId = RplId.Invalid();
15 protected RplId m_PlacingCharacterRplId = RplId.Invalid();
16 protected int m_iParentNodeId;
17 protected IEntity m_Parent;
19
21
22 //------------------------------------------------------------------------------------------------
25 protected override void OnPostInit(IEntity owner)
26 {
27 Math3D.MatrixIdentity4(m_vMat);
28 }
29
30 //------------------------------------------------------------------------------------------------
34 {
35 return m_ParentRplId;
36 }
37
38 //------------------------------------------------------------------------------------------------
42 {
43 return m_iParentNodeId;
44 }
45
46 //------------------------------------------------------------------------------------------------
55
56 //------------------------------------------------------------------------------------------------
59 // To be overridden, called when placement is done in SCR_ItemPlacementComponent
60 protected void PlacementDone(notnull ChimeraCharacter user)
61 {
63 s_OnPlacementDoneInvoker.Invoke(user, this);
64 }
65
66 //------------------------------------------------------------------------------------------------
68 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
69 protected void RPC_DoPlaceItem(RplId placingCharacterRplId)
70 {
71 EnablePhysics();
72 ActivateOwner(true);
73
74 m_ParentRplId = -1;
75 m_iParentNodeId = -1;
76
78
79 RplComponent characterRplComp = RplComponent.Cast(Replication.FindItem(placingCharacterRplId));
80 if (!characterRplComp)
81 return;
82
83 ChimeraCharacter placingCharacter = ChimeraCharacter.Cast(characterRplComp.GetEntity());
84 if (!placingCharacter)
85 return;
86
87 PlacementDone(placingCharacter);
88 }
89
90 //------------------------------------------------------------------------------------------------
97
98 //------------------------------------------------------------------------------------------------
102 protected bool ValidateEntity(notnull IEntity entity)
103 {
104 Physics physics = entity.GetPhysics();
105 if (physics && (physics.IsDynamic() || physics.IsKinematic()))
106 return false;
107
108 // F. e. Slotted vehicle parts are physically static, but their main parent (vehicle) is not, we need to check that
109 IEntity mainEntity = entity.GetRootParent();
110 if (mainEntity && mainEntity != entity)
111 {
112 physics = mainEntity.GetPhysics();
113 if (physics && physics.IsDynamic())
114 return false;
115 }
116
117 return true;
118 }
119
120 //------------------------------------------------------------------------------------------------
124 protected bool FilterCallback(notnull IEntity e)
125 {
126 Physics physics = e.GetPhysics();
127 if (physics)
128 {
129 if (physics.GetInteractionLayer() & EPhysicsLayerDefs.Water)
130 return true;
131 }
132
133 return ValidateEntity(e);
134 }
135
136 //------------------------------------------------------------------------------------------------
138 void SetPlacementPosition(vector right, vector up, vector forward, vector position, RplId characterRplId)
139 {
140 m_vMat[0] = right;
141 m_vMat[1] = up;
142 m_vMat[2] = forward;
143 m_vMat[3] = position;
144 m_bUseTransform = true;
145 m_PlacingCharacterRplId = characterRplId;
146 }
147
148 //------------------------------------------------------------------------------------------------
149 override bool OverridePlacementTransform(IEntity caller, out vector computedTransform[4])
150 {
151 if (m_bUseTransform)
152 {
153 m_bUseTransform = false;
154 computedTransform = m_vMat;
155
156 // Entity was purposefully "placed" somewhere so we assume it should stay there (e.g. mines and flags to mark them)
158 if (garbageSystem)
159 garbageSystem.Withdraw(GetOwner());
160
161 return true;
162 }
163
164 m_ParentRplId = -1;
165 m_iParentNodeId = -1;
166 m_PlacingCharacterRplId = RplId.Invalid();
167
168 return false;
169 }
170
171 //------------------------------------------------------------------------------------------------
172 override protected void OnPlacedOnGround()
173 {
174 // To enable again some of the logics for an item after it is placed on the ground.
175
176 ActivateOwner(true);
177
178 // Enable physics to receive contact events
179 Physics physics = GetOwner().GetPhysics();
180 if (physics)
181 EnablePhysics();
182 }
183
184 //------------------------------------------------------------------------------------------------
188 protected void PlayPlacedSound(vector up, vector position, string overrideSoundEvent = SCR_SoundEvent.SOUND_PLACE_OBJECT)
189 {
190 SCR_SoundDataComponent soundData;
191 SoundComponent soundComp = SoundComponent.Cast(GetOwner().FindComponent(SoundComponent));
192 if (!soundComp)
193 {
194 soundData = SCR_SoundDataComponent.Cast(GetOwner().FindComponent(SCR_SoundDataComponent));
195 if (!soundData)
196 return;
197 }
198
199 TraceParam param = new TraceParam();
200 param.Start = position;
201 param.End = param.Start - up;
202 param.Flags = TraceFlags.WORLD | TraceFlags.ENTS;
203 param.Exclude = GetOwner();
204 param.LayerMask = EPhysicsLayerPresets.Projectile;
205 GetOwner().GetWorld().TraceMove(param, null);
206
207 GameMaterial material = param.SurfaceProps;
208 if (!material)
209 return;
210
211 if (soundComp)
212 {
213 soundComp.SetSignalValueStr(SCR_AudioSource.SURFACE_SIGNAL_NAME, material.GetSoundInfo().GetSignalValue());
214 soundComp.SoundEvent(overrideSoundEvent);
215 }
216 else if (soundData)
217 {
218 const IEntity owner = GetOwner();
219 SCR_SoundManagerModule soundManager = SCR_SoundManagerModule.GetInstance(owner.GetWorld());
220 if (!soundManager)
221 return;
222
223 SCR_AudioSourceConfiguration audioSourceConfiguration = soundData.GetAudioSourceConfiguration(overrideSoundEvent);
224 if (!audioSourceConfiguration)
225 return;
226
227 SCR_AudioSource audioSource = soundManager.CreateAudioSource(owner, audioSourceConfiguration, position);
228 if (!audioSource)
229 return;
230
231 audioSource.SetSignalValue(SCR_AudioSource.SURFACE_SIGNAL_NAME, material.GetSoundInfo().GetSignalValue());
232
233 // Play sound
234 soundManager.PlayAudioSource(audioSource);
235 }
236 }
237
238 //------------------------------------------------------------------------------------------------
240 void PlaceItemWithParentChange(RplId newParentRplId, int nodeId = -1)
241 {
242 Rpc(RPC_DoPlaceItemWithParentChange, newParentRplId, nodeId, m_PlacingCharacterRplId);
244 }
245
246 //------------------------------------------------------------------------------------------------
250 [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
251 protected void RPC_DoPlaceItemWithParentChange(RplId newParentRplId, int nodeId, RplId placingCharacterRplId)
252 {
253 EnablePhysics();
254 ActivateOwner(true);
255
256 if (newParentRplId.IsValid())
257 {
258 m_ParentRplId = newParentRplId;
259 m_iParentNodeId = nodeId;
260 if (IsLocked())
261 m_OnLockedStateChangedInvoker.Insert(AttachToNewParentWhenUnlocked);
262 else
264 }
265 else
266 {
267 m_ParentRplId = -1;
268 m_iParentNodeId = -1;
269 }
270
272
273 RplComponent characterRplComp = RplComponent.Cast(Replication.FindItem(placingCharacterRplId));
274 if (!characterRplComp)
275 return;
276
277 ChimeraCharacter placingCharacter = ChimeraCharacter.Cast(characterRplComp.GetEntity());
278 if (!placingCharacter)
279 return;
280
281 PlacementDone(placingCharacter);
282 }
283
284 //------------------------------------------------------------------------------------------------
288 void SetNewParent(RplId parentId = RplId.Invalid(), int nodeId = -1)
289 {
290 if (m_ParentRplId == parentId)
291 return;
292
293 m_ParentRplId = parentId;
294 m_iParentNodeId = nodeId;
295
297 }
298
299 //------------------------------------------------------------------------------------------------
302 protected void AttachToNewParentWhenUnlocked(bool nowLocked)
303 {
304 if (nowLocked)
305 return;
306
307 m_OnLockedStateChangedInvoker.Remove(AttachToNewParentWhenUnlocked);
308
310 }
311
312 //------------------------------------------------------------------------------------------------
314 protected void AttachToNewParent()
315 {
316 if (!m_ParentRplId.IsValid())
317 return;
318
319 IEntity item = GetOwner();
320 if (!item || item.IsDeleted())
321 return;
322
323 RplComponent newParentRplComp = RplComponent.Cast(Replication.FindItem(m_ParentRplId));
324 IEntity newParentEntity;
325 if (newParentRplComp)
326 m_Parent = newParentRplComp.GetEntity(); //cache it as depending how this item will be transfered later we may not have an easy access to it
327
328 if (!m_Parent)
329 m_Parent = IEntity.Cast(Replication.FindItem(m_ParentRplId));
330
331 if (!m_Parent)
332 return;
333
335
336 RplComponent rplComp = RplComponent.Cast(item.FindComponent(RplComponent));
337 if (rplComp && newParentRplComp && rplComp.IsOwner())
338 {
339 RplNode explosiveCharge = rplComp.GetNode();
340 RplNode newParent = newParentRplComp.GetNode();
341
342 explosiveCharge.SetParent(newParent);
343 }
344
345 m_Parent.AddChild(item, m_iParentNodeId);
347 item.Update();
348
350 if (parentDamageManager)
351 {
352 SCR_HitZone hitZone = SCR_HitZone.Cast(parentDamageManager.GetDefaultHitZone());
353 if (hitZone)
355 }
356
357 m_OnParentSlotChangedInvoker.Insert(StartWatchingParentSlots);
358
360 if (iic)
361 iic.m_OnParentSlotChangedInvoker.Insert(DetachFromParent);
362
363 if (m_Parent == m_Parent.GetRootParent())
364 return;
365
366 m_RootParent = m_Parent.GetRootParent(); //cache it as when this item will be transfered we may not be able to tell which one it was
368 if (iic)
369 iic.m_OnParentSlotChangedInvoker.Insert(DetachFromParent);
370 }
371
372 //------------------------------------------------------------------------------------------------
376 {
377 if (hitZone.GetDamageState() == EDamageState.DESTROYED)
379 }
380
381 //------------------------------------------------------------------------------------------------
383 protected void DetachFromParent()
384 {
385 if (!m_Parent)
386 return;
387
388 IEntity owner = GetOwner();
389 if (!owner || owner.IsDeleted())
390 return;
391
392 m_ParentRplId = -1;
393 m_iParentNodeId = -1;
394 m_Parent.RemoveChild(owner, true);
395 array<IEntity> excludeArray = {m_Parent};
396 if (m_RootParent)
397 excludeArray.Insert(m_RootParent);
398
399 SCR_EntityHelper.SnapToGround(owner, excludeArray, onlyStatic: true);
400 owner.SetAngles({0, owner.GetAngles()[1], 0});
401 owner.Update();
402
404 if (parentDamageManager)
405 {
406 SCR_HitZone hitZone = SCR_HitZone.Cast(parentDamageManager.GetDefaultHitZone());
407 if (hitZone)
409 }
410
411 m_OnParentSlotChangedInvoker.Remove(StopWatchingParentSlots);
412
414 if (iic)
415 iic.m_OnParentSlotChangedInvoker.Remove(DetachFromParent);
416
417 m_Parent = null;
418 if (!m_RootParent)
419 return;
420
422 if (iic)
423 iic.m_OnParentSlotChangedInvoker.Remove(DetachFromParent);
424
425 m_RootParent = null;
426 }
427
428 //------------------------------------------------------------------------------------------------
431 {
432 m_OnParentSlotChangedInvoker.Remove(StartWatchingParentSlots);
433 m_OnParentSlotChangedInvoker.Insert(StopWatchingParentSlots);
434 }
435
436 //------------------------------------------------------------------------------------------------
438 protected void StopWatchingParentSlots()
439 {
440 if (!GetOwner())
441 return;
442
443 m_OnParentSlotChangedInvoker.Remove(StopWatchingParentSlots);
444
445 if (m_Parent)
446 {
448 if (parentDamageManager)
449 {
450 SCR_HitZone hitZone = SCR_HitZone.Cast(parentDamageManager.GetDefaultHitZone());
451 if (hitZone)
453 }
454
456 if (iic)
457 iic.m_OnParentSlotChangedInvoker.Remove(DetachFromParent);
458
459 m_Parent = null;
460 }
461
462 if (!m_RootParent)
463 return;
464
466 if (iic)
467 iic.m_OnParentSlotChangedInvoker.Remove(DetachFromParent);
468
469 m_RootParent = null;
470 }
471
472 //------------------------------------------------------------------------------------------------
473 override void OnDelete(IEntity owner)
474 {
476 }
477}
void SCR_AudioSource(SCR_AudioSourceConfiguration audioSourceConfiguration, vector mat[4])
bool IsLocked(IEntity user, BaseCompartmentSlot compartmentSlot)
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
vector position
ScriptInvokerBase< ScriptInvokerItemPlacedMethod > ScriptInvokerItemPlaced
proto external Managed FindComponent(typename typeName)
proto external void SetAngles(vector angles)
Same as SetYawPitchRoll(), but sets rotation around X, Y and Z axis.
proto external vector GetAngles()
Same as GetYawPitchRoll(), but returns rotation vector around X, Y and Z axis.
proto external Physics GetPhysics()
proto external void GetWorldTransform(out vector mat[])
See IEntity::GetTransform.
proto external int Update()
proto external BaseWorld GetWorld()
proto external bool SetWorldTransform(vector mat[4])
See IEntity::SetTransform. Returns false, if there is no change in transformation.
proto external bool IsDeleted()
proto external IEntity GetRootParent()
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
Script entry for garbage system modding.
static SCR_GarbageSystem GetByEntityWorld(IEntity entity)
ScriptInvoker GetOnDamageStateChanged(bool createNew=true)
Definition SCR_HitZone.c:32
void PlaceItemWithParentChange(RplId newParentRplId, int nodeId=-1)
Same as PlaceItem but with params that allow attaching the object to new parent entity.
void StartWatchingParentSlots()
Callback method triggered when item will finish its transfer to new parent when it is being attached ...
void SetPlacementPosition(vector right, vector up, vector forward, vector position, RplId characterRplId)
Authority method used to change the position at which item will placed when removed from the inventor...
override bool OverridePlacementTransform(IEntity caller, out vector computedTransform[4])
void PlacementDone(notnull ChimeraCharacter user)
void RPC_DoPlaceItemWithParentChange(RplId newParentRplId, int nodeId, RplId placingCharacterRplId)
static ScriptInvokerItemPlaced GetOnPlacementDoneInvoker()
void DetachFromParent()
Removes this entity from its parent hierarchy and places it on the ground.
void StopWatchingParentSlots()
Callback method when item is being transfered (f.e. picked up) after it was attached to some object.
void PlayPlacedSound(vector up, vector position, string overrideSoundEvent=SCR_SoundEvent.SOUND_PLACE_OBJECT)
void AttachToNewParent()
Method that will try to find new parent entity and make this entity a child of it.
void SetNewParent(RplId parentId=RplId.Invalid(), int nodeId=-1)
static ref ScriptInvokerItemPlaced s_OnPlacementDoneInvoker
proto external void SetSignalValueStr(string signal, float value)
EPhysicsLayerPresets
Enum is filled by C++ by data in project config PhysicsSettings.LayerPresets.
Definition gameLib.c:19
IEntity GetOwner()
Owner entity of the fuel tank.
EDamageState
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14
TraceFlags
Definition TraceFlags.c:13