DayZ 1.24
Loading...
Searching...
No Matches
CombinationLock.c File Reference

Go to the source code of this file.

Enumerations

enum  LockAction {
  NONE , DIAL_NUMBER_CHANED , DIAL_INDEX_CHANGED , LOCKED ,
  UNLOCKED , COUNT
}
 

Functions

void CombinationLock ()
 
void SetBaseLockValues ()
 
override void EEInit ()
 
void SetInitialized ()
 
override bool IsInitialized ()
 
override void OnItemLocationChanged (EntityAI old_owner, EntityAI new_owner)
 
override void OnStoreSave (ParamsWriteContext ctx)
 
override bool OnStoreLoad (ParamsReadContext ctx, int version)
 
override void AfterStoreLoad ()
 
void Synchronize ()
 
void ResetActionVar ()
 
override void OnVariablesSynchronized ()
 
void SetCombination (int combination)
 
void SetCombinationLocked (int combination)
 
int GetCombination ()
 
int GetLockDigits ()
 
void DialNextNumber ()
 
int GetDialIndex ()
 
void SetNextDial ()
 
void LockServer (EntityAI parent, bool ignore_combination=false)
 
void UnlockServer (EntityAI player, EntityAI parent)
 
void ShuffleLock ()
 
bool IsLocked ()
 
void CheckLockedStateServer ()
 
bool IsLockedOnGate ()
 
bool IsLockAttached ()
 
void DestroyLock ()
 
void UpdateVisuals ()
 
void UpdateSound ()
 
void ShowItem ()
 
void HideItem ()
 
void ShowAttached ()
 
void HideAttached ()
 
void SoundLockOpen ()
 
void SoundLockClose ()
 
void SoundLockChangeNumber ()
 
void SoundLockChangeDial ()
 
override void SetActions ()
 

Variables

enum LockAction m_LockDigits
 
int m_Combination
 
int m_CombinationLocked
 
int m_DialIndex
 
bool m_IsLocked
 
LockAction m_LockActionPerformed = LockAction.NONE
 
bool m_IsInitialized
 
const string SOUND_LOCK_OPEN = "combinationlock_open_SoundSet"
 
const string SOUND_LOCK_CLOSE = "combinationlock_close_SoundSet"
 
const string SOUND_LOCK_CHANGE_NUMBER = "combinationlock_changenumber_SoundSet"
 
const string SOUND_LOCK_CHANGE_DIAL = "combinationlock_changedial_SoundSet"
 
EffectSound m_Sound
 

Enumeration Type Documentation

◆ LockAction

Enumerator
NONE 
DIAL_NUMBER_CHANED 
DIAL_INDEX_CHANGED 
LOCKED 
UNLOCKED 
COUNT 

Definition at line 1 of file CombinationLock.c.

2{
3 NONE,
6 LOCKED,
8
10}
@ COUNT
@ DIAL_INDEX_CHANGED
@ UNLOCKED
@ LOCKED
@ DIAL_NUMBER_CHANED
@ NONE

Function Documentation

◆ AfterStoreLoad()

override void AfterStoreLoad ( )
protected

Definition at line 128 of file CombinationLock.c.

129 {
130 super.AfterStoreLoad();
131
132 //Check combination lock
133 if (GetGame().IsServer())
134 {
135 EntityAI parent = GetHierarchyParent();
136 if (parent && parent.IsInherited(BaseBuildingBase))
137 LockServer(parent, true);
138 }
139
140 //synchronize
141 Synchronize();
142 }
void LockServer(EntityAI parent, bool ignore_combination=false)
void Synchronize()
proto native CGame GetGame()

References GetGame(), LockServer(), and Synchronize().

◆ CheckLockedStateServer()

void CheckLockedStateServer ( )
protected

Definition at line 339 of file CombinationLock.c.

340 {
342 }
bool m_IsLocked
int m_Combination
int m_CombinationLocked

References m_Combination, m_CombinationLocked, and m_IsLocked.

