actiontakehybridattachment.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //!DEPRECATED
  2. class ActionTakeHybridAttachment: ActionInteractBase
  3. {
  4. string m_ItemName = "";
  5. void ActionTakeHybridAttachment()
  6. {
  7. m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_PICKUP_INVENTORY;
  8. m_CommandUIDProne = DayZPlayerConstants.CMD_ACTIONFB_PICKUP_INVENTORY;
  9. m_Text = "#take";
  10. }
  11. override void CreateConditionComponents()
  12. {
  13. m_ConditionItem = new CCINone;
  14. m_ConditionTarget = new CCTCursor;
  15. }
  16. override bool HasProneException()
  17. {
  18. return true;
  19. }
  20. override bool ActionConditionContinue( ActionData action_data )
  21. {
  22. return true;
  23. }
  24. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  25. {
  26. EntityAI tgt_entity = EntityAI.Cast( target.GetObject() );
  27. if ( tgt_entity && BaseBuildingBase.Cast(tgt_entity) &&!tgt_entity.IsBeingPlaced() )
  28. {
  29. string component_name = tgt_entity.GetActionComponentName( target.GetComponentIndex() );
  30. /*if (!tgt_entity.GetInventory().HasInventorySlot(InventorySlots.GetSlotIdFromString(component_name)))
  31. return false;*/
  32. ItemBase attachment = ItemBase.Cast(tgt_entity.FindAttachmentBySlotName(component_name));
  33. if ( attachment && player.GetInventory().CanAddEntityIntoInventory(attachment) && attachment.IsTakeable() )
  34. {
  35. return true;
  36. }
  37. }
  38. return false;
  39. }
  40. override bool CanBeUsedOnBack()
  41. {
  42. return true;
  43. }
  44. override bool InventoryReservation(ActionData action_data)
  45. {
  46. bool success = true;
  47. InventoryLocation il = new InventoryLocation;
  48. EntityAI tgt_entity = EntityAI.Cast( action_data.m_Target.GetObject() );
  49. string component_name = tgt_entity.GetActionComponentName( action_data.m_Target.GetComponentIndex() );
  50. ItemBase attachment;
  51. if ( tgt_entity && ItemBase.CastTo(attachment, tgt_entity.FindAttachmentBySlotName(component_name)) )
  52. {
  53. action_data.m_Player.GetInventory().FindFreeLocationFor( attachment , FindInventoryLocationType.ANY, il );
  54. if ( action_data.m_Player.GetInventory().HasInventoryReservation( attachment, il) )
  55. {
  56. success = false;
  57. }
  58. else
  59. {
  60. action_data.m_Player.GetInventory().AddInventoryReservationEx( attachment, il, GameInventory.c_InventoryReservationTimeoutMS);
  61. }
  62. }
  63. if ( success )
  64. {
  65. if( il )
  66. action_data.m_ReservedInventoryLocations.Insert(il);
  67. }
  68. return success;
  69. }
  70. override void OnExecute( ActionData action_data )
  71. {
  72. if (GetGame().IsDedicatedServer())
  73. {
  74. ClearActionJuncture(action_data);
  75. return;
  76. }
  77. //Debug.Log("[Action DEBUG] Start time stamp: " + action_data.m_Player.GetSimulationTimeStamp());
  78. EntityAI tgt_entity = EntityAI.Cast( action_data.m_Target.GetObject() );
  79. string component_name = tgt_entity.GetActionComponentName( action_data.m_Target.GetComponentIndex() );
  80. ItemBase attachment;
  81. if ( tgt_entity && ItemBase.CastTo(attachment, tgt_entity.FindAttachmentBySlotName(component_name)) )
  82. {
  83. InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
  84. InventoryLocation targetInventoryLocation = new InventoryLocation;
  85. attachment.GetInventory().GetCurrentInventoryLocation(targetInventoryLocation);
  86. ClearInventoryReservationEx(action_data);
  87. //SplitItemUtils.TakeOrSplitToInventoryLocation( action_data.m_Player, il );
  88. float stackable = attachment.GetTargetQuantityMax(il.GetSlot());
  89. if( stackable == 0 || stackable >= attachment.GetQuantity() )
  90. {
  91. action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
  92. }
  93. else
  94. {
  95. attachment.SplitIntoStackMaxToInventoryLocationClient( il );
  96. }
  97. }
  98. //action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
  99. }
  100. };