actionharvestcrops.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. class ActionHarvestCropsCB : ActionContinuousBaseCB
  2. {
  3. override void CreateActionComponent()
  4. {
  5. m_ActionData.m_ActionComponent = new CAContinuousTime(UATimeSpent.DEFAULT_HARVEST);
  6. }
  7. };
  8. class ActionHarvestCrops: ActionContinuousBase
  9. {
  10. PlantBase m_Plant;
  11. void ActionHarvestCrops()
  12. {
  13. m_CallbackClass = ActionHarvestCropsCB;
  14. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_INTERACT;
  15. m_FullBody = true;
  16. m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH;
  17. }
  18. override typename GetInputType()
  19. {
  20. return ContinuousInteractActionInput;
  21. }
  22. Slot GetPlantSlot(ActionTarget target)
  23. {
  24. GardenBase garden_base;
  25. if ( Class.CastTo(garden_base, target.GetObject()))
  26. {
  27. Slot slot;
  28. array<string> selections = new array<string>;
  29. garden_base.GetActionComponentNameList(target.GetComponentIndex(), selections);
  30. string selection;
  31. for (int s = 0; s < selections.Count(); s++)
  32. {
  33. selection = selections[s];
  34. slot = garden_base.GetSlotBySelection( selection );
  35. if (slot)
  36. break;
  37. }
  38. if ( slot && slot.GetPlant() )
  39. {
  40. return slot;
  41. }
  42. }
  43. return null;
  44. }
  45. override void OnActionInfoUpdate( PlayerBase player, ActionTarget target, ItemBase item )
  46. {
  47. m_Text = "#harvest";
  48. Slot slot = GetPlantSlot(target);
  49. if (slot)
  50. {
  51. m_Plant = PlantBase.Cast(slot.GetPlant());
  52. m_Text+= " " + MiscGameplayFunctions.GetItemDisplayName(m_Plant.GetCropsType());
  53. }
  54. }
  55. override void CreateConditionComponents()
  56. {
  57. m_ConditionItem = new CCINone;
  58. m_ConditionTarget = new CCTCursor(UAMaxDistances.SMALL);
  59. }
  60. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  61. {
  62. GardenBase garden_base;
  63. if ( Class.CastTo(garden_base, target.GetObject()))
  64. {
  65. Slot slot = GetPlantSlot(target);
  66. if (slot)
  67. {
  68. m_Plant = PlantBase.Cast(slot.GetPlant());
  69. if ( m_Plant && m_Plant.IsHarvestable())
  70. return true;
  71. }
  72. }
  73. return false;
  74. }
  75. override void OnFinishProgressServer( ActionData action_data )
  76. {
  77. if ( m_Plant )
  78. {
  79. m_Plant.Harvest( action_data.m_Player );
  80. }
  81. }
  82. };