actiondigworms.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. class ActionDigWormsCB : ActionContinuousBaseCB
  2. {
  3. override void CreateActionComponent()
  4. {
  5. float time_spent;
  6. time_spent = UATimeSpent.DIG_WORMS;
  7. if (m_ActionData.m_MainItem.KindOf("Knife"))
  8. time_spent = time_spent * 1.2;
  9. if (m_ActionData.m_Player.GetInColdArea())
  10. time_spent *= GameConstants.COLD_AREA_DIG_WORMS_MODIF;
  11. m_ActionData.m_ActionComponent = new CAContinuousTime(time_spent);
  12. }
  13. };
  14. class ActionDigWorms: ActionContinuousBase
  15. {
  16. void ActionDigWorms()
  17. {
  18. m_CallbackClass = ActionDigWormsCB;
  19. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DIGGIN_WORMS;
  20. m_FullBody = true;
  21. m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH;
  22. m_SpecialtyWeight = UASoftSkillsWeight.ROUGH_MEDIUM;
  23. m_Text = "#dig_up_worms";
  24. }
  25. override void CreateConditionComponents()
  26. {
  27. m_ConditionItem = new CCINonRuined;
  28. m_ConditionTarget = new CCTSurface(UAMaxDistances.DEFAULT);
  29. }
  30. override bool Can(PlayerBase player, ActionTarget target, ItemBase item, int condition_mask)
  31. {
  32. if (!super.Can(player, target, item, condition_mask))
  33. return false;
  34. return player.CheckFreeSpace(vector.Forward, 0.8, false);
  35. }
  36. override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
  37. {
  38. if (player.IsPlacingLocal())
  39. return false;
  40. return IsTargetFertile(target) && IsPlayerOnGround(player);
  41. }
  42. override bool ActionConditionContinue(ActionData action_data)
  43. {
  44. return IsPlayerOnGround(action_data.m_Player);
  45. }
  46. override bool HasTarget()
  47. {
  48. return true;
  49. }
  50. override void OnFinishProgressServer(ActionData action_data)
  51. {
  52. ItemBase worms;
  53. int count = action_data.m_MainItem.GetOnDigWormsAmount();
  54. for (int i = 0; i < count; i++)
  55. {
  56. Class.CastTo(worms, GetGame().CreateObjectEx("Worm", action_data.m_Player.GetPosition(), ECE_PLACE_ON_SURFACE));
  57. }
  58. MiscGameplayFunctions.DealEvinronmentAdjustedDmg(action_data.m_MainItem, action_data.m_Player, 4);
  59. }
  60. bool IsTargetFertile(ActionTarget target)
  61. {
  62. if (target)
  63. {
  64. string surface_type;
  65. vector position;
  66. position = target.GetCursorHitPos();
  67. GetGame().SurfaceGetType(position[0], position[2], surface_type);
  68. if (GetGame().IsSurfaceFertile(surface_type))
  69. {
  70. return true;
  71. }
  72. }
  73. return false;
  74. }
  75. bool IsPlayerOnGround(PlayerBase player)
  76. {
  77. vector position = player.GetPosition();
  78. float heightDiff = GetGame().SurfaceY(position[0], position[2]);
  79. heightDiff = position[1] - heightDiff;
  80. return heightDiff <= 0.4; // Player is considered on ground
  81. }
  82. //! DEPRECATED - See ItemBase.OverrideActionAnimation() to override commands for items
  83. void SetDiggignAnimation(ItemBase item);
  84. };