actioncreategreenhousegardenplot.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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() || player.GetInColdArea() )
  31. return false;
  32. Object target_object = target.GetObject();
  33. Land_Misc_Greenhouse greenHouse = Land_Misc_Greenhouse.Cast( target_object );
  34. Land_Misc_Polytunnel polytunnel = Land_Misc_Polytunnel.Cast( target_object) ;
  35. if ( target_object && ( greenHouse || polytunnel ) )
  36. {
  37. string action_selection = target_object.GetActionComponentName( target.GetComponentIndex() );
  38. //Update selections in model, name the desired part Soil to improve action condition check
  39. if ( action_selection != "soil" )
  40. return false;
  41. //check if there is any gardenplot objects in the current building
  42. ref array<Object> nearest_objects = new array<Object>;
  43. ref array<CargoBase> proxy_cargos = new array<CargoBase>;
  44. vector pos = target_object.GetPosition();
  45. pos[1] = pos[1] - 1; //Lower by one meter for check if plot already present
  46. GetGame().GetObjectsAtPosition3D( pos, 2, nearest_objects, proxy_cargos );
  47. for ( int i = 0; i < nearest_objects.Count(); ++i )
  48. {
  49. Object object = nearest_objects.Get( i );
  50. if ( object.IsInherited( GardenPlot ) )
  51. {
  52. return false;
  53. }
  54. }
  55. return true;
  56. }
  57. return false;
  58. }
  59. override void OnFinishProgressServer( ActionData action_data )
  60. {
  61. PlaceObjectActionData poActionData;
  62. poActionData = PlaceObjectActionData.Cast(action_data);
  63. EntityAI entity_for_placing = action_data.m_MainItem;
  64. Object targetObject = action_data.m_Target.GetObject();
  65. vector position = targetObject.GetPosition();
  66. //Depending on where we dig the required height offset is not the same
  67. Land_Misc_Greenhouse greenHouse = Land_Misc_Greenhouse.Cast( targetObject );
  68. Land_Misc_Polytunnel polytunnel = Land_Misc_Polytunnel.Cast( targetObject) ;
  69. if ( polytunnel )
  70. position[1] = position[1] - 1.15; //Lower Y position by roughly 1 meter to compensate for spawning location offset
  71. else
  72. position[1] = position[1] - 1.05;
  73. vector orientation = targetObject.GetOrientation();
  74. if ( GetGame().IsMultiplayer() )
  75. {
  76. Land_Misc_Polytunnel tunnel = Land_Misc_Polytunnel.Cast(action_data.m_Target.GetObject());
  77. if (tunnel)
  78. {
  79. m_GardenPlot = GardenPlot.Cast( GetGame().CreateObjectEx( "GardenPlotPolytunnel", position, ECE_KEEPHEIGHT ) );
  80. }
  81. else
  82. {
  83. m_GardenPlot = GardenPlot.Cast( GetGame().CreateObjectEx( "GardenPlotGreenhouse", position, ECE_KEEPHEIGHT ) );
  84. }
  85. m_GardenPlot.SetOrientation( orientation );
  86. }
  87. }
  88. override bool IsLockTargetOnUse()
  89. {
  90. return false;
  91. }
  92. }