actionmanagerbase.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. class TSelectableActionInfoArray extends array<ref TSelectableActionInfo>
  2. {
  3. bool IsSameAs(TSelectableActionInfoArray other)
  4. {
  5. if (this.Count() != other.Count())
  6. {
  7. return false;
  8. }
  9. for (int i = 0; i < Count(); ++i)
  10. {
  11. TSelectableActionInfo ai1 = this.Get(i);
  12. TSelectableActionInfo ai2 = other.Get(i);
  13. if (ai1.param2 != ai2.param2)
  14. {
  15. return false;
  16. }
  17. if (ai1.param3 != ai2.param3)
  18. {
  19. return false;
  20. }
  21. }
  22. return true;
  23. }
  24. }
  25. class ActionManagerBase
  26. {
  27. PlayerBase m_Player;
  28. protected ActionTarget m_TestedActionTarget;
  29. protected ItemBase m_TestedActionItem;
  30. protected ActionBase m_PrimaryAction;
  31. protected ActionTarget m_PrimaryActionTarget;
  32. protected ItemBase m_PrimaryActionItem;
  33. protected ActionBase m_SecondaryAction;
  34. protected ActionTarget m_SecondaryActionTarget;
  35. protected ItemBase m_SecondaryActionItem;
  36. bool m_PrimaryActionEnabled;
  37. bool m_SecondaryActionEnabled;
  38. bool m_TertiaryActionEnabled;
  39. ref TSelectableActionInfoArray m_SelectableActions;
  40. int m_SelectedActionIndex;
  41. bool m_SelectableActionsHasChanged;
  42. bool m_Interrupted;
  43. static ref array<ref ActionBase> m_ActionsArray;
  44. static ref map<typename, ActionBase> m_ActionNameActionMap;
  45. protected bool m_ActionWantEndRequest;
  46. protected bool m_ActionInputWantEnd;
  47. protected bool m_ActionsEnabled;
  48. protected bool m_ActionsAvaibale;
  49. protected bool m_IsRestrictedLookLimits; // restricts head look/aim limits while performing an action
  50. //Pending actions waiting for acknowledgment
  51. protected int m_PendingActionAcknowledgmentID;
  52. protected ref ActionData m_CurrentActionData;
  53. void ActionManagerBase(PlayerBase player)
  54. {
  55. m_Player = player;
  56. if (m_Player)
  57. {
  58. m_SelectableActions = new TSelectableActionInfoArray();
  59. m_SelectedActionIndex = 0;
  60. m_SelectableActionsHasChanged = false;
  61. m_PendingActionAcknowledgmentID = -1;
  62. m_CurrentActionData = NULL;
  63. m_Interrupted = false;
  64. ActionConstructor ac = new ActionConstructor();
  65. if (!m_ActionsArray)
  66. {
  67. ac.ConstructActions(m_ActionsArray, m_ActionNameActionMap);
  68. }
  69. m_ActionWantEndRequest = false;
  70. m_ActionInputWantEnd = false;
  71. }
  72. m_ActionsEnabled = true;
  73. m_ActionsAvaibale = true;
  74. }
  75. ActionBase GetRunningAction()
  76. {
  77. if (m_CurrentActionData)
  78. return m_CurrentActionData.m_Action;
  79. return null;
  80. }
  81. ItemBase GetRunningActionMainitem()
  82. {
  83. if (m_CurrentActionData)
  84. return m_CurrentActionData.m_MainItem;
  85. return null;
  86. }
  87. void EnableActions(bool enable)
  88. {
  89. m_ActionsEnabled = enable;
  90. }
  91. void Update(int pCurrentCommandID)
  92. {
  93. if (m_CurrentActionData)
  94. {
  95. if (m_Interrupted)
  96. {
  97. LocalInterrupt();
  98. }
  99. else if (m_CurrentActionData.m_State != UA_AM_PENDING && m_CurrentActionData.m_State != UA_AM_REJECTED && m_CurrentActionData.m_State != UA_AM_ACCEPTED)
  100. {
  101. m_CurrentActionData.m_Action.OnUpdate(m_CurrentActionData);
  102. }
  103. }
  104. else if (m_Interrupted)
  105. {
  106. m_Interrupted = false;
  107. }
  108. if (m_CurrentActionData) // again, can be nulled meanwhile
  109. {
  110. ActionContinuousBase action = ActionContinuousBase.Cast(m_CurrentActionData.m_Action);
  111. if (action && action.IsFullBody(m_Player) && action.IsCameraLockOnPerform())
  112. {
  113. if (!m_IsRestrictedLookLimits)
  114. {
  115. Vector2 angleUD = action.GetCameraUDAngle();
  116. m_IsRestrictedLookLimits = true;
  117. m_Player.SetLookLimits(angleUD.x, angleUD.y, -160, 160);
  118. m_Player.SetAimLimits(angleUD.x, angleUD.y, -180, 180);
  119. }
  120. return;
  121. }
  122. }
  123. if (m_IsRestrictedLookLimits)
  124. {
  125. m_IsRestrictedLookLimits = false;
  126. m_Player.SetLookLimits(-85, 85, -160, 160);
  127. m_Player.SetAimLimits(-85, 85, -180, 180);
  128. }
  129. }
  130. void OnSyncJuncture(int pJunctureID, ParamsReadContext pCtx)
  131. {
  132. int AcknowledgmentID;
  133. switch (pJunctureID)
  134. {
  135. case DayZPlayerSyncJunctures.SJ_ACTION_ACK_ACCEPT:
  136. pCtx.Read(AcknowledgmentID);
  137. if (m_CurrentActionData && AcknowledgmentID == m_PendingActionAcknowledgmentID)
  138. m_CurrentActionData.m_State = UA_AM_ACCEPTED;
  139. break;
  140. case DayZPlayerSyncJunctures.SJ_ACTION_ACK_REJECT:
  141. pCtx.Read(AcknowledgmentID);
  142. if (m_CurrentActionData && AcknowledgmentID == m_PendingActionAcknowledgmentID)
  143. m_CurrentActionData.m_State = UA_AM_REJECTED;
  144. break;
  145. case DayZPlayerSyncJunctures.SJ_ACTION_INTERRUPT:
  146. m_Interrupted = true;
  147. break;
  148. }
  149. }
  150. ActionTarget FindActionTarget();
  151. void StartDeliveredAction();
  152. static ActionBase GetActionVariant(typename actionName)
  153. {
  154. if (m_ActionNameActionMap)
  155. {
  156. ActionBase base_action = m_ActionNameActionMap.Get(actionName);
  157. ActionBase new_action = ActionBase.Cast(actionName.Spawn());
  158. new_action.CreateConditionComponents();
  159. new_action.SetID(base_action.GetID());
  160. new_action.SetInput(base_action.GetInput());
  161. return new_action;
  162. }
  163. return null;
  164. }
  165. static ActionBase GetAction(typename actionName)
  166. {
  167. if (m_ActionNameActionMap)
  168. return m_ActionNameActionMap.Get(actionName);
  169. return null;
  170. }
  171. static ActionBase GetAction(int actionID)
  172. {
  173. return m_ActionsArray.Get(actionID);
  174. }
  175. ActionBase GetContinuousAction()
  176. {
  177. return m_PrimaryAction;
  178. }
  179. ActionBase GetSingleUseAction()
  180. {
  181. return m_SecondaryAction;
  182. }
  183. TSelectableActionInfoArray GetSelectableActions()
  184. {
  185. return m_SelectableActions;
  186. }
  187. int GetSelectedActionIndex()
  188. {
  189. return m_SelectedActionIndex;
  190. }
  191. typename GetSelectedActionCategory();
  192. void SelectFirstActionCategory();
  193. void SelectNextActionCategory();
  194. void SelectPrevActionCategory();
  195. void SelectNextAction();
  196. void SelectPrevAction();
  197. void RequestEndAction();
  198. void EndActionInput();
  199. bool IsSelectableActionsChanged()
  200. {
  201. return m_SelectableActionsHasChanged;
  202. }
  203. //------------------------------------------------------
  204. bool ActionPossibilityCheck(int pCurrentCommandID)
  205. {
  206. if (!m_ActionsEnabled || m_Player.IsSprinting() || m_Player.IsUnconscious() || m_Player.GetCommandModifier_Action() || m_Player.GetCommand_Action() || m_Player.IsEmotePlaying())
  207. return false;
  208. if (m_Player.GetWeaponManager().IsRunning() || m_Player.GetThrowing().IsThrowingAnimationPlaying() || m_Player.GetDayZPlayerInventory().IsProcessing() || m_Player.IsItemsToDelete() || m_Player.IsRolling())
  209. return false;
  210. return (pCurrentCommandID == DayZPlayerConstants.COMMANDID_ACTION || pCurrentCommandID == DayZPlayerConstants.COMMANDID_MOVE || pCurrentCommandID == DayZPlayerConstants.COMMANDID_SWIM || pCurrentCommandID == DayZPlayerConstants.COMMANDID_LADDER || pCurrentCommandID == DayZPlayerConstants.COMMANDID_VEHICLE);
  211. }
  212. //------------------------------------------------------
  213. protected void SetActionContext(ActionTarget target, ItemBase item)
  214. {
  215. m_TestedActionTarget = target;
  216. m_TestedActionItem = item;
  217. }
  218. //------------------------------------------------------
  219. int GetActionState(ActionBase action)
  220. {
  221. if (m_CurrentActionData)
  222. {
  223. return m_CurrentActionData.m_State;
  224. }
  225. return UA_NONE;
  226. }
  227. //---------------------------------
  228. // EVENTS
  229. //---------------------------------
  230. void OnContinuousStart();
  231. void OnContinuousCancel();
  232. void OnSingleUse();
  233. void InterruptNoSync()
  234. {
  235. m_Interrupted = true;
  236. }
  237. void Interrupt()
  238. {
  239. if (m_CurrentActionData)
  240. {
  241. if(GetGame().IsMultiplayer())
  242. {
  243. RequestInterruptAction();
  244. }
  245. else
  246. {
  247. InterruptNoSync();
  248. }
  249. }
  250. }
  251. void RequestInterruptAction();
  252. protected void LocalInterrupt()
  253. {
  254. if (m_CurrentActionData && m_CurrentActionData.m_Action)
  255. m_CurrentActionData.m_Action.Interrupt(m_CurrentActionData);
  256. else
  257. m_Interrupted = false;
  258. }
  259. void OnInteractAction(); //Interact
  260. void OnInstantAction(typename user_action_type, Param data = null);
  261. void OnActionEnd()
  262. {
  263. if (LogManager.IsActionLogEnable())
  264. {
  265. if (m_CurrentActionData)
  266. Debug.ActionLog("Time stamp: " + m_CurrentActionData.m_Player.GetSimulationTimeStamp(), m_CurrentActionData.m_Action.ToString() , "n/a", "OnActionEnd", m_CurrentActionData.m_Player.ToString());
  267. Debug.ActionLog("Action data cleared ", this.ToString() , "n/a", "ActionEnd", m_CurrentActionData.m_Player.ToString());
  268. }
  269. if (m_CurrentActionData)
  270. m_CurrentActionData.m_Action.ActionCleanup(m_CurrentActionData);
  271. m_CurrentActionData = NULL;
  272. m_Player.ResetActionEndInput();
  273. }
  274. void OnJumpStart();
  275. void EndOrInterruptCurrentAction();
  276. bool OnInputUserDataProcess(int userDataType, ParamsReadContext ctx)
  277. {
  278. return false;
  279. }
  280. float GetActionComponentProgress()
  281. {
  282. if (m_CurrentActionData)
  283. return m_CurrentActionData.m_Action.GetProgress(m_CurrentActionData);
  284. return 0.0;
  285. }
  286. float GetACProgressWidgetMultiplier()
  287. {
  288. if (m_CurrentActionData)
  289. return m_CurrentActionData.m_Action.GetProgressWidgetMultiplier(m_CurrentActionData);
  290. return 1;
  291. }
  292. int GetActionState()
  293. {
  294. if (m_CurrentActionData)
  295. return m_CurrentActionData.m_Action.GetState(m_CurrentActionData);
  296. return UA_NONE;
  297. }
  298. ActionReciveData GetReciveData()
  299. {
  300. return null;
  301. }
  302. }