actiondismantlepart.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. class ActionDismantlePartCB : ActionContinuousBaseCB
  2. {
  3. override void CreateActionComponent()
  4. {
  5. float time = SetCallbackDuration(m_ActionData.m_MainItem);
  6. m_ActionData.m_ActionComponent = new CAContinuousTime( time );
  7. }
  8. float SetCallbackDuration( ItemBase item )
  9. {
  10. /*switch( item.Type() )
  11. {
  12. case Pickaxe:
  13. case Shovel:
  14. case FieldShovel:
  15. return UATimeSpent.BASEBUILDING_DECONSTRUCT_MEDIUM;
  16. case FirefighterAxe:
  17. return UATimeSpent.BASEBUILDING_DECONSTRUCT_FAST;
  18. default:
  19. return UATimeSpent.BASEBUILDING_DECONSTRUCT_SLOW;
  20. }*/
  21. return UATimeSpent.BASEBUILDING_DECONSTRUCT_SLOW;
  22. }
  23. };
  24. class ActionDismantlePart: ActionContinuousBase
  25. {
  26. void ActionDismantlePart()
  27. {
  28. m_CallbackClass = ActionDismantlePartCB;
  29. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DISASSEMBLE;
  30. m_FullBody = true;
  31. m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT;
  32. m_SpecialtyWeight = UASoftSkillsWeight.ROUGH_HIGH;
  33. m_Text = "#dismantle";
  34. }
  35. override void CreateConditionComponents()
  36. {
  37. m_ConditionItem = new CCINonRuined;
  38. m_ConditionTarget = new CCTNone;//CCTNonRuined( UAMaxDistances.BASEBUILDING );
  39. }
  40. override void OnActionInfoUpdate( PlayerBase player, ActionTarget target, ItemBase item )
  41. {
  42. ConstructionActionData construction_action_data = player.GetConstructionActionData();
  43. m_Text = "#dismantle " + construction_action_data.GetTargetPart().GetName();
  44. }
  45. override string GetText()
  46. {
  47. PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
  48. if ( player )
  49. {
  50. ConstructionActionData construction_action_data = player.GetConstructionActionData();
  51. ConstructionPart constrution_part = construction_action_data.GetTargetPart();
  52. if ( constrution_part )
  53. {
  54. return "#dismantle" + " " + constrution_part.GetName();
  55. }
  56. }
  57. return "";
  58. }
  59. override bool CanBeUsedLeaning()
  60. {
  61. return false;
  62. }
  63. override bool CanBeUsedInFreelook()
  64. {
  65. return false;
  66. }
  67. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  68. {
  69. if ( player.IsPlacingLocal() )
  70. return false;
  71. //Action not allowed if player has broken legs
  72. if (player.GetBrokenLegs() == eBrokenLegs.BROKEN_LEGS)
  73. return false;
  74. return DismantleCondition( player, target, item, true ) && player.m_MovementState.m_iStanceIdx != DayZPlayerConstants.STANCEIDX_PRONE;
  75. }
  76. override bool ActionConditionContinue( ActionData action_data )
  77. {
  78. return DismantleCondition( action_data.m_Player, action_data.m_Target, action_data.m_MainItem , false ) && action_data.m_Player.m_MovementState.m_iStanceIdx != DayZPlayerConstants.STANCEIDX_PRONE;
  79. }
  80. override void OnFinishProgressServer( ActionData action_data )
  81. {
  82. BaseBuildingBase base_building = BaseBuildingBase.Cast( action_data.m_Target.GetObject() );
  83. Construction construction = base_building.GetConstruction();
  84. ConstructionActionData construction_action_data = action_data.m_Player.GetConstructionActionData();
  85. ConstructionPart construction_part = construction_action_data.GetTargetPart();
  86. if ( construction.CanDismantlePart( construction_part.GetPartName(), action_data.m_MainItem ) )
  87. {
  88. //build
  89. construction.DismantlePartServer( action_data.m_Player, construction_part.GetPartName(), AT_DISMANTLE_PART );
  90. //add damage to tool
  91. action_data.m_MainItem.DecreaseHealth( UADamageApplied.DISMANTLE, false );
  92. }
  93. }
  94. //setup
  95. override bool SetupAction( PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = NULL )
  96. {
  97. if ( super.SetupAction( player, target, item, action_data, extra_data ) )
  98. {
  99. SetBuildingAnimation( item );
  100. return true;
  101. }
  102. return false;
  103. }
  104. protected void SetBuildingAnimation( ItemBase item )
  105. {
  106. switch ( item.Type() )
  107. {
  108. case Pickaxe:
  109. case Shovel:
  110. case FarmingHoe:
  111. case FieldShovel:
  112. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DIG;
  113. break;
  114. case Pliers:
  115. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_INTERACT;
  116. break;
  117. default:
  118. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DISASSEMBLE;
  119. break;
  120. }
  121. }
  122. protected bool DismantleCondition(PlayerBase player, ActionTarget target, ItemBase item, bool camera_check)
  123. {
  124. if (player && !player.IsPlacingLocal() && !player.IsPlacingServer())
  125. {
  126. Object targetObject = target.GetObject();
  127. EntityAI targetEntity;
  128. if (targetObject && targetObject.CanUseConstruction())
  129. {
  130. //invalid if is gate and is locked
  131. if (Class.CastTo(targetEntity, targetObject) && (targetEntity.FindAttachmentBySlotName("Att_CombinationLock") || targetEntity.FindAttachmentBySlotName("Material_FPole_Flag")) )
  132. return false;
  133. string partName = targetObject.GetActionComponentName(target.GetComponentIndex());
  134. BaseBuildingBase baseBuilding = BaseBuildingBase.Cast(targetObject);
  135. Construction construction = baseBuilding.GetConstruction();
  136. ConstructionPart constructionPart = construction.GetConstructionPartToDismantle(partName, item);
  137. if (constructionPart)
  138. {
  139. //invalid on gate if the gate is opened
  140. if (constructionPart.IsGate() && baseBuilding.IsOpened())
  141. return false;
  142. //camera and position checks
  143. bool checked = false;
  144. if (constructionPart.IsBase())
  145. checked = true;
  146. if (!checked && baseBuilding.IsPlayerInside(player, partName))
  147. {
  148. //Camera check (client-only)
  149. if (camera_check)
  150. {
  151. if (GetGame() && (!GetGame().IsDedicatedServer()))
  152. {
  153. if (baseBuilding.IsFacingCamera(partName))
  154. return false;
  155. }
  156. }
  157. checked = true;
  158. }
  159. if (checked)
  160. {
  161. ConstructionActionData constructionActionData = player.GetConstructionActionData();
  162. constructionActionData.SetTargetPart(constructionPart);
  163. return true;
  164. }
  165. }
  166. }
  167. }
  168. return false;
  169. }
  170. override string GetAdminLogMessage(ActionData action_data)
  171. {
  172. ConstructionActionData construction_action_data = action_data.m_Player.GetConstructionActionData();
  173. ConstructionPart construction_part = construction_action_data.GetTargetPart();
  174. string message = string.Format("Dismantled %1 from %2 with %3", construction_part.GetName(), action_data.m_Target.GetObject().GetDisplayName(), action_data.m_MainItem.GetDisplayName() );
  175. return message;
  176. }
  177. }