actionmanagerclient.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299
  1. typedef map<typename,ref array<ActionBase_Basic>> TInputActionMap;
  2. typedef map<typename,ref ActionInput> TTypeNameActionInputMap;
  3. class ActionManagerClient: ActionManagerBase
  4. {
  5. //Last send AcknowledgmentID (client can send more requests before recive ackfor first action)
  6. protected int m_LastAcknowledgmentID;
  7. protected bool m_ActionPossible;
  8. protected ref array<ref InventoryLocation> m_ReservedInventoryLocations; // obsolete
  9. protected ref InventoryActionHandler m_InventoryActionHandler;
  10. protected ref InventoryLocation m_HandInventoryLocationTest;
  11. protected ref TTypeNameActionInputMap m_RegistredInputsMap;
  12. protected ref array<ActionInput> m_OrederedAllActionInput;
  13. protected ref array<ActionInput> m_OrderedStandartActionInputs;
  14. protected ref array<ActionInput> m_DefaultOrderOfActionInputs;
  15. protected int m_SelectedActionInputToSrollIndex;
  16. protected bool m_IgnoreAutoInputEnd;
  17. protected ref ActionData m_PendingActionData;
  18. protected bool m_ActionWantEndRequest_Send; //Request to server was sended
  19. protected bool m_ActionInputWantEnd_Send;
  20. void ActionManagerClient(PlayerBase player)
  21. {
  22. m_HandInventoryLocationTest = new InventoryLocation;
  23. m_HandInventoryLocationTest.SetHands(player,null);
  24. m_LastAcknowledgmentID = 1;
  25. m_Targets = new ActionTargets(player);
  26. //m_ReservedInventoryLocations = new array<ref InventoryLocation>;
  27. m_InventoryActionHandler = new InventoryActionHandler(player);
  28. m_ActionWantEndRequest_Send = false;
  29. m_ActionInputWantEnd_Send = false;
  30. RegisterInputs(player);
  31. m_SelectedActionInputToSrollIndex = 0;
  32. }
  33. //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)
  34. override void Update(int pCurrentCommandID)
  35. {
  36. m_InventoryActionHandler.OnUpdate();
  37. super.Update(pCurrentCommandID);
  38. int currentCommandID = m_Player.GetCurrentCommandID();
  39. m_ActionPossible = ActionPossibilityCheck(currentCommandID);
  40. if (m_PendingActionData) //SP only
  41. {
  42. m_CurrentActionData = m_PendingActionData;
  43. m_CurrentActionData.m_Action.Start(m_CurrentActionData);
  44. if (m_CurrentActionData.m_Action.IsInstant())
  45. OnActionEnd();
  46. m_PendingActionData = null;
  47. }
  48. if (m_CurrentActionData)
  49. {
  50. if (m_CurrentActionData.m_State != UA_AM_PENDING && m_CurrentActionData.m_State != UA_AM_REJECTED && m_CurrentActionData.m_State != UA_AM_ACCEPTED)
  51. m_CurrentActionData.m_Action.OnUpdateClient(m_CurrentActionData);
  52. switch (m_CurrentActionData.m_State)
  53. {
  54. case UA_AM_PENDING:
  55. break;
  56. case UA_AM_ACCEPTED:
  57. int condition_mask = ActionBase.ComputeConditionMask(m_Player, m_CurrentActionData.m_Target, m_CurrentActionData.m_MainItem);
  58. m_CurrentActionData.m_Action.ClearInventoryReservationEx(m_CurrentActionData);
  59. bool can_be_action_done = ((condition_mask & m_CurrentActionData.m_Action.m_ConditionMask) == condition_mask);
  60. // check currentCommandID before start or reject
  61. if (m_ActionPossible && can_be_action_done)
  62. {
  63. m_CurrentActionData.m_Action.InventoryReservation(m_CurrentActionData);
  64. m_CurrentActionData.m_State = UA_START;
  65. m_CurrentActionData.m_Action.Start(m_CurrentActionData);
  66. if (m_CurrentActionData.m_Action.IsInstant())
  67. OnActionEnd();
  68. }
  69. else
  70. {
  71. RequestInterruptAction();
  72. OnActionEnd();
  73. }
  74. m_PendingActionAcknowledgmentID = -1;
  75. break;
  76. case UA_AM_REJECTED:
  77. OnActionEnd();
  78. m_PendingActionAcknowledgmentID = -1;
  79. break;
  80. default:
  81. ProcessActionRequestEnd();
  82. ProcessActionInputEnd();
  83. break;
  84. }
  85. }
  86. #ifdef DEVELOPER
  87. if (DeveloperFreeCamera.IsFreeCameraEnabledNoPlayerMovement())
  88. {
  89. m_ActionPossible = false;
  90. ResetInputsActions();
  91. }
  92. else
  93. {
  94. #endif
  95. if (!m_CurrentActionData)
  96. {
  97. bool isMenuOpen = false;
  98. #ifndef NO_GUI
  99. isMenuOpen = GetGame().GetUIManager().IsMenuOpen(MENU_INVENTORY);
  100. #endif
  101. if (m_Player.IsRaised() || isMenuOpen)
  102. {
  103. m_Targets.Clear();
  104. }
  105. else
  106. {
  107. m_Targets.Update();
  108. }
  109. FindContextualUserActions(currentCommandID);
  110. }
  111. InputsUpdate();
  112. #ifdef DEVELOPER
  113. }
  114. #endif
  115. }
  116. void RegisterInputs(PlayerBase player)
  117. {
  118. if (!m_RegistredInputsMap)
  119. {
  120. m_RegistredInputsMap = new TTypeNameActionInputMap;
  121. for (int i = 0; i < m_ActionsArray.Count(); i++)
  122. {
  123. ActionBase action = m_ActionsArray.Get(i);
  124. typename input_type_name = action.GetInputType();
  125. ref ActionInput ai;
  126. ai = ActionInput.Cast(m_RegistredInputsMap.Get(input_type_name));
  127. if (!ai)
  128. {
  129. ai = ActionInput.Cast(input_type_name.Spawn());
  130. m_RegistredInputsMap.Insert(input_type_name, ai);
  131. }
  132. action.SetInput(ai);
  133. }
  134. for (int j = 0; j < m_RegistredInputsMap.Count(); j++)
  135. {
  136. m_RegistredInputsMap.GetElement(j).Init(player, this);
  137. }
  138. SetActioninputOrder();
  139. }
  140. }
  141. //Set order of inputs base of priority (output -> m_OrederedAllActionInput)
  142. void SetActioninputOrder()
  143. {
  144. int i, j;
  145. int priority;
  146. ActionInput input;
  147. m_OrederedAllActionInput = new array<ActionInput>;
  148. map<int, ref array<ActionInput>> temp_map_for_sort = new map<int, ref array<ActionInput>>;
  149. array<int> array_of_priorities_to_sort = new array<int>;
  150. ref array<ActionInput> same_priority_input_array;
  151. for (i = 0; i < m_RegistredInputsMap.Count(); i++)
  152. {
  153. input = m_RegistredInputsMap.GetElement(i);
  154. priority = input.GetPriority();
  155. same_priority_input_array = temp_map_for_sort.Get(priority);
  156. if (same_priority_input_array)
  157. {
  158. same_priority_input_array.Insert(input);
  159. continue;
  160. }
  161. same_priority_input_array = new array<ActionInput>;
  162. same_priority_input_array.Insert(input);
  163. temp_map_for_sort.Insert(priority,same_priority_input_array);
  164. array_of_priorities_to_sort.Insert(priority);
  165. }
  166. array_of_priorities_to_sort.Sort();
  167. for (i = 0; i < array_of_priorities_to_sort.Count(); i++)
  168. {
  169. priority = array_of_priorities_to_sort[i];
  170. same_priority_input_array = temp_map_for_sort.Get(priority);
  171. for (j = 0; j < same_priority_input_array.Count(); j++)
  172. {
  173. input = same_priority_input_array.Get(j);
  174. m_OrederedAllActionInput.Insert(input);
  175. }
  176. }
  177. SetDefaultInputsOrder();
  178. }
  179. //Order for user action inputs - will be dynamically change base on context (more complex handling viz set m_OrderedStandartActionInputs in UpdateActionCategoryPriority())
  180. void SetDefaultInputsOrder()
  181. {
  182. int i, j;
  183. m_DefaultOrderOfActionInputs = new array<ActionInput>;
  184. m_OrderedStandartActionInputs = new array<ActionInput>;
  185. ActionInput input = m_RegistredInputsMap.Get(ContinuousDefaultActionInput);
  186. if (input)
  187. {
  188. m_OrderedStandartActionInputs.Insert(input);
  189. }
  190. input = m_RegistredInputsMap.Get(DefaultActionInput);
  191. if (input)
  192. {
  193. m_OrderedStandartActionInputs.Insert(input);
  194. }
  195. input = m_RegistredInputsMap.Get(ContinuousInteractActionInput);
  196. if (input)
  197. {
  198. m_OrderedStandartActionInputs.Insert(input);
  199. }
  200. input = m_RegistredInputsMap.Get(InteractActionInput);
  201. if (input)
  202. {
  203. m_OrderedStandartActionInputs.Insert(input);
  204. }
  205. for (i = 0; i < m_OrederedAllActionInput.Count(); i++)
  206. {
  207. for (j = 0; j < m_OrderedStandartActionInputs.Count(); j++)
  208. {
  209. if (m_OrederedAllActionInput[i] == m_OrderedStandartActionInputs[j])
  210. {
  211. m_DefaultOrderOfActionInputs.Insert(m_OrederedAllActionInput[i]);
  212. break;
  213. }
  214. }
  215. }
  216. }
  217. static ActionVariantManager GetVariantManager(typename actionName)
  218. {
  219. ActionBase action = GetAction(actionName);
  220. if (action)
  221. {
  222. return action.GetVariantManager();
  223. }
  224. //VME ACTION not exist typo most likely
  225. return null;
  226. }
  227. override void RequestEndAction()
  228. {
  229. if (!m_ActionWantEndRequest_Send)
  230. {
  231. m_ActionWantEndRequest = true;
  232. }
  233. }
  234. override void EndActionInput()
  235. {
  236. if (!m_ActionInputWantEnd_Send)
  237. {
  238. m_ActionInputWantEnd = true;
  239. }
  240. }
  241. void InputsUpdate()
  242. {
  243. ActionInput ain;
  244. if (m_CurrentActionData)
  245. {
  246. if (!m_ActionInputWantEnd)
  247. {
  248. ActionInput ai = m_CurrentActionData.m_Action.GetInput();
  249. ai.Update();
  250. if (m_Player.IsQBControl())
  251. {
  252. if (ai.JustActivate())
  253. m_Player.SetActionEndInput(m_CurrentActionData.m_Action);
  254. }
  255. else
  256. {
  257. if (ai.WasEnded() && (ai.GetInputType() == ActionInputType.AIT_CONTINUOUS || ai.GetInputType() == ActionInputType.AIT_CLICKCONTINUOUS) && !m_IgnoreAutoInputEnd)
  258. {
  259. EndActionInput();
  260. }
  261. }
  262. }
  263. }
  264. else
  265. {
  266. if (m_ActionsAvaibale)
  267. {
  268. for (int i = 0; i < m_OrederedAllActionInput.Count();i++)
  269. {
  270. ain = m_OrederedAllActionInput[i];
  271. ain.Update();
  272. if (ain.JustActivate())
  273. {
  274. ActionBase action = ain.GetAction();
  275. if (action)
  276. {
  277. ActionStart(action, ain.GetUsedActionTarget(), ain.GetUsedMainItem());
  278. break;
  279. }
  280. }
  281. }
  282. }
  283. }
  284. }
  285. void ProcessActionRequestEnd()
  286. {
  287. if (m_ActionWantEndRequest)
  288. {
  289. if (GetGame().IsMultiplayer() && !m_CurrentActionData.m_Action.IsLocal())
  290. {
  291. if (!m_ActionWantEndRequest_Send && ScriptInputUserData.CanStoreInputUserData())
  292. {
  293. if (LogManager.IsActionLogEnable())
  294. {
  295. Debug.ActionLog("Time stamp: " + m_Player.GetSimulationTimeStamp(), m_CurrentActionData.m_Action.ToString() , "n/a", "EndRequest", m_CurrentActionData.m_Player.ToString());
  296. }
  297. ScriptInputUserData ctx = new ScriptInputUserData;
  298. ctx.Write(INPUT_UDT_STANDARD_ACTION_END_REQUEST);
  299. ctx.Send();
  300. m_ActionWantEndRequest_Send = true;
  301. m_ActionWantEndRequest = false;
  302. m_CurrentActionData.m_Action.EndRequest(m_CurrentActionData);
  303. }
  304. }
  305. else
  306. {
  307. m_ActionWantEndRequest = false;
  308. m_CurrentActionData.m_Action.EndRequest(m_CurrentActionData);
  309. }
  310. }
  311. }
  312. void ProcessActionInputEnd()
  313. {
  314. if (m_ActionInputWantEnd)
  315. {
  316. if (GetGame().IsMultiplayer() && !m_CurrentActionData.m_Action.IsLocal())
  317. {
  318. if (!m_ActionInputWantEnd_Send && ScriptInputUserData.CanStoreInputUserData())
  319. {
  320. if (LogManager.IsActionLogEnable())
  321. {
  322. Debug.ActionLog("Time stamp: " + m_Player.GetSimulationTimeStamp(), m_CurrentActionData.m_Action.ToString() , "n/a", "EndInput", m_CurrentActionData.m_Player.ToString());
  323. }
  324. ScriptInputUserData ctxi = new ScriptInputUserData;
  325. ctxi.Write(INPUT_UDT_STANDARD_ACTION_INPUT_END);
  326. ctxi.Send();
  327. m_ActionInputWantEnd_Send = true;
  328. m_ActionInputWantEnd = false;
  329. m_CurrentActionData.m_Action.EndInput(m_CurrentActionData);
  330. }
  331. }
  332. else
  333. {
  334. if (!m_ActionInputWantEnd_Send)
  335. {
  336. m_ActionInputWantEnd_Send = true;
  337. m_ActionInputWantEnd = false;
  338. m_CurrentActionData.m_Action.EndInput(m_CurrentActionData);
  339. }
  340. }
  341. }
  342. }
  343. ActionBase GetPossibleAction(typename inputType)
  344. {
  345. ActionInput action_input = m_RegistredInputsMap.Get(inputType);
  346. if (action_input)
  347. {
  348. return action_input.GetAction();
  349. }
  350. return NULL;
  351. }
  352. array<ActionBase> GetPossibleActions(typename inputType)
  353. {
  354. ActionInput action_input = m_RegistredInputsMap.Get(inputType);
  355. if (action_input)
  356. {
  357. return action_input.GetPossibleActions();
  358. }
  359. return NULL;
  360. }
  361. int GetPossibleActionIndex(typename inputType)
  362. {
  363. ActionInput action_input = m_RegistredInputsMap.Get(inputType);
  364. if (action_input)
  365. {
  366. return action_input.GetPossibleActionIndex();
  367. }
  368. return -1;
  369. }
  370. int GetPossibleActionCount(typename inputType)
  371. {
  372. ActionInput action_input = m_RegistredInputsMap.Get(inputType);
  373. if (action_input)
  374. {
  375. return action_input.GetPossibleActionsCount();
  376. }
  377. return 0;
  378. }
  379. //--------------------------------------------------------
  380. // Alows to set different action to current contextual one
  381. //--------------------------------------------------------
  382. void InjectAction(ActionBase action, ActionTarget target, ItemBase item)
  383. {
  384. ActionInput ai = action.GetInput();
  385. ai.ForceAction(action, target, item);
  386. }
  387. void InjectAction(typename actionType, ActionTarget target, ItemBase item)
  388. {
  389. ActionBase action = GetAction(actionType);
  390. InjectAction(action, target, item);
  391. }
  392. void EjectAction(ActionBase action)
  393. {
  394. ActionInput ai = action.GetInput();
  395. ai.ClearForcedAction();
  396. }
  397. void EjectAction(typename actionType)
  398. {
  399. ActionBase action = GetAction(actionType);
  400. EjectAction(action);
  401. }
  402. void ForceTarget(Object targetObject)
  403. {
  404. Object parent = null;
  405. EntityAI targetEntity = EntityAI.Cast(targetObject);
  406. if (targetEntity)
  407. parent = targetEntity.GetHierarchyParent();
  408. m_ForceTarget = new ActionTarget(targetObject, parent, -1, vector.Zero, -1);
  409. }
  410. void ClearForceTarget()
  411. {
  412. m_ForceTarget = NULL;
  413. }
  414. //-------------------------------------------------------------------------
  415. override ActionTarget FindActionTarget()
  416. {
  417. if (m_ForceTarget)
  418. return m_ForceTarget;
  419. ActionTarget action_target;
  420. action_target = NULL;
  421. int targetsCount = m_Targets.GetTargetsCount();
  422. if (targetsCount)
  423. {
  424. for (int i = 0; i < targetsCount; ++i)
  425. {
  426. action_target = m_Targets.GetTarget(i);
  427. Object targetObject = action_target.GetObject();
  428. Object targetParent = action_target.GetParent();
  429. int surfaceLiquidType = action_target.GetSurfaceLiquidType();
  430. if (targetParent)
  431. {
  432. break;
  433. }
  434. if (targetObject)
  435. {
  436. break;
  437. }
  438. if (surfaceLiquidType != LIQUID_NONE)
  439. {
  440. break;
  441. }
  442. }
  443. }
  444. else
  445. {
  446. action_target = new ActionTarget(null, null, -1, vector.Zero, -1);
  447. }
  448. return action_target;
  449. }
  450. ItemBase FindActionItem()
  451. {
  452. ItemBase item;
  453. if (m_Player && m_Player.GetItemInHands() && m_Player.GetItemInHands().IsItemBase())
  454. {
  455. item = m_Player.GetItemInHands();
  456. }
  457. return item;
  458. }
  459. protected bool HasHandInventoryReservation()
  460. {
  461. m_HandInventoryLocationTest.SetHands(m_Player,m_Player.GetItemInHands());
  462. if (m_Player.GetHumanInventory().HasInventoryReservation(m_Player.GetItemInHands(),m_HandInventoryLocationTest))
  463. return true;
  464. return false;
  465. }
  466. protected void FindContextualUserActions(int pCurrentCommandID)
  467. {
  468. // TODO: NEEDS OPTIMIZATION (focus on UpdatePossibleActions > CraftingManager::OnUpdate)
  469. m_ActionsAvaibale = false;
  470. if (!m_ActionPossible || HasHandInventoryReservation() || GetGame().IsInventoryOpen())
  471. {
  472. ResetInputsActions();
  473. return;
  474. }
  475. if (!GetRunningAction())
  476. {
  477. ActionBase action;
  478. ActionTarget target;
  479. ItemBase item;
  480. // Gathering current inputs
  481. m_ActionsAvaibale = true;
  482. item = FindActionItem();
  483. target = FindActionTarget();
  484. int actionConditionMask = ActionBase.ComputeConditionMask(m_Player,target,item);
  485. for (int i = 0; i < m_OrederedAllActionInput.Count();i++)
  486. {
  487. ActionInput ain = m_OrederedAllActionInput[i];
  488. ain.UpdatePossibleActions(m_Player,target,item, actionConditionMask);
  489. }
  490. UpdateActionCategoryPriority();
  491. SetActionContext(target,item);
  492. }
  493. }
  494. //TOOD MW In progress
  495. protected bool LockInventory(ActionData action_data)
  496. {
  497. bool success = false;
  498. if (action_data.m_Action.IsInstant())
  499. {
  500. if (LogManager.IsActionLogEnable())
  501. {
  502. Debug.ActionLog("(-) Inventory lock - Not Used", action_data.m_Action.ToString() , "n/a", "LockInventory", action_data.m_Player.ToString());
  503. }
  504. success = true;
  505. }
  506. else
  507. {
  508. if (LogManager.IsActionLogEnable())
  509. {
  510. Debug.ActionLog("(X) Inventory lock", action_data.m_Action.ToString() , "n/a", "LockInventory", action_data.m_Player.ToString());
  511. }
  512. if (action_data.m_Action)
  513. {
  514. success = action_data.m_Action.InventoryReservation(action_data);
  515. }
  516. }
  517. return success;
  518. }
  519. void UnlockInventory(ActionData action_data)
  520. {
  521. if (LogManager.IsActionLogEnable())
  522. {
  523. Debug.ActionLog("(O) Inventory unlock", action_data.m_Action.ToString() , "n/a", "UnlockInventory", action_data.m_Player.ToString());
  524. }
  525. if (action_data.m_Action)
  526. action_data.m_Action.ClearInventoryReservationEx(action_data);
  527. }
  528. protected void ActionStart(ActionBase action, ActionTarget target, ItemBase item, Param extra_data = NULL)
  529. {
  530. if (!m_CurrentActionData && action && ActionPossibilityCheck(m_Player.GetCurrentCommandID()))
  531. {
  532. m_ActionWantEndRequest_Send = false;
  533. m_ActionInputWantEnd_Send = false;
  534. m_ActionWantEndRequest = false;
  535. m_ActionInputWantEnd = false;
  536. if (action.CanBePerformedFromQuickbar())
  537. m_Player.SetActionEndInput(action);
  538. HandleInputsOnActionStart(action);
  539. if (LogManager.IsActionLogEnable())
  540. {
  541. if ( target )
  542. {
  543. Debug.ActionLog("Item = " + item + ", " + target.DumpToString(), action.ToString() , "n/a", "ActionStart", m_Player.ToString());
  544. }
  545. else
  546. {
  547. Debug.ActionLog("Item = " + item + ", no target", action.ToString() , "n/a", "ActionStart", m_Player.ToString());
  548. }
  549. }
  550. m_Interrupted = false;
  551. if (GetGame().IsMultiplayer() && !action.IsLocal())
  552. {
  553. if (!ScriptInputUserData.CanStoreInputUserData())
  554. {
  555. DPrint("ScriptInputUserData already posted - ActionManagerClient");
  556. if (LogManager.IsActionLogEnable())
  557. {
  558. Debug.ActionLog("Cannot start because ScriptInputUserData is already used", action.ToString() , "n/a", "ActionStart", m_Player.ToString());
  559. }
  560. return;
  561. }
  562. }
  563. if (!action.SetupAction(m_Player, target, item, m_CurrentActionData, extra_data))
  564. {
  565. DPrint("Can not inicialize action" + action + " - ActionManagerClient");
  566. m_CurrentActionData = NULL;
  567. return;
  568. }
  569. if (LogManager.IsActionLogEnable())
  570. {
  571. Debug.ActionLog("Action data created wait to start", action.ToString() , "n/a", "ActionStart", m_Player.ToString());
  572. }
  573. if (GetGame().IsMultiplayer() && !action.IsLocal())
  574. {
  575. ScriptInputUserData ctx = new ScriptInputUserData;
  576. ctx.Write(INPUT_UDT_STANDARD_ACTION_START);
  577. ctx.Write(action.GetID());
  578. action.WriteToContext(ctx, m_CurrentActionData);
  579. if (action.UseAcknowledgment())
  580. {
  581. m_CurrentActionData.m_State = UA_AM_PENDING;
  582. m_PendingActionAcknowledgmentID = ++m_LastAcknowledgmentID;
  583. ctx.Write(m_PendingActionAcknowledgmentID);
  584. }
  585. ctx.Send();
  586. if (!action.UseAcknowledgment())
  587. {
  588. action.Start(m_CurrentActionData);
  589. if (action.IsInstant())
  590. OnActionEnd();
  591. }
  592. }
  593. else
  594. {
  595. action.Start(m_CurrentActionData);
  596. if (action.IsInstant())
  597. OnActionEnd();
  598. }
  599. }
  600. }
  601. void HandleInputsOnActionStart(ActionBase action)
  602. {
  603. for (int i = 0; i < m_OrederedAllActionInput.Count();i++)
  604. {
  605. ActionInput ain = m_OrederedAllActionInput[i];
  606. if (action.GetInput() == ain)
  607. {
  608. ain.OnActionStart();
  609. }
  610. else
  611. {
  612. ain.Reset();
  613. }
  614. }
  615. }
  616. void HandleInputsOnActionEnd()
  617. {
  618. ResetInputsState();
  619. }
  620. void ResetInputsState()
  621. {
  622. for (int i = 0; i < m_OrederedAllActionInput.Count();i++)
  623. {
  624. ActionInput ain = m_OrederedAllActionInput[i];
  625. ain.Reset();
  626. }
  627. }
  628. void ResetInputsActions()
  629. {
  630. for (int i = 0; i < m_OrederedAllActionInput.Count();i++)
  631. {
  632. ActionInput ain = m_OrederedAllActionInput[i];
  633. ain.ActionsSelectReset();
  634. }
  635. }
  636. override void OnJumpStart()
  637. {
  638. EndOrInterruptCurrentAction();
  639. }
  640. override void EndOrInterruptCurrentAction()
  641. {
  642. if (m_CurrentActionData)
  643. {
  644. if (m_CurrentActionData.m_State == UA_AM_PENDING || m_CurrentActionData.m_State == UA_AM_REJECTED || m_CurrentActionData.m_State == UA_AM_ACCEPTED)
  645. {
  646. OnActionEnd();
  647. m_PendingActionAcknowledgmentID = -1;
  648. }
  649. else
  650. {
  651. m_CurrentActionData.m_Action.Interrupt(m_CurrentActionData);
  652. }
  653. }
  654. }
  655. //Instant Action (Debug Actions) ---------------------------------
  656. override void OnInstantAction(typename user_action_type, Param data = NULL)
  657. {
  658. ActionBase action = GetAction(user_action_type);
  659. if (action)
  660. {
  661. ActionStart(action,NULL,NULL, data);
  662. }
  663. }
  664. #ifdef BOT
  665. /// used for bots
  666. void PerformAction(int user_action_id, ActionTarget target, ItemBase item, Param extraData = NULL)
  667. {
  668. ActionStart(GetAction(user_action_id), target, item, extraData);
  669. }
  670. #endif
  671. void PerformActionStart(ActionBase action, ActionTarget target, ItemBase item, Param extra_data = NULL)
  672. {
  673. if (!GetGame().IsMultiplayer())
  674. {
  675. m_PendingActionData = new ActionData;
  676. if (!action.SetupAction(m_Player,target,item,m_PendingActionData,extra_data))
  677. m_PendingActionData = null;
  678. }
  679. else
  680. ActionStart(action, target, item, extra_data);
  681. }
  682. override void OnActionEnd()
  683. {
  684. if (m_CurrentActionData)
  685. {
  686. UnlockInventory(m_CurrentActionData);
  687. if (m_CurrentActionData.m_Action.RemoveForceTargetAfterUse())
  688. m_InventoryActionHandler.DeactiveAction();
  689. super.OnActionEnd();
  690. HandleInputsOnActionEnd();
  691. }
  692. }
  693. void SetInventoryAction(ActionBase action_name, ItemBase target_item, ItemBase main_item)
  694. {
  695. m_InventoryActionHandler.SetAction(action_name, target_item, main_item);
  696. }
  697. void SetInventoryAction(ActionBase action_name, ActionTarget target, ItemBase main_item)
  698. {
  699. m_InventoryActionHandler.SetAction(action_name, target, main_item);
  700. }
  701. void UnsetInventoryAction()
  702. {
  703. m_InventoryActionHandler.DeactiveAction();
  704. }
  705. override typename GetSelectedActionCategory()
  706. {
  707. return m_OrderedStandartActionInputs[m_SelectedActionInputToSrollIndex].Type();
  708. }
  709. void UpdateActionCategoryPriority()
  710. {
  711. int i;
  712. int last_target_index = 0;
  713. for (i = 0; i < m_DefaultOrderOfActionInputs.Count(); i++)
  714. {
  715. if (m_DefaultOrderOfActionInputs[i].HasTarget())
  716. {
  717. m_OrderedStandartActionInputs[last_target_index] = m_DefaultOrderOfActionInputs[i];
  718. last_target_index++;
  719. }
  720. }
  721. for (i = 0; i < m_DefaultOrderOfActionInputs.Count(); i++)
  722. {
  723. if (!m_DefaultOrderOfActionInputs[i].HasTarget())
  724. {
  725. m_OrderedStandartActionInputs[last_target_index] = m_DefaultOrderOfActionInputs[i];
  726. last_target_index++;
  727. }
  728. }
  729. }
  730. override void SelectFirstActionCategory()
  731. {
  732. UpdateActionCategoryPriority();
  733. m_SelectedActionInputToSrollIndex = 0;
  734. for (int index = 0; index < m_OrderedStandartActionInputs.Count(); index++)
  735. {
  736. if (m_OrderedStandartActionInputs[index].GetPossibleActionsCount() > 1)
  737. {
  738. m_SelectedActionInputToSrollIndex = index;
  739. break;
  740. }
  741. }
  742. }
  743. override void SelectNextActionCategory()
  744. {
  745. int index;
  746. for (index = m_SelectedActionInputToSrollIndex + 1; index != m_SelectedActionInputToSrollIndex;;)
  747. {
  748. if (++index >= m_OrderedStandartActionInputs.Count())
  749. {
  750. index = 0;
  751. }
  752. if (m_OrderedStandartActionInputs[index].GetPossibleActionsCount() > 1)
  753. {
  754. m_SelectedActionInputToSrollIndex = index;
  755. break;
  756. }
  757. }
  758. }
  759. override void SelectPrevActionCategory()
  760. {
  761. int index;
  762. for (index = m_SelectedActionInputToSrollIndex; index != m_SelectedActionInputToSrollIndex;;)
  763. {
  764. if (--index < 0)
  765. {
  766. index = m_OrderedStandartActionInputs.Count() - 1;
  767. }
  768. if (m_OrderedStandartActionInputs[index].GetPossibleActionsCount() > 1)
  769. {
  770. m_SelectedActionInputToSrollIndex = index;
  771. break;
  772. }
  773. }
  774. }
  775. override void SelectNextAction()
  776. {
  777. ActionInput ai;
  778. if (m_SelectedActionInputToSrollIndex < m_OrderedStandartActionInputs.Count())
  779. {
  780. ai = m_OrderedStandartActionInputs[m_SelectedActionInputToSrollIndex];
  781. if (ai && ai.GetPossibleActionsCount() > 1)
  782. {
  783. ai.SelectNextAction();
  784. }
  785. }
  786. }
  787. override void SelectPrevAction()
  788. {
  789. ActionInput ai;
  790. if (m_SelectedActionInputToSrollIndex < m_OrderedStandartActionInputs.Count())
  791. {
  792. ai = m_OrderedStandartActionInputs[m_SelectedActionInputToSrollIndex];
  793. if (ai && ai.GetPossibleActionsCount() > 1)
  794. {
  795. ai.SelectPrevAction();
  796. }
  797. }
  798. }
  799. bool CanPerformActionFromQuickbar(ItemBase mainItem, ItemBase targetItem)
  800. {
  801. ItemBase itemInHand = m_Player.GetItemInHands();
  802. ActionTarget target;
  803. target = new ActionTarget(targetItem, null, -1, vector.Zero, -1);
  804. bool hasTarget = targetItem != NULL;
  805. if (mainItem)
  806. {
  807. array<ActionBase_Basic> actions;
  808. ActionBase picked_action;
  809. int i;
  810. mainItem.GetActions(QuickaBarActionInput, actions);
  811. if (actions)
  812. {
  813. for (i = 0; i < actions.Count(); i++)
  814. {
  815. picked_action = ActionBase.Cast(actions[i]);
  816. if (picked_action && picked_action.Can(m_Player,target, itemInHand))
  817. {
  818. if (hasTarget == picked_action.HasTarget())
  819. return true;
  820. }
  821. }
  822. }
  823. //First check continuous actions
  824. mainItem.GetActions(ContinuousDefaultActionInput, actions);
  825. if (actions)
  826. {
  827. for (i = 0; i < actions.Count(); i++)
  828. {
  829. picked_action = ActionBase.Cast(actions[i]);
  830. if (picked_action && picked_action.Can(m_Player,target, itemInHand) && picked_action.CanBePerformedFromQuickbar())
  831. {
  832. if (hasTarget == picked_action.HasTarget())
  833. return true;
  834. }
  835. }
  836. }
  837. //second single use actions
  838. mainItem.GetActions(DefaultActionInput, actions);
  839. if (actions)
  840. {
  841. for (i = 0; i < actions.Count(); i++)
  842. {
  843. picked_action = ActionBase.Cast(actions[i]);
  844. if (picked_action && picked_action.HasTarget() && picked_action.Can(m_Player,target, itemInHand) && picked_action.CanBePerformedFromQuickbar())
  845. {
  846. if (hasTarget == picked_action.HasTarget())
  847. return true;
  848. }
  849. }
  850. }
  851. }
  852. return false;
  853. }
  854. void PerformActionFromQuickbar(ItemBase mainItem, ItemBase targetItem)
  855. {
  856. ItemBase itemInHand = m_Player.GetItemInHands();
  857. ActionTarget target;
  858. ItemBase parent = null;
  859. if (targetItem)
  860. parent = ItemBase.Cast(targetItem.GetHierarchyParent());
  861. target = new ActionTarget(targetItem, parent, -1, vector.Zero, -1);
  862. bool hasTarget = targetItem != NULL;
  863. if (mainItem)
  864. {
  865. ActionBase picked_action;
  866. array<ActionBase_Basic> actions;
  867. int i;
  868. mainItem.GetActions(QuickaBarActionInput, actions);
  869. if (actions)
  870. {
  871. for (i = 0; i < actions.Count(); i++)
  872. {
  873. picked_action = ActionBase.Cast(actions[i]);
  874. if (picked_action && picked_action.HasTarget() && picked_action.Can(m_Player,target, itemInHand))
  875. {
  876. if (hasTarget == picked_action.HasTarget())
  877. {
  878. ActionStart(picked_action, target, mainItem);
  879. return;
  880. }
  881. }
  882. }
  883. }
  884. //First continuous actions
  885. mainItem.GetActions(ContinuousDefaultActionInput, actions);
  886. if (actions)
  887. {
  888. for (i = 0; i < actions.Count(); i++)
  889. {
  890. picked_action = ActionBase.Cast(actions[i]);
  891. if (picked_action && picked_action.HasTarget() && picked_action.Can(m_Player,target, itemInHand) && picked_action.CanBePerformedFromQuickbar())
  892. {
  893. if (hasTarget == picked_action.HasTarget())
  894. {
  895. ActionStart(picked_action, target, mainItem);
  896. return;
  897. }
  898. }
  899. }
  900. }
  901. //Second check single use actions
  902. mainItem.GetActions(DefaultActionInput, actions);
  903. if (actions)
  904. {
  905. for (i = 0; i < actions.Count(); i++)
  906. {
  907. picked_action = ActionBase.Cast(actions[i]);
  908. if (picked_action && picked_action.Can(m_Player,target, itemInHand) && picked_action.CanBePerformedFromQuickbar())
  909. {
  910. if (hasTarget == picked_action.HasTarget())
  911. {
  912. ActionStart(picked_action, target, mainItem);
  913. return;
  914. }
  915. }
  916. }
  917. }
  918. }
  919. }
  920. //TODO Variants support ???
  921. bool CanPerformActionFromInventory(ItemBase mainItem, ItemBase targetItem)
  922. {
  923. ItemBase itemInHand = m_Player.GetItemInHands();
  924. ActionTarget target;
  925. target = new ActionTarget(targetItem, null, -1, vector.Zero, -1);
  926. bool hasTarget = targetItem != NULL;
  927. if (mainItem)
  928. {
  929. array<ActionBase_Basic> actions;
  930. ActionBase picked_action;
  931. int i;
  932. //First check single use actions
  933. mainItem.GetActions(DefaultActionInput, actions);
  934. if (actions)
  935. {
  936. for (i = 0; i < actions.Count(); i++)
  937. {
  938. picked_action = ActionBase.Cast(actions[i]);
  939. if (picked_action && picked_action.Can(m_Player,target, itemInHand) && picked_action.CanBePerformedFromInventory())
  940. {
  941. if (hasTarget == picked_action.HasTarget())
  942. return true;
  943. }
  944. }
  945. }
  946. //Inventory specific actions
  947. mainItem.GetActions(InventoryOnlyActionInput, actions);
  948. if (actions)
  949. {
  950. for (i = 0; i < actions.Count(); i++)
  951. {
  952. picked_action = ActionBase.Cast(actions[i]);
  953. if (picked_action && picked_action.Can(m_Player,target, itemInHand))
  954. {
  955. if (hasTarget == picked_action.HasTarget())
  956. return true;
  957. }
  958. }
  959. }
  960. }
  961. return false;
  962. }
  963. //TODO Variants support ???
  964. void PerformActionFromInventory(ItemBase mainItem, ItemBase targetItem)
  965. {
  966. ItemBase itemInHand = m_Player.GetItemInHands();
  967. ActionTarget target;
  968. target = new ActionTarget(targetItem, null, -1, vector.Zero, -1);
  969. bool hasTarget = targetItem != NULL;
  970. if (mainItem)
  971. {
  972. ActionBase picked_action;
  973. array<ActionBase_Basic> actions;
  974. int i;
  975. //First check single use actions
  976. mainItem.GetActions(DefaultActionInput, actions);
  977. if (actions)
  978. {
  979. for (i = 0; i < actions.Count(); i++)
  980. {
  981. picked_action = ActionBase.Cast(actions[i]);
  982. if (picked_action && picked_action.Can(m_Player,target, itemInHand) && picked_action.CanBePerformedFromInventory())
  983. {
  984. if (hasTarget == picked_action.HasTarget())
  985. {
  986. ActionStart(picked_action, target, mainItem);
  987. return;
  988. }
  989. }
  990. }
  991. }
  992. //Inventory specific actions
  993. mainItem.GetActions(InventoryOnlyActionInput, actions);
  994. if (actions)
  995. {
  996. for (i = 0; i < actions.Count(); i++)
  997. {
  998. picked_action = ActionBase.Cast(actions[i]);
  999. if (picked_action && picked_action.Can(m_Player,target, itemInHand))
  1000. {
  1001. if (hasTarget == picked_action.HasTarget())
  1002. {
  1003. ActionStart(picked_action, target, mainItem);
  1004. return;
  1005. }
  1006. }
  1007. }
  1008. }
  1009. }
  1010. }
  1011. bool CanSetActionFromInventory(ItemBase mainItem, ItemBase targetItem)
  1012. {
  1013. ItemBase itemInHand = m_Player.GetItemInHands();
  1014. ActionTarget target;
  1015. EntityAI parent = null;
  1016. if (targetItem)
  1017. {
  1018. parent = targetItem.GetHierarchyParent();
  1019. }
  1020. target = new ActionTarget(targetItem, parent, -1, vector.Zero, -1);
  1021. bool hasTarget = targetItem != NULL;
  1022. if (mainItem)
  1023. {
  1024. array<ActionBase_Basic> actions;
  1025. array<ref ActionBase> variant_actions;
  1026. ActionBase picked_action;
  1027. int variants_count,v;
  1028. //First check single use actions
  1029. mainItem.GetActions(DefaultActionInput, actions);
  1030. if (actions)
  1031. {
  1032. for (int i = 0; i < actions.Count(); i++)
  1033. {
  1034. picked_action = ActionBase.Cast(actions[i]);
  1035. if (picked_action.HasVariants())
  1036. {
  1037. picked_action.UpdateVariants(itemInHand, targetItem, -1);
  1038. picked_action.GetVariants(variant_actions);
  1039. for (v = 0; v < variant_actions.Count(); v ++)
  1040. {
  1041. picked_action = variant_actions[v];
  1042. if (picked_action && picked_action.CanBeSetFromInventory() && picked_action.Can(m_Player,target, itemInHand))
  1043. {
  1044. if (hasTarget == picked_action.HasTarget())
  1045. return true;
  1046. }
  1047. }
  1048. }
  1049. else
  1050. {
  1051. if (picked_action && picked_action.CanBeSetFromInventory() && picked_action.Can(m_Player,target, itemInHand))
  1052. {
  1053. if (hasTarget == picked_action.HasTarget())
  1054. return true;
  1055. }
  1056. }
  1057. }
  1058. }
  1059. //second continuous actions
  1060. mainItem.GetActions(ContinuousDefaultActionInput, actions);
  1061. if (actions)
  1062. {
  1063. for (int j = 0; j < actions.Count(); j++)
  1064. {
  1065. picked_action = ActionBase.Cast(actions[j]);
  1066. if (picked_action.HasVariants())
  1067. {
  1068. picked_action.UpdateVariants(itemInHand, targetItem, -1);
  1069. picked_action.GetVariants(variant_actions);
  1070. for (v = 0; v < variant_actions.Count(); v ++)
  1071. {
  1072. picked_action = variant_actions[v];
  1073. if (picked_action && picked_action.HasTarget() && picked_action.CanBeSetFromInventory() && picked_action.Can(m_Player,target, itemInHand))
  1074. {
  1075. if (hasTarget == picked_action.HasTarget())
  1076. return true;
  1077. }
  1078. }
  1079. }
  1080. else
  1081. {
  1082. if (picked_action && picked_action.HasTarget() && picked_action.CanBeSetFromInventory() && picked_action.Can(m_Player,target, itemInHand))
  1083. {
  1084. if (hasTarget == picked_action.HasTarget())
  1085. return true;
  1086. }
  1087. }
  1088. }
  1089. }
  1090. }
  1091. return false;
  1092. }
  1093. //TODO fix for variants
  1094. void SetActionFromInventory(ItemBase mainItem, ItemBase targetItem)
  1095. {
  1096. ItemBase itemInHand = m_Player.GetItemInHands();
  1097. ActionTarget target;
  1098. target = new ActionTarget(targetItem, null, -1, vector.Zero, -1);
  1099. bool hasTarget = targetItem != NULL;
  1100. if (mainItem)
  1101. {
  1102. array<ActionBase_Basic> actions;
  1103. ActionBase picked_action;
  1104. //First check single use actions
  1105. mainItem.GetActions(DefaultActionInput, actions);
  1106. if (actions)
  1107. {
  1108. for (int i = 0; i < actions.Count(); i++)
  1109. {
  1110. picked_action = ActionBase.Cast(actions[i]);
  1111. if (picked_action && picked_action.Can(m_Player,target, itemInHand) && picked_action.CanBeSetFromInventory())
  1112. {
  1113. if (hasTarget == picked_action.HasTarget())
  1114. {
  1115. SetInventoryAction(picked_action, target, itemInHand);
  1116. return;
  1117. }
  1118. }
  1119. }
  1120. }
  1121. //second continuous actions
  1122. mainItem.GetActions(ContinuousDefaultActionInput, actions);
  1123. if (actions)
  1124. {
  1125. for (int j = 0; j < actions.Count(); j++)
  1126. {
  1127. picked_action = ActionBase.Cast(actions[j]);
  1128. if (picked_action && picked_action.HasTarget() && picked_action.Can(m_Player,target, itemInHand) && picked_action.CanBeSetFromInventory())
  1129. {
  1130. if (hasTarget == picked_action.HasTarget())
  1131. {
  1132. SetInventoryAction(picked_action, target, itemInHand);
  1133. return;
  1134. }
  1135. }
  1136. }
  1137. }
  1138. }
  1139. }
  1140. // disables automatic end of continuous action when input ended
  1141. void SetIgnoreAutomaticInputEnd(bool state)
  1142. {
  1143. m_IgnoreAutoInputEnd = state;
  1144. }
  1145. //! client requests action interrupt
  1146. override void RequestInterruptAction()
  1147. {
  1148. if (ScriptInputUserData.CanStoreInputUserData())
  1149. {
  1150. ScriptInputUserData ctx = new ScriptInputUserData;
  1151. ctx.Write(INPUT_UDT_STANDARD_ACTION_END_REQUEST);
  1152. ctx.Write(DayZPlayerConstants.CMD_ACTIONINT_INTERRUPT);
  1153. ctx.Send();
  1154. }
  1155. }
  1156. private ref ActionTarget m_ForceTarget;
  1157. private ref ActionTargets m_Targets;
  1158. };