Referenced by DialNextNumber(), LockServer(), and UnlockServer().

◆ CombinationLock()

void CombinationLock ( )
protected

Definition at line 33 of file CombinationLock.c.

34 {
36
37 //synchronized variables
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 }
enum LockAction m_LockDigits
void SetBaseLockValues()
LockAction
Definition EnMath.c:7
static proto float Pow(float v, float power)
Return power of v ^ power.

References m_LockDigits, Math::Pow(), and CombinationLock::SetBaseLockValues().

◆ DestroyLock()

void DestroyLock ( )
protected

Definition at line 366 of file CombinationLock.c.

367 {
368 GetGame().ObjectDelete(this);
369 }

References GetGame().

◆ DialNextNumber()

void DialNextNumber ( )
protected

Definition at line 196 of file CombinationLock.c.

197 {
198 string combination_text = m_Combination.ToString();
199 string dialed_text;
200
201 //insert zeros to dials with 0 value
203 for (int i = 0; i < length_diff; ++i)
205
206 //assemble the whole combination with increased part
207 for (int j = 0; j < combination_text.Length(); ++j)
208 {
209 if (j == m_DialIndex)
210 {
211 int next_dialed_number = combination_text.Get(j).ToInt() + 1;
212 if (next_dialed_number > 9)
214
215 dialed_text += next_dialed_number.ToString();
216 }
217 else
219 }
220
221 //set new number
223 m_LockActionPerformed = LockAction.DIAL_INDEX_CHANGED;
225
226 //synchronize
227 Synchronize();
228 }
void CheckLockedStateServer()
void SetCombination(int combination)
int m_DialIndex
LockAction m_LockActionPerformed

References CheckLockedStateServer(), m_Combination, m_DialIndex, m_LockActionPerformed, m_LockDigits, SetCombination(), and Synchronize().

◆ EEInit()

override void EEInit ( )
protected

Definition at line 54 of file CombinationLock.c.

55 {
56 super.EEInit();
57
58 GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(SetInitialized, 1000, false);
59 //SetInitialized();
60
61 //set visual on init
63 }
void SetInitialized()
void UpdateVisuals()
const int CALL_CATEGORY_GAMEPLAY
Definition tools.c:10

References CALL_CATEGORY_GAMEPLAY, GetGame(), SetInitialized(), and UpdateVisuals().

◆ GetCombination()

int GetCombination ( )
protected

Definition at line 185 of file CombinationLock.c.

186 {
187 return m_Combination;
188 }

References m_Combination.

◆ GetDialIndex()

int GetDialIndex ( )
protected

Definition at line 230 of file CombinationLock.c.

231 {
232 return m_DialIndex;
233 }

References m_DialIndex.

◆ GetLockDigits()

int GetLockDigits ( )
protected

Definition at line 190 of file CombinationLock.c.

191 {
192 return m_LockDigits;
193 }

References m_LockDigits.

◆ HideAttached()

void HideAttached ( )
protected

Definition at line 428 of file CombinationLock.c.

429 {
430 SetAnimationPhase("Combination_Lock_Attached", 1);
431 SetAnimationPhase("Lock_Attached_1", 1);
432 SetAnimationPhase("Lock_Attached_2", 1);
433 }

Referenced by UpdateVisuals().

◆ HideItem()

void HideItem ( )
protected

Definition at line 414 of file CombinationLock.c.

415 {
416 SetAnimationPhase("Combination_Lock_Item", 1);
417 SetAnimationPhase("Lock_Item_1", 1);
418 SetAnimationPhase("Lock_Item_2", 1);
419 }

Referenced by UpdateVisuals().

◆ IsInitialized()

override bool IsInitialized ( )
protected

Definition at line 70 of file CombinationLock.c.

71 {
72 return m_IsInitialized;
73 }
bool m_IsInitialized

References m_IsInitialized.

Referenced by ItemBase::EEItemAttached(), OnItemLocationChanged(), OnVariablesSynchronized(), and ItemBase::OnWorkStart().

