actioncreategreenhousegardenplot.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. class ActionCreateGreenhouseGardenPlotCB : ActionContinuousBaseCB
  2. {
  3. override void CreateActionComponent()
  4. {
  5. m_ActionData.m_ActionComponent = new CAContinuousTime(UATimeSpent.DIG_GARDEN);
  6. }
  7. };
  8. class ActionCreateGreenhouseGardenPlot: ActionContinuousBase
  9. {
  10. GardenPlot m_GardenPlot;
  11. private const float CAMERA_PITCH_THRESHOLD = -30;
  12. void ActionCreateGreenhouseGardenPlot()
  13. {
  14. m_CallbackClass = ActionCreateGreenhouseGardenPlotCB;
  15. m_FullBody = true;
  16. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DIGMANIPULATE;
  17. m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT;
  18. m_SpecialtyWeight = UASoftSkillsWeight.ROUGH_LOW;
  19. m_Text = "#make_garden_plot";
  20. }
  21. override void CreateConditionComponents()
  22. {
  23. m_ConditionItem = new CCINonRuined;
  24. m_ConditionTarget = new CCTCursor;
  25. }
  26. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  27. {
  28. if ( !target )
  29. return false;
  30. if ( player.IsPlacingLocal() )
  31. return false;
  32. if (!CfgGameplayHandler.GetDisableColdAreaPlacementCheck() && player.GetInColdArea())
  33. return false;
  34. Object target_object = target.GetObject();
  35. Land_Misc_Greenhouse greenHouse = Land_Misc_Greenhouse.Cast( target_object );
  36. Land_Misc_Polytunnel polytunnel = Land_Misc_Polytunnel.Cast( target_object) ;
  37. if ( target_object && ( greenHouse || polytunnel ) )
  38. {
  39. string action_selection = target_object.GetActionComponentName( target.GetComponentIndex() );
  40. //Update selections in model, name the desired part Soil to improve action condition check
  41. if ( action_selection != "soil" )
  42. return false;
  43. //check if there is any gardenplot objects in the current building
  44. ref array<Object> nearest_objects = new array<Object>;
  45. ref array<CargoBase> proxy_cargos = new array<CargoBase>;
  46. vector pos = target_object.GetPosition();
  47. pos[1] = pos[1] - 1; //Lower by one meter for check if plot already present
  48. GetGame().GetObjectsAtPosition3D( pos, 2, nearest_objects, proxy_cargos );
  49. for ( int i = 0; i < nearest_objects.Count(); ++i )
  50. {
  51. Object object = nearest_objects.Get( i );
  52. if ( object.IsInherited( GardenPlot ) )
  53. {
  54. return false;
  55. }
  56. }
  57. return true;
  58. }
  59. return false;
  60. }
  61. override void OnFinishProgressServer( ActionData action_data )
  62. {
  63. PlaceObjectActionData poActionData;
  64. poActionData = PlaceObjectActionData.Cast(action_data);
  65. EntityAI entity_for_placing = action_data.m_MainItem;
  66. Object targetObject = action_data.m_Target.GetObject();
  67. vector position = targetObject.GetPosition();
  68. //Depending on where we dig the required height offset is not the same
  69. Land_Misc_Greenhouse greenHouse = Land_Misc_Greenhouse.Cast( targetObject );
  70. Land_Misc_Polytunnel polytunnel = Land_Misc_Polytunnel.Cast( targetObject) ;
  71. if ( polytunnel )
  72. position[1] = position[1] - 1.15; //Lower Y position by roughly 1 meter to compensate for spawning location offset
  73. else
  74. position[1] = position[1] - 1.05;
  75. vector orientation = targetObject.GetOrientation();
  76. if ( GetGame().IsMultiplayer() )
  77. {
  78. Land_Misc_Polytunnel tunnel = Land_Misc_Polytunnel.Cast(action_data.m_Target.GetObject());
  79. if (tunnel)
  80. {
  81. m_GardenPlot = GardenPlot.Cast( GetGame().CreateObjectEx( "GardenPlotPolytunnel", position, ECE_KEEPHEIGHT ) );
  82. }
  83. else
  84. {
  85. m_GardenPlot = GardenPlot.Cast( GetGame().CreateObjectEx( "GardenPlotGreenhouse", position, ECE_KEEPHEIGHT ) );
  86. }
  87. m_GardenPlot.SetOrientation( orientation );
  88. }
  89. }
  90. override bool IsLockTargetOnUse()
  91. {
  92. return false;
  93. }
  94. }