actionswitchseats.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. class ActionSwitchSeats: ActionBase
  2. {
  3. void ActionSwitchSeats()
  4. {
  5. //m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_STARTENGINE;
  6. m_StanceMask = DayZPlayerConstants.STANCEMASK_ALL;
  7. m_SpecialtyWeight = 1.0;
  8. m_LockTargetOnUse = false;
  9. m_Text = "#change_seat";
  10. }
  11. override void CreateConditionComponents()
  12. {
  13. m_ConditionItem = new CCINone;
  14. m_ConditionTarget = new CCTObject;
  15. }
  16. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  17. {
  18. Transport trans = null;
  19. int nextSeatIdx = -1;
  20. HumanCommandVehicle vehCommand = player.GetCommand_Vehicle();
  21. if ( !vehCommand )
  22. return false;
  23. int componentIndex = target.GetComponentIndex();
  24. if ( !target )
  25. return false;
  26. if ( !Class.CastTo(trans, target.GetObject()) )
  27. return false;
  28. nextSeatIdx = trans.CrewPositionIndex( componentIndex );
  29. if ( nextSeatIdx < 0 )
  30. return false;
  31. Human crew = trans.CrewMember( nextSeatIdx );
  32. if ( crew )
  33. return false;
  34. if ( !trans.CanReachSeatFromSeat( trans.CrewMemberIndex( player ), nextSeatIdx ) )
  35. return false;
  36. return true;
  37. }
  38. override void OnStart(ActionData action_data)
  39. {
  40. super.OnStart(action_data);
  41. HumanCommandVehicle vehCommand = action_data.m_Player.GetCommand_Vehicle();
  42. if ( vehCommand )
  43. {
  44. Transport trans;
  45. if ( Class.CastTo(trans, action_data.m_Target.GetObject()) )
  46. {
  47. int nextSeat = trans.CrewPositionIndex( action_data.m_Target.GetComponentIndex() );
  48. int seat = trans.GetSeatAnimationType( nextSeat );
  49. if ( seat >= 0 )
  50. {
  51. //pTransportPositionIndex, int pVehicleSeat
  52. vehCommand.SwitchSeat( nextSeat, seat );
  53. action_data.m_Player.OnVehicleSwitchSeat( nextSeat );
  54. }
  55. }
  56. }
  57. }
  58. override void OnUpdate(ActionData action_data)
  59. {
  60. if(action_data.m_State == UA_START)
  61. {
  62. HumanCommandVehicle hcv = action_data.m_Player.GetCommand_Vehicle();
  63. if( !hcv || !action_data.m_Player.GetCommand_Vehicle().IsSwitchSeat() )
  64. {
  65. End(action_data);
  66. }
  67. }
  68. }
  69. override bool CanBeUsedInVehicle()
  70. {
  71. return true;
  72. }
  73. override bool AddActionJuncture(ActionData action_data)
  74. {
  75. Transport trans = Transport.Cast(action_data.m_Target.GetObject());
  76. bool accepted = false;
  77. int currSeat = trans.CrewMemberIndex(action_data.m_Player);
  78. int nextSeat = trans.CrewPositionIndex( action_data.m_Target.GetComponentIndex() );
  79. Transport transport = Transport.Cast(action_data.m_Target.GetObject());
  80. InventoryLocation il = new InventoryLocation;
  81. if (transport)
  82. {
  83. il.SetVehicle(transport, action_data.m_Player, nextSeat);
  84. //Lock target
  85. if (GetGame().AddInventoryJunctureEx(action_data.m_Player, action_data.m_Player, il, true, 10000))
  86. {
  87. accepted = true;
  88. action_data.m_ReservedInventoryLocations.Insert(il);
  89. }
  90. if(accepted)
  91. {
  92. il.SetVehicle(transport, action_data.m_Player, currSeat);
  93. if (GetGame().AddInventoryJunctureEx(action_data.m_Player, action_data.m_Player, il, true, 10000))
  94. {
  95. action_data.m_ReservedInventoryLocations.Insert(il);
  96. }
  97. else
  98. {
  99. ClearActionJuncture(action_data);
  100. accepted = false;
  101. }
  102. }
  103. }
  104. return accepted;
  105. }
  106. };