◆ IsLockAttached()

bool IsLockAttached ( )
protected

Definition at line 356 of file CombinationLock.c.

357 {
358 Fence fence = Fence.Cast(GetHierarchyParent());
359 if (fence)
360 return true;
361
362 return false;
363 }

Referenced by LockServer(), and UnlockServer().

◆ IsLocked()

bool IsLocked ( )
protected

Definition at line 334 of file CombinationLock.c.

335 {
336 return m_IsLocked;
337 }

References m_IsLocked.

◆ IsLockedOnGate()

bool IsLockedOnGate ( )
protected

Definition at line 344 of file CombinationLock.c.

345 {
346 Fence fence = Fence.Cast(GetHierarchyParent());
347 if (fence)
348 {
349 if (IsLocked())
350 return true;
351 }
352
353 return false;
354 }
bool IsLocked()

References IsLocked().

Referenced by UpdateVisuals().

◆ LockServer()

void LockServer ( EntityAI parent,
bool ignore_combination = false )
protected

Definition at line 254 of file CombinationLock.c.

255 {
256 if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] CombinationLock.LockServer " + " m_Combination=" + m_Combination + " m_CombinationLocked=" + m_CombinationLocked);
257 if (IsLockAttached())
258 {
260 {
262
263 //set slot lock
265 GetInventory().GetCurrentInventoryLocation(inventory_location);
266 parent.GetInventory().SetSlotLock(inventory_location.GetSlot(), true);
267
269 }
270 ShuffleLock();
271 SetTakeable(false);
273 //synchronize
274 Synchronize();
275 }
276
277 //reset performed action
278 //m_LockActionPerformed = LockAction.NONE;
279 }
class BaseBuildingBase extends ItemBase bsbDebugPrint(string s)
void ShuffleLock()
void SetCombinationLocked(int combination)
bool IsLockAttached()
override void SetTakeable(bool pState)
Definition ItemBase.c:8905
InventoryLocation.
static bool IsBaseBuildingLogEnable()
Definition Debug.c:779

References bsbDebugPrint(), CheckLockedStateServer(), LogManager::IsBaseBuildingLogEnable(), IsLockAttached(), m_Combination, m_CombinationLocked, m_LockActionPerformed, SetCombinationLocked(), SetTakeable(), ShuffleLock(), and Synchronize().

Referenced by AfterStoreLoad(), and OnItemLocationChanged().

◆ OnItemLocationChanged()

override void OnItemLocationChanged ( EntityAI old_owner,
EntityAI new_owner )
protected

Definition at line 75 of file CombinationLock.c.

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))
84 }
85 }
override bool IsInitialized()

References GetGame(), IsInitialized(), and LockServer().

◆ OnStoreLoad()

override bool OnStoreLoad ( ParamsReadContext ctx,
int version )
protected

Definition at line 97 of file CombinationLock.c.

98 {
99 if (!super.OnStoreLoad(ctx, version))
100 return false;
101
102 //--- Combination Lock data ---
103 //combination
104 if (!ctx.Read(m_Combination))
105 {
106 m_Combination = 0;
107 return false;
108 }
109
110 //combination locked
111 if (!ctx.Read(m_CombinationLocked))
112 {
114 return false;
115 }
116
117 //is lock attached
118 if (version < 105) //removed in 105
119 {
120 bool is_lock_attached;
121 if (!ctx.Read(is_lock_attached))
122 return false;
123 }
124
125 return true;
126 }

References m_Combination, and m_CombinationLocked.

◆ OnStoreSave()

override void OnStoreSave ( ParamsWriteContext ctx)
protected

Definition at line 88 of file CombinationLock.c.

89 {
90 super.OnStoreSave(ctx);
91
92 //write data
93 ctx.Write(m_Combination);
95 }

References m_Combination, and m_CombinationLocked.

◆ OnVariablesSynchronized()

