File size: 2,549 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
class DayZPlayerImplementJumpClimb
{
	void DayZPlayerImplementJumpClimb(DayZPlayerImplement pPlayer)
	{
		m_Player = pPlayer;
	}

	//! Only valid immediately after 'JumpOrClimb' is called
	bool WasSuccessful()
	{
		return m_bIsJumpInProgress || m_bWasClimb;
	}
	
	//! Can't change to bool return
	void JumpOrClimb()
	{
		//! Reset states
		m_bWasClimb = false;

		//! Early exit if the player is being heavy damaged so the stagger animation can't be skipped
		if (m_Player.IsInFullbodyDamageAnimation())
		{
			return;
		}

		SHumanCommandClimbSettings hcls = m_Player.GetDayZPlayerType().CommandClimbSettingsW();
		
		if ( m_Player.m_MovementState.m_iMovement != DayZPlayerConstants.MOVEMENTIDX_IDLE )
			hcls.m_fFwMaxDistance = 2.5;
		else
			hcls.m_fFwMaxDistance = 1.2;
		
		SHumanCommandClimbResult climbRes = new SHumanCommandClimbResult();
		
		HumanCommandClimb.DoClimbTest(m_Player, climbRes, 0);
		if ( climbRes.m_bIsClimb || climbRes.m_bIsClimbOver )
		{
			int climbType = GetClimbType(climbRes.m_fClimbHeight);

			if ( !m_Player.CanClimb( climbType,climbRes ) )
				return;

			if ( Climb(climbRes) )
			{
				if ( climbType == 1 )
					m_Player.DepleteStamina(EStaminaModifiers.VAULT);
				else if ( climbType == 2 )
					m_Player.DepleteStamina(EStaminaModifiers.CLIMB);

				return;
			}
		}
		
		if ( m_Player.CanJump() )
		{
			Jump();
			m_Player.DepleteStamina(EStaminaModifiers.JUMP);
		}
	}
	
	void CheckAndFinishJump(int pLandType = 0)
	{
		if ( m_bIsJumpInProgress )
		{
			m_bIsJumpInProgress = false;
			m_Player.OnJumpEnd(pLandType);
		}
	}
	
	private bool Climb(SHumanCommandClimbResult pClimbRes)
	{
		int climbType = GetClimbType(pClimbRes.m_fClimbHeight);	
		if( climbType != -1 )
		{
			m_Player.StartCommand_Climb(pClimbRes, climbType);
			m_Player.StopHandEvent();

			m_bWasClimb = true;
		}
		
		return climbType != -1;
	}
	
	private void Jump()
	{
		m_bIsJumpInProgress = true;
		m_Player.SetFallYDiff(m_Player.GetPosition()[1]);

		m_Player.OnJumpStart();
		m_Player.StartCommand_Fall(2.6);
		m_Player.StopHandEvent();
	}
	
	private int GetClimbType(float pHeight)
	{
		int climbType = -1;
        if( pHeight < 1.1 )
            climbType = 0;
        else if( pHeight >= 1.1 && pHeight < 1.7 )
            climbType = 1;
        else if( pHeight >= 1.7 && pHeight < 2.75 )
            climbType = 2;    
        
        return climbType;
	}
		
	// Public variable members
	bool m_bIsJumpInProgress = false;	
	
	// Private variable members
	private DayZPlayerImplement m_Player;
	private bool m_bWasClimb;
}