Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
barbedwire.c
Go to the documentation of this file.
1 class BarbedWire extends ItemBase
2 {
3  // Sounds lists
4  const static int SOUNDS_SPARK_COUNT = 4;
5  const static int SOUNDS_CUT_COUNT = 3;
6  const static int SOUNDS_COLLISION_COUNT = 4;
7  const static int SOUNDS_SHOCK_COUNT = 4;
8  const static float RANDOM_SPARK_INTERVAL = 5.0; // TO DO! Currently not used.
9 
10  const static string m_SoundsSpark[SOUNDS_SPARK_COUNT] = {"electricFenceSpark1", "electricFenceSpark2", "electricFenceSpark3", "electricFenceSpark4"};
11  const static string m_SoundsCut[SOUNDS_CUT_COUNT] = {"barbedFenceCut1", "barbedFenceCut2", "barbedFenceCut3"};
12  const static string m_SoundsCollision[SOUNDS_COLLISION_COUNT] = {"barbedFenceCollision1", "barbedFenceCollision2", "barbedFenceCollision3", "barbedFenceCollision4"};
13  const static string m_SoundsShock[SOUNDS_SHOCK_COUNT] = {"electricFenceShock1", "electricFenceShock2", "electricFenceShock3", "electricFenceShock4"};
14  const static string m_SoundBuzzLoop = "electricFenceBuzzLoop1";
15  ref protected EffectSound m_DeployLoopSound;
16 
17  SoundOnVehicle m_BuzzSoundLoop;
18 
19  ref Timer m_SparkEvent;
20  protected ref AreaDamageManager m_AreaDamage;
21 
22  protected bool m_TriggerActive;
23  protected bool m_IsPlaced;
24 
25  //mounting
26  protected bool m_IsMounted;
27  protected bool m_LastMountedState;
28  const string SOUND_MOUNT = "putDown_BarbedWire_SoundSet";
29  protected EffectSound m_MountSound;
30 
31 
32  void BarbedWire()
33  {
34  m_SparkEvent = new Timer( CALL_CATEGORY_SYSTEM );
35  m_TriggerActive = false;
36  m_IsPlaced = false;
37 
38  //synchronized variables
39  RegisterNetSyncVariableBool( "m_IsSoundSynchRemote" );
40  RegisterNetSyncVariableBool( "m_IsDeploySound" );
41  RegisterNetSyncVariableBool( "m_IsMounted" );
42  }
43 
44  void ~BarbedWire()
45  {
46  SEffectManager.DestroyEffect( m_DeployLoopSound );
47  }
48 
49  override void EEInit()
50  {
51  super.EEInit();
52 
53  GetGame().GetCallQueue( CALL_CATEGORY_GAMEPLAY ).CallLater( UpdateAttachmentSlot, 100, false );
54  }
55 
56  bool IsMounted()
57  {
58  return GetSlotLockedState();
59  }
60 
61  protected bool GetSlotLockedState()
62  {
63  BaseBuildingBase base_building = BaseBuildingBase.Cast( GetHierarchyParent() );
64  if ( base_building )
65  {
66  InventoryLocation inventory_location = new InventoryLocation;
67  GetInventory().GetCurrentInventoryLocation( inventory_location );
68  return base_building.GetInventory().GetSlotLock( inventory_location.GetSlot() );
69  }
70 
71  return false;
72  }
73 
74  void SetMountedState( bool is_mounted )
75  {
76  if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] " + GetDebugName(this) + " SetMountedState mounted=" + is_mounted);
77 
78  //lock slot
79  m_IsMounted = is_mounted;
80  LockAttachmentSlot( is_mounted );
81  SetTakeable( !is_mounted );
82 
83  //synchronize
84  Synchronize();
85  }
86 
87  protected void UpdateAttachmentSlot()
88  {
89  BaseBuildingBase base_building = BaseBuildingBase.Cast( GetHierarchyParent() );
90  if ( base_building )
91  {
92  InventoryLocation inventory_location = new InventoryLocation;
93  GetInventory().GetCurrentInventoryLocation( inventory_location );
94  bool is_mounted = base_building.GetInventory().GetSlotLock( inventory_location.GetSlot() );
95  string slot_name = InventorySlots.GetSlotName( inventory_location.GetSlot() );
96 
97  base_building.UpdateAttachmentVisuals( slot_name, is_mounted );
98  base_building.UpdateAttachmentPhysics( slot_name, is_mounted );
99  }
100  }
101 
102  protected void LockAttachmentSlot( bool lock_state )
103  {
104  BaseBuildingBase base_building = BaseBuildingBase.Cast( GetHierarchyParent() );
105  if ( base_building )
106  {
107  InventoryLocation inventory_location = new InventoryLocation;
108  GetInventory().GetCurrentInventoryLocation( inventory_location );
109  base_building.GetInventory().SetSlotLock( inventory_location.GetSlot(), lock_state );
110  //string slot_name = InventorySlots.GetSlotName( inventory_location.GetSlot() );
111  //base_building.UpdateAttachmentVisuals( slot_name, lock_state );
112  //base_building.UpdateAttachmentPhysics( slot_name, lock_state );
113  }
114  }
115 
116  // --- SYNCHRONIZATION
117  void Synchronize()
118  {
119  if ( GetGame().IsServer() )
120  {
121  SetSynchDirty();
122  }
123  }
124 
125  override void OnVariablesSynchronized()
126  {
127  super.OnVariablesSynchronized();
128 
129  if ( ( m_IsMounted && !m_LastMountedState ) || ( !m_IsMounted && m_LastMountedState ) )
130  {
131  //Play sound
132  PlaySoundSet( m_MountSound, SOUND_MOUNT, 0.1, 0.1 );
133  }
134  m_LastMountedState = m_IsMounted;
135 
136  if ( IsDeploySound() )
137  {
138  PlayDeploySound();
139  }
140 
141  if ( CanPlayDeployLoopSound() )
142  {
144  }
145 
147  {
149  }
150  }
151 
152  void PlayDeployLoopSound()
153  {
154  if ( !GetGame().IsDedicatedServer() )
155  {
156  if ( !m_DeployLoopSound || !m_DeployLoopSound.IsSoundPlaying() )
157  {
159  }
160  }
161  }
162 
163  void StopDeployLoopSound()
164  {
165  if ( !GetGame().IsDedicatedServer() )
166  {
167  m_DeployLoopSound.SetSoundFadeOut(0.5);
168  m_DeployLoopSound.SoundStop();
169  }
170  }
171 
172  // --- EVENTS
173  override void OnStoreSave( ParamsWriteContext ctx )
174  {
175  super.OnStoreSave( ctx );
176  }
177 
178  override bool OnStoreLoad( ParamsReadContext ctx, int version )
179  {
180  if ( !super.OnStoreLoad( ctx, version ) )
181  return false;
182 
183  //--- Barbed wire data ---
184  //is mounted (removed in ver. 105)
185  if ( version < 105 )
186  {
187  float is_mounted;
188  if ( !ctx.Read( is_mounted ) )
189  {
190  return false;
191  }
192  }
193  //---
194 
195  return true;
196  }
197 
198  override void AfterStoreLoad()
199  {
200  super.AfterStoreLoad();
201 
202  //set mounted state based on locked slot after everything is loaded
203  SetMountedState( GetSlotLockedState() );
204  }
205 
206  // ---
207  override void OnWorkStart()
208  {
209  SoundBuzzLoopStart();
210  if (m_TriggerActive)
211  { DestroyDamageTrigger(); }
212 
213  if (m_IsPlaced)
214  {
215  //TimerRandomSpark();
216  CreateElectrifiedDamageTrigger();
217  }
218  }
219 
220  override void OnWorkStop()
221  {
222  SoundBuzzLoopStop();
223  if (m_TriggerActive)
224  { DestroyDamageTrigger(); }
225 
226  if (m_IsPlaced)
227  { CreateDamageTrigger(); }
228 
229  m_SparkEvent.Stop();
230  }
231 
232  override void OnWork( float consumed_energy ) {}
233 
234  override void OnIsPlugged(EntityAI source_device)
235  {
236  SoundCut();
237  }
238 
239  override void OnIsUnplugged( EntityAI last_energy_source )
240  {
241  if (m_TriggerActive)
242  { DestroyDamageTrigger(); }
243  SoundCut();
244  }
245 
246  override void OnInventoryEnter(Man player)
247  {
248  super.OnInventoryEnter(player);
249  HideSelection("placing");
250  ShowSelection("zbytek");
251  if (m_TriggerActive)
252  { DestroyDamageTrigger(); }
253  GetCompEM().UnplugThis();
254  GetCompEM().UnplugAllDevices();
255  }
256 
257  // Area Damage triggers
258  // ---------------------------------------------------------
259  protected void CreateElectrifiedDamageTrigger()
260  {
261  m_AreaDamage = new AreaDamageRegular(this);
262  m_AreaDamage.SetExtents("-1 0 -0.4", "1 0.7 0.4");
263  m_AreaDamage.SetLoopInterval(0.3);
264  m_AreaDamage.SetHitZones({"RightLeg", "LeftLeg", "RightFoot", "LeftFoot"});
265  m_AreaDamage.SetAmmoName("BarbedWireHit");
266  m_AreaDamage.Spawn();
267  m_TriggerActive = true;
268  }
269 
270  protected void CreateDamageTrigger()
271  {
272  m_AreaDamage = new AreaDamageOneTime(this);
273  m_AreaDamage.SetExtents("-1 0 -0.4", "1 0.7 0.4");
274  m_AreaDamage.SetHitZones({"RightLeg", "LeftLeg", "RightFoot", "LeftFoot"});
275  m_AreaDamage.SetAmmoName("BarbedWireHit");
276  m_AreaDamage.Spawn();
277  m_TriggerActive = true;
278  }
279 
280  protected void DestroyDamageTrigger()
281  {
282  m_AreaDamage.Destroy();
283  m_TriggerActive = false;
284  }
285  // ---------------------------------------------------------
286 
287  // Controls spawn of random sparks
288  /*
289  protected void TimerRandomSpark() // TO DO: Come up with randomized functionality.
290  {
291  if ( GetCompEM().IsSwitchedOn() )
292  {
293  int plugged_devices = GetCompEM().GetEnergySource().GetCompEM().GetPluggedDevicesCount();
294  float rnd_time = Math.RandomFloat(0.3, RANDOM_SPARK_INTERVAL / plugged_devices + 1.0);
295  m_SparkEvent.Run(rnd_time + 0.3, this, "Spark", NULL, true);
296  }
297  }
298  */
299 
300  // Spawns spark particle effect and plays sound.
301  void Spark()
302  {
303  ParticleManager.GetInstance().PlayOnObject( ParticleList.BARBED_WIRE_SPARKS, this);
304  SoundSpark();
305  }
306 
307 
308  // SOUNDS
309  // ---------------------------------------------------------
310  void SoundCut()
311  {
312  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
313  {
314  int random_index = Math.RandomInt(0, SOUNDS_CUT_COUNT);
315  string sound_type = m_SoundsCut[random_index];
316  PlaySound(sound_type, 50);
317  }
318  }
319 
320  // Plays sound
321  void SoundSpark()
322  {
323  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
324  {
325  int random_index = Math.RandomInt(0, SOUNDS_SPARK_COUNT);
326  string sound_type = m_SoundsSpark[random_index];
327  PlaySound(sound_type, 50);
328  }
329  }
330 
331  // Plays sound
332  void SoundBuzzLoopStart()
333  {
334  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
335  {
336  if (!m_BuzzSoundLoop)
337  {
338  m_BuzzSoundLoop = PlaySoundLoop(m_SoundBuzzLoop, 50);
339  }
340  }
341  }
342 
343  // Stops sound
344  void SoundBuzzLoopStop()
345  {
346  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
347  {
348  if (m_BuzzSoundLoop)
349  {
350  GetGame().ObjectDelete(m_BuzzSoundLoop);
351  m_BuzzSoundLoop = NULL;
352  }
353  }
354  }
355 
356  // Plays an electric shock sound
357  void SoundElectricShock()
358  {
359  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
360  {
361  int random_index = Math.RandomInt(0, SOUNDS_SHOCK_COUNT);
362  string sound_type = m_SoundsShock[random_index];
363  PlaySound(sound_type, 50);
364  }
365  }
366 
367  // Plays a collision sound
368  void SoundCollision()
369  {
370  if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
371  {
372  int random_index = Math.RandomInt(0, SOUNDS_COLLISION_COUNT);
373  string sound_type = m_SoundsCollision[random_index];
374  PlaySound(sound_type, 50);
375  }
376  }
377  // ---------------------------------------------------------
378 
379  // Area Damage Pre/Post actions
380  // ---------------------------------------------------------
381  override void PreAreaDamageActions()
382  {
383  if ( GetCompEM().IsPlugged() && GetCompEM().IsSwitchedOn() )
384  {
385  Spark();
386  SoundElectricShock();
387  }
388  SoundCollision();
389  }
390 
391  override void PostAreaDamageActions()
392  {
393  //dmg to barbed wire here
394  MiscGameplayFunctions.DealAbsoluteDmg(this, 1000);
395  }
396  // ---------------------------------------------------------
397 
398 
399  // TODO: proper handling can be done once the ticket DAYZ-26145 is resolved
400  override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
401  {
402  super.OnItemLocationChanged(old_owner, new_owner);
403 
404  if (m_TriggerActive)
405  {
407  m_IsPlaced = false;
408  }
409  }
410 
411  //================================================================
412  // ADVANCED PLACEMENT
413  //================================================================
414 
415  override void OnPlacementComplete( Man player, vector position = "0 0 0", vector orientation = "0 0 0" )
416  {
417  super.OnPlacementComplete( player, position, orientation );
418 
419  if ( GetGame().IsServer() )
420  {
421  ShowAllSelections();
422  HideSelection("zbytek");
423 
424  if (!GetHierarchyParent())
425  {
426  if (GetCompEM().IsPlugged() && GetCompEM().IsWorking() )
427  { CreateElectrifiedDamageTrigger(); }
428  else
429  { CreateDamageTrigger(); }
430  m_IsPlaced = true;
431  }
432 
433  SetIsDeploySound( true );
434  }
435  }
436 
437  override string GetDeploySoundset()
438  {
439  return "placeBarbedWire_SoundSet";
440  }
441 
442  override string GetLoopDeploySoundset()
443  {
444  return "barbedwire_deploy_SoundSet";
445  }
446 
447  override void SetActions()
448  {
449  super.SetActions();
450 
454 
455  }
456 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
CALL_CATEGORY_SYSTEM
const int CALL_CATEGORY_SYSTEM
Definition: tools.c:8
CALL_CATEGORY_GAMEPLAY
const int CALL_CATEGORY_GAMEPLAY
Definition: tools.c:10
LogManager
Definition: debug.c:734
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
ActionAttachToConstruction
Definition: actionattachtoconstruction.c:1
Synchronize
void Synchronize(eInjuryHandlerLevels level)
Definition: injuryhandler.c:173
AreaDamageRegular
Definition: areadamageregulardeferred.c:2
ActionRestrainTarget
Definition: actionrestraintarget.c:23
OnWorkStop
override void OnWorkStop()
Definition: m18smokegrenade_colorbase.c:2
SetIsDeploySound
void SetIsDeploySound(bool is_deploy_sound)
Definition: itembase.c:4293
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
OnVariablesSynchronized
override void OnVariablesSynchronized()
Definition: anniversarymusicsource.c:42
PlayDeploySound
void PlayDeploySound()
Definition: itembase.c:4324
PlayDeployLoopSound
void PlayDeployLoopSound()
OnInventoryEnter
override protected void OnInventoryEnter(Man player)
Definition: fireworksbase.c:71
OnPlacementComplete
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
Definition: explosivesbase.c:133
GetLoopDeploySoundset
override string GetLoopDeploySoundset()
Definition: largetent.c:151
SetTakeable
override void SetTakeable(bool pState)
Definition: itembase.c:4226
IsDeploySound
bool IsDeploySound()
Definition: itembase.c:4298
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
DestroyDamageTrigger
protected void DestroyDamageTrigger()
Definition: areadamagemanager.c:418
GetPosition
class JsonUndergroundAreaTriggerData GetPosition
Definition: undergroundarealoader.c:9
EffectSound
Wrapper class for managing sound through SEffectManager.
Definition: effectsound.c:4
ParticleList
Definition: particlelist.c:11
vector
Definition: enconvert.c:105
AfterStoreLoad
void AfterStoreLoad()
Definition: emotemanager.c:577
BaseBuildingBase
Definition: fence.c:1
OnWork
override void OnWork(float consumed_energy)
Definition: smokegrenadebase.c:195
AddAction
void AddAction(typename actionName)
Definition: advancedcommunication.c:86
SetActions
void SetActions()
Definition: advancedcommunication.c:79
bsbDebugPrint
Chemlight_ColorBase bsbDebugPrint
m_AreaDamage
protected ref AreaDamageManager m_AreaDamage
Definition: fireplacebase.c:214
m_DeployLoopSound
protected ref EffectSound m_DeployLoopSound
Definition: trapbase.c:47
GetDebugName
override string GetDebugName()
Definition: dayzplayer.c:1126
OnStoreSave
void OnStoreSave(ParamsWriteContext ctx)
Definition: modifierbase.c:229
StopDeployLoopSound
void StopDeployLoopSound()
EEInit
override void EEInit()
Definition: contaminatedarea.c:27
CanPlayDeployLoopSound
bool CanPlayDeployLoopSound()
Definition: itembase.c:4360
AreaDamageManager
void AreaDamageManager(EntityAI parent)
Definition: areadamagemanager.c:22
PlaySound
void PlaySound()
Definition: hungersoundhandler.c:38
ActionRestrainSelf
Definition: actionrestrainself.c:23
Timer
Definition: dayzplayerimplement.c:62
CreateDamageTrigger
protected void CreateDamageTrigger()
Definition: areadamagemanager.c:397
Math
Definition: enmath.c:6
ParticleManager
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Definition: particlemanager.c:84
OnItemLocationChanged
override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
Definition: combinationlock.c:75
SEffectManager
Manager class for managing Effect (EffectParticle, EffectSound)
Definition: effectmanager.c:5
OnStoreLoad
bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition: modifiersmanager.c:270
GetDeploySoundset
override string GetDeploySoundset()
Definition: largetent.c:146
EntityAI
Definition: building.c:5
OnWorkStart
override void OnWorkStart()
Definition: smokegrenadebase.c:175