actionrepairpart.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. TODO:
  3. No pairing with part and tool similar to 'CanUseToolToBuildPart' exists here, since only one type of part is damage-able at this point.
  4. This should be handled by adding "repair_action_type" array to basebuilding and tool configs, this would allow for independent pairing of repair action.
  5. */
  6. class RepairPartActionReciveData : ActionReciveData
  7. {
  8. int m_ComponentIndexRecived;
  9. }
  10. class RepairPartActionData : ActionData
  11. {
  12. int m_ComponentIndex;
  13. }
  14. class ActionRepairPartCB : ActionContinuousBaseCB
  15. {
  16. override void CreateActionComponent()
  17. {
  18. float time = SetCallbackDuration(m_ActionData.m_MainItem);
  19. m_ActionData.m_ActionComponent = new CAContinuousRepeat( time );
  20. }
  21. float SetCallbackDuration( ItemBase item )
  22. {
  23. /*switch( item.Type() )
  24. {
  25. case WoodAxe:
  26. return UATimeSpent.BASEBUILDING_REPAIR_SLOW;
  27. default:
  28. return UATimeSpent.BASEBUILDING_REPAIR_FAST;
  29. }*/
  30. return UATimeSpent.BASEBUILDING_REPAIR_FAST;
  31. }
  32. };
  33. class ActionRepairPart: ActionDismantlePart
  34. {
  35. void ActionRepairPart()
  36. {
  37. m_CallbackClass = ActionRepairPartCB;
  38. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_ASSEMBLE;
  39. m_FullBody = true;
  40. m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT;
  41. m_SpecialtyWeight = UASoftSkillsWeight.ROUGH_HIGH;
  42. m_Text = "#repair";
  43. }
  44. override void CreateConditionComponents()
  45. {
  46. m_ConditionItem = new CCINonRuined;
  47. m_ConditionTarget = new CCTNonRuined( UAMaxDistances.BASEBUILDING );
  48. }
  49. override void OnActionInfoUpdate( PlayerBase player, ActionTarget target, ItemBase item )
  50. {
  51. ConstructionActionData construction_action_data = player.GetConstructionActionData();
  52. m_Text = "#repair " + construction_action_data.GetTargetPart().GetName();
  53. }
  54. override string GetText()
  55. {
  56. PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
  57. if ( player )
  58. {
  59. ConstructionActionData construction_action_data = player.GetConstructionActionData();
  60. ConstructionPart constrution_part = construction_action_data.GetTargetPart();
  61. if ( constrution_part )
  62. {
  63. return "#repair" + " " + constrution_part.GetName();
  64. }
  65. }
  66. return "";
  67. }
  68. override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
  69. {
  70. //Action not allowed if player has broken legs
  71. if (player.GetBrokenLegs() == eBrokenLegs.BROKEN_LEGS)
  72. return false;
  73. return RepairCondition( player, target, item, true );
  74. }
  75. override bool ActionConditionContinue( ActionData action_data )
  76. {
  77. return RepairCondition( action_data.m_Player, action_data.m_Target, action_data.m_MainItem , false );
  78. }
  79. override void OnFinishProgressServer( ActionData action_data )
  80. {
  81. BaseBuildingBase base_building = BaseBuildingBase.Cast( action_data.m_Target.GetObject() );
  82. Construction construction = base_building.GetConstruction();
  83. //repairing
  84. string part_name = action_data.m_Target.GetObject().GetActionComponentName( RepairPartActionData.Cast(action_data).m_ComponentIndex );
  85. string zone_name;
  86. PluginRepairing module_repairing;
  87. Class.CastTo(module_repairing, GetPlugin(PluginRepairing));
  88. DamageSystem.GetDamageZoneFromComponentName(base_building,part_name,zone_name);
  89. module_repairing.Repair(action_data.m_Player,action_data.m_MainItem,base_building,m_SpecialtyWeight,zone_name);
  90. //consume materials
  91. construction.TakeMaterialsServer(part_name,true);
  92. //add damage to tool
  93. action_data.m_MainItem.DecreaseHealth( UADamageApplied.REPAIR, false );
  94. }
  95. protected override void SetBuildingAnimation( ItemBase item )
  96. {
  97. switch( item.Type() )
  98. {
  99. case Pickaxe:
  100. case Shovel:
  101. case FarmingHoe:
  102. case FieldShovel:
  103. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DIG;
  104. break;
  105. case Pliers:
  106. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_INTERACT;
  107. break;
  108. default:
  109. m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_ASSEMBLE;
  110. break;
  111. }
  112. }
  113. override ActionData CreateActionData()
  114. {
  115. RepairPartActionData action_data = new RepairPartActionData;
  116. return action_data;
  117. }
  118. override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
  119. {
  120. super.WriteToContext(ctx, action_data);
  121. RepairPartActionData repair_action_data;
  122. if( HasTarget() && Class.CastTo(repair_action_data,action_data) )
  123. {
  124. repair_action_data.m_ComponentIndex = action_data.m_Target.GetComponentIndex();
  125. ctx.Write(repair_action_data.m_ComponentIndex);
  126. }
  127. }
  128. override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data )
  129. {
  130. if(!action_recive_data)
  131. {
  132. action_recive_data = new RepairPartActionReciveData;
  133. }
  134. RepairPartActionReciveData recive_data_repair = RepairPartActionReciveData.Cast(action_recive_data);
  135. super.ReadFromContext(ctx, action_recive_data);
  136. if( HasTarget() )
  137. {
  138. int component_index;
  139. if ( !ctx.Read(component_index) )
  140. return false;
  141. recive_data_repair.m_ComponentIndexRecived = component_index;
  142. }
  143. return true;
  144. }
  145. override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
  146. {
  147. super.HandleReciveData(action_recive_data, action_data);
  148. RepairPartActionReciveData recive_data_repair = RepairPartActionReciveData.Cast(action_recive_data);
  149. RepairPartActionData.Cast(action_data).m_ComponentIndex = recive_data_repair.m_ComponentIndexRecived;
  150. }
  151. protected bool RepairCondition( PlayerBase player, ActionTarget target, ItemBase item, bool camera_check )
  152. {
  153. string zone_name;
  154. Object target_object = target.GetObject();
  155. if ( target_object && target_object.CanUseConstruction() )
  156. {
  157. string part_name = target_object.GetActionComponentName( target.GetComponentIndex() );
  158. BaseBuildingBase base_building = BaseBuildingBase.Cast( target_object );
  159. Construction construction = base_building.GetConstruction();
  160. ConstructionPart construction_part = construction.GetConstructionPart( part_name );
  161. if ( construction_part )
  162. {
  163. //camera and position checks
  164. if ( !base_building.IsFacingPlayer( player, part_name ) && !player.GetInputController().CameraIsFreeLook() && base_building.HasProperDistance( construction_part.GetMainPartName(), player ) )
  165. {
  166. //Camera check (client-only)
  167. if ( camera_check )
  168. {
  169. if ( GetGame() && ( !GetGame().IsDedicatedServer() ) )
  170. {
  171. if ( base_building.IsFacingCamera( part_name ) )
  172. {
  173. return false;
  174. }
  175. }
  176. }
  177. //damage check
  178. DamageSystem.GetDamageZoneFromComponentName(base_building,part_name,zone_name);
  179. if ( base_building.GetHealthLevel(zone_name) < GameConstants.STATE_WORN || base_building.GetHealthLevel(zone_name) == GameConstants.STATE_RUINED )
  180. {
  181. return false;
  182. }
  183. //materials check
  184. if ( !construction.HasMaterials(part_name,true) )
  185. {
  186. return false;
  187. }
  188. ConstructionActionData construction_action_data = player.GetConstructionActionData();
  189. construction_action_data.SetTargetPart( construction_part );
  190. return true;
  191. }
  192. }
  193. }
  194. return false;
  195. }
  196. override string GetAdminLogMessage(ActionData action_data)
  197. {
  198. return " repaired " + action_data.m_Target.GetObject().GetDisplayName() + " with " + action_data.m_MainItem.GetDisplayName();
  199. }
  200. }