File size: 6,752 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
class SymptomBase
{
	const float MAX_TIME_ACTIVE_SAVEGUARD = 20;
	int m_Priority;
	SoundOnVehicle m_SoundObject;
	bool m_PlayedSound;
	bool m_IsActivated;
	PlayerBase m_Player;
	float m_ServerUpdateInterval = 1;
	float m_ServerUpdateDelta;
	bool m_IsTemplate = true;
	float m_ActivatedTime;
	int m_ID;//ID for the type of Symptom
	int m_UID;//unique ID
	bool m_IsClientOnly;
	bool m_DestroyOnAnimFinish = true;
	bool m_DestroyRequested = false;
	int m_SymptomType = -1;
	bool m_IsPersistent = false;
	SymptomManager m_Manager;
	bool m_SyncToClient = false;
	float m_Duration;
	bool m_AnimPlayRequested;
	int m_MaxCount = -1;//how many symptoms of this type can be queued up at the same time, '-1' for unlimited

	SymptomCB m_AnimCallback;
	
	ref array<Param> m_PersistentParams = new array<Param>;
	
	void SymptomBase()
	{
	}
	
	void ~SymptomBase()
	{

	}

	void Init(SymptomManager manager, PlayerBase player, int uid)
	{
		m_Manager = manager;
		m_Player = player;
		m_UID = uid;
		m_IsTemplate = false;
		OnInit();
	}
	
	int GetMaxCount()
	{
		return m_MaxCount;
	}
	
	int GetUID()
	{
		return m_UID;
	}

	void OnOwnerKilled()
	{
		
		
	}
	
	bool CanBeInterupted()
	{
		if (m_AnimPlayRequested) 
		{
			//Print("--------- preventing interrupt ---------");
			return false;
		}
		return true;
	}
	
	bool IsClientOnly()
	{
		return m_IsClientOnly;
	}
	
	
	void SetDuration(float duration)
	{
		m_Duration = duration;
	}
	
	float GetDuration()
	{
		return m_Duration;
	}
	
	string GetName()
	{
		return this.ClassName();		
	}

	SymptomManager GetManager()
	{
		return m_Manager;
	}
	
	int GetType()
	{
		return m_ID;
	}
	
	void SetParam(Param p)
	{
	
	}

	bool IsSyncToClient()
	{
		return m_SyncToClient;		
	}

	void GetPersistentParams(array<Param> params)
	{
		for (int i = 0; i < m_PersistentParams.Count(); i++)
		{
			params.Insert(m_PersistentParams.Get(i));
		}
	}

	void MakeParamObjectPersistent(Param object)
	{
		if ( !GetGame().IsServer() && !GetGame().IsMultiplayer() ) return;
		
		m_PersistentParams.Insert(object);
	}
	
	bool IsPersistent()
	{
		return m_IsPersistent;
	}
	
	bool IsPrimary()
	{
		if ( m_SymptomType == SymptomTypes.PRIMARY)
			return true;
		else return false;
	}
	
	PlayerBase GetPlayer()
	{
		return m_Player;		
	}

	int GetPriority()
	{
		return m_Priority;
	}
	
	bool OnConstructed(SymptomManager manager)
	{
		
	}
	
	void OnDestructed()
	{
		if ( IsActivated() ) Deactivate();
		if ( GetManager() ) m_Manager.OnSymptomExit(this, m_UID);
	}

	void Activate()
	{
		m_IsActivated = true;
		if ( GetGame() && GetGame().IsServer() )
		{
			OnGetActivatedServer(m_Player);
			if ( GetGame().IsMultiplayer() )
			{
				if ( IsSyncToClient() ) 
					SyncToClientActivated( GetType(), GetUID() );
				#ifdef DIAG_DEVELOPER
				GetManager().SendServerDebugToClient();
				#endif
			}
		}
		if ( !GetGame().IsDedicatedServer() )
		{
			OnGetActivatedClient(m_Player);
		}
	}
	
	void Deactivate()
	{
		if ( !GetGame() ) return;
		m_IsActivated = false;
		if ( GetGame().IsServer() ) 
		{
			OnGetDeactivatedServer(m_Player);
			if ( GetGame().IsMultiplayer() && IsSyncToClient() )
			{
				SyncToClientDeactivated( GetType(), GetUID() );
			}
		}
		if ( !GetGame().IsDedicatedServer() )
		{
			OnGetDeactivatedClient(m_Player);
		}
		
	}
	
	bool IsActivated()
	{
		return m_IsActivated;
	}
	
	
	
