Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
inventoryactionhandler.c
Go to the documentation of this file.
3 {
4  ActionBase m_action;
5  ActionTarget m_target;
6  ItemBase m_mainItem;
7  bool m_useItemInHands;
8 
9  PlayerBase m_player;
10 
11  bool m_isActive;
12  vector m_actionStartPos;
13 
14  const float MIN_DISTANCE_TO_INTERRUPT = 1.0;
15  const int IAH_SINGLE_USE = 1;
16  const int IAH_CONTINUOUS = 2;
17 
18 
20  {
21  m_player = player;
22  m_isActive = false;
23  m_action = null;
24  m_target = null;
25  m_mainItem = null;
26  m_useItemInHands = false;
27 
28  }
29 
30  void SetAction(ActionBase action, ItemBase target_item, ItemBase main_item )
31  {
32  Object target_parent = null;
33  if(target_item)
34  {
35  target_parent = target_item.GetHierarchyParent();
36  }
37  ActionTarget at = new ActionTarget(target_item, target_parent, -1, vector.Zero, -1);
38 
39  SetAction(action, at, main_item );
40  }
41 
42  void SetAction(ActionBase action, ActionTarget target, ItemBase main_item )
43  {
45  Class.CastTo(mngr, m_player.GetActionManager());
46 
47  m_action = action;
48  m_target = target;
49  m_mainItem = main_item;
50 
51  ItemBase itemInHand = m_player.GetItemInHands();
52  m_useItemInHands = main_item == itemInHand;
53 
54  m_actionStartPos = m_player.GetPosition();
55  m_isActive = true;
56 
57  //mngr.InjectAction( action, target, main_item );
58  mngr.ForceTarget(m_target.GetObject());
59 
60  GetGame().GetMission().HideInventory();
61  }
62 
63  bool IsActiveAction()
64  {
65  return m_isActive;
66  }
67 
68  void OnUpdate()
69  {
70 
71  if( !m_isActive ) return;
72 
73  if( m_player.IsRaised() || m_player.GetCommand_Melee() )
74  {
75  DeactiveAction();
76  return;
77  }
78 
79  if( GetGame().IsInventoryOpen() )
80  {
81  DeactiveAction();
82  return;
83  }
84 
85  if (m_useItemInHands)
86  {
87  ItemBase handItem = m_player.GetItemInHands();
88 
89  if( handItem != m_mainItem )
90  {
91  DeactiveAction();
92  return;
93  }
94  }
95 
96  if( Math.AbsFloat( vector.Distance(m_actionStartPos, m_player.GetPosition())) > MIN_DISTANCE_TO_INTERRUPT )
97  {
98  DeactiveAction();
99  return;
100  }
101 
102 
103  }
104 
105  void DeactiveAction()
106  {
107  if( !m_isActive ) return;
108 
109  m_isActive = false;
110 
111  ActionManagerClient mngr;
112  Class.CastTo(mngr, m_player.GetActionManager());
113 
114  mngr.EjectAction(m_action);
115  mngr.ClearForceTarget();
116 
117  m_player.GetCraftingManager().ResetInventoryCraft();
118 
119  m_action = null;
120  m_target = null;
121  m_mainItem = null;
122  m_useItemInHands = false;
123  }
124 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
m_player
DayZPlayer m_player
Definition: randomgeneratorsyncmanager.c:15
m_action
class WeaponEndAction extends WeaponStartAction m_action
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
ActionTarget
class ActionTargets ActionTarget
Object
Definition: objecttyped.c:1
ActionManagerClient
Definition: actionmanagerclient.c:4
ActionBase
void ActionBase()
Definition: actionbase.c:73
InventoryActionHandler
Client only - manage set up crafting on client.
Definition: inventoryactionhandler.c:2
Math
Definition: enmath.c:6
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10