actiondiggardenplot.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. class ActionDigGardenPlotCB : ActiondeployObjectCB
  2. {
  3. override void CreateActionComponent()
  4. {
  5. m_ActionData.m_ActionComponent = new CAContinuousTime(UATimeSpent.DIG_GARDEN);
  6. }
  7. };
  8. class ActionDigGardenPlot: ActionDeployObject
  9. {
  10. GardenPlot m_GardenPlot;
  11. void ActionDigGardenPlot()
  12. {
  13. m_CallbackClass = ActionDigGardenPlotCB;
  14. m_FullBody = true;
  15. m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT;
  16. m_SpecialtyWeight = UASoftSkillsWeight.ROUGH_LOW;
  17. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DIGMANIPULATE;
  18. m_Text = "#make_garden_plot";
  19. }
  20. override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
  21. {
  22. //Client
  23. if (!GetGame().IsDedicatedServer())
  24. {
  25. //Action not allowed if player has broken legs
  26. if (player.GetBrokenLegs() == eBrokenLegs.BROKEN_LEGS)
  27. return false;
  28. if (!CfgGameplayHandler.GetDisableColdAreaPlacementCheck() && player.GetInColdArea())
  29. return false;
  30. if (player.IsPlacingLocal())
  31. {
  32. Hologram hologram = player.GetHologramLocal();
  33. GardenPlot item_GP;
  34. Class.CastTo(item_GP, hologram.GetProjectionEntity());
  35. CheckSurfaceBelowGardenPlot(player, item_GP, hologram);
  36. if (!hologram.IsColliding())
  37. {
  38. return true;
  39. }
  40. }
  41. return false;
  42. }
  43. //Server
  44. return true;
  45. }
  46. override void SetupAnimation(ItemBase item)
  47. {
  48. if (item)
  49. {
  50. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DIG;
  51. }
  52. }
  53. void CheckSurfaceBelowGardenPlot(PlayerBase player, GardenPlot item_GP, Hologram hologram)
  54. {
  55. vector min_max[2];
  56. item_GP.GetCollisionBox(min_max);
  57. float offset = min_max[1][1] - min_max[0][1];
  58. //Print(offset);
  59. vector pos_adjusted = item_GP.GetPosition();
  60. pos_adjusted[1] = pos_adjusted[1] + offset;
  61. if (item_GP.CanBePlaced(player, /*item_GP.GetPosition()*/pos_adjusted) )
  62. {
  63. if (item_GP.CanBePlaced(NULL, item_GP.CoordToParent(hologram.GetLeftCloseProjectionVector())))
  64. {
  65. if (item_GP.CanBePlaced(NULL, item_GP.CoordToParent(hologram.GetRightCloseProjectionVector())))
  66. {
  67. if (item_GP.CanBePlaced(NULL, item_GP.CoordToParent(hologram.GetLeftFarProjectionVector())))
  68. {
  69. if (item_GP.CanBePlaced(NULL, item_GP.CoordToParent(hologram.GetRightFarProjectionVector())))
  70. {
  71. hologram.SetIsCollidingGPlot(false);
  72. return;
  73. }
  74. }
  75. }
  76. }
  77. }
  78. hologram.SetIsCollidingGPlot(true);
  79. }
  80. override void DropDuringPlacing(PlayerBase player)
  81. {
  82. }
  83. override void OnFinishProgressClient(ActionData action_data)
  84. {
  85. PlaceObjectActionData poActionData;
  86. poActionData = PlaceObjectActionData.Cast(action_data);
  87. poActionData.m_AlreadyPlaced = true;
  88. }
  89. override void OnFinishProgressServer(ActionData action_data)
  90. {
  91. PlaceObjectActionData poActionData;
  92. poActionData = PlaceObjectActionData.Cast(action_data);
  93. EntityAI entity_for_placing = action_data.m_MainItem;
  94. vector position = action_data.m_Player.GetLocalProjectionPosition();
  95. vector orientation = action_data.m_Player.GetLocalProjectionOrientation();
  96. if (GetGame().IsMultiplayer())
  97. {
  98. m_GardenPlot = GardenPlot.Cast(action_data.m_Player.GetHologramServer().PlaceEntity(entity_for_placing));
  99. m_GardenPlot.SetOrientation(orientation);
  100. action_data.m_Player.GetHologramServer().CheckPowerSource();
  101. action_data.m_Player.PlacingCompleteServer();
  102. m_GardenPlot.OnPlacementComplete(action_data.m_Player);
  103. }
  104. //local singleplayer
  105. if (!GetGame().IsMultiplayer())
  106. {
  107. m_GardenPlot = GardenPlot.Cast(action_data.m_Player.GetHologramLocal().PlaceEntity(entity_for_placing));
  108. m_GardenPlot.SetOrientation(orientation);
  109. action_data.m_Player.PlacingCompleteServer();
  110. action_data.m_Player.PlacingCompleteLocal();
  111. m_GardenPlot.OnPlacementComplete(action_data.m_Player);
  112. }
  113. GetGame().ClearJuncture(action_data.m_Player, entity_for_placing);
  114. action_data.m_MainItem.SetIsBeingPlaced(false);
  115. poActionData.m_AlreadyPlaced = true;
  116. MiscGameplayFunctions.DealEvinronmentAdjustedDmg(action_data.m_MainItem, action_data.m_Player, 10);
  117. }
  118. };