DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
RemotelyActivatedItemBehaviour.c
См. документацию.
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
13 {
14 m_Parent = pParent;
15
18 }
19
21 {
22 if (m_Parent)
23 Unpair();
24 }
25
27 {
28 m_IsTrigger = true;
29 }
30
32 {
33 Pair();
34 }
35
40
41 bool OnStoreLoad(ParamsReadContext ctx, int version)
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)
53 Pair(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)
75 Pair(receiver);
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 {
106 Pair(device);
107 }
108 }
109
110 void Pair(notnull EntityAI device)
111 {
112 m_PairDevice = device;
113 SetPairDeviceNetIds(device);
114
115 if (device != m_Parent && (!m_Parent.GetPairDevice() || m_Parent.GetPairDevice() != m_PairDevice))
116 m_PairDevice.PairRemote(m_Parent);
117
118 m_PairDevice.SetSynchDirty();
119 m_Parent.SetSynchDirty();
120 }
121
122 void Unpair()
123 {
126
127 if (m_PairDevice)
128 {
129 m_PairDevice.SetSynchDirty();
130 m_PairDevice = null;
131 }
132
133 if (m_PersistentPairID != int.MIN)
134 {
137 }
138
139 m_PersistentPairID = int.MIN;
140 m_Parent.SetSynchDirty();
141 }
142
144 {
145 return m_PairDevice;
146 }
147
148 bool IsPaired()
149 {
150 return m_PairDevice != null;
151 }
152
153 void SetPairDeviceNetIds(notnull EntityAI device)
154 {
155 device.GetNetworkID(m_PairDeviceNetIdLow, m_PairDeviceNetIdHigh);
156 }
157
159 {
161 }
162
164 {
166 }
167}
map
Определения ControlsXboxNew.c:4
const int MIN
Определения EnConvert.c:28
const int MAX
Определения EnConvert.c:27
Определения Building.c:6
Определения EnMath.c:7
void SetPairDeviceNetIds(notnull EntityAI device)
bool OnStoreLoad(ParamsReadContext ctx, int version)
void RemotelyActivatedItemBehaviour(notnull EntityAI pParent)
static ref map< int, EntityAI > m_RemoteReceivers
void Pair(notnull EntityAI device)
void OnStoreSave(ParamsWriteContext ctx)
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
static proto int RandomInt(int min, int max)
Returns a random int number between and min [inclusive] and max [exclusive].