actiondrinkpondcontinuous.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. float amount = UAQuantityConsumed.DRINK;
  56. EConsumeType consumeType;
  57. int liquidSource = GetLiquidSource(action_data.m_Target);
  58. switch (liquidSource)
  59. {
  60. case LIQUID_CLEANWATER:
  61. consumeType = EConsumeType.ENVIRO_WELL;
  62. break;
  63. default:
  64. consumeType = EConsumeType.ENVIRO_POND;
  65. break;
  66. }
  67. action_data.m_Player.Consume(null, amount, consumeType);
  68. }
  69. override void OnEndAnimationLoopServer(ActionData action_data)
  70. {
  71. if (action_data.m_Player.HasBloodyHands() && !action_data.m_Player.GetInventory().FindAttachment(InventorySlots.GLOVES))
  72. {
  73. action_data.m_Player.SetBloodyHandsPenalty();
  74. }
  75. }
  76. override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
  77. {
  78. super.WriteToContext(ctx, action_data);
  79. if (HasTarget())
  80. {
  81. ctx.Write(action_data.m_Target.GetCursorHitPos());
  82. return;
  83. }
  84. ctx.Write(vector.Zero);
  85. }
  86. override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
  87. {
  88. super.ReadFromContext(ctx, action_recive_data);
  89. if (HasTarget())
  90. {
  91. vector cursorPosition;
  92. if (!ctx.Read(cursorPosition))
  93. return false;
  94. action_recive_data.m_Target.SetCursorHitPos(cursorPosition);
  95. }
  96. return true;
  97. }
  98. protected int GetLiquidSource(ActionTarget target)
  99. {
  100. vector hitPosition = target.GetCursorHitPos();
  101. string surfaceType;
  102. int liquidSource;
  103. g_Game.SurfaceGetType3D(hitPosition[0], hitPosition[1], hitPosition[2], surfaceType);
  104. string path = "CfgSurfaces " + surfaceType + " liquidType";
  105. liquidSource = GetGame().ConfigGetInt(path);
  106. return liquidSource;
  107. }
  108. }