override void OnVariablesSynchronized ( )
protected

Definition at line 162 of file CombinationLock.c.

163 {
164 super.OnVariablesSynchronized();
165 //update visuals (client)
167
168 //update sound (client)
170 UpdateSound();
171
172 if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] CombinationLock.OnVariablesSynchronized " + " m_Combination=" + m_Combination + " m_CombinationLocked=" + m_CombinationLocked);
173 }
void UpdateSound()

References bsbDebugPrint(), LogManager::IsBaseBuildingLogEnable(), m_Combination, m_CombinationLocked, m_LockActionPerformed, UpdateSound(), and UpdateVisuals().

◆ ResetActionVar()

void ResetActionVar ( )
protected

Definition at line 157 of file CombinationLock.c.

158 {
160 }

References m_LockActionPerformed.

Referenced by Synchronize().

◆ SetActions()

◆ SetBaseLockValues()

void SetBaseLockValues ( )
protected

Definition at line 45 of file CombinationLock.c.

46 {
47 //set lock init values
48 m_LockDigits = 3;
49 m_Combination = 111;
51 m_IsLocked = false;
52 }

References m_Combination, m_CombinationLocked, m_IsLocked, and m_LockDigits.

◆ SetCombination()

void SetCombination ( int combination)
protected

Definition at line 175 of file CombinationLock.c.

176 {
178 }

References m_Combination.

Referenced by DialNextNumber(), and ShuffleLock().

◆ SetCombinationLocked()

void SetCombinationLocked ( int combination)
protected

Definition at line 180 of file CombinationLock.c.

181 {
183 }

References m_CombinationLocked.

Referenced by LockServer().

◆ SetInitialized()

void SetInitialized ( )
protected

Definition at line 65 of file CombinationLock.c.

66 {
67 m_IsInitialized = true;
68 }

References m_IsInitialized.

Referenced by EEInit().

◆ SetNextDial()

void SetNextDial ( )
protected

Definition at line 235 of file CombinationLock.c.

236 {
237 if (m_LockDigits > 1)
238 {
239 if (m_DialIndex <= m_LockDigits - 2)
240 m_DialIndex++;
241 else if (m_DialIndex >= m_LockDigits > - 1)
242 m_DialIndex = 0;
243 }
244 else
245 m_DialIndex = 0;
246
247 //performed action
248 m_LockActionPerformed = LockAction.DIAL_NUMBER_CHANED;
249 //synchronize
250 Synchronize();
251 }

References m_DialIndex, m_LockActionPerformed, m_LockDigits, and Synchronize().

◆ ShowAttached()

void ShowAttached ( )
protected

Definition at line 421 of file CombinationLock.c.

422 {
423 SetAnimationPhase("Combination_Lock_Attached", 0);
424 SetAnimationPhase("Lock_Attached_1", 0);
425 SetAnimationPhase("Lock_Attached_2", 0);
426 }

Referenced by UpdateVisuals().

◆ ShowItem()

void ShowItem ( )
protected

Definition at line 407 of file CombinationLock.c.

408 {
409 SetAnimationPhase("Combination_Lock_Item", 0);
410 SetAnimationPhase("Lock_Item_1", 0);
411 SetAnimationPhase("Lock_Item_2", 0);
412 }

Referenced by UpdateVisuals().

◆ ShuffleLock()

void ShuffleLock ( )
protected

Definition at line 313 of file CombinationLock.c.

314 {
315 string combination_text = m_Combination.ToString();
316 string shuffled_text;
317
318 //insert zeros to dials with 0 value
320 for (int i = 0; i < length_diff; ++i)
322
323 //assemble the whole combination with increased part
324 for (int j = 0; j < combination_text.Length(); ++j)
325 {
326 int dial_number = combination_text.Get(j).ToInt();
327 dial_number = (dial_number + Math.RandomInt(1, 9)) % 10;
329 }
330
332 }
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].

References m_Combination, m_LockDigits, Math::RandomInt(), and SetCombination().

