DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
CombinationLock.c
См. документацию.
11
12class CombinationLock extends ItemBase
13{
14 int m_LockDigits; //how many digits will the combination contain
15 int m_Combination; //actual combination that is dialed on lock
16 int m_CombinationLocked; //combination that was dialed on lock before the shuffle
17 int m_DialIndex; //index of current combination dial
18 protected bool m_IsLocked;
19
21
22 protected bool m_IsInitialized;
23
24 //Sounds
25 //build
26 const string SOUND_LOCK_OPEN = "combinationlock_open_SoundSet";
27 const string SOUND_LOCK_CLOSE = "combinationlock_close_SoundSet";
28 const string SOUND_LOCK_CHANGE_NUMBER = "combinationlock_changenumber_SoundSet";
29 const string SOUND_LOCK_CHANGE_DIAL = "combinationlock_changedial_SoundSet";
30
32
34 {
36
37 //synchronized variables
38 int combination_length = Math.Pow( 10, m_LockDigits );
39 RegisterNetSyncVariableBool( "m_IsLocked" );
40 RegisterNetSyncVariableInt( "m_Combination", 0, combination_length - 1 );
41 RegisterNetSyncVariableInt( "m_DialIndex", 0, m_LockDigits - 1 );
42 RegisterNetSyncVariableInt( "m_LockActionPerformed", 0, LockAction.COUNT );
43 }
44
45 protected void SetBaseLockValues()
46 {
47 //set lock init values
48 m_LockDigits = 3;
49 m_Combination = 111;
51 m_IsLocked = false;
52 }
53
54 override void EEInit()
55 {
56 super.EEInit();
57
59 //SetInitialized();
60
61 //set visual on init
63 }
64
66 {
67 m_IsInitialized = true;
68 }
69
70 override bool IsInitialized()
71 {
72 return m_IsInitialized;
73 }
74
75 override void OnItemLocationChanged( EntityAI old_owner, EntityAI new_owner )
76 {
77 super.OnItemLocationChanged( old_owner, new_owner );
78
79 //Check combination lock
80 if ( GetGame().IsServer() )
81 {
82 if ( IsInitialized() && new_owner && new_owner.IsInherited( BaseBuildingBase ) )
83 {
84 LockServer( new_owner );
85 }
86 }
87 }
88
89 // --- EVENTS
90 override void OnStoreSave( ParamsWriteContext ctx )
91 {
92 super.OnStoreSave( ctx );
93
94 //write data
95 ctx.Write( m_Combination );
97 }
98
99 override bool OnStoreLoad( ParamsReadContext ctx, int version )
100 {
101 if ( !super.OnStoreLoad( ctx, version ) )
102 return false;
103
104 //--- Combination Lock data ---
105 //combination
106 if ( !ctx.Read( m_Combination ) )
107 {
108 m_Combination = 0;
109 return false;
110 }
111
112 //combination locked
113 if ( !ctx.Read( m_CombinationLocked ) )
114 {
116 return false;
117 }
118
119 //is lock attached
120 if ( version < 105 ) //removed in 105
121 {
122 bool is_lock_attached;
123 if ( !ctx.Read( is_lock_attached ) )
124 {
125 return false;
126 }
127 }
128
129 return true;
130 }
131
132 override void AfterStoreLoad()
133 {
134 super.AfterStoreLoad();
135
136 //Check combination lock
137 if ( GetGame().IsServer() )
138 {
139 EntityAI parent = GetHierarchyParent();
140 if ( parent && parent.IsInherited( BaseBuildingBase ) )
141 {
142 LockServer( parent, true );
143 }
144 }
145
146 //synchronize
147 Synchronize();
148 }
149
150 // --- SYNCHRONIZATION
152 {
153 if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] CombinationLock.Synchronize " + " m_Combination=" + m_Combination + " m_CombinationLocked=" + m_CombinationLocked);
154 if ( GetGame().IsServer() )
155 {
156 SetSynchDirty();
157 GetGame().GetCallQueue( CALL_CATEGORY_SYSTEM ).CallLater( ResetActionVar, 1000);//synced var used to trigger client sound needs to be reset after triggering the sound
159 }
160 }
161
162
164 {
166 }
167
169 {
170 super.OnVariablesSynchronized();
171 //update visuals (client)
173
174 //update sound (client)
176 UpdateSound();
177
178 if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] CombinationLock.OnVariablesSynchronized " + " m_Combination=" + m_Combination + " m_CombinationLocked=" + m_CombinationLocked);
179 }
180
181 void SetCombination( int combination )
182 {
183 m_Combination = combination;
184 }
185
186 void SetCombinationLocked( int combination )
187 {
188 m_CombinationLocked = combination;
189 }
190
192 {
193 return m_Combination;
194 }
195
197 {
198 return m_LockDigits;
199 }
200
201 // --- ACTIONS
203 {
204 string combination_text = m_Combination.ToString();
205 string dialed_text;
206
207 //insert zeros to dials with 0 value
208 int length_diff = m_LockDigits - combination_text.Length();
209 for ( int i = 0; i < length_diff; ++i )
210 {
211 combination_text = "0" + combination_text;
212 }
213
214 //assemble the whole combination with increased part
215 for ( int j = 0; j < combination_text.Length(); ++j )
216 {
217 if ( j == m_DialIndex )
218 {
219 int next_dialed_number = combination_text.Get( j ).ToInt() + 1;
220 if ( next_dialed_number > 9 )
221 {
222 next_dialed_number = 0;
223 }
224
225 dialed_text += next_dialed_number.ToString();
226 }
227 else
228 {
229 dialed_text += combination_text.Get( j );
230 }
231 }
232
233 //set new number
234 SetCombination( dialed_text.ToInt() );
235 m_LockActionPerformed = LockAction.DIAL_INDEX_CHANGED;
237
238 //synchronize
239 Synchronize();
240 }
241
243 {
244 return m_DialIndex;
245 }
246
248 {
249 if ( m_LockDigits > 1 )
250 {
251 if ( m_DialIndex <= m_LockDigits - 2 )
252 {
253 m_DialIndex++;
254 }
255 else if ( m_DialIndex >= m_LockDigits > - 1 )
256 {
257 m_DialIndex = 0;
258 }
259 }
260 else
261 {
262 m_DialIndex = 0;
263 }
264
265 //performed action
266 m_LockActionPerformed = LockAction.DIAL_NUMBER_CHANED;
267 //synchronize
268 Synchronize();
269 }
270
271 //Lock lock
272 void LockServer( EntityAI parent, bool ignore_combination = false )
273 {
274 if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] CombinationLock.LockServer " + " m_Combination=" + m_Combination + " m_CombinationLocked=" + m_CombinationLocked);
275 if ( IsLockAttached() )
276 {
277 if ( !ignore_combination )
278 {
280
281 //set slot lock
282 InventoryLocation inventory_location = new InventoryLocation;
283 GetInventory().GetCurrentInventoryLocation( inventory_location );
284 parent.GetInventory().SetSlotLock( inventory_location.GetSlot(), true );
285
287 }
288 ShuffleLock();
289 SetTakeable(false);
291 //synchronize
292 Synchronize();
293 }
294
295 //reset performed action
296 //m_LockActionPerformed = LockAction.NONE;
297 }
298
299 void UnlockServer( EntityAI player, EntityAI parent )
300 {
301 if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] CombinationLock.UnlockServer " + " m_Combination=" + m_Combination + " m_CombinationLocked=" + m_CombinationLocked);
302 if ( IsLockAttached() )
303 {
304 Fence fence = Fence.Cast( parent );
305
306 //set slot unlock
307 InventoryLocation inventory_location = new InventoryLocation;
308 GetInventory().GetCurrentInventoryLocation( inventory_location );
309 fence.GetInventory().SetSlotLock( inventory_location.GetSlot(), false );
310
311 //drop entity from attachment slot
312 if (GetGame().IsMultiplayer())
313 {
314 if (player)
315 player.ServerDropEntity(this);
316 else
317 parent.GetInventory().DropEntity(InventoryMode.SERVER, parent, this);
318 }
319 else
320 {
321 if (player)
322 player.LocalDropEntity(this);
323 else
324 parent.GetInventory().DropEntity(InventoryMode.LOCAL, parent, this);
325 }
326
327 SetPosition( fence.GetKitSpawnPosition() );
328 PlaceOnSurface();
329
331 SetTakeable(true);
333 //synchronize
334 Synchronize();
335 }
336
337 //reset performed action
338 //m_LockActionPerformed = LockAction.NONE;
339 }
340
341 //Shuffle lock
343 {
344 string combination_text = m_Combination.ToString();
345 string shuffled_text;
346
347 //insert zeros to dials with 0 value
348 int length_diff = m_LockDigits - combination_text.Length();
349 for ( int i = 0; i < length_diff; ++i )
350 {
351 combination_text = "0" + combination_text;
352 }
353
354 //assemble the whole combination with increased part
355 for ( int j = 0; j < combination_text.Length(); ++j )
356 {
357 int dial_number = combination_text.Get( j ).ToInt();
358 dial_number = ( dial_number + Math.RandomInt( 1, 9 ) ) % 10;
359 shuffled_text = shuffled_text + dial_number.ToString();
360 }
361
362 SetCombination( shuffled_text.ToInt() );
363 }
364
365 bool IsLocked()
366 {
367 return m_IsLocked;
368 }
369
374
376 {
377 Fence fence = Fence.Cast( GetHierarchyParent() );
378 if ( fence )
379 {
380 if ( IsLocked() )
381 {
382 return true;
383 }
384 }
385
386 return false;
387 }
388
390 {
391 Fence fence = Fence.Cast( GetHierarchyParent() );
392 if ( fence )
393 {
394 return true;
395 }
396
397 return false;
398 }
399
400 //destroy lock
402 {
403 GetGame().ObjectDelete( this );
404 }
405
406 // --- VISUALS
408 {
409 //Client/Server
410 if ( IsLockedOnGate() )
411 {
414 }
415 else
416 {
419 }
420 }
421
423 {
424 //was locked
425 if ( m_LockActionPerformed == LockAction.LOCKED )
426 {
428 }
429
430 //was unlocked
431 if ( m_LockActionPerformed == LockAction.UNLOCKED )
432 {
434 }
435
436 //next dial index
437 if ( m_LockActionPerformed == LockAction.DIAL_INDEX_CHANGED )
438 {
440 }
441
442 //dialed new number
443 if ( m_LockActionPerformed == LockAction.DIAL_NUMBER_CHANED )
444 {
446 }
447 }
448
449 //Show/Hide anims
450 protected void ShowItem()
451 {
452 SetAnimationPhase( "Combination_Lock_Item", 0 );
453 SetAnimationPhase( "Lock_Item_1", 0 );
454 SetAnimationPhase( "Lock_Item_2", 0 );
455 }
456
457 protected void HideItem()
458 {
459 SetAnimationPhase( "Combination_Lock_Item", 1 );
460 SetAnimationPhase( "Lock_Item_1", 1 );
461 SetAnimationPhase( "Lock_Item_2", 1 );
462 }
463
464 protected void ShowAttached()
465 {
466 SetAnimationPhase( "Combination_Lock_Attached", 0 );
467 SetAnimationPhase( "Lock_Attached_1", 0 );
468 SetAnimationPhase( "Lock_Attached_2", 0 );
469 }
470
471 protected void HideAttached()
472 {
473 SetAnimationPhase( "Combination_Lock_Attached", 1 );
474 SetAnimationPhase( "Lock_Attached_1", 1 );
475 SetAnimationPhase( "Lock_Attached_2", 1 );
476 }
477 // ---
478
479 //================================================================
480 // SOUNDS
481 //================================================================
482 protected void SoundLockOpen()
483 {
484 PlaySoundSet( m_Sound, SOUND_LOCK_OPEN, 0, 0 );
485 }
486
487 protected void SoundLockClose()
488 {
489 PlaySoundSet( m_Sound, SOUND_LOCK_CLOSE, 0, 0 );
490 }
491
493 {
494 PlaySoundSet( m_Sound, SOUND_LOCK_CHANGE_NUMBER, 0, 0 );
495 }
496
498 {
499 PlaySoundSet( m_Sound, SOUND_LOCK_CHANGE_DIAL, 0, 0 );
500 }
501
512}
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Определения Inventory.c:22
ActionDialCombinationLockCB ActionContinuousBaseCB ActionDialCombinationLock()
Определения ActionDialCombinationLock.c:13
ActionDialCombinationLockOnTargetCB ActionContinuousBaseCB ActionDialCombinationLockOnTarget()
void AddAction(typename actionName)
Определения AdvancedCommunication.c:220
void SetActions()
Определения AdvancedCommunication.c:213
override void OnVariablesSynchronized()
Определения AnniversaryMusicSource.c:42
class BaseBuildingBase extends ItemBase bsbDebugPrint(string s)
Определения BaseBuildingBase.c:1292
override bool IsInitialized()
Определения CombinationLock.c:70
void HideAttached()
Определения CombinationLock.c:471
void SoundLockClose()
Определения CombinationLock.c:487
void SetInitialized()
Определения CombinationLock.c:65
void ShuffleLock()
Определения CombinationLock.c:342
void UpdateSound()
Определения CombinationLock.c:422
void ResetActionVar()
Определения CombinationLock.c:163
bool m_IsInitialized
Определения CombinationLock.c:22
const string SOUND_LOCK_CHANGE_NUMBER
Определения CombinationLock.c:28
int GetLockDigits()
Определения CombinationLock.c:196
bool IsLockedOnGate()
Определения CombinationLock.c:375
const string SOUND_LOCK_CHANGE_DIAL
Определения CombinationLock.c:29
void SetNextDial()
Определения CombinationLock.c:247
void SoundLockOpen()
Определения CombinationLock.c:482
void ShowAttached()
Определения CombinationLock.c:464
void LockServer(EntityAI parent, bool ignore_combination=false)
Определения CombinationLock.c:272
void SoundLockChangeNumber()
Определения CombinationLock.c:492
const string SOUND_LOCK_OPEN
Определения CombinationLock.c:26
enum LockAction m_LockDigits
void CheckLockedStateServer()
Определения CombinationLock.c:370
void CombinationLock()
Определения CombinationLock.c:33
void ShowItem()
Определения CombinationLock.c:450
void SetCombination(int combination)
Определения CombinationLock.c:181
void SetCombinationLocked(int combination)
Определения CombinationLock.c:186
LockAction
Определения CombinationLock.c:2
@ DIAL_INDEX_CHANGED
Определения CombinationLock.c:5
@ UNLOCKED
Определения CombinationLock.c:7
@ LOCKED
Определения CombinationLock.c:6
@ DIAL_NUMBER_CHANED
Определения CombinationLock.c:4
int GetCombination()
Определения CombinationLock.c:191
void Synchronize()
Определения CombinationLock.c:151
void SoundLockChangeDial()
Определения CombinationLock.c:497
int m_Combination
Определения CombinationLock.c:15
const string SOUND_LOCK_CLOSE
Определения CombinationLock.c:27
void UnlockServer(EntityAI player, EntityAI parent)
Определения CombinationLock.c:299
int m_CombinationLocked
Определения CombinationLock.c:16
bool IsLockAttached()
Определения CombinationLock.c:389
int m_DialIndex
Определения CombinationLock.c:17
int GetDialIndex()
Определения CombinationLock.c:242
LockAction m_LockActionPerformed
Определения CombinationLock.c:20
void DialNextNumber()
Определения CombinationLock.c:202
void DestroyLock()
Определения CombinationLock.c:401
void HideItem()
Определения CombinationLock.c:457
void UpdateVisuals()
Определения Construction.c:188
override void EEInit()
Определения ContaminatedArea.c:42
@ COUNT
Определения EGameStateIcons.c:7
void AfterStoreLoad()
Определения EmoteManager.c:580
EffectSound m_Sound
Определения HungerSoundHandler.c:18
override void SetTakeable(bool pState)
Определения ItemBase.c:9042
override void OnItemLocationChanged(EntityAI old_owner, EntityAI new_owner)
Определения ItemBase.c:5983
bool m_IsLocked
Определения ModifierBase.c:26
bool IsLocked()
Определения ModifierBase.c:140
void OnStoreSave(ParamsWriteContext ctx)
Определения ModifiersManager.c:229
bool OnStoreLoad(ParamsReadContext ctx, int version)
Определения ModifiersManager.c:265
Определения Fence.c:2
override ScriptCallQueue GetCallQueue(int call_category)
Определения DayZGame.c:1187
proto native void ObjectDelete(Object obj)
override void SetBaseLockValues()
Определения CombinationLock4.c:3
Wrapper class for managing sound through SEffectManager.
Определения EffectSound.c:5
override bool ServerDropEntity(notnull EntityAI item)
Определения Man.c:137
override bool LocalDropEntity(notnull EntityAI item)
Определения Man.c:132
Определения Building.c:6
proto native int GetSlot()
returns slot id if current type is Attachment
InventoryLocation.
Определения InventoryLocation.c:29
Определения InventoryItem.c:731
static bool IsBaseBuildingLogEnable()
Определения Debug.c:698
Определения Debug.c:594
Определения EnMath.c:7
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 Write(void value_out)
proto bool Read(void value_in)
Serializer ParamsReadContext
Определения gameplay.c:15
proto native CGame GetGame()
Serializer ParamsWriteContext
Определения gameplay.c:16
proto native void SetPosition(vector position)
Set the world position of the Effect.
Определения Effect.c:438
static proto float Pow(float v, float power)
Return power of v ^ power.
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].
@ NONE
No flags.
Определения EnProfiler.c:11
proto native int Length()
Returns length of string.
proto string Get(int index)
Gets n-th character from string.
proto native int ToInt()
Converts string to integer.
const int CALL_CATEGORY_GAMEPLAY
Определения tools.c:10
const int CALL_CATEGORY_SYSTEM
Определения tools.c:8