actionemptybottlebase.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. class ActionEmptyBottleBaseCB : ActionContinuousBaseCB
  2. {
  3. bool m_RPCStopAlreadySent;//since stopping contains a sound tail, we need to stop it only once, this bool ensures that
  4. override void CreateActionComponent()
  5. {
  6. float EmptiedQuantity;
  7. Bottle_Base bottle = Bottle_Base.Cast(m_ActionData.m_MainItem);
  8. if (bottle)
  9. EmptiedQuantity = bottle.GetLiquidEmptyRate() * bottle.GetLiquidThroughputCoef();
  10. m_ActionData.m_ActionComponent = new CAContinuousEmpty(EmptiedQuantity);
  11. }
  12. override void EndActionComponent()
  13. {
  14. ActionContinuousBase action = ActionContinuousBase.Cast(m_ActionData.m_Action);
  15. if (action.UseAlternativeInterrupt(m_ActionData))
  16. SetCommand(DayZPlayerConstants.CMD_ACTIONINT_FINISH);
  17. else
  18. SetCommand(DayZPlayerConstants.CMD_ACTIONINT_END);
  19. }
  20. };
  21. class ActionEmptyBottleBase: ActionContinuousBase
  22. {
  23. void ActionEmptyBottleBase()
  24. {
  25. m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_EMPTY_VESSEL;
  26. m_SpecialtyWeight = UASoftSkillsWeight.PRECISE_LOW;
  27. m_CallbackClass = ActionEmptyBottleBaseCB;
  28. m_FullBody = false;
  29. m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH;
  30. m_Text = "#empty";
  31. }
  32. override void CreateConditionComponents()
  33. {
  34. m_ConditionItem = new CCINonRuined;
  35. m_ConditionTarget = new CCTNone;
  36. }
  37. override bool HasTarget()
  38. {
  39. return false;
  40. }
  41. override bool HasAlternativeInterrupt()
  42. {
  43. return true;
  44. }
  45. override bool UseAlternativeInterrupt(ActionData action_data)
  46. {
  47. return HasAlternativeInterrupt() && (action_data.m_ActionComponent.GetProgress() >= 1);
  48. }
  49. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  50. {
  51. if ( GetGame().IsServer() && GetGame().IsMultiplayer() )
  52. return true;
  53. return item.IsLiquidPresent() && item.GetQuantity() > item.GetQuantityMin() && !item.GetIsFrozen();
  54. }
  55. override bool ActionConditionContinue( ActionData action_data )
  56. {
  57. return true;
  58. }
  59. override void OnStartAnimationLoop( ActionData action_data )
  60. {
  61. SendRPC(action_data,true);
  62. }
  63. override void OnEndAnimationLoop( ActionData action_data )
  64. {
  65. SendRPC(action_data,false);
  66. }
  67. override void OnEndServer( ActionData action_data )
  68. {
  69. SendRPC(action_data,false);
  70. super.OnEndServer(action_data);
  71. }
  72. protected void SendRPC(ActionData actionData, bool enable)
  73. {
  74. if ( !GetGame().IsMultiplayer() || GetGame().IsServer() )
  75. {
  76. ActionEmptyBottleBaseCB comp = ActionEmptyBottleBaseCB.Cast(actionData.m_Callback);
  77. if (comp.m_RPCStopAlreadySent)
  78. return;
  79. Bottle_Base target_vessel = Bottle_Base.Cast( actionData.m_MainItem );
  80. Param1<bool> play = new Param1<bool>( enable );
  81. GetGame().RPCSingleParam( target_vessel, SoundTypeBottle.EMPTYING, play, true );
  82. if (!enable)
  83. comp.m_RPCStopAlreadySent = true;
  84. }
  85. }
  86. };