actiondrinkpondcontinuous.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. void ActionDrinkPondContinuous()
  13. {
  14. m_CallbackClass = ActionDrinkPondContinuousCB;
  15. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DRINKPOND;
  16. m_FullBody = true;
  17. m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH;
  18. m_Text = "#drink";
  19. }
  20. override bool IsDrink()
  21. {
  22. return true;
  23. }
  24. override typename GetInputType()
  25. {
  26. return ContinuousInteractActionInput;
  27. }
  28. override bool CanBeUsedInFreelook()
  29. {
  30. return false;
  31. }
  32. override void CreateConditionComponents()
  33. {
  34. m_ConditionItem = new CCINone();
  35. m_ConditionTarget = new CCTWaterSurfaceEx(UAMaxDistances.DEFAULT, LIQUID_GROUP_DRINKWATER - LIQUID_SNOW - LIQUID_HOTWATER);
  36. }
  37. override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
  38. {
  39. if (item && item.IsHeavyBehaviour())
  40. return false;
  41. return player.CanEatAndDrink();
  42. }
  43. override void OnStart(ActionData action_data)
  44. {
  45. super.OnStart(action_data);
  46. action_data.m_Player.TryHideItemInHands(true);
  47. }
  48. override void OnEnd(ActionData action_data)
  49. {
  50. action_data.m_Player.TryHideItemInHands(false);
  51. }
  52. override void OnFinishProgressServer(ActionData action_data)
  53. {
  54. Param1<float> nacdata = Param1<float>.Cast(action_data.m_ActionComponent.GetACData());
  55. if (nacdata)
  56. {
  57. EConsumeType consumeType;
  58. int liquidSource = GetLiquidSource(action_data.m_Target);
  59. switch (liquidSource)
  60. {
  61. case LIQUID_CLEANWATER:
  62. consumeType = EConsumeType.ENVIRO_WELL;
  63. break;
  64. default:
  65. consumeType = EConsumeType.ENVIRO_POND;
  66. break;
  67. }
  68. PlayerConsumeData consumeData = new PlayerConsumeData();
  69. consumeData.m_Type = consumeType;
  70. consumeData.m_Amount = UAQuantityConsumed.DRINK;
  71. consumeData.m_Source = null;
  72. consumeData.m_Agents = action_data.m_Player.GetBloodyHandsPenaltyAgents();
  73. consumeData.m_LiquidType = liquidSource;
  74. action_data.m_Player.Consume(consumeData);
  75. }
  76. }
  77. override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
  78. {
  79. super.WriteToContext(ctx, action_data);
  80. if (HasTarget())
  81. {
  82. ctx.Write(action_data.m_Target.GetCursorHitPos());
  83. return;
  84. }
  85. ctx.Write(vector.Zero);
  86. }
  87. override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
  88. {
  89. super.ReadFromContext(ctx, action_recive_data);
  90. if (HasTarget())
  91. {
  92. vector cursorPosition;
  93. if (!ctx.Read(cursorPosition))
  94. return false;
  95. action_recive_data.m_Target.SetCursorHitPos(cursorPosition);
  96. }
  97. return true;
  98. }
  99. protected int GetLiquidSource(ActionTarget target)
  100. {
  101. vector hitPosition = target.GetCursorHitPos();
  102. string surfaceType;
  103. int liquidSource;
  104. g_Game.SurfaceGetType3D(hitPosition[0], hitPosition[1], hitPosition[2], surfaceType);
  105. string path = "CfgSurfaces " + surfaceType + " liquidType";
  106. liquidSource = GetGame().ConfigGetInt(path);
  107. return liquidSource;
  108. }
  109. }