actionmanagerserver.c 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. class ActionManagerServer: ActionManagerBase
  2. {
  3. protected ActionBase m_PendingAction;
  4. ref ActionReciveData m_PendingActionReciveData;
  5. void ActionManagerServer(PlayerBase player)
  6. {
  7. m_PendingAction = null;
  8. m_PendingActionReciveData = null;
  9. }
  10. //------------------------------------------
  11. //EVENTS
  12. //------------------------------------------
  13. override void OnJumpStart()
  14. {
  15. EndOrInterruptCurrentAction();
  16. }
  17. override void EndOrInterruptCurrentAction()
  18. {
  19. if (m_CurrentActionData)
  20. {
  21. if (m_CurrentActionData.m_State == UA_AM_PENDING || m_CurrentActionData.m_State == UA_AM_REJECTED || m_CurrentActionData.m_State == UA_AM_ACCEPTED)
  22. {
  23. OnActionEnd();
  24. m_PendingActionAcknowledgmentID = -1;
  25. }
  26. else
  27. {
  28. m_CurrentActionData.m_Action.Interrupt(m_CurrentActionData);
  29. }
  30. }
  31. }
  32. override bool OnInputUserDataProcess(int userDataType, ParamsReadContext ctx)
  33. {
  34. switch (userDataType)
  35. {
  36. case INPUT_UDT_STANDARD_ACTION_START:
  37. {
  38. bool success = true;
  39. int actionID = 0;
  40. if (!ctx.Read(actionID))
  41. return false;
  42. ActionBase recvAction = GetAction(actionID);
  43. if (!recvAction)
  44. return false;
  45. if (!recvAction.ReadFromContext(ctx, m_PendingActionReciveData))
  46. success = false;
  47. m_PendingAction = recvAction;
  48. if (recvAction.UseAcknowledgment())
  49. {
  50. int ackID;
  51. if (!ctx.Read(ackID))
  52. success = false;
  53. m_PendingActionAcknowledgmentID = ackID;
  54. }
  55. break;
  56. }
  57. case INPUT_UDT_STANDARD_ACTION_END_REQUEST:
  58. {
  59. //Debug.Log("Action want end request, STS = " + m_Player.GetSimulationTimeStamp());
  60. int commandID = -10;
  61. ctx.Read(commandID);
  62. if (commandID == DayZPlayerConstants.CMD_ACTIONINT_INTERRUPT)
  63. {
  64. //Print("INPUT_UDT_STANDARD_ACTION_END_REQUEST | CMD_ACTIONINT_INTERRUPT");
  65. RequestInterruptAction();
  66. }
  67. else
  68. {
  69. //Print("INPUT_UDT_STANDARD_ACTION_END_REQUEST | m_ActionWantEndRequest");
  70. m_ActionWantEndRequest = true;
  71. }
  72. }
  73. case INPUT_UDT_STANDARD_ACTION_INPUT_END:
  74. {
  75. //Debug.Log("Action input ended, STS = " + m_Player.GetSimulationTimeStamp());
  76. m_ActionInputWantEnd = true;
  77. }
  78. default:
  79. return false;
  80. }
  81. if (!success)
  82. {
  83. //Debug.Log("[AM] OnInputUserDataProcess INPUT_UDT_STANDARD_ACTION_START Error");
  84. if (recvAction.UseAcknowledgment())
  85. {
  86. DayZPlayerSyncJunctures.SendActionAcknowledgment(m_Player, m_PendingActionAcknowledgmentID, false);
  87. }
  88. else
  89. {
  90. RequestInterruptAction();
  91. }
  92. return false;
  93. }
  94. return true;
  95. }
  96. override void StartDeliveredAction()
  97. {
  98. if (!m_CurrentActionData)
  99. {
  100. //! error - expected action data
  101. return;
  102. }
  103. m_Interrupted = false;
  104. bool accepted = false;
  105. ActionBase pickedAction = m_CurrentActionData.m_Action;
  106. ActionTarget target = m_CurrentActionData.m_Target;
  107. ItemBase item = m_CurrentActionData.m_MainItem;
  108. if (LogManager.IsActionLogEnable())
  109. {
  110. if (target)
  111. {
  112. Debug.ActionLog("Item = " + item + ", " + target.DumpToString(), pickedAction.ToString() , "n/a", "DeliveredAction", m_Player.ToString());
  113. }
  114. else
  115. {
  116. Debug.ActionLog("Item = " + item + ", NULL", pickedAction.ToString() , "n/a", "DeliveredAction", m_Player.ToString());
  117. }
  118. }
  119. if (!m_Player.GetCommandModifier_Action() && !m_Player.GetCommand_Action() && !m_Player.IsSprinting() && pickedAction && pickedAction.Can(m_Player,target,item))
  120. {
  121. if (pickedAction.AddActionJuncture(m_CurrentActionData))
  122. accepted = true;
  123. }
  124. if (accepted)
  125. {
  126. if (LogManager.IsActionLogEnable())
  127. {
  128. Debug.ActionLog("Action accepted", pickedAction.ToString() , "n/a", "CheckDeliveredAction", m_Player.ToString() );
  129. }
  130. //Debug.Log("[AM] Action acccepted");
  131. if (pickedAction.UseAcknowledgment())
  132. {
  133. //Unlock target
  134. m_CurrentActionData.m_State = UA_AM_PENDING;
  135. DayZPlayerSyncJunctures.SendActionAcknowledgment(m_Player, m_PendingActionAcknowledgmentID, true);
  136. }
  137. else
  138. {
  139. m_CurrentActionData.m_State = UA_AM_ACCEPTED;
  140. }
  141. }
  142. else
  143. {
  144. if (LogManager.IsActionLogEnable())
  145. {
  146. Debug.ActionLog("Action rejected", pickedAction.ToString() , "n/a", "CheckDeliveredAction", m_Player.ToString() );
  147. }
  148. if (pickedAction.UseAcknowledgment())
  149. {
  150. DayZPlayerSyncJunctures.SendActionAcknowledgment(m_Player, m_PendingActionAcknowledgmentID, false);
  151. }
  152. else
  153. {
  154. RequestInterruptAction();
  155. }
  156. }
  157. }
  158. override void OnActionEnd()
  159. {
  160. //Debug.Log("Action ended - hard, STS = " + m_Player.GetSimulationTimeStamp());
  161. if (m_CurrentActionData)
  162. {
  163. m_CurrentActionData.m_Action.ClearActionJuncture(m_CurrentActionData);
  164. super.OnActionEnd();
  165. }
  166. }
  167. //pCurrentCommandID is command ID at time of call command handler, some called methods can change actual true value (need call m_Player.GetCurrentCommandID() for actual command ID)
  168. override void Update(int pCurrentCommandID)
  169. {
  170. super.Update(pCurrentCommandID);
  171. int currentCommandID = m_Player.GetCurrentCommandID();
  172. //Debug.Log("m_ActionWantEnd " + m_ActionInputWantEnd);
  173. if (m_PendingAction)
  174. {
  175. if (m_CurrentActionData)
  176. {
  177. DayZPlayerSyncJunctures.SendActionAcknowledgment(m_Player, m_PendingActionAcknowledgmentID, false);
  178. }
  179. else
  180. {
  181. m_ActionWantEndRequest = false;
  182. m_ActionInputWantEnd = false;
  183. bool success = true;
  184. ActionTarget target = new ActionTarget(null, null, -1, vector.Zero, 0);
  185. if ( LogManager.IsActionLogEnable() )
  186. {
  187. Debug.ActionLog("n/a", m_PendingAction.ToString() , "n/a", "HandlePendingAction", m_Player.ToString() );
  188. }
  189. if (!m_PendingAction.SetupAction(m_Player,target,m_Player.GetItemInHands(),m_CurrentActionData))
  190. {
  191. success = false;
  192. }
  193. //Debug.Log("[AM] Action data synced (" + m_Player + ") success: " + success);
  194. if (success)
  195. {
  196. StartDeliveredAction();
  197. }
  198. else
  199. {
  200. if (m_PendingAction.UseAcknowledgment())
  201. {
  202. DayZPlayerSyncJunctures.SendActionAcknowledgment(m_Player, m_PendingActionAcknowledgmentID, false);
  203. }
  204. else
  205. {
  206. RequestInterruptAction();
  207. }
  208. }
  209. }
  210. m_PendingAction = null;
  211. m_PendingActionReciveData = null;
  212. }
  213. if (m_CurrentActionData)
  214. {
  215. if (m_CurrentActionData.m_State != UA_AM_PENDING && m_CurrentActionData.m_State != UA_AM_REJECTED && m_CurrentActionData.m_State != UA_AM_ACCEPTED)
  216. {
  217. m_CurrentActionData.m_Action.OnUpdateServer(m_CurrentActionData);
  218. }
  219. //Debug.Log("m_CurrentActionData.m_State: " + m_CurrentActionData.m_State +" m_ActionWantEnd: " + m_ActionWantEndRequest );
  220. switch (m_CurrentActionData.m_State)
  221. {
  222. case UA_AM_PENDING:
  223. break;
  224. case UA_AM_ACCEPTED:
  225. // check currentCommandID before start or reject
  226. int condition_mask = ActionBase.ComputeConditionMask(m_Player, m_CurrentActionData.m_Target, m_CurrentActionData.m_MainItem);
  227. bool canActionPerform = ((condition_mask & m_CurrentActionData.m_Action.m_ConditionMask) == condition_mask);
  228. if (canActionPerform && ActionPossibilityCheck(currentCommandID))
  229. {
  230. m_CurrentActionData.m_State = UA_START;
  231. m_CurrentActionData.m_Action.Start(m_CurrentActionData);
  232. if (m_CurrentActionData.m_Action && m_CurrentActionData.m_Action.IsInstant())
  233. OnActionEnd();
  234. }
  235. else
  236. {
  237. RequestInterruptAction();
  238. }
  239. m_PendingActionAcknowledgmentID = -1;
  240. break;
  241. case UA_AM_REJECTED:
  242. OnActionEnd();
  243. m_PendingActionAcknowledgmentID = -1;
  244. break;
  245. default:
  246. if (m_ActionInputWantEnd)
  247. {
  248. m_ActionInputWantEnd = false;
  249. m_CurrentActionData.m_Action.EndInput(m_CurrentActionData);
  250. }
  251. if (m_ActionWantEndRequest)
  252. {
  253. m_ActionWantEndRequest = false;
  254. m_CurrentActionData.m_Action.EndRequest(m_CurrentActionData);
  255. }
  256. break;
  257. }
  258. }
  259. }
  260. //! server requests action interrupt
  261. override void RequestInterruptAction()
  262. {
  263. if (m_CurrentActionData)
  264. DayZPlayerSyncJunctures.SendActionInterrupt(m_Player);
  265. }
  266. override ActionReciveData GetReciveData()
  267. {
  268. return m_PendingActionReciveData;
  269. }
  270. }