actionattachwithswich.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. class ActionAttachWithSwitch: ActionAttach
  2. {
  3. void ActionAttachWithSwitch()
  4. {
  5. }
  6. override void CreateConditionComponents()
  7. {
  8. m_ConditionItem = new CCINonRuined;
  9. m_ConditionTarget = new CCTNonRuined( UAMaxDistances.DEFAULT );
  10. m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_ATTACHITEM;
  11. m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH;
  12. }
  13. override typename GetInputType()
  14. {
  15. return InventoryOnlyActionInput;
  16. }
  17. override bool CanBePerformedFromInventory()
  18. {
  19. return true;
  20. }
  21. override ActionData CreateActionData()
  22. {
  23. AttachActionData action_data = new AttachActionData;
  24. return action_data;
  25. }
  26. override bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = NULL)
  27. {
  28. ref InventoryLocation il = new InventoryLocation;
  29. if (!GetGame().IsDedicatedServer())
  30. {
  31. EntityAI target_entity;
  32. if ( target.IsProxy() )
  33. {
  34. target_entity = EntityAI.Cast( target.GetParent() );
  35. }
  36. else
  37. {
  38. target_entity = EntityAI.Cast( target.GetObject() );
  39. }
  40. if (!target_entity.GetInventory().FindFreeLocationFor( item, FindInventoryLocationType.ATTACHMENT, il ))
  41. return false;
  42. }
  43. if ( super.SetupAction( player, target, item, action_data, extra_data))
  44. {
  45. if (!GetGame().IsDedicatedServer())
  46. {
  47. AttachActionData action_data_a = AttachActionData.Cast(action_data);
  48. action_data_a.m_AttSlot = il.GetSlot();
  49. }
  50. return true;
  51. }
  52. return false;
  53. }
  54. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  55. {
  56. EntityAI target_entity = EntityAI.Cast( target.GetObject() );
  57. if( !item.CanSwitchDuringAttach(target_entity) )
  58. return false;
  59. if ( target_entity && item )
  60. {
  61. if ( target_entity.GetInventory() && target_entity.GetInventory().CanAddAttachment( item ) )
  62. {
  63. return true;
  64. }
  65. }
  66. return false;
  67. }
  68. override void OnExecuteServer( ActionData action_data )
  69. {
  70. if (GetGame().IsMultiplayer())
  71. return;
  72. ClearInventoryReservationEx(action_data);
  73. AttachActionData action_data_a = AttachActionData.Cast(action_data);
  74. EntityAI target_EAI;
  75. if ( action_data.m_Target.IsProxy() )
  76. {
  77. target_EAI = EntityAI.Cast( action_data_a.m_Target.GetParent() );
  78. }
  79. else
  80. {
  81. target_EAI = EntityAI.Cast( action_data_a.m_Target.GetObject() );
  82. }
  83. if (target_EAI && action_data_a.m_MainItem)
  84. {
  85. ref InventoryLocation il = new InventoryLocation;
  86. il.SetAttachment( target_EAI, action_data.m_MainItem, action_data_a.m_AttSlot );
  87. action_data.m_Player.PredictiveForceSwapEntities( target_EAI, action_data.m_MainItem, il );
  88. }
  89. }
  90. override void OnExecuteClient( ActionData action_data )
  91. {
  92. ClearInventoryReservationEx(action_data);
  93. AttachActionData action_data_a = AttachActionData.Cast(action_data);
  94. EntityAI target_EAI;
  95. if ( action_data.m_Target.IsProxy() )
  96. {
  97. target_EAI = EntityAI.Cast( action_data_a.m_Target.GetParent() );
  98. }
  99. else
  100. {
  101. target_EAI = EntityAI.Cast( action_data_a.m_Target.GetObject() );
  102. }
  103. if (target_EAI && action_data_a.m_MainItem)
  104. {
  105. ref InventoryLocation il = new InventoryLocation;
  106. il.SetAttachment( target_EAI, action_data.m_MainItem, action_data_a.m_AttSlot );
  107. action_data.m_Player.PredictiveForceSwapEntities( target_EAI, action_data.m_MainItem, il );
  108. }
  109. }
  110. }