actionremoveseed.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. class ActionRemoveSeed: ActionInteractBase
  2. {
  3. SeedBase m_Seed;
  4. void ActionRemoveSeed()
  5. {
  6. m_Text = "#take";
  7. }
  8. override typename GetInputType()
  9. {
  10. return ContinuousInteractActionInput;
  11. }
  12. override void CreateConditionComponents()
  13. {
  14. m_ConditionItem = new CCINone;
  15. m_ConditionTarget = new CCTCursor(UAMaxDistances.SMALL);
  16. }
  17. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  18. {
  19. if ( player.GetCommand_Vehicle() )
  20. return false;
  21. GardenBase garden_base;
  22. if ( Class.CastTo( garden_base, target.GetObject() ) )
  23. {
  24. Slot slot;
  25. array<string> selections = new array<string>;
  26. garden_base.GetActionComponentNameList( target.GetComponentIndex(), selections );
  27. string selection;
  28. for (int s = 0; s < selections.Count(); s++)
  29. {
  30. selection = selections[s];
  31. slot = garden_base.GetSlotBySelection( selection );
  32. if ( slot )
  33. break;
  34. }
  35. //Can only remove seed if slot is not watered to prevent VME
  36. if ( slot && slot.GetSeed() )
  37. {
  38. if ( slot.GetWateredState() != 0 )
  39. return false;
  40. m_Seed = SeedBase.Cast( slot.GetSeed() );
  41. if ( m_Seed )
  42. {
  43. if ( player.GetInventory().CanAddEntityIntoInventory( m_Seed ) && m_Seed.GetHierarchyRootPlayer() != player )
  44. return true;
  45. else
  46. return player.GetInventory().CanAddEntityIntoHands( m_Seed );
  47. }
  48. }
  49. }
  50. return false;
  51. }
  52. override bool InventoryReservation(ActionData action_data)
  53. {
  54. bool success = true;
  55. InventoryLocation il = new InventoryLocation;
  56. if ( m_Seed )
  57. {
  58. action_data.m_Player.GetInventory().FindFreeLocationFor( m_Seed , FindInventoryLocationType.ANY, il );
  59. if ( action_data.m_Player.GetInventory().HasInventoryReservation( m_Seed, il ) )
  60. {
  61. success = false;
  62. }
  63. else
  64. {
  65. action_data.m_Player.GetInventory().AddInventoryReservationEx( m_Seed, il, GameInventory.c_InventoryReservationTimeoutMS );
  66. }
  67. }
  68. if ( success )
  69. {
  70. if ( il )
  71. action_data.m_ReservedInventoryLocations.Insert( il );
  72. }
  73. return success;
  74. }
  75. override void OnExecuteClient(ActionData action_data)
  76. {
  77. super.OnExecuteClient(action_data);
  78. PlayerBase player = action_data.m_Player;
  79. float stackable;
  80. InventoryLocation il;
  81. //We place in inventory
  82. if ( !player.GetInventory().CanAddEntityIntoHands( m_Seed ) )
  83. {
  84. il = action_data.m_ReservedInventoryLocations.Get( 0 );
  85. InventoryLocation targetInventoryLocation = new InventoryLocation;
  86. m_Seed.GetInventory().GetCurrentInventoryLocation( targetInventoryLocation );
  87. stackable = m_Seed.GetTargetQuantityMax( il.GetSlot() );
  88. ClearInventoryReservationEx(action_data);
  89. if ( stackable == 0 || stackable >= m_Seed.GetQuantity() )
  90. {
  91. player.PredictiveTakeToDst( targetInventoryLocation, il );
  92. }
  93. else
  94. {
  95. m_Seed.SplitIntoStackMaxToInventoryLocationClient( il );
  96. }
  97. }
  98. else
  99. {
  100. //We place in hands
  101. ClearInventoryReservationEx(action_data);
  102. stackable = m_Seed.GetTargetQuantityMax( -1 );
  103. if ( stackable == 0 || stackable >= m_Seed.GetQuantity() )
  104. {
  105. action_data.m_Player.PredictiveTakeEntityToHands( m_Seed );
  106. }
  107. else
  108. {
  109. il = new InventoryLocation;
  110. il.SetHands( action_data.m_Player, m_Seed );
  111. m_Seed.SplitIntoStackMaxToInventoryLocationClient( il );
  112. }
  113. }
  114. }
  115. };