actiondrinkpondcontinuous.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. class ActionDrinkPondContinuousCB : ActionContinuousBaseCB
  2. {
  3. override void CreateActionComponent()
  4. {
  5. m_ActionData.m_ActionComponent = new CAContinuousRepeat(UATimeSpent.DRINK_POND);
  6. }
  7. }
  8. class ActionDrinkPondContinuous : ActionContinuousBase
  9. {
  10. private const float WATER_DRANK_PER_SEC = 35;
  11. protected const string ALLOWED_WATER_SURFACES = string.Format("%1|%2", UAWaterType.FRESH, UAWaterType.STILL);
  12. protected int m_AllowedLiquidMask;
  13. void ActionDrinkPondContinuous()
  14. {
  15. m_CallbackClass = ActionDrinkPondContinuousCB;
  16. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DRINKPOND;
  17. m_FullBody = true;
  18. m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH;
  19. m_Text = "#drink";
  20. m_AllowedLiquidMask = LIQUID_GROUP_DRINKWATER;
  21. m_AllowedLiquidMask &= ~LIQUID_SNOW;
  22. m_AllowedLiquidMask &= ~LIQUID_HOTWATER;
  23. }
  24. override bool IsDrink()
  25. {
  26. return true;
  27. }
  28. override typename GetInputType()
  29. {
  30. return ContinuousInteractActionInput;
  31. }
  32. override bool CanBeUsedInFreelook()
  33. {
  34. return false;
  35. }
  36. override void CreateConditionComponents()
  37. {
  38. m_ConditionItem = new CCINone();
  39. m_ConditionTarget = new CCTWaterSurfaceEx(UAMaxDistances.DEFAULT, m_AllowedLiquidMask);
  40. }
  41. override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
  42. {
  43. if (item && item.IsHeavyBehaviour())
  44. return false;
  45. int liquidType = LIQUID_NONE;
  46. liquidType = target.GetSurfaceLiquidType();
  47. return liquidType & m_AllowedLiquidMask && player.CanEatAndDrink();
  48. }
  49. override void OnStart(ActionData action_data)
  50. {
  51. super.OnStart(action_data);
  52. action_data.m_Player.TryHideItemInHands(true);
  53. }
  54. override void OnEnd(ActionData action_data)
  55. {
  56. action_data.m_Player.TryHideItemInHands(false);
  57. }
  58. override void OnFinishProgressServer(ActionData action_data)
  59. {
  60. Param1<float> nacdata = Param1<float>.Cast(action_data.m_ActionComponent.GetACData());
  61. if (nacdata)
  62. {
  63. EConsumeType consumeType;
  64. CCTWaterSurfaceEx waterCheck = CCTWaterSurfaceEx.Cast(m_ConditionTarget);
  65. if (!waterCheck)
  66. return;
  67. int liquidSource = waterCheck.GetLiquidType();
  68. switch (liquidSource)
  69. {
  70. case LIQUID_CLEANWATER:
  71. consumeType = EConsumeType.ENVIRO_WELL;
  72. break;
  73. default:
  74. consumeType = EConsumeType.ENVIRO_POND;
  75. break;
  76. }
  77. PlayerConsumeData consumeData = new PlayerConsumeData();
  78. consumeData.m_Type = consumeType;
  79. consumeData.m_Amount = UAQuantityConsumed.DRINK;
  80. consumeData.m_Source = null;
  81. consumeData.m_Agents = action_data.m_Player.GetBloodyHandsPenaltyAgents();
  82. consumeData.m_LiquidType = liquidSource;
  83. action_data.m_Player.Consume(consumeData);
  84. }
  85. }
  86. override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
  87. {
  88. super.WriteToContext(ctx, action_data);
  89. if (HasTarget())
  90. {
  91. ctx.Write(action_data.m_Target.GetCursorHitPos());
  92. return;
  93. }
  94. ctx.Write(vector.Zero);
  95. }
  96. override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
  97. {
  98. super.ReadFromContext(ctx, action_recive_data);
  99. if (HasTarget())
  100. {
  101. vector cursorPosition;
  102. if (!ctx.Read(cursorPosition))
  103. return false;
  104. action_recive_data.m_Target.SetCursorHitPos(cursorPosition);
  105. }
  106. return true;
  107. }
  108. override bool IsLockTargetOnUse()
  109. {
  110. return false;
  111. }
  112. // DEPRECATED
  113. [Obsolete("CCTWaterSurfaceEx::GetSurfaceLiquidType can be used instead")]
  114. protected int GetLiquidSource(ActionTarget target)
  115. {
  116. vector hitPosition = target.GetCursorHitPos();
  117. string surfaceType;
  118. int liquidSource;
  119. g_Game.SurfaceGetType3D(hitPosition[0], hitPosition[1], hitPosition[2], surfaceType);
  120. string path = "CfgSurfaces " + surfaceType + " liquidType";
  121. liquidSource = GetGame().ConfigGetInt(path);
  122. return liquidSource;
  123. }
  124. }