statebase.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. class SymptomBase
  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. SymptomCB m_AnimCallback;
  26. ref array<Param> m_PersistentParams = new array<Param>;
  27. void SymptomBase()
  28. {
  29. }
  30. void ~SymptomBase()
  31. {
  32. }
  33. void Init(SymptomManager manager, PlayerBase player, int uid)
  34. {
  35. m_Manager = manager;
  36. m_Player = player;
  37. m_UID = uid;
  38. m_IsTemplate = false;
  39. OnInit();
  40. }
  41. int GetMaxCount()
  42. {
  43. return m_MaxCount;
  44. }
  45. int GetUID()
  46. {
  47. return m_UID;
  48. }
  49. void OnOwnerKilled()
  50. {
  51. }
  52. bool CanBeInterupted()
  53. {
  54. if (m_AnimPlayRequested)
  55. {
  56. //Print("--------- preventing interrupt ---------");
  57. return false;
  58. }
  59. return true;
  60. }
  61. bool IsClientOnly()
  62. {
  63. return m_IsClientOnly;
  64. }
  65. void SetDuration(float duration)
  66. {
  67. m_Duration = duration;
  68. }
  69. float GetDuration()
  70. {
  71. return m_Duration;
  72. }
  73. string GetName()
  74. {
  75. return this.ClassName();
  76. }
  77. SymptomManager GetManager()
  78. {
  79. return m_Manager;
  80. }
  81. int GetType()
  82. {
  83. return m_ID;
  84. }
  85. void SetParam(Param p)
  86. {
  87. }
  88. bool IsSyncToClient()
  89. {
  90. return m_SyncToClient;
  91. }
  92. //! This symptom is synchronized to remotes in a form id within symptom manager
  93. bool IsSyncToRemotes()
  94. {
  95. return false;
  96. }
  97. void GetPersistentParams(array<Param> params)
  98. {
  99. for (int i = 0; i < m_PersistentParams.Count(); i++)
  100. {
  101. params.Insert(m_PersistentParams.Get(i));
  102. }
  103. }
  104. void MakeParamObjectPersistent(Param object)
  105. {
  106. if ( !GetGame().IsServer() && !GetGame().IsMultiplayer() ) return;
  107. m_PersistentParams.Insert(object);
  108. }
  109. bool IsPersistent()
  110. {
  111. return m_IsPersistent;
  112. }
  113. bool IsPrimary()
  114. {
  115. if ( m_SymptomType == SymptomTypes.PRIMARY)
  116. return true;
  117. else return false;
  118. }
  119. // override this if you want the symptom to be played also while the player is unconscious
  120. bool AllowInUnconscious()
  121. {
  122. return false;
  123. }
  124. PlayerBase GetPlayer()
  125. {
  126. return m_Player;
  127. }
  128. int GetPriority()
  129. {
  130. return m_Priority;
  131. }
  132. bool OnConstructed(SymptomManager manager)
  133. {
  134. }
  135. void OnDestructed()
  136. {
  137. if ( IsActivated() ) Deactivate();
  138. if ( GetManager() ) m_Manager.OnSymptomExit(this, m_UID);
  139. }
  140. void Activate()
  141. {
  142. m_IsActivated = true;
  143. if ( GetGame() && GetGame().IsServer() )
  144. {
  145. OnGetActivatedServer(m_Player);
  146. if ( GetGame().IsMultiplayer() )
  147. {
  148. if ( IsSyncToClient() )
  149. SyncToClientActivated( GetType(), GetUID() );
  150. #ifdef DIAG_DEVELOPER
  151. GetManager().SendServerDebugToClient();
  152. #endif
  153. }
  154. }
  155. if ( !GetGame().IsDedicatedServer() )
  156. {
  157. OnGetActivatedClient(m_Player);
  158. }
  159. }
  160. void Deactivate()
  161. {
  162. if ( !GetGame() ) return;
  163. m_IsActivated = false;
  164. if ( GetGame().IsServer() )
  165. {
  166. OnGetDeactivatedServer(m_Player);
  167. if ( GetGame().IsMultiplayer() && IsSyncToClient() )
  168. {
  169. SyncToClientDeactivated( GetType(), GetUID() );
  170. }
  171. }
  172. if ( !GetGame().IsDedicatedServer() )
  173. {
  174. OnGetDeactivatedClient(m_Player);
  175. }
  176. }
  177. bool IsActivated()
  178. {
  179. return m_IsActivated;
  180. }
  181. void Update(float deltatime)
  182. {
  183. if ( GetGame().IsServer() )
  184. {
  185. m_ServerUpdateDelta += deltatime;
  186. if (m_ServerUpdateDelta > m_ServerUpdateInterval )
  187. {
  188. m_ActivatedTime += m_ServerUpdateDelta;
  189. OnUpdateServer(m_Player, m_ServerUpdateDelta);
  190. m_ServerUpdateDelta = 0;
  191. }
  192. }
  193. if ( GetGame().IsClient() )
  194. {
  195. OnUpdateClient(m_Player, deltatime);
  196. }
  197. if ( GetGame().IsServer() && !GetGame().IsMultiplayer() && !GetGame().IsMissionMainMenu() )
  198. {
  199. OnUpdateClient(m_Player, deltatime);
  200. }
  201. CheckDestroy();
  202. }
  203. void PlayAnimationFB(int animation, int stance_mask, float running_time = -1)
  204. {
  205. DayZPlayerSyncJunctures.SendPlayerSymptomFB(m_Player, animation, GetType() , stance_mask, running_time );
  206. m_AnimPlayRequested = true;
  207. }
  208. void PlayAnimationADD(int type)
  209. {
  210. DayZPlayerSyncJunctures.SendPlayerSymptomADD(m_Player, type, GetType());
  211. m_AnimPlayRequested = true;
  212. }
  213. void PlaySound(EPlayerSoundEventID id)
  214. {
  215. GetPlayer().RequestSoundEvent(id);
  216. m_PlayedSound = true;
  217. }
  218. void SyncToClientActivated( int SYMPTOM_id, int uid )
  219. {
  220. if ( !GetPlayer() ) return;
  221. CachedObjectsParams.PARAM2_INT_INT.param1 = SYMPTOM_id;
  222. CachedObjectsParams.PARAM2_INT_INT.param2 = uid;
  223. GetGame().RPCSingleParam(GetPlayer(), ERPCs.RPC_PLAYER_SYMPTOM_ON, CachedObjectsParams.PARAM2_INT_INT,true,GetPlayer().GetIdentity() );
  224. }
  225. void SyncToClientDeactivated( int SYMPTOM_id, int uid )
  226. {
  227. if ( !GetPlayer() ) return;
  228. CachedObjectsParams.PARAM2_INT_INT.param1 = SYMPTOM_id;
  229. CachedObjectsParams.PARAM2_INT_INT.param2 = uid;
  230. GetGame().RPCSingleParam(GetPlayer(), ERPCs.RPC_PLAYER_SYMPTOM_OFF, CachedObjectsParams.PARAM2_INT_INT,true,GetPlayer().GetIdentity() );
  231. }
  232. void CheckSoundFinished()
  233. {
  234. if (GetGame().IsServer())
  235. {
  236. if (m_PlayedSound && m_ActivatedTime >= m_Duration)
  237. RequestDestroy();
  238. }
  239. }
  240. void CheckDestroy()
  241. {
  242. CheckSoundFinished();
  243. if ( IsPrimary() && m_ActivatedTime > MAX_TIME_ACTIVE_SAVEGUARD)
  244. {
  245. RequestDestroy();
  246. }
  247. if (m_DestroyRequested)
  248. Destroy();
  249. }
  250. SmptAnimMetaBase SpawnAnimMetaObject()
  251. {
  252. return null;
  253. }
  254. void RequestDestroy()
  255. {
  256. m_DestroyRequested = true;
  257. //if(!IsActivated() ) Destroy();
  258. }
  259. void Destroy()
  260. {
  261. if (!m_IsTemplate)
  262. OnDestructed();
  263. }
  264. //!gets called upon animation Symptom exit
  265. void AnimationFinish()
  266. {
  267. //Print("*********** OnAnimationFinish ************");
  268. if ( m_DestroyOnAnimFinish ) RequestDestroy();
  269. OnAnimationFinish();
  270. }
  271. void AnimationPlayFailed()
  272. {
  273. OnAnimationPlayFailed();
  274. AnimationFinish();
  275. }
  276. void AnimationStart()
  277. {
  278. OnAnimationStart();
  279. }
  280. protected void OnAnimationFinish();
  281. protected void OnAnimationStart();
  282. protected void OnAnimationPlayFailed();
  283. //!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
  284. void OnInit();
  285. //!gets called every frame
  286. void OnUpdateServer(PlayerBase player, float deltatime);
  287. bool CanActivate(){return true;}//server only
  288. //!gets called every frame
  289. void OnUpdateClient(PlayerBase player, float deltatime);
  290. //!gets called once on an Symptom which is being activated
  291. void OnGetActivatedServer(PlayerBase player);
  292. void OnGetActivatedClient(PlayerBase player);
  293. //!only gets called once on an active Symptom that is being deactivated
  294. void OnGetDeactivatedServer(PlayerBase player);
  295. void OnGetDeactivatedClient(PlayerBase player);
  296. }