DayZ 1.24
Loading...
Searching...
No Matches
RemotelyActivatedItemBehaviour.c
Go to the documentation of this file.
2{
3 protected EntityAI m_Parent;
4 protected bool m_IsTrigger;
6 protected int m_PairDeviceNetIdLow;
7 protected int m_PairDeviceNetIdHigh;
8 protected int m_PersistentPairID = int.MIN;
9
11
19
21 {
22 if (m_Parent)
23 Unpair();
24 }
25
27 {
28 m_IsTrigger = true;
29 }
30
32 {
33 Pair();
34 }
35
40
42 {
43 if (!ctx.Read(m_PersistentPairID))
44 return false;
45
46 if (m_PersistentPairID == int.MIN)//default value, no point in going further
47 return true;
48
49 if (m_IsTrigger)//trigger
50 {
52 if (receiver)
54 }
55 else // remotely controlled device
56 {
57 m_RemoteReceivers.Insert(m_PersistentPairID, m_Parent);//receivers will register themselves upon being loaded from the storage
58 }
59
60 return true;
61 }
62
64 {
66 {
68 if (receiver)
69 {
70 //if both the receiver and trigger are somewhere in the world outside of the player inventory, there is no guarantee
71 //that the pairing is going to be succesful during the 'OnStoreLoad' event as that requires the receiver to already be loaded when the trigger is being loaded
72 //therefore, it's necessary to also perform pairing in this event, which happens at the end of the storage loading process
73 //do note that this event is not called when the entity is being loaded as part of the player inventory, therefore, we need to pair both in 'OnStoreLoad' and here to handle both situations
74 //(when the trigger is in the player's inventory, it always loads correctly after the receiver, which is always in the world)
76 }
77 }
78 }
79
80
82 {
83 int randomID = Math.RandomInt(0, int.MAX);
84 if (m_RemoteReceivers.Contains(randomID))
85 {
86 //it's very unlikely to have a collision here, but lets handle it anyway
87 return GeneratePersistentID();
88 }
89 else
90 return randomID;
91 }
92
94 {
96
97 if (!m_IsTrigger)
98 m_RemoteReceivers.Insert(id, m_Parent);
99 }
100
101 void Pair()
102 {
103 EntityAI device = EntityAI.Cast(GetGame().GetObjectByNetworkId(GetPairDeviceNetIdLow(), GetPairDeviceNetIdHigh()));
104 if (device)
105 Pair(device);
106 }
107
109 {
112
113 if (device != m_Parent && (!m_Parent.GetPairDevice() || m_Parent.GetPairDevice() != m_PairDevice))
114 m_PairDevice.PairRemote(m_Parent);
115
116 m_PairDevice.SetSynchDirty();
117 m_Parent.SetSynchDirty();
118 }
119
120 void Unpair()
121 {
124
125 if (m_PairDevice)
126 {
127 m_PairDevice.SetSynchDirty();
129 }
130
131 if (m_PersistentPairID != int.MIN)
132 {
135 }
136
137 m_PersistentPairID = int.MIN;
138 m_Parent.SetSynchDirty();
139 }
140
142 {
143 return m_PairDevice;
144 }
145
146 bool IsPaired()
147 {
148 return m_PairDevice != null;
149 }
150
155
157 {
159 }
160
162 {
164 }
165}
const int MIN
Definition EnConvert.c:28
const int MAX
Definition EnConvert.c:27
Definition EnMath.c:7
void SetPairDeviceNetIds(notnull EntityAI device)
static ref map< int, EntityAI > m_RemoteReceivers
bool OnStoreLoad(ParamsReadContext ctx, int version)
void RemotelyActivatedItemBehaviour(notnull EntityAI pParent)
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto native CGame GetGame()
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].