Referenced by LockServer().

◆ SoundLockChangeDial()

void SoundLockChangeDial ( )
protected

Definition at line 454 of file CombinationLock.c.

455 {
456 PlaySoundSet(m_Sound, SOUND_LOCK_CHANGE_DIAL, 0, 0);
457 }
const string SOUND_LOCK_CHANGE_DIAL
EffectSound m_Sound

References m_Sound, and SOUND_LOCK_CHANGE_DIAL.

Referenced by UpdateSound().

◆ SoundLockChangeNumber()

void SoundLockChangeNumber ( )
protected

Definition at line 449 of file CombinationLock.c.

450 {
451 PlaySoundSet(m_Sound, SOUND_LOCK_CHANGE_NUMBER, 0, 0);
452 }
const string SOUND_LOCK_CHANGE_NUMBER

References m_Sound, and SOUND_LOCK_CHANGE_NUMBER.

Referenced by UpdateSound().

◆ SoundLockClose()

void SoundLockClose ( )
protected

Definition at line 444 of file CombinationLock.c.

445 {
446 PlaySoundSet(m_Sound, SOUND_LOCK_CLOSE, 0, 0);
447 }
const string SOUND_LOCK_CLOSE

References m_Sound, and SOUND_LOCK_CLOSE.

Referenced by UpdateSound().

◆ SoundLockOpen()

void SoundLockOpen ( )
protected

Definition at line 439 of file CombinationLock.c.

440 {
441 PlaySoundSet(m_Sound, SOUND_LOCK_OPEN, 0, 0);
442 }
const string SOUND_LOCK_OPEN

References m_Sound, and SOUND_LOCK_OPEN.

Referenced by UpdateSound().

◆ Synchronize()

void Synchronize ( )
protected

Definition at line 145 of file CombinationLock.c.

146 {
147 if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] CombinationLock.Synchronize " + " m_Combination=" + m_Combination + " m_CombinationLocked=" + m_CombinationLocked);
148 if (GetGame().IsServer())
149 {
150 SetSynchDirty();
151 GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(ResetActionVar, 1000); //synced var used to trigger client sound needs to be reset after triggering the sound
153 }
154 }
void ResetActionVar()
const int CALL_CATEGORY_SYSTEM
Definition tools.c:8

References bsbDebugPrint(), CALL_CATEGORY_SYSTEM, GetGame(), LogManager::IsBaseBuildingLogEnable(), m_Combination, m_CombinationLocked, ResetActionVar(), and UpdateVisuals().

Referenced by AfterStoreLoad(), CheckValue(), DialNextNumber(), EEItemAttached(), EEItemDetached(), Weapon::FillChamber(), Heating(), LockServer(), RefreshAudioVisualsOnClient(), RemoveAudioVisualsOnClient(), SetFireState(), SetNextDial(), SetOvenState(), SetStoneCircleState(), Weapon::SpawnAttachedMagazine(), StartFire(), StopFire(), and UnlockServer().

◆ UnlockServer()

void UnlockServer ( EntityAI player,
EntityAI parent )
protected

Definition at line 281 of file CombinationLock.c.

282 {
283 if (LogManager.IsBaseBuildingLogEnable()) bsbDebugPrint("[bsb] CombinationLock.UnlockServer " + " m_Combination=" + m_Combination + " m_CombinationLocked=" + m_CombinationLocked);
284 if (IsLockAttached())
285 {
286 Fence fence = Fence.Cast(parent);
287
288 //set slot unlock
290 GetInventory().GetCurrentInventoryLocation(inventory_location);
291 fence.GetInventory().SetSlotLock(inventory_location.GetSlot(), false);
292
293 //drop entity from attachment slot
294 if (player)
295 player.ServerDropEntity(this);
296 else
297 parent.GetInventory().DropEntity(InventoryMode.SERVER, parent, this);
298 SetPosition(fence.GetKitSpawnPosition());
299 PlaceOnSurface();
300
302 SetTakeable(true);
304 //synchronize
305 Synchronize();
306 }
307
308 //reset performed action
309 //m_LockActionPerformed = LockAction.NONE;
310 }
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition Inventory.c:22
proto native void SetPosition(vector position)
Set the world position of the Effect.
Definition Effect.c:420

