Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
dayzplayerimplementthrowing.c
Go to the documentation of this file.
2 {
4  {
5  m_Player = pPlayer;
6  SetThrowingModeEnabled(false);
7 
8  ResetState();
9  }
10 
11  void HandleThrowing(HumanInputController pHic, HumanCommandWeapons pHcw, EntityAI pEntityInHands, float pDt)
12  {
13  if ( !pEntityInHands && !m_bThrowingAnimationPlaying )
14  {
15  if ( m_bThrowingModeEnabled )
16  {
17  SetThrowingModeEnabled(false);
18  pHcw.SetThrowingMode(false);
19  }
20 
21  return;
22  }
23 
25  SetThrowingModeEnabled(pHcw.IsThrowingMode());
26 
28  if ( pHic.IsThrowingModeChange() && CanChangeThrowingStance(pHic) )
29  {
30  ResetState();
31 
32  pHcw.SetActionProgressParams(0, 0);
33  pHcw.SetThrowingMode(!m_bThrowingModeEnabled);
34  }
35 
37  if ( m_bThrowingModeEnabled )
38  {
40 
41  if ( !CanContinueThrowingEx(pHic, pEntityInHands) )
42  {
43  SetThrowingModeEnabled(false);
44  ResetState();
45 
46  pHcw.SetActionProgressParams(0, 0);
47  pHcw.SetThrowingMode(false);
48 
49  return;
50  }
51 
53  if ( pHcw.WasItemLeaveHandsEvent() )
54  {
55  float lr = pHcw.GetBaseAimingAngleLR();
56  float ud = pHcw.GetBaseAimingAngleUD();
57  vector aimOrientation = m_Player.GetOrientation();
58  aimOrientation[0] = aimOrientation[0] + lr;
59 
60  //add 5 deg
61  aimOrientation[1] = aimOrientation[1] + ud + 5;
62 
63 
64  m_Player.GetHumanInventory().ThrowEntity(pEntityInHands, aimOrientation.AnglesToVector(), c_fThrowingForceMin + m_fThrowingForce01 * (c_fThrowingForceMax - c_fThrowingForceMin));
65  return;
66  }
67 
69  if ( !m_bThrowingAnimationPlaying )
70  {
71  if ( pHic.IsAttackButton() )
72  {
73  if ( !m_bThrowingInProgress )
74  m_bThrowingInProgress = true;
75 
76  m_fThrowingForce01 += pDt * c_fThrowingForceCoef;
77  if ( m_fThrowingForce01 > 1.0 )
78  m_fThrowingForce01 = 1.0;
79 
80  pHcw.SetActionProgressParams(m_fThrowingForce01, 0);
81  }
82  else
83  {
84  HumanCommandMove hcm = m_Player.GetCommand_Move();
85  bool standingFromBack = hcm && hcm.IsStandingFromBack();
86 
87  if ( m_bThrowingInProgress && !standingFromBack)
88  {
89  m_bThrowingInProgress = false;
90 
91  int throwType = 1;
92 
93  HumanItemBehaviorCfg itemCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
94  itemCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
95  if ( itemCfg )
96  {
97  switch ( itemCfg.m_iType )
98  {
99  case ItemBehaviorType.TWOHANDED:
100  case ItemBehaviorType.POLEARMS:
101  throwType = 2;
102  break;
103  case ItemBehaviorType.FIREARMS:
104  throwType = 3;
105  }
106  }
107 
108  pHcw.ThrowItem(throwType);
109  m_bThrowingAnimationPlaying = true;
110  }
111  }
112  }
113  }
114  else
115  {
116  ResetState();
117  }
118  }
119 
120  void ResetState()
121  {
122  m_fThrowingForce01 = 0;
123  m_bThrowingInProgress = false;
124  m_bThrowingAnimationPlaying = false;
125  }
126 
127  void SetThrowingModeEnabled(bool enable)
128  {
129  if (enable != m_bThrowingModeEnabled)
130  {
131  m_Player.OnThrowingModeChange(enable);
132  }
133  m_bThrowingModeEnabled = enable;
134  }
135 
136  bool IsThrowingModeEnabled()
137  {
138  return m_bThrowingModeEnabled;
139  }
140 
142  bool IsThrowingInProgress()
143  {
144  return m_bThrowingInProgress;
145  }
146 
148  bool IsThrowingAnimationPlaying()
149  {
150  return m_bThrowingAnimationPlaying;
151  }
152 
153  bool CanChangeThrowingStance(HumanInputController pHic)
154  {
155  // basic stance has priority
156  if( pHic.IsStanceChange() )
157  return false;
158 
159  // don't change mode in raise
160  if( pHic.IsWeaponRaised() )
161  return false;
162 
163  // check if it's not a heavy item
164  HumanItemBehaviorCfg itemCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
165  if( itemCfg && itemCfg.m_iType == ItemBehaviorType.HEAVY )
166  return false;
167 
168 /* HumanMovementState movementState = new HumanMovementState();
169  m_Player.GetMovementState(movementState);
170  if( movementState.IsInProne() )
171  return false;*/
172 
173  PlayerBase playerPB = PlayerBase.Cast(m_Player);
174  if( playerPB )
175  {
176  if( playerPB.GetEmoteManager().IsEmotePlaying() )
177  return false;
178 
179  if( playerPB.GetActionManager().GetRunningAction() != NULL )
180  return false;
181 
182  if( playerPB.IsRestrained() || playerPB.IsItemsToDelete())
183  return false;
184 
185  if( playerPB.GetDayZPlayerInventory().IsProcessing() )
186  return false;
187 
188  if( playerPB.GetWeaponManager().IsRunning() )
189  return false;
190  }
191 
192  if (!CheckFreeSpace() )
193  return false;
194 
195  return true;
196  }
197 
198  bool CanContinueThrowing(HumanInputController pHic)
199  {
200  HumanItemBehaviorCfg itemInHandsCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
201  bool boo = false;
202  UAInterface input_interface = m_Player.GetInputInterface();
203  if(input_interface && input_interface.SyncedPress("UAGear"))
204  {
205  boo = true;
206  }
207  if( boo || pHic.IsWeaponRaised() || (itemInHandsCfg && itemInHandsCfg.m_iType == ItemBehaviorType.HEAVY) )
208  {
209  return false;
210  }
211 
212  if (!CheckFreeSpace() )
213  return false;
214 
215  return true;
216  }
217 
218  bool CanContinueThrowingEx(HumanInputController pHic, EntityAI pEntityInHands)
219  {
220  if ( pEntityInHands == null )
221  return false;
222 
223  return CanContinueThrowing(pHic);
224  }
225 
226  bool CheckFreeSpace()
227  {
228  return m_Player.CheckFreeSpace(vector.Forward, 0.7, false);
229  }
230 
231  private DayZPlayer m_Player;
232  private bool m_bThrowingModeEnabled;
233  private bool m_bThrowingInProgress;
234  private bool m_bThrowingAnimationPlaying;
235  private float m_fThrowingForce01;
236 
237  private const float c_fThrowingForceMin = 20.0;
238  private const float c_fThrowingForceMax = 90.0;
239  private const float c_fThrowingForceCoef = 1.0;
240 }
DayZPlayer
Definition: dayzplayerimplement.c:72
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
DayZPlayerImplementThrowing
Definition: dayzplayerimplementthrowing.c:1
HumanCommandMove
Definition: human.c:433
HumanInputController
Definition: human.c:17
HumanCommandWeapons
Definition: human.c:986
HumanItemBehaviorCfg
Definition: humanitems.c:5
UAInterface
Definition: uainput.c:95
EntityAI
Definition: building.c:5