actionmanagerserver.c 7.8 KB

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