File size: 5,752 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
class DayZPlayerImplementThrowing
{
	void DayZPlayerImplementThrowing(DayZPlayer pPlayer)
	{
		m_Player = pPlayer;
		SetThrowingModeEnabled(false);
		
		ResetState();
	}
	
	void HandleThrowing(HumanInputController pHic, HumanCommandWeapons pHcw, EntityAI pEntityInHands, float pDt)
	{
		if ( !pEntityInHands && !m_bThrowingAnimationPlaying )
		{
			if ( m_bThrowingModeEnabled )
			{
				SetThrowingModeEnabled(false);
				pHcw.SetThrowingMode(false);
			}
			
			return;
		}
		
		//! current state
		SetThrowingModeEnabled(pHcw.IsThrowingMode());
		
		//! handle mode change
		if ( pHic.IsThrowingModeChange() && CanChangeThrowingStance(pHic) )
		{
			ResetState();
			
			pHcw.SetActionProgressParams(0, 0);
			pHcw.SetThrowingMode(!m_bThrowingModeEnabled);
		}
		
		//! handle action
		if ( m_bThrowingModeEnabled )
		{
			//! cancel throwing in case of raising hands or heavy item in hands
			
			if ( !CanContinueThrowingEx(pHic, pEntityInHands) )
			{
				SetThrowingModeEnabled(false);
				ResetState();
			
				pHcw.SetActionProgressParams(0, 0);
				pHcw.SetThrowingMode(false);
				
				return;
			}
			
			//! check event for throw
			if ( pHcw.WasItemLeaveHandsEvent() )
			{
				float lr = pHcw.GetBaseAimingAngleLR();
				float ud = pHcw.GetBaseAimingAngleUD();
				vector aimOrientation = m_Player.GetOrientation();
				aimOrientation[0] = aimOrientation[0] + lr;
				
				//add 5 deg 
				aimOrientation[1] = aimOrientation[1] + ud + 5;


				m_Player.GetHumanInventory().ThrowEntity(pEntityInHands, aimOrientation.AnglesToVector(), c_fThrowingForceMin + m_fThrowingForce01 * (c_fThrowingForceMax - c_fThrowingForceMin));
				return;
			}

			//! handle throw force
			if ( !m_bThrowingAnimationPlaying )
			{
				if ( pHic.IsAttackButton() )
				{
					if ( !m_bThrowingInProgress )
						m_bThrowingInProgress = true;
					
					m_fThrowingForce01 += pDt * c_fThrowingForceCoef;
					if ( m_fThrowingForce01 > 1.0 )
						m_fThrowingForce01 = 1.0;
					
					pHcw.SetActionProgressParams(m_fThrowingForce01, 0);
				}
				else
				{
					HumanCommandMove hcm = m_Player.GetCommand_Move();
					bool standingFromBack = hcm && hcm.IsStandingFromBack();
					
					if ( m_bThrowingInProgress && !standingFromBack)
					{
						m_bThrowingInProgress = false;
						
						int throwType = 1;
						
						HumanItemBehaviorCfg itemCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
						itemCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
						if ( itemCfg )
						{
							switch ( itemCfg.m_iType )
							{
								case ItemBehaviorType.TWOHANDED:
								case ItemBehaviorType.POLEARMS:
									throwType = 2;
									break;
								case ItemBehaviorType.FIREARMS:
									throwType = 3;
							}
						}
						
						pHcw.ThrowItem(throwType);
						m_bThrowingAnimationPlaying = true;
					}
				}
			}
		}
		else
		{
			ResetState();
		}
	}
	
	void ResetState()
	{
		m_fThrowingForce01 = 0;
		m_bThrowingInProgress = false;
		m_bThrowingAnimationPlaying = false;
	}
	
	void SetThrowingModeEnabled(bool enable)
	{
		if (enable != m_bThrowingModeEnabled)
		{
			m_Player.OnThrowingModeChange(enable);
		}
		m_bThrowingModeEnabled = enable;
	}
	
	bool IsThrowingModeEnabled()
	{
		return m_bThrowingModeEnabled;
	}
	
	//! Throwing wind-up only (button hold)
	bool IsThrowingInProgress()
	{
		return m_bThrowingInProgress;
	}
	
	//! Throwing animation after button release
	bool IsThrowingAnimationPlaying()
	{
		return m_bThrowingAnimationPlaying;
	}
	
	bool CanChangeThrowingStance(HumanInputController pHic)
	{
		// basic stance has priority
		if( pHic.IsStanceChange() )
			return false;
		
		// don't change mode in raise
		if( pHic.IsWeaponRaised() )
			return false;
			
		// check if it's not a heavy item
		HumanItemBehaviorCfg itemCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
		if( itemCfg && itemCfg.m_iType == ItemBehaviorType.HEAVY )
			return false;
		
/*		HumanMovementState movementState = new HumanMovementState();
		m_Player.GetMovementState(movementState);
		if( movementState.IsInProne() )
			return false;*/
		
		PlayerBase playerPB = PlayerBase.Cast(m_Player);
		if( playerPB )
		{
			if( playerPB.GetEmoteManager().IsEmotePlaying() )
				return false;
		
			if( playerPB.GetActionManager().GetRunningAction() != NULL )
				return false;
		
			if( playerPB.IsRestrained() || playerPB.IsItemsToDelete())
				return false;
		
			if( playerPB.GetDayZPlayerInventory().IsProcessing() )
				return false;
		
			if( playerPB.GetWeaponManager().IsRunning() )
				return false;
		}
		
		if (!CheckFreeSpace() )
			return false;

		return true;
	}
	
	bool CanContinueThrowing(HumanInputController pHic)
	{
		HumanItemBehaviorCfg itemInHandsCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
		bool boo = false;
		UAInterface input_interface = m_Player.GetInputInterface();
		if(input_interface && input_interface.SyncedPress("UAGear"))
		{
			boo = true;
		}
		if( boo || pHic.IsWeaponRaised() || (itemInHandsCfg && itemInHandsCfg.m_iType == ItemBehaviorType.HEAVY) )
		{
			return false;
		}
		
		if (!CheckFreeSpace() )
			return false;

		return true;
	}
	
	bool CanContinueThrowingEx(HumanInputController pHic, EntityAI pEntityInHands)
	{
		if ( pEntityInHands == null )
			return false;
		
		return CanContinueThrowing(pHic);
	}
	
	bool CheckFreeSpace()
	{
		return m_Player.CheckFreeSpace(vector.Forward, 0.7, false);
	}
	
	private DayZPlayer m_Player;
	private bool m_bThrowingModeEnabled;
	private bool m_bThrowingInProgress;
	private bool m_bThrowingAnimationPlaying;
	private float m_fThrowingForce01;
	
	private const float c_fThrowingForceMin = 20.0;
	private const float c_fThrowingForceMax = 90.0;
	private const float c_fThrowingForceCoef = 1.0;
}