References bsbDebugPrint(), CheckLockedStateServer(), LogManager::IsBaseBuildingLogEnable(), IsLockAttached(), m_Combination, m_CombinationLocked, m_LockActionPerformed, SetPosition(), SetTakeable(), and Synchronize().

◆ UpdateSound()

void UpdateSound ( )
protected

Definition at line 387 of file CombinationLock.c.

388 {
389 //was locked
390 if (m_LockActionPerformed == LockAction.LOCKED)
392
393 //was unlocked
394 if (m_LockActionPerformed == LockAction.UNLOCKED)
396
397 //next dial index
398 if (m_LockActionPerformed == LockAction.DIAL_INDEX_CHANGED)
400
401 //dialed new number
402 if (m_LockActionPerformed == LockAction.DIAL_NUMBER_CHANED)
404 }
void SoundLockClose()
void SoundLockOpen()
void SoundLockChangeNumber()
void SoundLockChangeDial()

References m_LockActionPerformed, SoundLockChangeDial(), SoundLockChangeNumber(), SoundLockClose(), and SoundLockOpen().

Referenced by OnVariablesSynchronized().

◆ UpdateVisuals()

void UpdateVisuals ( )
protected

Definition at line 372 of file CombinationLock.c.

373 {
374 //Client/Server
375 if (IsLockedOnGate())
376 {
377 GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(HideItem, 0, false);
378 GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(ShowAttached, 0, false);
379 }
380 else
381 {
382 GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(ShowItem, 0, false);
383 GetGame().GetCallQueue(CALL_CATEGORY_GAMEPLAY).CallLater(HideAttached, 0, false);
384 }
385 }
void HideAttached()
bool IsLockedOnGate()
void ShowAttached()
void ShowItem()
void HideItem()

References CALL_CATEGORY_GAMEPLAY, GetGame(), HideAttached(), HideItem(), IsLockedOnGate(), ShowAttached(), and ShowItem().

Variable Documentation

◆ m_Combination

◆ m_CombinationLocked

◆ m_DialIndex

int m_DialIndex

Definition at line 17 of file CombinationLock.c.

Referenced by DialNextNumber(), GetDialIndex(), and SetNextDial().

◆ m_IsInitialized

bool m_IsInitialized
protected

Definition at line 22 of file CombinationLock.c.

Referenced by IsInitialized(), and SetInitialized().

◆ m_IsLocked

bool m_IsLocked
protected

Definition at line 18 of file CombinationLock.c.

◆ m_LockActionPerformed

◆ m_LockDigits

◆ m_Sound

EffectSound m_Sound
protected

Definition at line 31 of file CombinationLock.c.

◆ SOUND_LOCK_CHANGE_DIAL

const string SOUND_LOCK_CHANGE_DIAL = "combinationlock_changedial_SoundSet"
protected

Definition at line 29 of file CombinationLock.c.

Referenced by SoundLockChangeDial().

◆ SOUND_LOCK_CHANGE_NUMBER

const string SOUND_LOCK_CHANGE_NUMBER = "combinationlock_changenumber_SoundSet"
protected

Definition at line 28 of file CombinationLock.c.

Referenced by SoundLockChangeNumber().

◆ SOUND_LOCK_CLOSE

const string SOUND_LOCK_CLOSE = "combinationlock_close_SoundSet"
protected

Definition at line 27 of file CombinationLock.c.

Referenced by SoundLockClose().

◆ SOUND_LOCK_OPEN

const string SOUND_LOCK_OPEN = "combinationlock_open_SoundSet"
protected

Definition at line 26 of file CombinationLock.c.

Referenced by SoundLockOpen().