Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionrepaircarchassis.c
Go to the documentation of this file.
1 class RepairCarChassisActionReciveData : ActionReciveData
2 {
3  string m_DamageZoneRecived;
4 }
5 
6 class RepairCarChassisActionData : ActionData
7 {
8  string m_DamageZone;
9 }
10 
12 {
13  override void CreateActionComponent()
14  {
15  m_ActionData.m_ActionComponent = new CAContinuousTime(UATimeSpent.BASEBUILDING_REPAIR_FAST);
16  }
17 };
18 
20 {
21  protected typename m_LastValidType;
22  protected string m_CurrentDamageZone;
23  protected int m_LastValidComponentIndex;
24 
26  {
27  m_CallbackClass = ActionRepairCarChassisCB;
29  m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_INTERACT;
30  m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT;
31  m_FullBody = true;
32  m_LockTargetOnUse = false;
33  m_Text = "#repair";
34 
36  }
37 
38  override void CreateConditionComponents()
39  {
42  }
43 
44  override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
45  {
46  if (player.GetBrokenLegs() == eBrokenLegs.BROKEN_LEGS)
47  return false;
48 
49  CarScript car = CarScript.Cast(target.GetObject());
50  if (!car || !player)
51  {
52  return false;
53  }
54 
55  if (GetGame().IsMultiplayer() && GetGame().IsServer())
56  {
57  return true;
58  }
59 
60  if (m_LastValidType != target.Type() || m_LastValidComponentIndex != target.GetComponentIndex() || m_CurrentDamageZone == "")
61  {
62  string damageZone = "";
63  array<string> selections = new array<string>();
64  car.GetActionComponentNameList(target.GetComponentIndex(), selections);
65 
66  foreach (string selection : selections)
67  {
68  //NOTE: relevant fire geometry and view geometry selection names MUST match in order to get a valid damage zone
69  if (car && DamageSystem.GetDamageZoneFromComponentName(car, selection, damageZone))
70  {
71  if (damageZone == "Engine")
72  continue;
73 
74  int zoneHP = car.GetHealthLevel(damageZone);
75  if (zoneHP > GameConstants.STATE_WORN && zoneHP < GameConstants.STATE_RUINED)
76  {
77  m_CurrentDamageZone = damageZone;
78  m_LastValidComponentIndex = target.GetComponentIndex();
79 
80  //Determine if using a "Special" item for repairing
81  WoodenPlank plank = WoodenPlank.Cast(item);
82  Fabric tarp = Fabric.Cast(item);
83 
84  //Prevent planks and tarp from repairing non related areas
85  if ((tarp || plank) && (damageZone != "BackWood" && damageZone != "BackTarp"))
86  return false;
87 
88  return true;
89  }
90  }
91  }
92  }
93 
94  return false;
95  }
96 
97  override void OnFinishProgressServer(ActionData action_data)
98  {
99  Object tgObject = action_data.m_Target.GetObject();
100 
101  string damageZone = RepairCarPartActionData.Cast(action_data).m_DamageZone;
102  if (!GetGame().IsMultiplayer())
103  damageZone = m_CurrentDamageZone;
104 
105  if (tgObject && damageZone != "")
106  {
107  CarScript car = CarScript.Cast(tgObject);
108  if (car)
109  {
110  int newDmgLevel = Math.Clamp(car.GetHealthLevel(damageZone) - 1, GameConstants.STATE_WORN, GameConstants.STATE_RUINED);
111  float zoneMax = car.GetMaxHealth(damageZone, "");
112  float randomValue = Math.RandomFloatInclusive(zoneMax * 0.05, zoneMax * 0.15);
113 
114  switch (newDmgLevel)
115  {
116  case GameConstants.STATE_BADLY_DAMAGED:
117  car.SetHealth(damageZone, "", (zoneMax * GameConstants.DAMAGE_RUINED_VALUE) + randomValue);
118  break;
119  case GameConstants.STATE_DAMAGED:
120  car.SetHealth(damageZone, "", (zoneMax * GameConstants.DAMAGE_BADLY_DAMAGED_VALUE) + randomValue);
121  break;
122  case GameConstants.STATE_WORN:
123  car.SetHealth(damageZone, "", (zoneMax * GameConstants.DAMAGE_DAMAGED_VALUE) + randomValue);
124  break;
125  }
126 
127  if (action_data.m_MainItem.HasQuantity())
128  {
129  if (action_data.m_MainItem.GetQuantity() > 1)
130  {
131  int qnt = action_data.m_MainItem.GetQuantity();
132  Fabric usedTarp = Fabric.Cast(action_data.m_MainItem);
133  WoodenPlank usedPlank = WoodenPlank.Cast(action_data.m_MainItem);
134  if (usedTarp || usedPlank)
135  {
136  qnt -= 1;
137  }
138  else
139  {
140  qnt -= action_data.m_MainItem.GetQuantityMax() * 0.25;
141  }
142 
143  action_data.m_MainItem.SetQuantity(qnt);
144  }
145  else
146  {
147  action_data.m_MainItem.Delete();
148  }
149  }
150  }
151  }
152  }
153 
154  override ActionData CreateActionData()
155  {
156  RepairCarPartActionData actionData = new RepairCarPartActionData();
157  return actionData;
158  }
159 
160  override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
161  {
162  super.WriteToContext(ctx, action_data);
163  RepairCarPartActionData repairActionData;
164 
165  if (HasTarget() && Class.CastTo(repairActionData, action_data))
166  {
167  repairActionData.m_DamageZone = m_CurrentDamageZone;
168  ctx.Write(repairActionData.m_DamageZone);
169  }
170  }
171 
172  override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
173  {
174  if (!action_recive_data)
175  {
176  action_recive_data = new RepairCarPartActionReciveData();
177  }
178 
179  super.ReadFromContext(ctx, action_recive_data);
180  RepairCarPartActionReciveData recieveDataRepair = RepairCarPartActionReciveData.Cast(action_recive_data);
181 
182  if (HasTarget())
183  {
184  string zone;
185  if (!ctx.Read(zone))
186  {
187  return false;
188  }
189 
190  recieveDataRepair.m_DamageZoneRecived = zone;
191  }
192 
193  return true;
194  }
195 
196  override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
197  {
198  super.HandleReciveData(action_recive_data, action_data);
199 
200  RepairCarPartActionReciveData recieveDataRepair = RepairCarPartActionReciveData.Cast(action_recive_data);
201  RepairCarPartActionData.Cast(action_data).m_DamageZone = recieveDataRepair.m_DamageZoneRecived;
202  }
203 };
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
CAContinuousTime
Definition: cacontinuoustime.c:1
RepairCarChassisActionReciveData
Definition: actionrepaircarchassis.c:1
UASoftSkillsWeight
Definition: actionconstants.c:118
RepairCarPartActionReciveData
Definition: actionrepaircarpart.c:1
CarScript
Definition: civiliansedan.c:1
UAMaxDistances
Definition: actionconstants.c:104
HasTarget
bool HasTarget()
Definition: actionbase.c:232
eBrokenLegs
eBrokenLegs
Definition: ebrokenlegs.c:1
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
Object
Definition: objecttyped.c:1
m_DamageZone
RepairCarChassisActionReciveData m_DamageZone
CCTCursor
Definition: cctcursor.c:1
UATimeSpent
Definition: actionconstants.c:26
ActionContinuousBaseCB
Definition: actioncontinuousbase.c:1
Fabric
Definition: crafting.c:106
m_LockTargetOnUse
protected bool m_LockTargetOnUse
Definition: actionbase.c:51
array< string >
m_CurrentDamageZone
string m_CurrentDamageZone
Definition: actionrepaircarengine.c:22
m_Text
protected string m_Text
Definition: actionbase.c:49
GameConstants
Definition: constants.c:612
m_ConditionItem
ref CCIBase m_ConditionItem
Definition: actionbase.c:55
ActionRepairCarChassisCB
Definition: actionrepaircarchassis.c:11
ActionContinuousBase
Definition: actioncontinuousbase.c:132
CCINonRuined
Definition: ccinonruined.c:1
m_LastValidComponentIndex
int m_LastValidComponentIndex
Definition: actionrepaircarengine.c:23
Math
Definition: enmath.c:6
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
ActionRepairCarChassis
Definition: actionrepaircarchassis.c:19