actiontakeitem.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*class ActionTakeItemReciveData : ActionReciveData
  2. {
  3. ref InventoryLocation m_InventoryLocation;
  4. }*/
  5. class ActionTakeItem: ActionInteractBase
  6. {
  7. string m_ItemName = "";
  8. void ActionTakeItem()
  9. {
  10. m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_PICKUP_INVENTORY;
  11. m_CommandUIDProne = DayZPlayerConstants.CMD_ACTIONFB_PICKUP_INVENTORY;
  12. m_Text = "#take";
  13. }
  14. override void CreateConditionComponents()
  15. {
  16. m_ConditionItem = new CCINone;
  17. m_ConditionTarget = new CCTObject(UAMaxDistances.DEFAULT);
  18. }
  19. override bool HasProneException()
  20. {
  21. return true;
  22. }
  23. override bool ActionConditionContinue( ActionData action_data )
  24. {
  25. return true;
  26. }
  27. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  28. {
  29. ItemBase tgt_item = ItemBase.Cast( target.GetObject() );
  30. if ( tgt_item && !tgt_item.IsTakeable() ) return false;
  31. if ( tgt_item && tgt_item.IsBeingPlaced() ) return false;
  32. EntityAI tgt_parent = EntityAI.Cast( target.GetParent() );
  33. EntityAI tgt_entity = EntityAI.Cast( target.GetObject() );
  34. if ( tgt_entity && (!tgt_parent || BaseBuildingBase.Cast(tgt_parent)) )
  35. {
  36. if ( tgt_entity && tgt_entity.IsItemBase() && player.GetInventory().CanAddEntityIntoInventory(tgt_entity) && tgt_entity.GetHierarchyRootPlayer() != player )
  37. {
  38. if ( tgt_parent && (!tgt_item.CanDetachAttachment(tgt_parent) || !tgt_parent.CanReleaseAttachment(tgt_item)) )
  39. return false;
  40. return true;
  41. }
  42. }
  43. return false;
  44. }
  45. override bool CanBeUsedOnBack()
  46. {
  47. return true;
  48. }
  49. /*override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
  50. {
  51. super.WriteToContext(ctx, action_data);
  52. InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
  53. il.WriteToContext(ctx);
  54. }
  55. override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data )
  56. {
  57. if(!action_recive_data)
  58. {
  59. action_recive_data = new ActionTakeItemReciveData;
  60. }
  61. if(super.ReadFromContext(ctx, action_recive_data))
  62. {
  63. ActionTakeItemReciveData recive_data_ti = ActionTakeItemReciveData.Cast(action_recive_data);
  64. recive_data_ti.m_InventoryLocation = new InventoryLocation;
  65. if(recive_data_ti.m_InventoryLocation.ReadFromContext(ctx))
  66. {
  67. return true;
  68. }
  69. }
  70. return false;
  71. }
  72. override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
  73. {
  74. super.HandleReciveData(action_recive_data, action_data);
  75. ActionTakeItemReciveData recive_data_ti = ActionTakeItemReciveData.Cast(action_recive_data);
  76. action_data.m_ReservedInventoryLocations.Insert(recive_data_ti.m_InventoryLocation);
  77. } */
  78. override bool InventoryReservation(ActionData action_data)
  79. {
  80. bool success = true;
  81. InventoryLocation il = new InventoryLocation;
  82. ItemBase targetItem;
  83. if ( ItemBase.CastTo(targetItem, action_data.m_Target.GetObject()) )
  84. {
  85. action_data.m_Player.GetInventory().FindFreeLocationFor( targetItem , FindInventoryLocationType.ANY, il );
  86. if ( action_data.m_Player.GetInventory().HasInventoryReservation( targetItem, il) )
  87. {
  88. success = false;
  89. }
  90. else
  91. {
  92. action_data.m_Player.GetInventory().AddInventoryReservationEx( targetItem, il, GameInventory.c_InventoryReservationTimeoutMS);
  93. }
  94. }
  95. if ( success )
  96. {
  97. if( il )
  98. action_data.m_ReservedInventoryLocations.Insert(il);
  99. }
  100. return success;
  101. }
  102. override void OnExecute(ActionData action_data)
  103. {
  104. if (GetGame().IsDedicatedServer())
  105. {
  106. ClearActionJuncture(action_data);
  107. return;
  108. }
  109. //Debug.Log("[Action DEBUG] Start time stamp: " + action_data.m_Player.GetSimulationTimeStamp());
  110. ItemBase ntarget = ItemBase.Cast(action_data.m_Target.GetObject());
  111. InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
  112. InventoryLocation targetInventoryLocation = new InventoryLocation;
  113. ntarget.GetInventory().GetCurrentInventoryLocation(targetInventoryLocation);
  114. ClearInventoryReservationEx(action_data);
  115. //SplitItemUtils.TakeOrSplitToInventoryLocation( action_data.m_Player, il );
  116. float stackable = ntarget.GetTargetQuantityMax(il.GetSlot());
  117. if( stackable == 0 || stackable >= ntarget.GetQuantity() )
  118. {
  119. action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
  120. }
  121. else
  122. {
  123. ClearInventoryReservationEx(action_data);
  124. ntarget.SplitIntoStackMaxToInventoryLocationClient( il );
  125. }
  126. //action_data.m_Player.PredictiveTakeToDst(targetInventoryLocation, il);
  127. }
  128. };