actionrepacktent.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. class ActionRepackTentCB : ActionContinuousBaseCB
  2. {
  3. override void CreateActionComponent()
  4. {
  5. m_ActionData.m_ActionComponent = new CAContinuousTime( UATimeSpent.UNPACK );
  6. }
  7. void DropDuringRepacking()
  8. {
  9. vector orientation = m_ActionData.m_Player.GetOrientation();
  10. vector position = m_ActionData.m_Player.GetPosition() + m_ActionData.m_Player.GetDirection();
  11. vector rotation_matrix[3];
  12. float direction[4];
  13. InventoryLocation source = new InventoryLocation;
  14. InventoryLocation destination = new InventoryLocation;
  15. Math3D.YawPitchRollMatrix( orientation, rotation_matrix );
  16. Math3D.MatrixToQuat( rotation_matrix, direction );
  17. vector ground_position = position;
  18. ground_position[1] = GetGame().SurfaceY(ground_position[0],ground_position[2]);
  19. if ( vector.DistanceSq( m_ActionData.m_Player.GetPosition(), ground_position ) > UAMaxDistances.DEFAULT * UAMaxDistances.DEFAULT)
  20. {
  21. if ( m_ActionData.m_MainItem.GetInventory().GetCurrentInventoryLocation( source ) )
  22. {
  23. destination.SetGroundEx( m_ActionData.m_MainItem, position, direction );
  24. m_ActionData.m_Player.PredictiveTakeToDst(source, destination);
  25. }
  26. }
  27. else
  28. {
  29. if ( m_ActionData.m_MainItem.GetInventory().GetCurrentInventoryLocation( source ) )
  30. {
  31. destination.SetGroundEx( m_ActionData.m_MainItem, ground_position, direction );
  32. m_ActionData.m_Player.PredictiveTakeToDst(source, destination);
  33. }
  34. }
  35. }
  36. };
  37. //!DEPRECATED
  38. class ActionRepackTent: ActionContinuousBase
  39. {
  40. EntityAI m_RepackedEntity;
  41. bool m_IsFinished;
  42. void ActionRepackTent()
  43. {
  44. m_CallbackClass = ActionRepackTentCB;
  45. m_SpecialtyWeight = UASoftSkillsWeight.PRECISE_LOW;
  46. m_CommandUID = 0;
  47. m_FullBody = true;
  48. m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_ERECT;
  49. m_Text = "#repack_tent";
  50. }
  51. override void CreateConditionComponents()
  52. {
  53. m_ConditionItem = new CCINone;
  54. m_ConditionTarget = new CCTNone;
  55. }
  56. override bool HasTarget()
  57. {
  58. return false;
  59. }
  60. override bool HasProgress()
  61. {
  62. return true;
  63. }
  64. override bool ActionConditionContinue( ActionData action_data )
  65. {
  66. return true;
  67. }
  68. override bool HasAlternativeInterrupt()
  69. {
  70. return true;
  71. }
  72. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  73. {
  74. if ( !player.IsPlacingLocal() )
  75. {
  76. return true;
  77. }
  78. return false;
  79. }
  80. override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = NULL)
  81. {
  82. SetupAnimation( item );
  83. if ( super.SetupAction(player, target, item, action_data, extra_data ))
  84. {
  85. return true;
  86. }
  87. return false;
  88. }
  89. override void OnStartServer( ActionData action_data )
  90. {
  91. super.OnStartServer(action_data);
  92. m_RepackedEntity = null;
  93. m_IsFinished = false;
  94. }
  95. override void OnFinishProgressServer( ActionData action_data )
  96. {
  97. Param1<bool> play = new Param1<bool>( false );
  98. GetGame().RPCSingleParam( action_data.m_MainItem, SoundTypeTent.REPACK, play, true );
  99. m_IsFinished = true;
  100. }
  101. override void OnEndServer( ActionData action_data )
  102. {
  103. super.OnEndServer(action_data);
  104. if ( m_IsFinished )
  105. {
  106. if ( action_data.m_MainItem.IsInherited( TentBase ) )
  107. {
  108. RepackLambda lambda_back_pack = new RepackLambda(action_data.m_MainItem, "LargeTentBackPack", action_data.m_Player);
  109. action_data.m_Player.ServerReplaceItemElsewhereWithNewInHands(lambda_back_pack);
  110. }
  111. if ( action_data.m_MainItem.IsInherited( Clothing ) )
  112. {
  113. RepackLambda lambda_tent = new RepackLambda(action_data.m_MainItem, "LargeTent", action_data.m_Player);
  114. action_data.m_Player.ServerReplaceItemElsewhereWithNewInHands(lambda_tent);
  115. }
  116. }
  117. else
  118. {
  119. if ( GetGame().IsMultiplayer() )
  120. {
  121. if ( action_data.m_MainItem )
  122. {
  123. action_data.m_Player.ServerTakeEntityToHands( action_data.m_MainItem );
  124. }
  125. }
  126. else
  127. {
  128. if ( action_data.m_MainItem )
  129. {
  130. action_data.m_Player.LocalTakeEntityToHands( action_data.m_MainItem );
  131. }
  132. }
  133. }
  134. }
  135. void SetupAnimation( ItemBase item )
  136. {
  137. if ( item.IsHeavyBehaviour() )
  138. {
  139. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DEPLOY_HEAVY;
  140. }
  141. else if ( item.IsOneHandedBehaviour() )
  142. {
  143. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DEPLOY_1HD;
  144. }
  145. else if ( item.IsTwoHandedBehaviour() )
  146. {
  147. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DEPLOY_2HD;
  148. }
  149. else
  150. {
  151. Print("Error: check " + item + " behaviour");
  152. }
  153. }
  154. override void OnStartAnimationLoopClient( ActionData action_data )
  155. {
  156. if ( action_data.m_Player.GetItemInHands() )
  157. ActionRepackTentCB.Cast(action_data.m_Callback).DropDuringRepacking();
  158. }
  159. override void OnStartAnimationLoopServer( ActionData action_data )
  160. {
  161. Param1<bool> play = new Param1<bool>( false );
  162. if ( !GetGame().IsMultiplayer() )
  163. {
  164. if ( action_data.m_Player.GetItemInHands() )
  165. ActionRepackTentCB.Cast(action_data.m_Callback).DropDuringRepacking();
  166. }
  167. if ( action_data.m_Player.GetItemInHands() )
  168. {
  169. play = new Param1<bool>( true );
  170. GetGame().RPCSingleParam( action_data.m_MainItem, SoundTypeTent.REPACK, play, true );
  171. }
  172. }
  173. override void OnEndAnimationLoop( ActionData action_data )
  174. {
  175. if ( !GetGame().IsMultiplayer() || GetGame().IsServer() )
  176. {
  177. Param1<bool> play = new Param1<bool>( false );
  178. GetGame().RPCSingleParam( action_data.m_MainItem, SoundTypeTent.REPACK, play, true );
  179. }
  180. }
  181. override string GetAdminLogMessage(ActionData action_data)
  182. {
  183. return " re-packed " + action_data.m_Target.GetObject().GetDisplayName() + " with Hands ";
  184. }
  185. };
  186. class RepackLambda : TurnItemIntoItemLambda
  187. {
  188. EntityAI m_RepackedNewEntity;
  189. void RepackLambda (EntityAI old_item, string new_item_type, PlayerBase player)
  190. {
  191. InventoryLocation hands = new InventoryLocation;
  192. hands.SetHands( player, null );
  193. OverrideNewLocation( hands );
  194. }
  195. };