statebase.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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. PlayerBase GetPlayer()
  120. {
  121. return m_Player;
  122. }
  123. int GetPriority()
  124. {
  125. return m_Priority;
  126. }
  127. bool OnConstructed(SymptomManager manager)
  128. {
  129. }
  130. void OnDestructed()
  131. {
  132. if ( IsActivated() ) Deactivate();
  133. if ( GetManager() ) m_Manager.OnSymptomExit(this, m_UID);
  134. }
  135. void Activate()
  136. {
  137. m_IsActivated = true;
  138. if ( GetGame() && GetGame().IsServer() )
  139. {
  140. OnGetActivatedServer(m_Player);
  141. if ( GetGame().IsMultiplayer() )
  142. {
  143. if ( IsSyncToClient() )
  144. SyncToClientActivated( GetType(), GetUID() );
  145. #ifdef DIAG_DEVELOPER
  146. GetManager().SendServerDebugToClient();
  147. #endif
  148. }
  149. }
  150. if ( !GetGame().IsDedicatedServer() )
  151. {
  152. OnGetActivatedClient(m_Player);
  153. }
  154. }
  155. void Deactivate()
  156. {
  157. if ( !GetGame() ) return;
  158. m_IsActivated = false;
  159. if ( GetGame().IsServer() )
  160. {
  161. OnGetDeactivatedServer(m_Player);
  162. if ( GetGame().IsMultiplayer() && IsSyncToClient() )
  163. {
  164. SyncToClientDeactivated( GetType(), GetUID() );
  165. }
  166. }
  167. if ( !GetGame().IsDedicatedServer() )
  168. {
  169. OnGetDeactivatedClient(m_Player);
  170. }
  171. }
  172. bool IsActivated()
  173. {
  174. return m_IsActivated;
  175. }
  176. void Update(float deltatime)
  177. {
  178. if ( GetGame().IsServer() )
  179. {
  180. m_ServerUpdateDelta += deltatime;
  181. if (m_ServerUpdateDelta > m_ServerUpdateInterval )
  182. {
  183. m_ActivatedTime += m_ServerUpdateDelta;
  184. OnUpdateServer(m_Player, m_ServerUpdateDelta);
  185. m_ServerUpdateDelta = 0;
  186. }
  187. }
  188. if ( GetGame().IsClient() )
  189. {
  190. OnUpdateClient(m_Player, deltatime);
  191. }
  192. if ( GetGame().IsServer() && !GetGame().IsMultiplayer() && !GetGame().IsMissionMainMenu() )
  193. {
  194. OnUpdateClient(m_Player, deltatime);
  195. }
  196. CheckDestroy();
  197. }
  198. void PlayAnimationFB(int animation, int stance_mask, float running_time = -1)
  199. {
  200. DayZPlayerSyncJunctures.SendPlayerSymptomFB(m_Player, animation, GetType() , stance_mask, running_time );
  201. m_AnimPlayRequested = true;
  202. }
  203. void PlayAnimationADD(int type)
  204. {
  205. DayZPlayerSyncJunctures.SendPlayerSymptomADD(m_Player, type, GetType());
  206. m_AnimPlayRequested = true;
  207. }
  208. void PlaySound(EPlayerSoundEventID id)
  209. {
  210. GetPlayer().RequestSoundEvent(id);
  211. m_PlayedSound = true;
  212. }
  213. void SyncToClientActivated( int SYMPTOM_id, int uid )
  214. {
  215. if ( !GetPlayer() ) return;
  216. CachedObjectsParams.PARAM2_INT_INT.param1 = SYMPTOM_id;
  217. CachedObjectsParams.PARAM2_INT_INT.param2 = uid;
  218. GetGame().RPCSingleParam(GetPlayer(), ERPCs.RPC_PLAYER_SYMPTOM_ON, CachedObjectsParams.PARAM2_INT_INT,true,GetPlayer().GetIdentity() );
  219. }
  220. void SyncToClientDeactivated( int SYMPTOM_id, int uid )
  221. {
  222. if ( !GetPlayer() ) return;
  223. CachedObjectsParams.PARAM2_INT_INT.param1 = SYMPTOM_id;
  224. CachedObjectsParams.PARAM2_INT_INT.param2 = uid;
  225. GetGame().RPCSingleParam(GetPlayer(), ERPCs.RPC_PLAYER_SYMPTOM_OFF, CachedObjectsParams.PARAM2_INT_INT,true,GetPlayer().GetIdentity() );
  226. }
  227. void CheckSoundFinished()
  228. {
  229. if (GetGame().IsServer())
  230. {
  231. if (m_PlayedSound && m_ActivatedTime >= m_Duration)
  232. RequestDestroy();
  233. }
  234. }
  235. void CheckDestroy()
  236. {
  237. CheckSoundFinished();
  238. if ( IsPrimary() && m_ActivatedTime > MAX_TIME_ACTIVE_SAVEGUARD)
  239. {
  240. RequestDestroy();
  241. }
  242. if (m_DestroyRequested)
  243. Destroy();
  244. }
  245. SmptAnimMetaBase SpawnAnimMetaObject()
  246. {
  247. return null;
  248. }
  249. void RequestDestroy()
  250. {
  251. m_DestroyRequested = true;
  252. //if(!IsActivated() ) Destroy();
  253. }
  254. void Destroy()
  255. {
  256. if (!m_IsTemplate)
  257. OnDestructed();
  258. }
  259. //!gets called upon animation Symptom exit
  260. void AnimationFinish()
  261. {
  262. //Print("*********** OnAnimationFinish ************");
  263. if ( m_DestroyOnAnimFinish ) RequestDestroy();
  264. OnAnimationFinish();
  265. }
  266. void AnimationPlayFailed()
  267. {
  268. OnAnimationPlayFailed();
  269. AnimationFinish();
  270. }
  271. void AnimationStart()
  272. {
  273. OnAnimationStart();
  274. }
  275. protected void OnAnimationFinish();
  276. protected void OnAnimationStart();
  277. protected void OnAnimationPlayFailed();
  278. //!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
  279. void OnInit();
  280. //!gets called every frame
  281. void OnUpdateServer(PlayerBase player, float deltatime);
  282. bool CanActivate(){return true;}//server only
  283. //!gets called every frame
  284. void OnUpdateClient(PlayerBase player, float deltatime);
  285. //!gets called once on an Symptom which is being activated
  286. void OnGetActivatedServer(PlayerBase player);
  287. void OnGetActivatedClient(PlayerBase player);
  288. //!only gets called once on an active Symptom that is being deactivated
  289. void OnGetDeactivatedServer(PlayerBase player);
  290. void OnGetDeactivatedClient(PlayerBase player);
  291. }