Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
pluginobjectsinteractionmanager.c
Go to the documentation of this file.
1 class PluginObjectsInteractionManager extends PluginBase
2 {
3  private ref array<Object> m_LockedObjects;
4  private ref array<float> m_LockedObjectsDecay;
5  private const float TIME_TO_FORCED_UNLOCK = 60;
6  private const float TICK_RATE = 10;
7  private ref Timer m_DecayTimer;
8 
9  void PluginObjectsInteractionManager()
10  {
11  m_LockedObjects = new array<Object>;
12  m_LockedObjectsDecay = new array<float>;
13  //TIMERDEPRECATED - timer for decaying objects
14  m_DecayTimer = new Timer();
15  m_DecayTimer.Run(TICK_RATE, this, "Decay", NULL,true);
16  }
17 
18  bool IsFree(Object target)
19  {
20  if ( target && m_LockedObjects.Count() > 0 )
21  {
22  for ( int i = 0; i < m_LockedObjects.Count(); i++ )
23  {
24  if ( m_LockedObjects.Get(i) == target )
25  {
26  return false;
27  }
28  }
29  }
30  return true;
31  }
32 
33  void Lock(Object target)
34  {
35  if ( target && !IsFree(target) )
36  {
37  m_LockedObjects.Insert(target);
38  m_LockedObjectsDecay.Insert(0);
39  }
40  }
41 
42  void Release(Object target)
43  {
44  if ( target && m_LockedObjects.Count() > 0 )
45  {
46  for ( int i = 0; i < m_LockedObjects.Count(); i++ )
47  {
48  if ( m_LockedObjects.Get(i) == target )
49  {
50  m_LockedObjects.Remove(i);
51  m_LockedObjectsDecay.Remove(i);
52  break;
53  }
54  }
55  }
56  }
57 
58  //FAILSAFE - checks periodically locked objects and releases them automaticaly if given time has passed
59  void Decay()
60  {
61  if ( m_LockedObjectsDecay.Count() > 0 )
62  {
63  for ( int i = 0; i < m_LockedObjectsDecay.Count(); i++ )
64  {
65  if ( m_LockedObjectsDecay.Get(i) >= TIME_TO_FORCED_UNLOCK )
66  {
67  m_LockedObjects.Remove(i);
68  m_LockedObjectsDecay.Remove(i);
69  }
70  else
71  {
72  m_LockedObjectsDecay.Get(i) += TICK_RATE;
73  }
74  }
75  }
76  }
77 };
Release
private void Release(vector pos)
Definition: easteregg.c:185
PluginBase
Definition: pluginadminlog.c:1
Object
Definition: objecttyped.c:1
array< Object >
m_DecayTimer
protected float m_DecayTimer
Definition: edible_base.c:13
Timer
Definition: dayzplayerimplement.c:62