DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
ActionRepairCarChassis.c
Go to the documentation of this file.
1class RepairCarChassisActionReciveData : ActionReciveData
2{
4}
5
6class RepairCarChassisActionData : ActionData
7{
9}
10
12{
13 override void CreateActionComponent()
14 {
16 }
17};
18
20{
21 protected typename m_LastValidType;
22 protected string m_CurrentDamageZone;
24
26 {
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
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 {
117 car.SetHealth(damageZone, "", (zoneMax * GameConstants.DAMAGE_RUINED_VALUE) + randomValue);
118 break;
120 car.SetHealth(damageZone, "", (zoneMax * GameConstants.DAMAGE_BADLY_DAMAGED_VALUE) + randomValue);
121 break;
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
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};
protected float m_SpecialtyWeight
Definition ActionBase.c:68
bool HasTarget()
Definition ActionBase.c:232
protected bool m_LockTargetOnUse
Definition ActionBase.c:51
ref CCIBase m_ConditionItem
Definition ActionBase.c:55
ref CCTBase m_ConditionTarget
Definition ActionBase.c:56
protected string m_Text
Definition ActionBase.c:49
protected bool m_FullBody
Definition ActionBase.c:52
protected int m_StanceMask
Definition ActionBase.c:53
RepairCarChassisActionReciveData m_DamageZone
class ActionTargets ActionTarget
eBrokenLegs
Definition EBrokenLegs.c:2
protected ActionData m_ActionData
ItemBase m_MainItem
Definition ActionBase.c:28
ref CABase m_ActionComponent
Definition ActionBase.c:30
ref ActionTarget m_Target
Definition ActionBase.c:32
override void OnFinishProgressServer(ActionData action_data)
override ActionData CreateActionData()
protected string m_CurrentDamageZone
override void CreateConditionComponents()
override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
Super root of all classes in Enforce script.
Definition EnScript.c:11
Definition EnMath.c:7
Serialization general interface. Serializer API works with:
Definition Serializer.c:56
proto bool Write(void value_out)
proto bool Read(void value_in)
const float REPAIR
const float BASEBUILDING_REPAIR_FAST
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZPlayerConstants
defined in C++
Definition dayzplayer.c:602
proto native CGame GetGame()
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
const float DAMAGE_RUINED_VALUE
Definition constants.c:758
const float DAMAGE_DAMAGED_VALUE
Definition constants.c:756
const float DAMAGE_BADLY_DAMAGED_VALUE
Definition constants.c:757
const int STATE_RUINED
Definition constants.c:742
const int STATE_BADLY_DAMAGED
Definition constants.c:743
const int STATE_DAMAGED
Definition constants.c:744
const int STATE_WORN
Definition constants.c:745
static proto float Clamp(float value, float min, float max)
Clamps 'value' to 'min' if it is lower than 'min', or to 'max' if it is higher than 'max'.
static float RandomFloatInclusive(float min, float max)
Returns a random float number between and min [inclusive] and max [inclusive].
Definition EnMath.c:86