actiongetintransport.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. class ActionGetInTransport: ActionBase
  2. {
  3. void ActionGetInTransport()
  4. {
  5. m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_ERECT;
  6. m_Text = "#get_in_vehicle";
  7. }
  8. override void CreateConditionComponents()
  9. {
  10. m_ConditionItem = new CCINone;
  11. m_ConditionTarget = new CCTCursorNoRuinCheck;
  12. }
  13. override typename GetInputType()
  14. {
  15. return ContinuousInteractActionInput;
  16. }
  17. override bool HasProgress()
  18. {
  19. return false;
  20. }
  21. override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
  22. {
  23. Transport trans = null;
  24. if (!target)
  25. {
  26. return false;
  27. }
  28. if (!Class.CastTo(trans, target.GetObject()))
  29. {
  30. return false;
  31. }
  32. if (player.GetItemInHands() && player.GetItemInHands().IsHeavyBehaviour())
  33. {
  34. return false;
  35. }
  36. if (player.GetCommand_Vehicle())
  37. {
  38. return false;
  39. }
  40. int componentIndex = target.GetComponentIndex();
  41. int crew_index = trans.CrewPositionIndex(componentIndex);
  42. if (crew_index < 0)
  43. {
  44. return false;
  45. }
  46. Human crew = trans.CrewMember(crew_index);
  47. if (crew)
  48. {
  49. return false;
  50. }
  51. if (!trans.CrewCanGetThrough(crew_index) || !trans.IsAreaAtDoorFree(crew_index))
  52. {
  53. return false;
  54. }
  55. array<string> selections = new array<string>();
  56. trans.GetActionComponentNameList(componentIndex, selections);
  57. for (int i = 0; i < selections.Count(); i++)
  58. {
  59. if (trans.CanReachSeatFromDoors(selections[i], player.GetPosition(), 1.0))
  60. {
  61. return true;
  62. }
  63. }
  64. return false;
  65. }
  66. override void Start(ActionData action_data)
  67. {
  68. super.Start( action_data );
  69. Transport trans = Transport.Cast(action_data.m_Target.GetObject());
  70. int componentIndex = action_data.m_Target.GetComponentIndex();
  71. int crew_index = trans.CrewPositionIndex(componentIndex);
  72. int seat = trans.GetSeatAnimationType(crew_index);
  73. HumanCommandVehicle vehCommand = action_data.m_Player.StartCommand_Vehicle(trans, crew_index, seat);
  74. if (vehCommand)
  75. {
  76. vehCommand.SetVehicleType(trans.GetAnimInstance());
  77. GetDayZGame().GetBacklit().OnEnterCar();
  78. }
  79. }
  80. override void OnStartServer(ActionData action_data)
  81. {
  82. super.OnStartServer(action_data);
  83. CarScript car = CarScript.Cast(action_data.m_Target.GetObject());
  84. if (car)
  85. {
  86. car.ForceUpdateLightsStart();
  87. }
  88. }
  89. override bool CanBeUsedInRestrain()
  90. {
  91. return true;
  92. }
  93. override void OnUpdate(ActionData action_data)
  94. {
  95. if (action_data.m_State == UA_START)
  96. {
  97. if (!action_data.m_Player.GetCommand_Vehicle() || !action_data.m_Player.GetCommand_Vehicle().IsGettingIn())
  98. {
  99. End(action_data);
  100. }
  101. }
  102. }
  103. override int GetActionCategory()
  104. {
  105. return AC_INTERACT;
  106. }
  107. override void OnEnd(ActionData action_data)
  108. {
  109. CarScript car = CarScript.Cast(action_data.m_Target.GetObject());
  110. if (car && GetGame().IsServer())
  111. {
  112. car.ForceUpdateLightsEnd();
  113. }
  114. }
  115. override bool AddActionJuncture(ActionData action_data)
  116. {
  117. Transport trans = Transport.Cast(action_data.m_Target.GetObject());
  118. bool accepted = false;
  119. int nextSeat = trans.CrewPositionIndex( action_data.m_Target.GetComponentIndex() );
  120. Transport transport = Transport.Cast(action_data.m_Target.GetObject());
  121. InventoryLocation il = new InventoryLocation;
  122. if (transport)
  123. {
  124. il.SetVehicle(transport, action_data.m_Player, nextSeat);
  125. //Lock target
  126. if (GetGame().AddInventoryJunctureEx(action_data.m_Player, action_data.m_Player, il, true, 10000))
  127. {
  128. accepted = true;
  129. action_data.m_ReservedInventoryLocations.Insert(il);
  130. }
  131. }
  132. return accepted;
  133. }
  134. };