actionopendoors.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. class ActionOpenDoors: ActionInteractBase
  2. {
  3. ref NoiseParams m_NoisePar;
  4. void ActionOpenDoors()
  5. {
  6. m_CommandUID = DayZPlayerConstants.CMD_ACTIONMOD_OPENDOORFW;
  7. m_StanceMask = DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_ERECT;
  8. m_Text = "#open";
  9. }
  10. override void CreateConditionComponents()
  11. {
  12. m_ConditionItem = new CCINone();
  13. m_ConditionTarget = new CCTCursor();
  14. }
  15. protected bool CheckIfDoorIsLocked()
  16. {
  17. return true;
  18. }
  19. protected bool CreatesNoise()
  20. {
  21. return true;
  22. }
  23. override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
  24. {
  25. if (!target)
  26. return false;
  27. if (!IsBuilding(target))
  28. return false;
  29. Building building;
  30. if (Class.CastTo(building, target.GetObject()))
  31. {
  32. int doorIndex = building.GetDoorIndex(target.GetComponentIndex());
  33. if (doorIndex != -1)
  34. {
  35. if (!IsInReach(player, target, UAMaxDistances.DEFAULT))
  36. return false;
  37. return building.CanDoorBeOpened(doorIndex, CheckIfDoorIsLocked());
  38. }
  39. }
  40. return false;
  41. }
  42. override void OnStartServer(ActionData action_data)
  43. {
  44. super.OnStartServer(action_data);
  45. Building building;
  46. if (Class.CastTo(building, action_data.m_Target.GetObject()))
  47. {
  48. int doorIndex = building.GetDoorIndex(action_data.m_Target.GetComponentIndex());
  49. if (doorIndex != -1)
  50. {
  51. if (building.CanDoorBeOpened(doorIndex, CheckIfDoorIsLocked()))
  52. {
  53. building.OpenDoor(doorIndex);
  54. }
  55. }
  56. }
  57. }
  58. override void OnEndServer(ActionData action_data)
  59. {
  60. super.OnEndServer(action_data);
  61. m_NoisePar = new NoiseParams();
  62. m_NoisePar.LoadFromPath("CfgVehicles SurvivorBase NoiseActionDefault");
  63. NoiseSystem noise = GetGame().GetNoiseSystem();
  64. if (noise && CreatesNoise())
  65. {
  66. if (action_data.m_Player)
  67. noise.AddNoisePos(action_data.m_Player, action_data.m_Target.GetObject().GetPosition(), m_NoisePar, NoiseAIEvaluate.GetNoiseReduction(GetGame().GetWeather()));
  68. }
  69. }
  70. override bool IsLockTargetOnUse()
  71. {
  72. return false;
  73. }
  74. }
  75. class ActionLockedDoors : ActionOpenDoors
  76. {
  77. override bool CheckIfDoorIsLocked()
  78. {
  79. return false;
  80. }
  81. override protected bool CreatesNoise()
  82. {
  83. return false;
  84. }
  85. };