Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionrepairpart.c
Go to the documentation of this file.
1 
2 /*
3 TODO:
4 No pairing with part and tool similar to 'CanUseToolToBuildPart' exists here, since only one type of part is damage-able at this point.
5 This should be handled by adding "repair_action_type" array to basebuilding and tool configs, this would allow for independent pairing of repair action.
6 */
7 
8 class RepairPartActionReciveData : ActionReciveData
9 {
10  int m_ComponentIndexRecived;
11 }
12 
13 class RepairPartActionData : ActionData
14 {
15  int m_ComponentIndex;
16 }
17 
19 {
20  override void CreateActionComponent()
21  {
22  float time = SetCallbackDuration(m_ActionData.m_MainItem);
23  m_ActionData.m_ActionComponent = new CAContinuousRepeat( time );
24  }
25 
26  float SetCallbackDuration( ItemBase item )
27  {
28  /*switch( item.Type() )
29  {
30  case WoodAxe:
31  return UATimeSpent.BASEBUILDING_REPAIR_SLOW;
32  default:
33  return UATimeSpent.BASEBUILDING_REPAIR_FAST;
34  }*/
35  return UATimeSpent.BASEBUILDING_REPAIR_FAST;
36  }
37 };
38 
40 {
41  void ActionRepairPart()
42  {
43  m_CallbackClass = ActionRepairPartCB;
44  m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_ASSEMBLE;
45  m_FullBody = true;
46  m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT;
47 
49  m_Text = "#repair";
50  }
51 
52  override void CreateConditionComponents()
53  {
55  m_ConditionTarget = new CCTNonRuined( UAMaxDistances.BASEBUILDING );
56  }
57 
58  override void OnActionInfoUpdate( PlayerBase player, ActionTarget target, ItemBase item )
59  {
60  ConstructionActionData construction_action_data = player.GetConstructionActionData();
61  m_Text = "#repair " + construction_action_data.GetTargetPart().GetName();
62  }
63 
64  override string GetText()
65  {
66  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
67  if ( player )
68  {
69  ConstructionActionData construction_action_data = player.GetConstructionActionData();
70  ConstructionPart constrution_part = construction_action_data.GetTargetPart();
71 
72  if ( constrution_part )
73  {
74  return "#repair" + " " + constrution_part.GetName();
75  }
76  }
77 
78  return "";
79  }
80 
81  override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item )
82  {
83  //Action not allowed if player has broken legs
84  if (player.GetBrokenLegs() == eBrokenLegs.BROKEN_LEGS)
85  return false;
86 
87  return RepairCondition( player, target, item, true );
88  }
89 
90  override bool ActionConditionContinue( ActionData action_data )
91  {
92  return RepairCondition( action_data.m_Player, action_data.m_Target, action_data.m_MainItem , false );
93  }
94 
95  override void OnFinishProgressServer( ActionData action_data )
96  {
97  BaseBuildingBase base_building = BaseBuildingBase.Cast( action_data.m_Target.GetObject() );
98  Construction construction = base_building.GetConstruction();
99 
100  //repairing
101  string part_name = action_data.m_Target.GetObject().GetActionComponentName( RepairPartActionData.Cast(action_data).m_ComponentIndex );
102  string zone_name;
103  PluginRepairing module_repairing;
104  Class.CastTo(module_repairing, GetPlugin(PluginRepairing));
105 
106  DamageSystem.GetDamageZoneFromComponentName(base_building,part_name,zone_name);
107  module_repairing.Repair(action_data.m_Player,action_data.m_MainItem,base_building,m_SpecialtyWeight,zone_name);
108 
109  //consume materials
110  construction.TakeMaterialsServer(part_name,true);
111 
112  //add damage to tool
113  action_data.m_MainItem.DecreaseHealth( UADamageApplied.REPAIR, false );
114 
115  action_data.m_Player.GetSoftSkillsManager().AddSpecialty( m_SpecialtyWeight );
116  }
117 
118  protected override void SetBuildingAnimation( ItemBase item )
119  {
120  switch( item.Type() )
121  {
122  case Pickaxe:
123  case Shovel:
124  case FarmingHoe:
125  case FieldShovel:
126  m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_DIG;
127  break;
128  case Pliers:
129  m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_INTERACT;
130  break;
131  default:
132  m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_ASSEMBLE;
133  break;
134  }
135  }
136 
137  override ActionData CreateActionData()
138  {
139  RepairPartActionData action_data = new RepairPartActionData;
140  return action_data;
141  }
142 
143  override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
144  {
145  super.WriteToContext(ctx, action_data);
146  RepairPartActionData repair_action_data;
147 
148  if( HasTarget() && Class.CastTo(repair_action_data,action_data) )
149  {
150  repair_action_data.m_ComponentIndex = action_data.m_Target.GetComponentIndex();
151  ctx.Write(repair_action_data.m_ComponentIndex);
152  }
153  }
154 
155  override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data )
156  {
157  if(!action_recive_data)
158  {
159  action_recive_data = new RepairPartActionReciveData;
160  }
161  RepairPartActionReciveData recive_data_repair = RepairPartActionReciveData.Cast(action_recive_data);
162 
163  super.ReadFromContext(ctx, action_recive_data);
164 
165  if( HasTarget() )
166  {
167  int component_index;
168  if ( !ctx.Read(component_index) )
169  return false;
170 
171  recive_data_repair.m_ComponentIndexRecived = component_index;
172  }
173  return true;
174  }
175 
176  override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
177  {
178  super.HandleReciveData(action_recive_data, action_data);
179 
180  RepairPartActionReciveData recive_data_repair = RepairPartActionReciveData.Cast(action_recive_data);
181  RepairPartActionData.Cast(action_data).m_ComponentIndex = recive_data_repair.m_ComponentIndexRecived;
182  }
183 
184  protected bool RepairCondition( PlayerBase player, ActionTarget target, ItemBase item, bool camera_check )
185  {
186  string zone_name;
187 
188  Object target_object = target.GetObject();
189  if ( target_object && target_object.CanUseConstruction() )
190  {
191  string part_name = target_object.GetActionComponentName( target.GetComponentIndex() );
192 
193  BaseBuildingBase base_building = BaseBuildingBase.Cast( target_object );
194  Construction construction = base_building.GetConstruction();
195  ConstructionPart construction_part = construction.GetConstructionPart( part_name );
196 
197  if ( construction_part )
198  {
199  //camera and position checks
200  if ( !base_building.IsFacingPlayer( player, part_name ) && !player.GetInputController().CameraIsFreeLook() && base_building.HasProperDistance( construction_part.GetMainPartName(), player ) )
201  {
202  //Camera check (client-only)
203  if ( camera_check )
204  {
205  if ( GetGame() && ( !GetGame().IsDedicatedServer() ) )
206  {
207  if ( base_building.IsFacingCamera( part_name ) )
208  {
209  return false;
210  }
211  }
212  }
213 
214  //damage check
215  DamageSystem.GetDamageZoneFromComponentName(base_building,part_name,zone_name);
216  if ( base_building.GetHealthLevel(zone_name) < GameConstants.STATE_WORN || base_building.GetHealthLevel(zone_name) == GameConstants.STATE_RUINED )
217  {
218  return false;
219  }
220 
221  //materials check
222  if ( !construction.HasMaterials(part_name,true) )
223  {
224  return false;
225  }
226 
227  ConstructionActionData construction_action_data = player.GetConstructionActionData();
228  construction_action_data.SetTargetPart( construction_part );
229  return true;
230  }
231  }
232  }
233 
234  return false;
235  }
236 
237  override string GetAdminLogMessage(ActionData action_data)
238  {
239  return " repaired " + action_data.m_Target.GetObject().GetDisplayName() + " with " + action_data.m_MainItem.GetDisplayName();
240  }
241 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
ConstructionActionData
Definition: constructionactiondata.c:1
ActionDismantlePart
Definition: actiondismantlepart.c:26
CAContinuousRepeat
Definition: cacontinuousrepeat.c:1
UADamageApplied
Definition: actionconstants.c:130
FarmingHoe
Definition: farminghoe.c:1
Construction
void Construction(BaseBuildingBase parent)
Definition: construction.c:26
UASoftSkillsWeight
Definition: actionconstants.c:118
UAMaxDistances
Definition: actionconstants.c:104
HasTarget
bool HasTarget()
Definition: actionbase.c:232
eBrokenLegs
eBrokenLegs
Definition: ebrokenlegs.c:1
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
Serializer
Serialization general interface. Serializer API works with:
Definition: serializer.c:55
m_FullBody
protected bool m_FullBody
Definition: actionbase.c:52
PlayerBase
Definition: playerbaseclient.c:1
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
BaseBuildingBase
Definition: fence.c:1
ActionRepairPartCB
Definition: actionrepairpart.c:18
CCTNonRuined
Definition: cctnonruined.c:1
Object
Definition: objecttyped.c:1
UATimeSpent
Definition: actionconstants.c:26
ActionContinuousBaseCB
Definition: actioncontinuousbase.c:1
m_ComponentIndex
RepairPartActionReciveData m_ComponentIndex
RepairPartActionReciveData
Definition: actionrepairpart.c:8
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
m_Text
protected string m_Text
Definition: actionbase.c:49
GameConstants
Definition: constants.c:612
ActionRepairPart
Definition: actionrepairpart.c:39
ConstructionPart
Definition: constructionpart.c:1
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
CCINonRuined
Definition: ccinonruined.c:1
m_ConditionTarget
ref CCTBase m_ConditionTarget
Definition: actionbase.c:56
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
m_SpecialtyWeight
protected float m_SpecialtyWeight
Definition: actionbase.c:68
m_StanceMask
protected int m_StanceMask
Definition: actionbase.c:53