	void Update(float deltatime)
	{
		if ( GetGame().IsServer() ) 
		{
			m_ServerUpdateDelta += deltatime;
			if (m_ServerUpdateDelta > m_ServerUpdateInterval )
			{
				m_ActivatedTime += m_ServerUpdateDelta;
				OnUpdateServer(m_Player, m_ServerUpdateDelta);
				m_ServerUpdateDelta = 0;
			}
		}
		if ( GetGame().IsClient() )
		{
			OnUpdateClient(m_Player, deltatime);
		}
		if ( GetGame().IsServer() && !GetGame().IsMultiplayer() && !GetGame().IsMissionMainMenu() )
		{
			OnUpdateClient(m_Player, deltatime);
		}
		CheckDestroy();
	}
	
	void PlayAnimationFB(int animation, int stance_mask, float running_time = -1)
	{
		DayZPlayerSyncJunctures.SendPlayerSymptomFB(m_Player, animation, GetType() , stance_mask, running_time );
		m_AnimPlayRequested = true;
	}
	
	void PlayAnimationADD(int type)
	{
		DayZPlayerSyncJunctures.SendPlayerSymptomADD(m_Player, type, GetType());
		m_AnimPlayRequested = true;
	}
		
	void PlaySound(EPlayerSoundEventID id)
	{
		GetPlayer().RequestSoundEvent(id);
		m_PlayedSound = true;
	}

	void SyncToClientActivated( int SYMPTOM_id, int uid )
	{
		if ( !GetPlayer() ) return;
		
		CachedObjectsParams.PARAM2_INT_INT.param1 = SYMPTOM_id;
		CachedObjectsParams.PARAM2_INT_INT.param2 = uid;
		GetGame().RPCSingleParam(GetPlayer(), ERPCs.RPC_PLAYER_SYMPTOM_ON, CachedObjectsParams.PARAM2_INT_INT,true,GetPlayer().GetIdentity() );
	}
	
	void SyncToClientDeactivated( int SYMPTOM_id, int uid )
	{
		if ( !GetPlayer() ) return;
		CachedObjectsParams.PARAM2_INT_INT.param1 = SYMPTOM_id;
		CachedObjectsParams.PARAM2_INT_INT.param2 = uid;
		GetGame().RPCSingleParam(GetPlayer(), ERPCs.RPC_PLAYER_SYMPTOM_OFF, CachedObjectsParams.PARAM2_INT_INT,true,GetPlayer().GetIdentity() );
	}

	void CheckSoundFinished()
	{
		if (GetGame().IsServer())
		{
			if (m_PlayedSound && m_ActivatedTime >= m_Duration)
				RequestDestroy();
		}
	}
	
	void CheckDestroy()
	{
		CheckSoundFinished();
		if ( IsPrimary() && m_ActivatedTime > MAX_TIME_ACTIVE_SAVEGUARD)
		{
			RequestDestroy();
		}
		
		if (m_DestroyRequested) 
			Destroy();
	}
	
	SmptAnimMetaBase SpawnAnimMetaObject()
	{
		return null;
	}
	

	void RequestDestroy()
	{
		m_DestroyRequested = true;
		//if(!IsActivated() ) Destroy();
	}

	void Destroy()
	{
		if (!m_IsTemplate)
			OnDestructed();
	}
	
	//!gets called upon animation Symptom exit
	void AnimationFinish()
	{
		//Print("*********** OnAnimationFinish ************");
		if ( m_DestroyOnAnimFinish ) RequestDestroy();
		OnAnimationFinish();
	}
	
	void AnimationPlayFailed()
	{
		OnAnimationPlayFailed();
		AnimationFinish();
	}
	
	void AnimationStart()
	{
		OnAnimationStart();
	}
	
	protected void OnAnimationFinish();
	protected void OnAnimationStart();
	protected void OnAnimationPlayFailed();

	
	//!this is just for the Symptom parameters set-up and is called even if the Symptom doesn't execute, don't put any gameplay code in here
	void OnInit();
	
	//!gets called every frame
	void OnUpdateServer(PlayerBase player, float deltatime);
	bool CanActivate(){return true;}//server only
	//!gets called every frame
	void OnUpdateClient(PlayerBase player, float deltatime);
	//!gets called once on an Symptom which is being activated
	void OnGetActivatedServer(PlayerBase player);
	void OnGetActivatedClient(PlayerBase player);
	//!only gets called once on an active Symptom that is being deactivated
	void OnGetDeactivatedServer(PlayerBase player);
	void OnGetDeactivatedClient(PlayerBase player);
}