Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
statebase.c
Go to the documentation of this file.
2 {
3  const float MAX_TIME_ACTIVE_SAVEGUARD = 20;
4  int m_Priority;
5  SoundOnVehicle m_SoundObject;
6  bool m_PlayedSound;
7  bool m_IsActivated;
8  PlayerBase m_Player;
9  float m_ServerUpdateInterval = 1;
10  float m_ServerUpdateDelta;
11  bool m_IsTemplate = true;
12  float m_ActivatedTime;
13  int m_ID;//ID for the type of Symptom
14  int m_UID;//unique ID
15  bool m_IsClientOnly;
16  bool m_DestroyOnAnimFinish = true;
17  bool m_DestroyRequested = false;
18  int m_SymptomType = -1;
19  bool m_IsPersistent = false;
20  SymptomManager m_Manager;
21  bool m_SyncToClient = false;
22  float m_Duration;
23  bool m_AnimPlayRequested;
24  int m_MaxCount = -1;//how many symptoms of this type can be queued up at the same time, '-1' for unlimited
25 
26  SymptomCB m_AnimCallback;
27 
28  ref array<Param> m_PersistentParams = new array<Param>;
29 
30  void SymptomBase()
31  {
32  }
33 
34  void ~SymptomBase()
35  {
36 
37  }
38 
39  void Init(SymptomManager manager, PlayerBase player, int uid)
40  {
41  m_Manager = manager;
42  m_Player = player;
43  m_UID = uid;
44  m_IsTemplate = false;
45  OnInit();
46  }
47 
48  int GetMaxCount()
49  {
50  return m_MaxCount;
51  }
52 
53  int GetUID()
54  {
55  return m_UID;
56  }
57 
58  void OnOwnerKilled()
59  {
60 
61 
62  }
63 
64  bool CanBeInterupted()
65  {
66  if (m_AnimPlayRequested)
67  {
68  //Print("--------- preventing interrupt ---------");
69  return false;
70  }
71  return true;
72  }
73 
74  bool IsClientOnly()
75  {
76  return m_IsClientOnly;
77  }
78 
79 
80  void SetDuration(float duration)
81  {
82  m_Duration = duration;
83  }
84 
85  float GetDuration()
86  {
87  return m_Duration;
88  }
89 
90  string GetName()
91  {
92  return this.ClassName();
93  }
94 
95  SymptomManager GetManager()
96  {
97  return m_Manager;
98  }
99 
100  int GetType()
101  {
102  return m_ID;
103  }
104 
105  void SetParam(Param p)
106  {
107 
108  }
109 
110  bool IsSyncToClient()
111  {
112  return m_SyncToClient;
113  }
114 
115  void GetPersistentParams(array<Param> params)
116  {
117  for (int i = 0; i < m_PersistentParams.Count(); i++)
118  {
119  params.Insert(m_PersistentParams.Get(i));
120  }
121  }
122 
123  void MakeParamObjectPersistent(Param object)
124  {
125  if ( !GetGame().IsServer() && !GetGame().IsMultiplayer() ) return;
126 
127  m_PersistentParams.Insert(object);
128  }
129 
130  bool IsPersistent()
131  {
132  return m_IsPersistent;
133  }
134 
135  bool IsPrimary()
136  {
137  if ( m_SymptomType == SymptomTypes.PRIMARY)
138  return true;
139  else return false;
140  }
141 
142  PlayerBase GetPlayer()
143  {
144  return m_Player;
145  }
146 
147  int GetPriority()
148  {
149  return m_Priority;
150  }
151 
152  bool OnConstructed(SymptomManager manager)
153  {
154 
155  }
156 
157  void OnDestructed()
158  {
159  if ( IsActivated() ) Deactivate();
160  if ( GetManager() ) m_Manager.OnSymptomExit(this, m_UID);
161  }
162 
163  void Activate()
164  {
165  m_IsActivated = true;
166  if ( GetGame() && GetGame().IsServer() )
167  {
168  OnGetActivatedServer(m_Player);
169  if ( GetGame().IsMultiplayer() )
170  {
171  if ( IsSyncToClient() )
172  SyncToClientActivated( GetType(), GetUID() );
173  #ifdef DIAG_DEVELOPER
174  GetManager().SendServerDebugToClient();
175  #endif
176  }
177  }
178  if ( !GetGame().IsDedicatedServer() )
179  {
180  OnGetActivatedClient(m_Player);
181  }
182  }
183 
184  void Deactivate()
185  {
186  if ( !GetGame() ) return;
187  m_IsActivated = false;
188  if ( GetGame().IsServer() )
189  {
190  OnGetDeactivatedServer(m_Player);
191  if ( GetGame().IsMultiplayer() && IsSyncToClient() )
192  {
193  SyncToClientDeactivated( GetType(), GetUID() );
194  }
195  }
196  if ( !GetGame().IsDedicatedServer() )
197  {
198  OnGetDeactivatedClient(m_Player);
199  }
200 
201  }
202 
203  bool IsActivated()
204  {
205  return m_IsActivated;
206  }
207 
208 
209 
210  void Update(float deltatime)
211  {
212  if ( GetGame().IsServer() )
213  {
214  m_ServerUpdateDelta += deltatime;
215  if (m_ServerUpdateDelta > m_ServerUpdateInterval )
216  {
217  m_ActivatedTime += m_ServerUpdateDelta;
218  OnUpdateServer(m_Player, m_ServerUpdateDelta);
219  m_ServerUpdateDelta = 0;
220  }
221  }
222  if ( GetGame().IsClient() )
223  {
224  OnUpdateClient(m_Player, deltatime);
225  }
226  if ( GetGame().IsServer() && !GetGame().IsMultiplayer() && !GetGame().IsMissionMainMenu() )
227  {
228  OnUpdateClient(m_Player, deltatime);
229  }
230  CheckDestroy();
231  }
232 
233  void PlayAnimationFB(int animation, int stance_mask, float running_time = -1)
234  {
235  DayZPlayerSyncJunctures.SendPlayerSymptomFB(m_Player, animation, GetType() , stance_mask, running_time );
236  m_AnimPlayRequested = true;
237  }
238 
239  void PlayAnimationADD(int type)
240  {
241  DayZPlayerSyncJunctures.SendPlayerSymptomADD(m_Player, type, GetType());
242  m_AnimPlayRequested = true;
243  }
244 
245  void PlaySound(EPlayerSoundEventID id)
246  {
247  GetPlayer().RequestSoundEvent(id);
248  m_PlayedSound = true;
249  }
250 
251  void SyncToClientActivated( int SYMPTOM_id, int uid )
252  {
253  if ( !GetPlayer() ) return;
254 
255  CachedObjectsParams.PARAM2_INT_INT.param1 = SYMPTOM_id;
256  CachedObjectsParams.PARAM2_INT_INT.param2 = uid;
257  GetGame().RPCSingleParam(GetPlayer(), ERPCs.RPC_PLAYER_SYMPTOM_ON, CachedObjectsParams.PARAM2_INT_INT,true,GetPlayer().GetIdentity() );
258  }
259 
260  void SyncToClientDeactivated( int SYMPTOM_id, int uid )
261  {
262  if ( !GetPlayer() ) return;
263  CachedObjectsParams.PARAM2_INT_INT.param1 = SYMPTOM_id;
264  CachedObjectsParams.PARAM2_INT_INT.param2 = uid;
265  GetGame().RPCSingleParam(GetPlayer(), ERPCs.RPC_PLAYER_SYMPTOM_OFF, CachedObjectsParams.PARAM2_INT_INT,true,GetPlayer().GetIdentity() );
266  }
267 
268  void CheckSoundFinished()
269  {
270  if (GetGame().IsServer())
271  {
272  if (m_PlayedSound && m_ActivatedTime >= m_Duration)
273  RequestDestroy();
274  }
275  }
276 
277  void CheckDestroy()
278  {
279  CheckSoundFinished();
280  if ( IsPrimary() && m_ActivatedTime > MAX_TIME_ACTIVE_SAVEGUARD)
281  {
282  RequestDestroy();
283  }
284 
285  if (m_DestroyRequested)
286  Destroy();
287  }
288 
289  SmptAnimMetaBase SpawnAnimMetaObject()
290  {
291  return null;
292  }
293 
294 
295  void RequestDestroy()
296  {
297  m_DestroyRequested = true;
298  //if(!IsActivated() ) Destroy();
299  }
300 
301  void Destroy()
302  {
303  if (!m_IsTemplate)
304  OnDestructed();
305  }
306 
308  void AnimationFinish()
309  {
310  //Print("*********** OnAnimationFinish ************");
311  if ( m_DestroyOnAnimFinish ) RequestDestroy();
312  OnAnimationFinish();
313  }
314 
315  void AnimationPlayFailed()
316  {
317  OnAnimationPlayFailed();
318  AnimationFinish();
319  }
320 
321  void AnimationStart()
322  {
323  OnAnimationStart();
324  }
325 
326  protected void OnAnimationFinish();
327  protected void OnAnimationStart();
328  protected void OnAnimationPlayFailed();
329 
330 
332  void OnInit();
333 
335  void OnUpdateServer(PlayerBase player, float deltatime);
336  bool CanActivate(){return true;}//server only
338  void OnUpdateClient(PlayerBase player, float deltatime);
340  void OnGetActivatedServer(PlayerBase player);
341  void OnGetActivatedClient(PlayerBase player);
343  void OnGetDeactivatedServer(PlayerBase player);
344  void OnGetDeactivatedClient(PlayerBase player);
345 }
GetGame
proto native CGame GetGame()
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
m_Priority
int m_Priority
Definition: bioslobbyservice.c:34
m_Manager
ModifiersManager m_Manager
Definition: modifierbase.c:12
m_Duration
float m_Duration
Definition: bullethitreaction.c:56
CachedObjectsParams
Definition: utilityclasses.c:9
SymptomManager
Definition: statemanager.c:42
SymptomBase
Definition: statebase.c:1
m_SymptomType
int m_SymptomType
Definition: smptanimmeta.c:13
m_DestroyRequested
bool m_DestroyRequested
Definition: smptanimmeta.c:15
PlayerBase
Definition: playerbaseclient.c:1
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
DayZPlayerSyncJunctures
Definition: dayzplayersyncjunctures.c:4
m_IsPersistent
bool m_IsPersistent
Definition: modifierbase.c:16
m_ActivatedTime
float m_ActivatedTime
Definition: modifierbase.c:14
array< Param >
SymptomTypes
SymptomTypes
Definition: statemanager.c:26
ERPCs
ERPCs
Definition: erpcs.c:1
EPlayerSoundEventID
EPlayerSoundEventID
Definition: playersoundeventhandler.c:1
m_ID
protected int m_ID
ID of effect, given by SEffectManager when registered (automatically done when playing through it)
Definition: effect.c:49
SmptAnimMetaBase
Definition: smptanimmeta.c:82