dayzplayerimplementthrowing.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. class DayZPlayerImplementThrowing
  2. {
  3. void DayZPlayerImplementThrowing(DayZPlayer pPlayer)
  4. {
  5. m_Player = pPlayer;
  6. SetThrowingModeEnabled(false);
  7. ResetState();
  8. }
  9. void HandleThrowing(HumanInputController pHic, HumanCommandWeapons pHcw, EntityAI pEntityInHands, float pDt)
  10. {
  11. if ( !pEntityInHands && !m_bThrowingAnimationPlaying )
  12. {
  13. if ( m_bThrowingModeEnabled )
  14. {
  15. SetThrowingModeEnabled(false);
  16. pHcw.SetThrowingMode(false);
  17. }
  18. return;
  19. }
  20. //! current state
  21. SetThrowingModeEnabled(pHcw.IsThrowingMode());
  22. //! handle mode change
  23. if ( pHic.IsThrowingModeChange() && CanChangeThrowingStance(pHic) )
  24. {
  25. ResetState();
  26. pHcw.SetActionProgressParams(0, 0);
  27. pHcw.SetThrowingMode(!m_bThrowingModeEnabled);
  28. }
  29. //! handle action
  30. if ( m_bThrowingModeEnabled )
  31. {
  32. //! cancel throwing in case of raising hands or heavy item in hands
  33. if ( !CanContinueThrowingEx(pHic, pEntityInHands) )
  34. {
  35. SetThrowingModeEnabled(false);
  36. ResetState();
  37. pHcw.SetActionProgressParams(0, 0);
  38. pHcw.SetThrowingMode(false);
  39. return;
  40. }
  41. //! check event for throw
  42. if ( pHcw.WasItemLeaveHandsEvent() )
  43. {
  44. float lr = pHcw.GetBaseAimingAngleLR();
  45. float ud = pHcw.GetBaseAimingAngleUD();
  46. vector aimOrientation = m_Player.GetOrientation();
  47. aimOrientation[0] = aimOrientation[0] + lr;
  48. //add 5 deg
  49. aimOrientation[1] = aimOrientation[1] + ud + 5;
  50. m_Player.GetHumanInventory().ThrowEntity(pEntityInHands, aimOrientation.AnglesToVector(), c_fThrowingForceMin + m_fThrowingForce01 * (c_fThrowingForceMax - c_fThrowingForceMin));
  51. return;
  52. }
  53. //! handle throw force
  54. if ( !m_bThrowingAnimationPlaying )
  55. {
  56. if ( pHic.IsAttackButton() )
  57. {
  58. if ( !m_bThrowingInProgress )
  59. m_bThrowingInProgress = true;
  60. m_fThrowingForce01 += pDt * c_fThrowingForceCoef;
  61. if ( m_fThrowingForce01 > 1.0 )
  62. m_fThrowingForce01 = 1.0;
  63. pHcw.SetActionProgressParams(m_fThrowingForce01, 0);
  64. }
  65. else
  66. {
  67. HumanCommandMove hcm = m_Player.GetCommand_Move();
  68. bool standingFromBack = hcm && hcm.IsStandingFromBack();
  69. if ( m_bThrowingInProgress && !standingFromBack)
  70. {
  71. m_bThrowingInProgress = false;
  72. int throwType = 1;
  73. HumanItemBehaviorCfg itemCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
  74. itemCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
  75. if ( itemCfg )
  76. {
  77. switch ( itemCfg.m_iType )
  78. {
  79. case ItemBehaviorType.TWOHANDED:
  80. case ItemBehaviorType.POLEARMS:
  81. throwType = 2;
  82. break;
  83. case ItemBehaviorType.FIREARMS:
  84. throwType = 3;
  85. }
  86. }
  87. pHcw.ThrowItem(throwType);
  88. m_bThrowingAnimationPlaying = true;
  89. }
  90. }
  91. }
  92. }
  93. else
  94. {
  95. ResetState();
  96. }
  97. }
  98. void ResetState()
  99. {
  100. m_fThrowingForce01 = 0;
  101. m_bThrowingInProgress = false;
  102. m_bThrowingAnimationPlaying = false;
  103. }
  104. void SetThrowingModeEnabled(bool enable)
  105. {
  106. if (enable != m_bThrowingModeEnabled)
  107. {
  108. m_Player.OnThrowingModeChange(enable);
  109. }
  110. m_bThrowingModeEnabled = enable;
  111. }
  112. bool IsThrowingModeEnabled()
  113. {
  114. return m_bThrowingModeEnabled;
  115. }
  116. //! Throwing wind-up only (button hold)
  117. bool IsThrowingInProgress()
  118. {
  119. return m_bThrowingInProgress;
  120. }
  121. //! Throwing animation after button release
  122. bool IsThrowingAnimationPlaying()
  123. {
  124. return m_bThrowingAnimationPlaying;
  125. }
  126. bool CanChangeThrowingStance(HumanInputController pHic)
  127. {
  128. // basic stance has priority
  129. if( pHic.IsStanceChange() )
  130. return false;
  131. // don't change mode in raise
  132. if( pHic.IsWeaponRaised() )
  133. return false;
  134. // check if it's not a heavy item
  135. HumanItemBehaviorCfg itemCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
  136. if( itemCfg && itemCfg.m_iType == ItemBehaviorType.HEAVY )
  137. return false;
  138. /* HumanMovementState movementState = new HumanMovementState();
  139. m_Player.GetMovementState(movementState);
  140. if( movementState.IsInProne() )
  141. return false;*/
  142. PlayerBase playerPB = PlayerBase.Cast(m_Player);
  143. if( playerPB )
  144. {
  145. if( playerPB.GetEmoteManager().IsEmotePlaying() )
  146. return false;
  147. if( playerPB.GetActionManager().GetRunningAction() != NULL )
  148. return false;
  149. if( playerPB.IsRestrained() || playerPB.IsItemsToDelete())
  150. return false;
  151. if( playerPB.GetDayZPlayerInventory().IsProcessing() )
  152. return false;
  153. if( playerPB.GetWeaponManager().IsRunning() )
  154. return false;
  155. }
  156. if (!CheckFreeSpace() )
  157. return false;
  158. return true;
  159. }
  160. bool CanContinueThrowing(HumanInputController pHic)
  161. {
  162. HumanItemBehaviorCfg itemInHandsCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
  163. bool boo = false;
  164. UAInterface input_interface = m_Player.GetInputInterface();
  165. if(input_interface && input_interface.SyncedPress("UAGear"))
  166. {
  167. boo = true;
  168. }
  169. if( boo || pHic.IsWeaponRaised() || (itemInHandsCfg && itemInHandsCfg.m_iType == ItemBehaviorType.HEAVY) )
  170. {
  171. return false;
  172. }
  173. if (!CheckFreeSpace() )
  174. return false;
  175. return true;
  176. }
  177. bool CanContinueThrowingEx(HumanInputController pHic, EntityAI pEntityInHands)
  178. {
  179. if ( pEntityInHands == null )
  180. return false;
  181. return CanContinueThrowing(pHic);
  182. }
  183. bool CheckFreeSpace()
  184. {
  185. return m_Player.CheckFreeSpace(vector.Forward, 0.7, false);
  186. }
  187. private DayZPlayer m_Player;
  188. private bool m_bThrowingModeEnabled;
  189. private bool m_bThrowingInProgress;
  190. private bool m_bThrowingAnimationPlaying;
  191. private float m_fThrowingForce01;
  192. private const float c_fThrowingForceMin = 20.0;
  193. private const float c_fThrowingForceMax = 90.0;
  194. private const float c_fThrowingForceCoef = 1.0;
  195. }