actionlockattachment.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //Transfer locktypes from BasicDefines.hpp here. This is mostly for readability
  2. //NONE must be 0 as it is actively used below
  3. enum eLockTypes
  4. {
  5. NONE = 0,
  6. LOCK_SCREW = 1,
  7. LOCK_BOLT = 2,
  8. LOCK_NUT = 3,
  9. LOCK_WIRE = 4
  10. }
  11. class ActionLockAttachmentCB : ActionContinuousBaseCB
  12. {
  13. override void CreateActionComponent()
  14. {
  15. m_ActionData.m_ActionComponent = new CAContinuousTime( UATimeSpent.BASEBUILDING_REPAIR_FAST );
  16. }
  17. };
  18. class ActionLockAttachment: ActionContinuousBase
  19. {
  20. private const string LOCK_VERSION = "#widget_lock";
  21. private const string UNLOCK_VERSION = "#widget_unlock";
  22. private string m_Name = LOCK_VERSION;
  23. void ActionLockAttachment()
  24. {
  25. m_CallbackClass = ActionLockAttachmentCB;
  26. m_SpecialtyWeight = UASoftSkillsWeight.PRECISE_LOW;
  27. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_INTERACT;
  28. m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT;
  29. m_FullBody = true;
  30. }
  31. override void OnActionInfoUpdate( PlayerBase player, ActionTarget target, ItemBase item )
  32. {
  33. ItemBase target_IB = ItemBase.Cast(target.GetObject());
  34. if ( target_IB.IsLockedInSlot() )
  35. m_Text = UNLOCK_VERSION;
  36. else if ( target_IB.IsAlive() )
  37. m_Text = LOCK_VERSION;
  38. else
  39. m_Text = "";
  40. }
  41. override void CreateConditionComponents()
  42. {
  43. m_ConditionItem = new CCINonRuined;
  44. m_ConditionTarget = new CCTCursorNoRuinCheck(UAMaxDistances.SMALL);
  45. }
  46. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  47. {
  48. if ( !target )
  49. return false;
  50. EntityAI parent_EAI = EntityAI.Cast(target.GetParent());
  51. ItemBase target_IB = ItemBase.Cast(target.GetObject());
  52. array<int> compLock = item.m_CompatibleLocks;
  53. int targetType = eLockTypes.NONE;
  54. if ( target_IB && parent_EAI )
  55. {
  56. //CAR DOOR HANDLING
  57. //I don't really like this, but sometimes specifics have to be handled in generics
  58. CarDoor targetDoor = CarDoor.Cast(target_IB);
  59. if ( targetDoor )
  60. {
  61. InventoryLocation loc = new InventoryLocation();
  62. bool isPresent = targetDoor.GetInventory().GetCurrentInventoryLocation( loc );
  63. if ( !isPresent || loc.GetSlot() == -1 )
  64. return false;
  65. string slotName = InventorySlots.GetSlotName( loc.GetSlot() );
  66. if ( slotName && CarScript.Cast( parent_EAI ).GetCarDoorsState( slotName ) != CarDoorState.DOORS_OPEN )
  67. return false;
  68. }
  69. //END OF CAR DOOR SPECIFICS
  70. if ( target_IB.IsLockedInSlot() )
  71. m_Name = UNLOCK_VERSION;
  72. else if ( target_IB.IsAlive() )
  73. m_Name = LOCK_VERSION;
  74. else if ( !target_IB.IsLockedInSlot() )
  75. return false;
  76. targetType = target_IB.GetLockType();
  77. for (int i = 0; i < compLock.Count(); i++)
  78. {
  79. if ( targetType == compLock[i] && targetType != eLockTypes.NONE)
  80. {
  81. return true;
  82. }
  83. }
  84. }
  85. return false;
  86. }
  87. override void OnStartAnimationLoop( ActionData action_data )
  88. {
  89. super.OnStartAnimationLoop( action_data );
  90. if ( !GetGame().IsMultiplayer() || GetGame().IsServer() )
  91. {
  92. ItemBase target_IB = ItemBase.Cast( action_data.m_Target.GetObject() );
  93. Param2<bool, string> play = new Param2<bool, string>( true, action_data.m_MainItem.GetLockSoundSet() );
  94. GetGame().RPCSingleParam( target_IB, ERPCs.RPC_SOUND_LOCK_ATTACH, play, true );
  95. }
  96. }
  97. override void OnEnd( ActionData action_data )
  98. {
  99. if ( !GetGame().IsMultiplayer() || GetGame().IsServer() )
  100. {
  101. ItemBase target_IB = ItemBase.Cast( action_data.m_Target.GetObject() );
  102. Param2<bool, string> play = new Param2<bool, string>( false, action_data.m_MainItem.GetLockSoundSet() );
  103. GetGame().RPCSingleParam( target_IB, ERPCs.RPC_SOUND_LOCK_ATTACH, play, true );
  104. }
  105. }
  106. override void OnEndAnimationLoop( ActionData action_data )
  107. {
  108. super.OnEndAnimationLoop( action_data );
  109. if ( !GetGame().IsMultiplayer() || GetGame().IsServer() )
  110. {
  111. ItemBase target_IB = ItemBase.Cast( action_data.m_Target.GetObject() );
  112. Param2<bool, string> play = new Param2<bool, string>( false, action_data.m_MainItem.GetLockSoundSet() );
  113. GetGame().RPCSingleParam( target_IB, ERPCs.RPC_SOUND_LOCK_ATTACH, play, true );
  114. }
  115. }
  116. override void OnFinishProgressServer( ActionData action_data )
  117. {
  118. ItemBase target_IB = ItemBase.Cast(action_data.m_Target.GetObject());
  119. MiscGameplayFunctions.DealAbsoluteDmg(action_data.m_MainItem, 5);
  120. if (target_IB.IsLockedInSlot())
  121. {
  122. target_IB.UnlockFromParent();
  123. return;
  124. }
  125. target_IB.LockToParent();
  126. }
  127. }