DayZ 1.24
Loading...
Searching...
No Matches
BarbedWire.c
Go to the documentation of this file.
1class 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";
16
18
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";
30
31
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
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 {
67 GetInventory().GetCurrentInventoryLocation(inventory_location);
68 return base_building.GetInventory().GetSlotLock(inventory_location.GetSlot());
69 }
70
71 return false;
72 }
73
75 {
76 if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] " + GetDebugName(this) + " SetMountedState mounted=" + is_mounted);
77
78 //lock slot
79 m_IsMounted = is_mounted;
82
83 //synchronize
85 }
86
87 protected void UpdateAttachmentSlot()
88 {
89 BaseBuildingBase base_building = BaseBuildingBase.Cast(GetHierarchyParent());
90 if (base_building)
91 {
93 GetInventory().GetCurrentInventoryLocation(inventory_location);
94 bool is_mounted = base_building.GetInventory().GetSlotLock(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 {
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
118 {
119 if (GetGame().IsServer())
120 SetSynchDirty();
121 }
122
124 {
125 super.OnVariablesSynchronized();
126
127 if ((m_IsMounted && !m_LastMountedState) || (!m_IsMounted && m_LastMountedState))
128 {
129 //Play sound
130 PlaySoundSet(m_MountSound, SOUND_MOUNT, 0.1, 0.1);
131 }
132 m_LastMountedState = m_IsMounted;
133
134 if (IsDeploySound())
136
139
142 }
143
145 {
146 if (!GetGame().IsDedicatedServer())
147 {
148 if (!m_DeployLoopSound || !m_DeployLoopSound.IsSoundPlaying())
150 }
151 }
152
154 {
155 if (!GetGame().IsDedicatedServer())
156 {
157 m_DeployLoopSound.SetSoundFadeOut(0.5);
158 m_DeployLoopSound.SoundStop();
159 }
160 }
161
162 // --- EVENTS
164 {
165 super.OnStoreSave(ctx);
166 }
167
168 override bool OnStoreLoad(ParamsReadContext ctx, int version)
169 {
170 if (!super.OnStoreLoad(ctx, version))
171 return false;
172
173 //--- Barbed wire data ---
174 //is mounted (removed in ver. 105)
175 if (version < 105)
176 {
177 float is_mounted;
178 if (!ctx.Read(is_mounted))
179 return false;
180 }
181 //---
182
183 return true;
184 }
185
186 override void AfterStoreLoad()
187 {
188 super.AfterStoreLoad();
189
190 //set mounted state based on locked slot after everything is loaded
192 }
193
194 // ---
195 override void OnWorkStart()
196 {
198 if (m_TriggerActive)
200
201 if (m_IsPlaced)
202 {
203 //TimerRandomSpark();
205 }
206 }
207
208 override void OnWorkStop()
209 {
211 if (m_TriggerActive)
213
214 if (m_IsPlaced)
216
217 m_SparkEvent.Stop();
218 }
219
220 override void OnWork(float consumed_energy) {}
221
223 {
224 SoundCut();
225 }
226
228 {
229 if (m_TriggerActive)
231 SoundCut();
232 }
233
234 override void OnInventoryEnter(Man player)
235 {
236 super.OnInventoryEnter(player);
237 HideSelection("placing");
238 ShowSelection("zbytek");
239 if (m_TriggerActive)
241 GetCompEM().UnplugThis();
242 GetCompEM().UnplugAllDevices();
243 }
244
245 // Area Damage triggers
246 // ---------------------------------------------------------
248 {
250 m_AreaDamage.SetExtents("-1 0 -0.4", "1 0.7 0.4");
251 m_AreaDamage.SetLoopInterval(0.3);
252 m_AreaDamage.SetHitZones({"RightLeg", "LeftLeg", "RightFoot", "LeftFoot"});
253 m_AreaDamage.SetAmmoName("BarbedWireHit");
254 m_AreaDamage.Spawn();
255 m_TriggerActive = true;
256 }
257
258 protected void CreateDamageTrigger()
259 {
260 m_AreaDamage = new AreaDamageOneTime(this);
261 m_AreaDamage.SetExtents("-1 0 -0.4", "1 0.7 0.4");
262 m_AreaDamage.SetHitZones({"RightLeg", "LeftLeg", "RightFoot", "LeftFoot"});
263 m_AreaDamage.SetAmmoName("BarbedWireHit");
264 m_AreaDamage.Spawn();
265 m_TriggerActive = true;
266 }
267
268 protected void DestroyDamageTrigger()
269 {
270 m_AreaDamage.Destroy();
271 m_TriggerActive = false;
272 }
273 // ---------------------------------------------------------
274
275 // Controls spawn of random sparks
276 /*
277 protected void TimerRandomSpark() // TO DO: Come up with randomized functionality.
278 {
279 if ( GetCompEM().IsSwitchedOn() )
280 {
281 int plugged_devices = GetCompEM().GetEnergySource().GetCompEM().GetPluggedDevicesCount();
282 float rnd_time = Math.RandomFloat(0.3, RANDOM_SPARK_INTERVAL / plugged_devices + 1.0);
283 m_SparkEvent.Run(rnd_time + 0.3, this, "Spark", NULL, true);
284 }
285 }
286 */
287
288 // Spawns spark particle effect and plays sound.
289 void Spark()
290 {
291 ParticleManager.GetInstance().PlayOnObject(ParticleList.BARBED_WIRE_SPARKS, this);
292 SoundSpark();
293 }
294
295
296 // SOUNDS
297 // ---------------------------------------------------------
298 void SoundCut()
299 {
300 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // client side
301 {
302 int random_index = Math.RandomInt(0, SOUNDS_CUT_COUNT);
303 string sound_type = m_SoundsCut[random_index];
305 }
306 }
307
308 // Plays sound
310 {
311 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // client side
312 {
313 int random_index = Math.RandomInt(0, SOUNDS_SPARK_COUNT);
314 string sound_type = m_SoundsSpark[random_index];
316 }
317 }
318
319 // Plays sound
321 {
322 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // client side
323 {
324 if (!m_BuzzSoundLoop)
325 m_BuzzSoundLoop = PlaySoundLoop(m_SoundBuzzLoop, 50);
326 }
327 }
328
329 // Stops sound
331 {
332 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // client side
333 {
334 if (m_BuzzSoundLoop)
335 {
336 GetGame().ObjectDelete(m_BuzzSoundLoop);
337 m_BuzzSoundLoop = NULL;
338 }
339 }
340 }
341
342 // Plays an electric shock sound
344 {
345 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // client side
346 {
347 int random_index = Math.RandomInt(0, SOUNDS_SHOCK_COUNT);
348 string sound_type = m_SoundsShock[random_index];
350 }
351 }
352
353 // Plays a collision sound
355 {
356 if (!GetGame().IsServer() || !GetGame().IsMultiplayer()) // client side
357 {
358 int random_index = Math.RandomInt(0, SOUNDS_COLLISION_COUNT);
359 string sound_type = m_SoundsCollision[random_index];
361 }
362 }
363 // ---------------------------------------------------------
364
365 // Area Damage Pre/Post actions
366 // ---------------------------------------------------------
367 override void PreAreaDamageActions()
368 {
369 if (GetCompEM().IsPlugged() && GetCompEM().IsSwitchedOn())
370 {
371 Spark();
373 }
375 }
376
377 override void PostAreaDamageActions()
378 {
379 //dmg to barbed wire here
380 MiscGameplayFunctions.DealAbsoluteDmg(this, 1000);
381 }
382 // ---------------------------------------------------------
383
384
385 // TODO: proper handling can be done once the ticket DAYZ-26145 is resolved
387 {
388 super.OnItemLocationChanged(old_owner, new_owner);
389
390 if (m_TriggerActive)
391 {
393 m_IsPlaced = false;
394 }
395 }
396
397 //================================================================
398 // ADVANCED PLACEMENT
399 //================================================================
400
401 override void OnPlacementComplete(Man player, vector position = "0 0 0", vector orientation = "0 0 0")
402 {
403 super.OnPlacementComplete(player, position, orientation);
404
405 if (GetGame().IsServer())
406 {
407 ShowAllSelections();
408 HideSelection("zbytek");
409
410 if (!GetHierarchyParent())
411 {
412 if (GetCompEM().IsPlugged() && GetCompEM().IsWorking())
414 else
416 m_IsPlaced = true;
417 }
418
419 SetIsDeploySound(true);
420 }
421 }
422
423 override string GetDeploySoundset()
424 {
425 return "placeBarbedWire_SoundSet";
426 }
427
428 override string GetLoopDeploySoundset()
429 {
430 return "barbedwire_deploy_SoundSet";
431 }
432
433 override void SetActions()
434 {
435 super.SetActions();
436
440
441 }
442}
void AddAction(typename actionName)
class BaseBuildingBase extends ItemBase bsbDebugPrint(string s)
ref AreaDamageManager m_AreaDamage
void PlaySound()
void SetIsDeploySound(bool is_deploy_sound)
Definition ItemBase.c:8972
bool CanPlayDeployLoopSound()
Definition ItemBase.c:9039
override void SetTakeable(bool pState)
Definition ItemBase.c:8905
void PlayDeploySound()
Definition ItemBase.c:9003
bool IsDeploySound()
Definition ItemBase.c:8977
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
ref EffectSound m_DeployLoopSound
Definition TrapBase.c:47
class JsonUndergroundAreaTriggerData GetPosition
Wrapper class for managing sound through SEffectManager.
Definition EffectSound.c:5
InventoryLocation.
provides access to slot configuration
static proto native owned string GetSlotName(int id)
converts slot_id to string
void CreateElectrifiedDamageTrigger()
Definition BarbedWire.c:247
void DestroyDamageTrigger()
Definition BarbedWire.c:268
override void OnInventoryEnter(Man player)
Definition BarbedWire.c:234
void ~BarbedWire()
Definition BarbedWire.c:44
bool m_LastMountedState
Definition BarbedWire.c:27
override void OnWork(float consumed_energy)
Definition BarbedWire.c:220
override void OnIsPlugged(EntityAI source_device)
Definition BarbedWire.c:222
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Definition BarbedWire.c:168
bool GetSlotLockedState()
Definition BarbedWire.c:61
override void OnWorkStart()
Definition BarbedWire.c:195
void Synchronize()
Definition BarbedWire.c:117
static const int SOUNDS_SHOCK_COUNT
Definition BarbedWire.c:7
override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
Definition BarbedWire.c:386
void PlayDeployLoopSound()
Definition BarbedWire.c:144
override void SetActions()
Definition BarbedWire.c:433
ref AreaDamageManager m_AreaDamage
Definition BarbedWire.c:20
override void PostAreaDamageActions()
Definition BarbedWire.c:377
SoundOnVehicle m_BuzzSoundLoop
Definition BarbedWire.c:17
void SoundSpark()
Definition BarbedWire.c:309
void CreateDamageTrigger()
Definition BarbedWire.c:258
bool m_IsMounted
Definition BarbedWire.c:26
override string GetDeploySoundset()
Definition BarbedWire.c:423
override void OnWorkStop()
Definition BarbedWire.c:208
override void OnStoreSave(ParamsWriteContext ctx)
Definition BarbedWire.c:163
void SoundCut()
Definition BarbedWire.c:298
override void AfterStoreLoad()
Definition BarbedWire.c:186
bool IsMounted()
Definition BarbedWire.c:56
void SoundElectricShock()
Definition BarbedWire.c:343
void SetMountedState(bool is_mounted)
Definition BarbedWire.c:74
void LockAttachmentSlot(bool lock_state)
Definition BarbedWire.c:102
void SoundCollision()
Definition BarbedWire.c:354
void SoundBuzzLoopStop()
Definition BarbedWire.c:330
static const int SOUNDS_SPARK_COUNT
Definition BarbedWire.c:4
void SoundBuzzLoopStart()
Definition BarbedWire.c:320
override void OnVariablesSynchronized()
Definition BarbedWire.c:123
override void OnIsUnplugged(EntityAI last_energy_source)
Definition BarbedWire.c:227
EffectSound m_DeployLoopSound
Definition BarbedWire.c:15
ref Timer m_SparkEvent
Definition BarbedWire.c:19
override void EEInit()
Definition BarbedWire.c:49
override string GetLoopDeploySoundset()
Definition BarbedWire.c:428
static const int SOUNDS_COLLISION_COUNT
Definition BarbedWire.c:6
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
Definition BarbedWire.c:401
void Spark()
Definition BarbedWire.c:289
bool m_IsPlaced
Definition BarbedWire.c:23
override void PreAreaDamageActions()
Definition BarbedWire.c:367
EffectSound m_MountSound
Definition BarbedWire.c:29
void UpdateAttachmentSlot()
Definition BarbedWire.c:87
void StopDeployLoopSound()
Definition BarbedWire.c:153
bool m_TriggerActive
Definition BarbedWire.c:22
void BarbedWire()
Definition BarbedWire.c:32
static const int SOUNDS_CUT_COUNT
Definition BarbedWire.c:5
static bool IsBaseBuildingLogEnable()
Definition Debug.c:779
Definition EnMath.c:7
static const int BARBED_WIRE_SPARKS
Manager class for managing Effect (EffectParticle, EffectSound)
static EffectSound PlaySound(string sound_set, vector position, float play_fade_in=0, float stop_fade_out=0, bool loop=false)
Create and play an EffectSound.
static void DestroyEffect(Effect effect)
Unregisters, stops and frees the Effect.
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
override string GetDebugName()
proto native CGame GetGame()
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8