actiontakearrow.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. class ActionTakeArrow: ActionTakeItem
  2. {
  3. void ActionTakeArrow()
  4. {
  5. m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_PICKUP_HANDS;
  6. m_Text = "#take";
  7. }
  8. override void CreateConditionComponents()
  9. {
  10. m_ConditionItem = new CCINone();
  11. m_ConditionTarget = new CCTObject(UAMaxDistances.DEFAULT);
  12. }
  13. override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
  14. {
  15. EntityAI targetEntity = EntityAI.Cast(target.GetObject());
  16. if (!targetEntity || (targetEntity && targetEntity.IsManagingArrows() && !targetEntity.IsDamageDestroyed()))
  17. return false;
  18. ArrowManagerBase arrowManager = targetEntity.GetArrowManager();
  19. if (arrowManager)
  20. {
  21. ItemBase arrow = ItemBase.Cast(arrowManager.GetFirstArrow());
  22. if (arrow)
  23. {
  24. if (player.GetInventory().CanAddEntityIntoInventory(arrow))
  25. return true;
  26. }
  27. }
  28. return false;
  29. }
  30. override Object GetDisplayInteractObject(PlayerBase player, ActionTarget target)
  31. {
  32. EntityAI targetEntity = EntityAI.Cast(target.GetObject());
  33. if (!targetEntity || (targetEntity && targetEntity.IsManagingArrows() && !targetEntity.IsDamageDestroyed()))
  34. return null;
  35. ArrowManagerBase arrowManager = targetEntity.GetArrowManager();
  36. if (arrowManager)
  37. {
  38. return arrowManager.GetFirstArrow();
  39. }
  40. return null;
  41. }
  42. override bool CanBeUsedOnBack()
  43. {
  44. return false;
  45. }
  46. override bool InventoryReservation(ActionData action_data)
  47. {
  48. bool success = true;
  49. InventoryLocation il = new InventoryLocation();
  50. EntityAI targetEntity;
  51. if (EntityAI.CastTo(targetEntity, action_data.m_Target.GetObject()))
  52. {
  53. ArrowManagerBase arrowManager = targetEntity.GetArrowManager();
  54. if (arrowManager)
  55. {
  56. ItemBase targetArrow = ItemBase.Cast(arrowManager.GetFirstArrow());
  57. if (targetArrow)
  58. {
  59. action_data.m_Player.GetInventory().FindFreeLocationFor(targetArrow , FindInventoryLocationType.ANY, il);
  60. if (action_data.m_Player.GetInventory().HasInventoryReservation(targetArrow, il))
  61. {
  62. success = false;
  63. }
  64. else
  65. {
  66. action_data.m_Player.GetInventory().AddInventoryReservationEx(targetArrow, il, GameInventory.c_InventoryReservationTimeoutMS);
  67. }
  68. }
  69. }
  70. }
  71. if (success)
  72. {
  73. if (il)
  74. action_data.m_ReservedInventoryLocations.Insert(il);
  75. }
  76. return success;
  77. }
  78. override void OnExecute(ActionData action_data)
  79. {
  80. if (GetGame().IsDedicatedServer())
  81. {
  82. ClearActionJuncture(action_data);
  83. return;
  84. }
  85. InventoryLocation il = action_data.m_ReservedInventoryLocations.Get(0);
  86. ClearInventoryReservationEx(action_data);
  87. ItemBase arrow = ItemBase.Cast(il.GetItem());
  88. InventoryLocation arrowInventoryLocation = new InventoryLocation;
  89. arrow.GetInventory().GetCurrentInventoryLocation(arrowInventoryLocation);
  90. float stackable = arrow.GetTargetQuantityMax(il.GetSlot());
  91. if ( stackable == 0 || stackable >= arrow.GetQuantity() )
  92. {
  93. action_data.m_Player.PredictiveTakeToDst(arrowInventoryLocation, il);
  94. }
  95. else
  96. {
  97. arrow.SplitIntoStackMaxToInventoryLocationClient( il );
  98. }
  99. }
  100. }