actionunrestraintarget.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. class ActionUnrestrainTargetCB : ActionContinuousBaseCB
  2. {
  3. const float DEFAULT_UNRESTRAIN_TIME = 2;
  4. override void CreateActionComponent()
  5. {
  6. float time = ObtainUnrestrainTime();
  7. if( time <=0 )
  8. {
  9. time = DEFAULT_UNRESTRAIN_TIME;
  10. }
  11. if( m_ActionData.m_Player.IsQuickRestrain() )
  12. {
  13. time = DEBUG_QUICK_UNRESTRAIN_TIME;
  14. }
  15. m_ActionData.m_ActionComponent = new CAContinuousTime(time);
  16. }
  17. float ObtainUnrestrainTime()
  18. {
  19. PlayerBase target_player = PlayerBase.Cast(m_ActionData.m_Target.GetObject());
  20. PlayerBase source_player = m_ActionData.m_Player;
  21. if (target_player.IsRestrained())
  22. {
  23. EntityAI item_in_hands_source = source_player.GetItemInHands();
  24. ItemBase item_in_hands_target = target_player.GetItemInHands();
  25. CachedObjectsArrays.ARRAY_STRING.Clear();
  26. item_in_hands_target.ConfigGetTextArray( "CanBeUnrestrainedBy", CachedObjectsArrays.ARRAY_STRING );
  27. string item_in_hands_name = item_in_hands_source.GetType();
  28. for(int i = 0; i < CachedObjectsArrays.ARRAY_STRING.Count(); i++)
  29. {
  30. if((i % 2) == 0)
  31. {
  32. string class_name = CachedObjectsArrays.ARRAY_STRING.Get(i);
  33. if( GetGame().IsKindOf(item_in_hands_name, class_name) )
  34. {
  35. float value = CachedObjectsArrays.ARRAY_STRING.Get(i+1).ToFloat();
  36. return value;
  37. }
  38. }
  39. }
  40. }
  41. return -1;
  42. }
  43. };
  44. class ActionUnrestrainTarget: ActionContinuousBase
  45. {
  46. void ActionUnrestrainTarget()
  47. {
  48. m_CallbackClass = ActionUnrestrainTargetCB;
  49. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_UNRESTRAINTARGET;
  50. m_FullBody = true;
  51. m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH;
  52. m_SpecialtyWeight = UASoftSkillsWeight.PRECISE_LOW;
  53. m_Text = "#unrestrain";
  54. }
  55. override void CreateConditionComponents()
  56. {
  57. m_ConditionTarget = new CCTMan(UAMaxDistances.DEFAULT, false);
  58. m_ConditionItem = new CCINonRuined;
  59. }
  60. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  61. {
  62. PlayerBase other_player = PlayerBase.Cast(target.GetObject());
  63. EntityAI item_in_hands_source = player.GetItemInHands();
  64. if( other_player.IsRestrained() )
  65. {
  66. //Print("is restrained");
  67. EntityAI item_in_hands_target = other_player.GetItemInHands();
  68. CachedObjectsArrays.ARRAY_STRING.Clear();
  69. if( item_in_hands_target )
  70. {
  71. item_in_hands_target.ConfigGetTextArray( "CanBeUnrestrainedBy", CachedObjectsArrays.ARRAY_STRING );
  72. string item_in_hands_name = item_in_hands_source.GetType();
  73. for(int i = 0; i < CachedObjectsArrays.ARRAY_STRING.Count(); i++)
  74. {
  75. if((i % 2) == 0)
  76. {
  77. string class_name = CachedObjectsArrays.ARRAY_STRING.Get(i);
  78. if( GetGame().IsKindOf(item_in_hands_name, class_name) )
  79. {
  80. return true;
  81. }
  82. }
  83. }
  84. }
  85. }
  86. return false;
  87. }
  88. override void OnFinishProgressServer( ActionData action_data )
  89. {
  90. PlayerBase player_target = PlayerBase.Cast(action_data.m_Target.GetObject());
  91. PlayerBase player_source = PlayerBase.Cast(action_data.m_Player);
  92. if (CanReceiveAction(action_data.m_Target) && player_target.IsRestrained())
  93. {
  94. EntityAI unrestraining_tool = action_data.m_MainItem;
  95. EntityAI restraining_item = player_target.GetItemInHands();
  96. player_target.SetRestrained(false);
  97. //Damage applied to tool
  98. CachedObjectsArrays.ARRAY_STRING.Clear();
  99. restraining_item.ConfigGetTextArray( "CanBeUnrestrainedBy", CachedObjectsArrays.ARRAY_STRING );
  100. restraining_item.ConfigGetFloatArray( "CanBeUnrestrainedByDMG", CachedObjectsArrays.ARRAY_FLOAT );
  101. string item_in_hands_name = unrestraining_tool.GetType();
  102. float damageToTool = 0;
  103. for(int i = 0; i < CachedObjectsArrays.ARRAY_STRING.Count(); i++)
  104. {
  105. string class_name = CachedObjectsArrays.ARRAY_STRING.Get(i);
  106. if( GetGame().IsKindOf(item_in_hands_name, class_name) )
  107. {
  108. damageToTool = CachedObjectsArrays.ARRAY_FLOAT.Get(i/2);
  109. break;
  110. }
  111. }
  112. MiscGameplayFunctions.DealAbsoluteDmg(action_data.m_MainItem, damageToTool);
  113. //---------------------------
  114. MiscGameplayFunctions.TransformRestrainItem(restraining_item, unrestraining_tool, player_source, player_target);
  115. }
  116. }
  117. };
  118. class ReplaceAndDestroyLambda : TurnItemIntoItemLambdaAnimSysNotifyLambda
  119. {
  120. PlayerBase m_TargetPlayer;
  121. bool m_Destroy;
  122. bool m_Drop;
  123. void ReplaceAndDestroyLambda(EntityAI old_item, string new_item_type, PlayerBase player, bool destroy = false)
  124. {
  125. m_TargetPlayer = player;
  126. m_Destroy = destroy;
  127. m_OldItem = old_item;
  128. }
  129. override void OnSuccess(EntityAI new_item)
  130. {
  131. super.OnSuccess(new_item);
  132. if ( m_Destroy )
  133. {
  134. new_item.SetHealth("","",0);
  135. }
  136. }
  137. };
  138. class ReplaceAndDestroyLambdaEx : ReplaceAndDestroyLambda
  139. {
  140. void ReplaceAndDestroyLambdaEx(EntityAI old_item, string new_item_type, PlayerBase player, bool destroy = false, bool enableDrop = true)
  141. {
  142. m_Drop = enableDrop;
  143. }
  144. override protected EntityAI CreateNewEntity()
  145. {
  146. EntityAI newItem = super.CreateNewEntity();
  147. if (!newItem && m_Drop)
  148. {
  149. newItem = EntityAI.Cast(GetGame().CreateObjectEx(m_NewItemType, m_TargetPlayer.GetPosition(), ECE_PLACE_ON_SURFACE|ECE_LOCAL));
  150. }
  151. return newItem;
  152. }
  153. };