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