Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
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 //clear inventoy reservation in case item is reserved (e.g. action was executed on this player)
65 pEntityInHands.GetInventory().GetCurrentInventoryLocation(loc);
66 m_Player.GetInventory().ClearInventoryReservationEx(pEntityInHands, loc);
67
68 m_Player.GetHumanInventory().ThrowEntity(pEntityInHands, aimOrientation.AnglesToVector(), c_fThrowingForceMin + m_fThrowingForce01 * (c_fThrowingForceMax - c_fThrowingForceMin));
69 return;
70 }
71
73 if ( !m_bThrowingAnimationPlaying )
74 {
75 if ( pHic.IsAttackButton() )
76 {
77 if ( !m_bThrowingInProgress )
78 m_bThrowingInProgress = true;
79
80 m_fThrowingForce01 += pDt * c_fThrowingForceCoef;
81 if ( m_fThrowingForce01 > 1.0 )
82 m_fThrowingForce01 = 1.0;
83
84 pHcw.SetActionProgressParams(m_fThrowingForce01, 0);
85 }
86 else
87 {
88 HumanCommandMove hcm = m_Player.GetCommand_Move();
89 bool standingFromBack = hcm && hcm.IsStandingFromBack();
90
91 if ( m_bThrowingInProgress && !standingFromBack)
92 {
93 m_bThrowingInProgress = false;
94
95 int throwType = 1;
96
97 HumanItemBehaviorCfg itemCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
98 itemCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
99 if ( itemCfg )
100 {
101 switch ( itemCfg.m_iType )
102 {
103 case ItemBehaviorType.TWOHANDED:
104 case ItemBehaviorType.POLEARMS:
105 throwType = 2;
106 break;
107 case ItemBehaviorType.FIREARMS:
108 throwType = 3;
109 }
110 }
111
112 pHcw.ThrowItem(throwType);
113 m_bThrowingAnimationPlaying = true;
114 }
115 }
116 }
117 }
118 else
119 {
120 ResetState();
121 }
122 }
123
124 void ResetState()
125 {
126 m_fThrowingForce01 = 0;
127 m_bThrowingInProgress = false;
128 m_bThrowingAnimationPlaying = false;
129 }
130
131 void SetThrowingModeEnabled(bool enable)
132 {
133 if (enable != m_bThrowingModeEnabled)
134 {
135 m_Player.OnThrowingModeChange(enable);
136 }
137 m_bThrowingModeEnabled = enable;
138 }
139
140 bool IsThrowingModeEnabled()
141 {
142 return m_bThrowingModeEnabled;
143 }
144
146 bool IsThrowingInProgress()
147 {
148 return m_bThrowingInProgress;
149 }
150
152 bool IsThrowingAnimationPlaying()
153 {
154 return m_bThrowingAnimationPlaying;
155 }
156
157 bool CanChangeThrowingStance(HumanInputController pHic)
158 {
159 // basic stance has priority
160 if( pHic.IsStanceChange() )
161 return false;
162
163 // don't change mode in raise
164 if( pHic.IsWeaponRaised() )
165 return false;
166
167 // check if it's not a heavy item
168 HumanItemBehaviorCfg itemCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
169 if( itemCfg && itemCfg.m_iType == ItemBehaviorType.HEAVY )
170 return false;
171
172/* HumanMovementState movementState = new HumanMovementState();
173 m_Player.GetMovementState(movementState);
174 if( movementState.IsInProne() )
175 return false;*/
176
177 PlayerBase playerPB = PlayerBase.Cast(m_Player);
178 if( playerPB )
179 {
180 if( playerPB.GetEmoteManager().IsEmotePlaying() )
181 return false;
182
183 if( playerPB.GetActionManager().GetRunningAction() != NULL )
184 return false;
185
186 if( playerPB.IsRestrained() || playerPB.IsItemsToDelete())
187 return false;
188
189 if( playerPB.GetDayZPlayerInventory().IsProcessing() )
190 return false;
191
192 if( playerPB.GetWeaponManager().IsRunning() )
193 return false;
194 }
195
196 if (!CheckFreeSpace() )
197 return false;
198
199 return true;
200 }
201
202 bool CanContinueThrowing(HumanInputController pHic)
203 {
204 HumanItemBehaviorCfg itemInHandsCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
205 bool boo = false;
206 UAInterface input_interface = m_Player.GetInputInterface();
207 if(input_interface && input_interface.SyncedPress("UAGear"))
208 {
209 boo = true;
210 }
211 if( boo || pHic.IsWeaponRaised() || (itemInHandsCfg && itemInHandsCfg.m_iType == ItemBehaviorType.HEAVY) )
212 {
213 return false;
214 }
215
216 if (!CheckFreeSpace() )
217 return false;
218
219 return true;
220 }
221
222 bool CanContinueThrowingEx(HumanInputController pHic, EntityAI pEntityInHands)
223 {
224 if ( pEntityInHands == null )
225 return false;
226
227 return CanContinueThrowing(pHic);
228 }
229
230 bool CheckFreeSpace()
231 {
232 return m_Player.CheckFreeSpace(vector.Forward, 0.7, false);
233 }
234
235 private DayZPlayer m_Player;
236 private bool m_bThrowingModeEnabled;
237 private bool m_bThrowingInProgress;
238 private bool m_bThrowingAnimationPlaying;
239 private float m_fThrowingForce01;
240
241 private const float c_fThrowingForceMin = 20.0;
242 private const float c_fThrowingForceMax = 90.0;
243 private const float c_fThrowingForceCoef = 1.0;
244}
InventoryLocation.