actiondiggardenplot.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 || player.GetInColdArea())
  27. return false;
  28. if (player.IsPlacingLocal())
  29. {
  30. Hologram hologram = player.GetHologramLocal();
  31. GardenPlot item_GP;
  32. Class.CastTo(item_GP, hologram.GetProjectionEntity());
  33. CheckSurfaceBelowGardenPlot(player, item_GP, hologram);
  34. if (!hologram.IsColliding())
  35. {
  36. return true;
  37. }
  38. }
  39. return false;
  40. }
  41. //Server
  42. return true;
  43. }
  44. override void SetupAnimation(ItemBase item)
  45. {
  46. if (item)
  47. {
  48. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DIG;
  49. }
  50. }
  51. void CheckSurfaceBelowGardenPlot(PlayerBase player, GardenPlot item_GP, Hologram hologram)
  52. {
  53. vector min_max[2];
  54. item_GP.GetCollisionBox(min_max);
  55. float offset = min_max[1][1] - min_max[0][1];
  56. //Print(offset);
  57. vector pos_adjusted = item_GP.GetPosition();
  58. pos_adjusted[1] = pos_adjusted[1] + offset;
  59. if (item_GP.CanBePlaced(player, /*item_GP.GetPosition()*/pos_adjusted) )
  60. {
  61. if (item_GP.CanBePlaced(NULL, item_GP.CoordToParent(hologram.GetLeftCloseProjectionVector())))
  62. {
  63. if (item_GP.CanBePlaced(NULL, item_GP.CoordToParent(hologram.GetRightCloseProjectionVector())))
  64. {
  65. if (item_GP.CanBePlaced(NULL, item_GP.CoordToParent(hologram.GetLeftFarProjectionVector())))
  66. {
  67. if (item_GP.CanBePlaced(NULL, item_GP.CoordToParent(hologram.GetRightFarProjectionVector())))
  68. {
  69. hologram.SetIsCollidingGPlot(false);
  70. return;
  71. }
  72. }
  73. }
  74. }
  75. }
  76. hologram.SetIsCollidingGPlot(true);
  77. }
  78. override void DropDuringPlacing(PlayerBase player)
  79. {
  80. }
  81. override void OnFinishProgressClient(ActionData action_data)
  82. {
  83. PlaceObjectActionData poActionData;
  84. poActionData = PlaceObjectActionData.Cast(action_data);
  85. poActionData.m_AlreadyPlaced = true;
  86. }
  87. override void OnFinishProgressServer(ActionData action_data)
  88. {
  89. PlaceObjectActionData poActionData;
  90. poActionData = PlaceObjectActionData.Cast(action_data);
  91. EntityAI entity_for_placing = action_data.m_MainItem;
  92. vector position = action_data.m_Player.GetLocalProjectionPosition();
  93. vector orientation = action_data.m_Player.GetLocalProjectionOrientation();
  94. if (GetGame().IsMultiplayer())
  95. {
  96. m_GardenPlot = GardenPlot.Cast(action_data.m_Player.GetHologramServer().PlaceEntity(entity_for_placing));
  97. m_GardenPlot.SetOrientation(orientation);
  98. action_data.m_Player.GetHologramServer().CheckPowerSource();
  99. action_data.m_Player.PlacingCompleteServer();
  100. m_GardenPlot.OnPlacementComplete(action_data.m_Player);
  101. }
  102. //local singleplayer
  103. if (!GetGame().IsMultiplayer())
  104. {
  105. m_GardenPlot = GardenPlot.Cast(action_data.m_Player.GetHologramLocal().PlaceEntity(entity_for_placing));
  106. m_GardenPlot.SetOrientation(orientation);
  107. action_data.m_Player.PlacingCompleteServer();
  108. action_data.m_Player.PlacingCompleteLocal();
  109. m_GardenPlot.OnPlacementComplete(action_data.m_Player);
  110. }
  111. GetGame().ClearJuncture(action_data.m_Player, entity_for_placing);
  112. action_data.m_MainItem.SetIsBeingPlaced(false);
  113. poActionData.m_AlreadyPlaced = true;
  114. action_data.m_MainItem.SoundSynchRemoteReset();
  115. MiscGameplayFunctions.DealEvinronmentAdjustedDmg(action_data.m_MainItem, action_data.m_Player, 10);
  116. }
  117. };