DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
BarbedWire.c
См. документацию.
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";
15
16 SoundOnVehicle m_BuzzSoundLoop;
17
20
21 protected bool m_TriggerActive;
22 protected bool m_IsPlaced;
23
24 //mounting
25 protected bool m_IsMounted;
26 protected bool m_LastMountedState;
27 const string SOUND_MOUNT = "putDown_BarbedWire_SoundSet";
29
30
32 {
34 m_TriggerActive = false;
35 m_IsPlaced = false;
36
37 //synchronized variables
38 RegisterNetSyncVariableBool( "m_IsMounted" );
39 }
40
41 override void EEInit()
42 {
43 super.EEInit();
44
46 }
47
48 bool IsMounted()
49 {
50 return GetSlotLockedState();
51 }
52
53 protected bool GetSlotLockedState()
54 {
55 BaseBuildingBase base_building = BaseBuildingBase.Cast( GetHierarchyParent() );
56 if ( base_building )
57 {
58 InventoryLocation inventory_location = new InventoryLocation;
59 GetInventory().GetCurrentInventoryLocation( inventory_location );
60 return base_building.GetInventory().GetSlotLock( inventory_location.GetSlot() );
61 }
62
63 return false;
64 }
65
66 void SetMountedState( bool is_mounted )
67 {
68 if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] " + GetDebugName(this) + " SetMountedState mounted=" + is_mounted);
69
70 //lock slot
71 m_IsMounted = is_mounted;
72 LockAttachmentSlot( is_mounted );
73 SetTakeable( !is_mounted );
74
75 //synchronize
77 }
78
79 protected void UpdateAttachmentSlot()
80 {
81 BaseBuildingBase base_building = BaseBuildingBase.Cast( GetHierarchyParent() );
82 if ( base_building )
83 {
84 InventoryLocation inventory_location = new InventoryLocation;
85 GetInventory().GetCurrentInventoryLocation( inventory_location );
86 bool is_mounted = base_building.GetInventory().GetSlotLock( inventory_location.GetSlot() );
87 string slot_name = InventorySlots.GetSlotName( inventory_location.GetSlot() );
88
89 base_building.UpdateAttachmentVisuals( slot_name, is_mounted );
90 base_building.UpdateAttachmentPhysics( slot_name, is_mounted );
91 }
92 }
93
94 protected void LockAttachmentSlot( bool lock_state )
95 {
96 BaseBuildingBase base_building = BaseBuildingBase.Cast( GetHierarchyParent() );
97 if ( base_building )
98 {
99 InventoryLocation inventory_location = new InventoryLocation;
100 GetInventory().GetCurrentInventoryLocation( inventory_location );
101 base_building.GetInventory().SetSlotLock( inventory_location.GetSlot(), lock_state );
102 //string slot_name = InventorySlots.GetSlotName( inventory_location.GetSlot() );
103 //base_building.UpdateAttachmentVisuals( slot_name, lock_state );
104 //base_building.UpdateAttachmentPhysics( slot_name, lock_state );
105 }
106 }
107
108 // --- SYNCHRONIZATION
110 {
111 if ( GetGame().IsServer() )
112 {
113 SetSynchDirty();
114 }
115 }
116
118 {
119 super.OnVariablesSynchronized();
120
122 {
123 //Play sound
124 PlaySoundSet( m_MountSound, SOUND_MOUNT, 0.1, 0.1 );
125 }
127 }
128
129 // --- EVENTS
130 override void OnStoreSave( ParamsWriteContext ctx )
131 {
132 super.OnStoreSave( ctx );
133 }
134
135 override bool OnStoreLoad( ParamsReadContext ctx, int version )
136 {
137 if ( !super.OnStoreLoad( ctx, version ) )
138 return false;
139
140 //--- Barbed wire data ---
141 //is mounted (removed in ver. 105)
142 if ( version < 105 )
143 {
144 float is_mounted;
145 if ( !ctx.Read( is_mounted ) )
146 {
147 return false;
148 }
149 }
150 //---
151
152 return true;
153 }
154
155 override void AfterStoreLoad()
156 {
157 super.AfterStoreLoad();
158
159 //set mounted state based on locked slot after everything is loaded
161 }
162
163 // ---
164 override void OnWorkStart()
165 {
167 if (m_TriggerActive)
169
170 if (m_IsPlaced)
171 {
172 //TimerRandomSpark();
174 }
175 }
176
177 override void OnWorkStop()
178 {
180 if (m_TriggerActive)
182
183 if (m_IsPlaced)
185
186 m_SparkEvent.Stop();
187 }
188
189 override void OnWork( float consumed_energy ) {}
190
191 override void OnIsPlugged(EntityAI source_device)
192 {
193 SoundCut();
194 }
195
196 override void OnIsUnplugged( EntityAI last_energy_source )
197 {
198 if (m_TriggerActive)
200 SoundCut();
201 }
202
203 override void OnInventoryEnter(Man player)
204 {
205 super.OnInventoryEnter(player);
206 HideSelection("placing");
207 ShowSelection("zbytek");
208 if (m_TriggerActive)
210 GetCompEM().UnplugThis();
211 GetCompEM().UnplugAllDevices();
212 }
213
214 // Area Damage triggers
215 // ---------------------------------------------------------
217 {
219 m_AreaDamage.SetExtents("-1 0 -0.4", "1 0.7 0.4");
220 m_AreaDamage.SetLoopInterval(0.3);
221 m_AreaDamage.SetHitZones({"RightLeg", "LeftLeg", "RightFoot", "LeftFoot"});
222 m_AreaDamage.SetAmmoName("BarbedWireHit");
223 m_AreaDamage.Spawn();
224 m_TriggerActive = true;
225 }
226
227 protected void CreateDamageTrigger()
228 {
229 m_AreaDamage = new AreaDamageOneTime(this);
230 m_AreaDamage.SetExtents("-1 0 -0.4", "1 0.7 0.4");
231 m_AreaDamage.SetHitZones({"RightLeg", "LeftLeg", "RightFoot", "LeftFoot"});
232 m_AreaDamage.SetAmmoName("BarbedWireHit");
233 m_AreaDamage.Spawn();
234 m_TriggerActive = true;
235 }
236
237 protected void DestroyDamageTrigger()
238 {
239 m_AreaDamage.Destroy();
240 m_TriggerActive = false;
241 }
242 // ---------------------------------------------------------
243
244 // Controls spawn of random sparks
245 /*
246 protected void TimerRandomSpark() // TO DO: Come up with randomized functionality.
247 {
248 if ( GetCompEM().IsSwitchedOn() )
249 {
250 int plugged_devices = GetCompEM().GetEnergySource().GetCompEM().GetPluggedDevicesCount();
251 float rnd_time = Math.RandomFloat(0.3, RANDOM_SPARK_INTERVAL / plugged_devices + 1.0);
252 m_SparkEvent.Run(rnd_time + 0.3, this, "Spark", NULL, true);
253 }
254 }
255 */
256
257 // Spawns spark particle effect and plays sound.
258 void Spark()
259 {
260 ParticleManager.GetInstance().PlayOnObject( ParticleList.BARBED_WIRE_SPARKS, this);
261 SoundSpark();
262 }
263
264
265 // SOUNDS
266 // ---------------------------------------------------------
267 void SoundCut()
268 {
269 if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
270 {
271 int random_index = Math.RandomInt(0, SOUNDS_CUT_COUNT);
272 string sound_type = m_SoundsCut[random_index];
273 PlaySound(sound_type, 50);
274 }
275 }
276
277 // Plays sound
279 {
280 if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
281 {
282 int random_index = Math.RandomInt(0, SOUNDS_SPARK_COUNT);
283 string sound_type = m_SoundsSpark[random_index];
284 PlaySound(sound_type, 50);
285 }
286 }
287
288 // Plays sound
290 {
291 if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
292 {
293 if (!m_BuzzSoundLoop)
294 {
295 m_BuzzSoundLoop = PlaySoundLoop(m_SoundBuzzLoop, 50);
296 }
297 }
298 }
299
300 // Stops sound
302 {
303 if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
304 {
305 if (m_BuzzSoundLoop)
306 {
308 m_BuzzSoundLoop = NULL;
309 }
310 }
311 }
312
313 // Plays an electric shock sound
315 {
316 if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
317 {
318 int random_index = Math.RandomInt(0, SOUNDS_SHOCK_COUNT);
319 string sound_type = m_SoundsShock[random_index];
320 PlaySound(sound_type, 50);
321 }
322 }
323
324 // Plays a collision sound
326 {
327 if ( !GetGame().IsServer() || !GetGame().IsMultiplayer() ) // client side
328 {
329 int random_index = Math.RandomInt(0, SOUNDS_COLLISION_COUNT);
330 string sound_type = m_SoundsCollision[random_index];
331 PlaySound(sound_type, 50);
332 }
333 }
334 // ---------------------------------------------------------
335
336 // Area Damage Pre/Post actions
337 // ---------------------------------------------------------
338 override void PreAreaDamageActions()
339 {
340 if ( GetCompEM().IsPlugged() && GetCompEM().IsSwitchedOn() )
341 {
342 Spark();
344 }
346 }
347
348 override void PostAreaDamageActions()
349 {
350 //dmg to barbed wire here
351 MiscGameplayFunctions.DealAbsoluteDmg(this, 1000);
352 }
353 // ---------------------------------------------------------
354
355
356 // TODO: proper handling can be done once the ticket DAYZ-26145 is resolved
357 override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
358 {
359 super.OnItemLocationChanged(old_owner, new_owner);
360
361 if (m_TriggerActive)
362 {
364 m_IsPlaced = false;
365 }
366 }
367
368 //================================================================
369 // ADVANCED PLACEMENT
370 //================================================================
371
372 override void OnPlacementComplete( Man player, vector position = "0 0 0", vector orientation = "0 0 0" )
373 {
374 super.OnPlacementComplete( player, position, orientation );
375
376 if ( GetGame().IsServer() )
377 {
378 ShowAllSelections();
379 HideSelection("zbytek");
380
381 if (!GetHierarchyParent())
382 {
383 if (GetCompEM().IsPlugged() && GetCompEM().IsWorking() )
385 else
387 m_IsPlaced = true;
388 }
389 }
390 }
391
392 override string GetDeploySoundset()
393 {
394 return "placeBarbedWire_SoundSet";
395 }
396
397 override string GetLoopDeploySoundset()
398 {
399 return "barbedwire_deploy_SoundSet";
400 }
401
402 override void SetActions()
403 {
404 super.SetActions();
405
409
410 }
411
413 protected ref EffectSound m_DeployLoopSound; //DEPRECATED in favor of m_DeployLoopSoundEx
414
417}
void AddAction(typename actionName)
Определения AdvancedCommunication.c:220
void AreaDamageManager(EntityAI parent)
Определения AreaDamageManager.c:22
class BaseBuildingBase extends ItemBase bsbDebugPrint(string s)
Определения BaseBuildingBase.c:1292
void PlaySound()
Определения HungerSoundHandler.c:38
override void SetTakeable(bool pState)
Определения ItemBase.c:9042
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
Определения ParticleManager.c:88
override ScriptCallQueue GetCallQueue(int call_category)
Определения DayZGame.c:1187
proto native void ObjectDelete(Object obj)
Wrapper class for managing sound through SEffectManager.
Определения EffectSound.c:5
Определения Building.c:6
proto native int GetSlot()
returns slot id if current type is Attachment
InventoryLocation.
Определения InventoryLocation.c:29
static proto native owned string GetSlotName(int id)
converts slot_id to string
provides access to slot configuration
Определения InventorySlots.c:6
void CreateElectrifiedDamageTrigger()
Определения BarbedWire.c:216
void DestroyDamageTrigger()
Определения BarbedWire.c:237
override void OnInventoryEnter(Man player)
Определения BarbedWire.c:203
static const string m_SoundsShock[SOUNDS_SHOCK_COUNT]
Определения BarbedWire.c:13
bool m_LastMountedState
Определения BarbedWire.c:26
override void OnWork(float consumed_energy)
Определения BarbedWire.c:189
override void OnIsPlugged(EntityAI source_device)
Определения BarbedWire.c:191
override bool OnStoreLoad(ParamsReadContext ctx, int version)
Определения BarbedWire.c:135
bool GetSlotLockedState()
Определения BarbedWire.c:53
override void OnWorkStart()
Определения BarbedWire.c:164
void Synchronize()
Определения BarbedWire.c:109
static const int SOUNDS_SHOCK_COUNT
Определения BarbedWire.c:7
override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
Определения BarbedWire.c:357
static const string m_SoundsCut[SOUNDS_CUT_COUNT]
Определения BarbedWire.c:11
void PlayDeployLoopSound()
static const string m_SoundBuzzLoop
Определения BarbedWire.c:14
override void SetActions()
Определения BarbedWire.c:402
ref AreaDamageManager m_AreaDamage
Определения BarbedWire.c:19
override void PostAreaDamageActions()
Определения BarbedWire.c:348
SoundOnVehicle m_BuzzSoundLoop
Определения BarbedWire.c:16
void SoundSpark()
Определения BarbedWire.c:278
void CreateDamageTrigger()
Определения BarbedWire.c:227
void BaseBuildingBase()
Определения BaseBuildingBase.c:39
ref EffectSound m_DeployLoopSound
DEPRECATED.
Определения BarbedWire.c:413
bool m_IsMounted
Определения BarbedWire.c:25
override string GetDeploySoundset()
Определения BarbedWire.c:392
override void OnWorkStop()
Определения BarbedWire.c:177
override void OnStoreSave(ParamsWriteContext ctx)
Определения BarbedWire.c:130
void SoundCut()
Определения BarbedWire.c:267
override void AfterStoreLoad()
Определения BarbedWire.c:155
bool IsMounted()
Определения BarbedWire.c:48
void SoundElectricShock()
Определения BarbedWire.c:314
void SetMountedState(bool is_mounted)
Определения BarbedWire.c:66
void LockAttachmentSlot(bool lock_state)
Определения BarbedWire.c:94
void SoundCollision()
Определения BarbedWire.c:325
void SoundBuzzLoopStop()
Определения BarbedWire.c:301
static const int SOUNDS_SPARK_COUNT
Определения BarbedWire.c:4
void SoundBuzzLoopStart()
Определения BarbedWire.c:289
override void OnVariablesSynchronized()
Определения BarbedWire.c:117
override void OnIsUnplugged(EntityAI last_energy_source)
Определения BarbedWire.c:196
ref Timer m_SparkEvent
Определения BarbedWire.c:18
override void EEInit()
Определения BarbedWire.c:41
override string GetLoopDeploySoundset()
Определения BarbedWire.c:397
static const int SOUNDS_COLLISION_COUNT
Определения BarbedWire.c:6
override void OnPlacementComplete(Man player, vector position="0 0 0", vector orientation="0 0 0")
Определения BarbedWire.c:372
void Spark()
Определения BarbedWire.c:258
bool m_IsPlaced
Определения BarbedWire.c:22
override void PreAreaDamageActions()
Определения BarbedWire.c:338
EffectSound m_MountSound
Определения BarbedWire.c:28
static const string m_SoundsCollision[SOUNDS_COLLISION_COUNT]
Определения BarbedWire.c:12
void UpdateAttachmentSlot()
Определения BarbedWire.c:79
void StopDeployLoopSound()
DEPRECATED.
bool m_TriggerActive
Определения BarbedWire.c:21
void BarbedWire()
Определения BarbedWire.c:31
static const float RANDOM_SPARK_INTERVAL
Определения BarbedWire.c:8
const string SOUND_MOUNT
Определения BarbedWire.c:27
static const string m_SoundsSpark[SOUNDS_SPARK_COUNT]
Определения BarbedWire.c:10
static const int SOUNDS_CUT_COUNT
Определения BarbedWire.c:5
Определения InventoryItem.c:731
static bool IsBaseBuildingLogEnable()
Определения Debug.c:698
Определения Debug.c:594
Определения EnMath.c:7
static const int BARBED_WIRE_SPARKS
Определения ParticleList.c:140
Определения ParticleList.c:12
proto void CallLater(func fn, int delay=0, bool repeat=false, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
adds call into the queue with given parameters and arguments (arguments are held in memory until the ...
proto bool Read(void value_in)
Определения DayZPlayerImplement.c:63
Определения EnConvert.c:106
override string GetDebugName()
Определения dayzplayer.c:1170
Serializer ParamsReadContext
Определения gameplay.c:15
proto native CGame GetGame()
Serializer ParamsWriteContext
Определения gameplay.c:16
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
Определения tools.c:10
const int CALL_CATEGORY_SYSTEM
Определения tools.c:8