dayzplayerimplementthrowing.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. //clear inventoy reservation in case item is reserved (e.g. action was executed on this player)
  51. InventoryLocation loc = new InventoryLocation;
  52. pEntityInHands.GetInventory().GetCurrentInventoryLocation(loc);
  53. m_Player.GetInventory().ClearInventoryReservationEx(pEntityInHands, loc);
  54. m_Player.GetHumanInventory().ThrowEntity(pEntityInHands, aimOrientation.AnglesToVector(), c_fThrowingForceMin + m_fThrowingForce01 * (c_fThrowingForceMax - c_fThrowingForceMin));
  55. return;
  56. }
  57. //! handle throw force
  58. if ( !m_bThrowingAnimationPlaying )
  59. {
  60. if ( pHic.IsAttackButton() )
  61. {
  62. if ( !m_bThrowingInProgress )
  63. m_bThrowingInProgress = true;
  64. m_fThrowingForce01 += pDt * c_fThrowingForceCoef;
  65. if ( m_fThrowingForce01 > 1.0 )
  66. m_fThrowingForce01 = 1.0;
  67. pHcw.SetActionProgressParams(m_fThrowingForce01, 0);
  68. }
  69. else
  70. {
  71. HumanCommandMove hcm = m_Player.GetCommand_Move();
  72. bool standingFromBack = hcm && hcm.IsStandingFromBack();
  73. if ( m_bThrowingInProgress && !standingFromBack)
  74. {
  75. m_bThrowingInProgress = false;
  76. int throwType = 1;
  77. HumanItemBehaviorCfg itemCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
  78. itemCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
  79. if ( itemCfg )
  80. {
  81. switch ( itemCfg.m_iType )
  82. {
  83. case ItemBehaviorType.TWOHANDED:
  84. case ItemBehaviorType.POLEARMS:
  85. throwType = 2;
  86. break;
  87. case ItemBehaviorType.FIREARMS:
  88. throwType = 3;
  89. }
  90. }
  91. pHcw.ThrowItem(throwType);
  92. m_bThrowingAnimationPlaying = true;
  93. }
  94. }
  95. }
  96. }
  97. else
  98. {
  99. ResetState();
  100. }
  101. }
  102. void ResetState()
  103. {
  104. m_fThrowingForce01 = 0;
  105. m_bThrowingInProgress = false;
  106. m_bThrowingAnimationPlaying = false;
  107. }
  108. void SetThrowingModeEnabled(bool enable)
  109. {
  110. if (enable != m_bThrowingModeEnabled)
  111. {
  112. m_Player.OnThrowingModeChange(enable);
  113. }
  114. m_bThrowingModeEnabled = enable;
  115. }
  116. bool IsThrowingModeEnabled()
  117. {
  118. return m_bThrowingModeEnabled;
  119. }
  120. //! Throwing wind-up only (button hold)
  121. bool IsThrowingInProgress()
  122. {
  123. return m_bThrowingInProgress;
  124. }
  125. //! Throwing animation after button release
  126. bool IsThrowingAnimationPlaying()
  127. {
  128. return m_bThrowingAnimationPlaying;
  129. }
  130. bool CanChangeThrowingStance(HumanInputController pHic)
  131. {
  132. // basic stance has priority
  133. if( pHic.IsStanceChange() )
  134. return false;
  135. // don't change mode in raise
  136. if( pHic.IsWeaponRaised() )
  137. return false;
  138. // check if it's not a heavy item
  139. HumanItemBehaviorCfg itemCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
  140. if( itemCfg && itemCfg.m_iType == ItemBehaviorType.HEAVY )
  141. return false;
  142. /* HumanMovementState movementState = new HumanMovementState();
  143. m_Player.GetMovementState(movementState);
  144. if( movementState.IsInProne() )
  145. return false;*/
  146. PlayerBase playerPB = PlayerBase.Cast(m_Player);
  147. if( playerPB )
  148. {
  149. if( playerPB.GetEmoteManager().IsEmotePlaying() )
  150. return false;
  151. if( playerPB.GetActionManager().GetRunningAction() != NULL )
  152. return false;
  153. if( playerPB.IsRestrained() || playerPB.IsItemsToDelete())
  154. return false;
  155. if( playerPB.GetDayZPlayerInventory().IsProcessing() )
  156. return false;
  157. if( playerPB.GetWeaponManager().IsRunning() )
  158. return false;
  159. }
  160. if (!CheckFreeSpace() )
  161. return false;
  162. return true;
  163. }
  164. bool CanContinueThrowing(HumanInputController pHic)
  165. {
  166. HumanItemBehaviorCfg itemInHandsCfg = m_Player.GetItemAccessor().GetItemInHandsBehaviourCfg();
  167. bool boo = false;
  168. UAInterface input_interface = m_Player.GetInputInterface();
  169. if(input_interface && input_interface.SyncedPress("UAGear"))
  170. {
  171. boo = true;
  172. }
  173. if( boo || pHic.IsWeaponRaised() || (itemInHandsCfg && itemInHandsCfg.m_iType == ItemBehaviorType.HEAVY) )
  174. {
  175. return false;
  176. }
  177. if (!CheckFreeSpace() )
  178. return false;
  179. return true;
  180. }
  181. bool CanContinueThrowingEx(HumanInputController pHic, EntityAI pEntityInHands)
  182. {
  183. if ( pEntityInHands == null )
  184. return false;
  185. return CanContinueThrowing(pHic);
  186. }
  187. bool CheckFreeSpace()
  188. {
  189. return m_Player.CheckFreeSpace(vector.Forward, 0.7, false);
  190. }
  191. private DayZPlayer m_Player;
  192. private bool m_bThrowingModeEnabled;
  193. private bool m_bThrowingInProgress;
  194. private bool m_bThrowingAnimationPlaying;
  195. private float m_fThrowingForce01;
  196. private const float c_fThrowingForceMin = 20.0;
  197. private const float c_fThrowingForceMax = 90.0;
  198. private const float c_fThrowingForceCoef = 1.0;
  199. }