actionmanagerclient.c 33 KB

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