actioncontinuousbase.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. class ActionContinuousBaseCB : ActionBaseCB
  2. {
  3. bool m_inLoop = false;
  4. bool m_callLoopEnd = false;
  5. bool CancelCondition()
  6. {
  7. if ( !m_ActionData )
  8. {
  9. return DefaultCancelCondition();
  10. }
  11. if ((GetState() == STATE_LOOP_LOOP || GetState() == STATE_LOOP_LOOP2 || m_inLoop) )
  12. {
  13. ActionContinuousBase actionS = ActionContinuousBase.Cast(m_ActionData.m_Action);
  14. if ( m_ActionData.m_State == UA_INITIALIZE )
  15. {
  16. actionS.OnStartAnimationLoop( m_ActionData );
  17. m_ActionData.m_State = UA_PROCESSING;
  18. m_callLoopEnd = true;
  19. }
  20. if (!m_Interrupted)
  21. actionS.Do(m_ActionData, m_ActionData.m_State);
  22. }
  23. else if (m_callLoopEnd == true)
  24. {
  25. ActionContinuousBase actionE = ActionContinuousBase.Cast(m_ActionData.m_Action);
  26. actionE.OnEndAnimationLoop( m_ActionData );
  27. m_callLoopEnd = false;
  28. }
  29. return DefaultCancelCondition();
  30. }
  31. void SetInLoop(bool value)
  32. {
  33. m_inLoop = value;
  34. }
  35. override void InitActionComponent()
  36. {
  37. m_Interrupted = false;
  38. m_Canceled = false;
  39. m_inLoop = false;
  40. CreateActionComponent();
  41. if ( m_ActionData.m_ActionComponent )
  42. {
  43. m_ActionData.m_ActionComponent.Init(m_ActionData);
  44. }
  45. m_ActionData.m_State = UA_INITIALIZE;
  46. RegisterAnimationEvent("ActionExecStart", UA_IN_START);
  47. RegisterAnimationEvent("ActionExecEnd", UA_IN_END);
  48. RegisterAnimationEvent("ActionExec", UA_ANIM_EVENT);
  49. EnableCancelCondition(true);
  50. m_SoundObject = m_ActionData.m_Action.PlayActionSound(m_ActionData.m_Player);
  51. }
  52. //TODO: consider this for general use
  53. /*override void EndActionComponent()
  54. {
  55. ActionContinuousBase action = ActionContinuousBase.Cast(m_ActionData.m_Action);
  56. if (m_ActionData.m_State != UA_FINISHED)
  57. m_Canceled = true;
  58. if (m_ActionData.m_State == UA_FINISHED || m_ActionData.m_State == UA_CANCEL)
  59. {
  60. if (action.UseAlternativeInterrupt(m_ActionData))
  61. SetCommand(DayZPlayerConstants.CMD_ACTIONINT_FINISH);
  62. else
  63. SetCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
  64. }
  65. else
  66. {
  67. SetCommand(DayZPlayerConstants.CMD_ACTIONINT_INTERRUPT);
  68. }
  69. }*/
  70. override void EndActionComponent()
  71. {
  72. // TODO for second type animation SetCommand(DayZPlayerConstants.CMD_ACTIONINT_FINISH);
  73. if ( m_ActionData.m_State == UA_FINISHED )
  74. {
  75. SetCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
  76. }
  77. else if (m_ActionData.m_State == UA_CANCEL )
  78. {
  79. ActionContinuousBase action = ActionContinuousBase.Cast(m_ActionData.m_Action);
  80. if(action.HasAlternativeInterrupt())
  81. {
  82. SetCommand(DayZPlayerConstants.CMD_ACTIONINT_FINISH);
  83. }
  84. else
  85. {
  86. SetCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
  87. }
  88. m_Canceled = true;
  89. return;
  90. //Cancel();
  91. }
  92. else
  93. {
  94. m_Canceled = true;
  95. SetCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
  96. return;
  97. }
  98. m_ActionData.m_State = UA_FINISHED;
  99. }
  100. void UserEndsAction()
  101. {
  102. if ( m_ActionData.m_ActionComponent )
  103. {
  104. m_ActionData.m_State = m_ActionData.m_ActionComponent.Cancel(m_ActionData);
  105. }
  106. //EndActionComponent(); //already handled in 'AnimatedActionBase::Do' on cancel
  107. }
  108. };
  109. class ActionContinuousBase : AnimatedActionBase
  110. {
  111. PluginAdminLog m_AdminLog;
  112. void ActionContinuousBase()
  113. {
  114. m_CallbackClass = ActionContinuousBaseCB;
  115. m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_EAT;
  116. if( GetGame() && GetGame().IsServer() )
  117. {
  118. m_AdminLog = PluginAdminLog.Cast( GetPlugin(PluginAdminLog) );
  119. }
  120. }
  121. override void OnEndInput( ActionData action_data )
  122. {
  123. ActionContinuousBaseCB callback;
  124. if( Class.CastTo(callback, action_data.m_Callback) )
  125. {
  126. if ( callback.GetState() != callback.STATE_LOOP_END && callback.GetState() != callback.STATE_LOOP_END2 )
  127. {
  128. callback.UserEndsAction();
  129. }
  130. }
  131. }
  132. bool HasAlternativeInterrupt()
  133. {
  134. return false;
  135. }
  136. bool UseAlternativeInterrupt(ActionData action_data)
  137. {
  138. return false;
  139. }
  140. // lock default camera while performing the action
  141. bool IsCameraLockOnPerform()
  142. {
  143. return true;
  144. }
  145. // camera up/down angle when performing a fullbody action
  146. // values beetwen 0 and -90 (looking at ground) / 0 and 90 (looking above)
  147. Vector2 GetCameraUDAngle()
  148. {
  149. Vector2 udAngle = new Vector2(-70, 45);
  150. return udAngle;
  151. }
  152. // camera (heading) left/right angle when performing a fullbody action
  153. // values beetwen 0 and -180 (left restriction) / 0 and 180 (right restriction)
  154. Vector2 GetCameraLRAngle()
  155. {
  156. Vector2 lrAngle = new Vector2(-70, 70);
  157. return lrAngle;
  158. }
  159. override typename GetInputType()
  160. {
  161. return ContinuousDefaultActionInput;
  162. }
  163. override int GetActionCategory()
  164. {
  165. return AC_CONTINUOUS;
  166. }
  167. override void OnAnimationEvent(ActionData action_data)
  168. {
  169. super.OnAnimationEvent(action_data);
  170. ActionContinuousBaseCB callback;
  171. if (Class.CastTo(callback, action_data.m_Callback))
  172. {
  173. if (action_data.m_DelayedAnimationEventID == UA_IN_START)
  174. {
  175. OnStartAnimationLoop(action_data);
  176. callback.SetInLoop(true);
  177. }
  178. else if (action_data.m_DelayedAnimationEventID == UA_IN_END)
  179. {
  180. OnEndAnimationLoop(action_data);
  181. callback.SetInLoop(false);
  182. }
  183. }
  184. }
  185. void OnStartAnimationLoop( ActionData action_data )
  186. {
  187. if ( LogManager.IsActionLogEnable() )
  188. {
  189. Debug.ActionLog("Time stamp: " + action_data.m_Player.GetSimulationTimeStamp(), this.ToString() , "n/a", "OnStartAnimationLoop", action_data.m_Player.ToString() );
  190. }
  191. if (GetGame().IsServer())
  192. {
  193. OnStartAnimationLoopServer(action_data);
  194. }
  195. else
  196. {
  197. OnStartAnimationLoopClient(action_data);
  198. }
  199. action_data.m_WasExecuted = false;
  200. }
  201. void OnEndAnimationLoop( ActionData action_data )
  202. {
  203. if ( LogManager.IsActionLogEnable() )
  204. {
  205. Debug.ActionLog("Time stamp: " + action_data.m_Player.GetSimulationTimeStamp(), this.ToString() , "n/a", "OnEndAnimationLoop", action_data.m_Player.ToString() );
  206. }
  207. if (GetGame().IsServer())
  208. {
  209. OnEndAnimationLoopServer(action_data);
  210. }
  211. else
  212. {
  213. OnEndAnimationLoopClient(action_data);
  214. }
  215. action_data.m_WasExecuted = false;
  216. }
  217. void OnFinishProgress( ActionData action_data )
  218. {
  219. if ( LogManager.IsActionLogEnable() )
  220. {
  221. Debug.ActionLog("Time stamp: " + action_data.m_Player.GetSimulationTimeStamp(), this.ToString() , "n/a", "OnFinishProgress", action_data.m_Player.ToString() );
  222. }
  223. if (GetGame().IsServer())
  224. {
  225. OnFinishProgressServer(action_data);
  226. if ( m_AdminLog )
  227. {
  228. m_AdminLog.OnContinouousAction( action_data );
  229. }
  230. }
  231. else
  232. {
  233. OnFinishProgressClient(action_data);
  234. }
  235. action_data.m_WasExecuted = false;
  236. }
  237. protected void OnStartAnimationLoopServer( ActionData action_data ) //method called on start main animation loop (after in animation part )
  238. {
  239. action_data.m_WasActionStarted = true;
  240. }
  241. protected void OnStartAnimationLoopClient( ActionData action_data ) //method called on start main animation loop (after in animation part )
  242. {
  243. action_data.m_WasActionStarted = true;
  244. }
  245. protected void OnEndAnimationLoopServer( ActionData action_data ) //method called on finish main animation loop (before out animation part )
  246. {
  247. }
  248. protected void OnEndAnimationLoopClient( ActionData action_data ) //method called on finish main animation loop (before out animation part )
  249. {
  250. }
  251. protected void OnFinishProgressServer( ActionData action_data )
  252. {
  253. }
  254. protected void OnFinishProgressClient( ActionData action_data )
  255. {
  256. }
  257. };