Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
actionrepairvehiclepartbase.c
Go to the documentation of this file.
1class RepairVehiclePartActionReciveData : ActionReciveData
2{
3 string m_DamageZoneRecived;
4}
5
6class RepairVehiclePartActionData : ActionData
7{
9}
10
12{
13 override void CreateActionComponent()
14 {
15 m_ActionData.m_ActionComponent = new CAContinuousRepeat(UATimeSpent.BASEBUILDING_REPAIR_FAST);
16 }
17};
18
20{
21 protected string m_CurrentDamageZone; // needs to be assigned in action condition so it can be properly written to context
22
28
29 override void OnFinishProgressServer(ActionData action_data)
30 {
31 AdjustVehicleHealthServer(action_data);
32 AdjustItemQuantityServer(action_data);
33 }
34
35 protected void AdjustVehicleHealthServer(ActionData action_data)
36 {
37 Object tgObject = action_data.m_Target.GetObject();
38
39 string damageZone = RepairVehiclePartActionData.Cast(action_data).m_DamageZone;
40 if (!GetGame().IsMultiplayer())
41 damageZone = m_CurrentDamageZone;
42
43 if (tgObject && damageZone != "")
44 {
45 Transport vehicle = Transport.Cast(tgObject);
46 if (vehicle)
47 {
48 int newDmgLevel = Math.Clamp(vehicle.GetHealthLevel(damageZone) - 1, GameConstants.STATE_WORN, GameConstants.STATE_RUINED);
49 float zoneMax = vehicle.GetMaxHealth(damageZone, "");
50 float randomValue = Math.RandomFloatInclusive(zoneMax * 0.05, zoneMax * 0.15);
51
52 switch (newDmgLevel)
53 {
54 case GameConstants.STATE_BADLY_DAMAGED:
55 vehicle.SetHealth(damageZone, "", (zoneMax * GameConstants.DAMAGE_RUINED_VALUE) + randomValue);
56 break;
57 case GameConstants.STATE_DAMAGED:
58 vehicle.SetHealth(damageZone, "", (zoneMax * GameConstants.DAMAGE_BADLY_DAMAGED_VALUE) + randomValue);
59 break;
60 case GameConstants.STATE_WORN:
61 vehicle.SetHealth(damageZone, "", (zoneMax * GameConstants.DAMAGE_DAMAGED_VALUE) + randomValue);
62 break;
63 }
64 }
65 }
66 }
67
68 protected void AdjustItemQuantityServer(ActionData action_data)
69 {
70 if (action_data.m_MainItem.HasQuantity())
71 {
72 if (action_data.m_MainItem.GetQuantity() > 1)
73 {
74 int qnt = action_data.m_MainItem.GetQuantity() - action_data.m_MainItem.GetQuantityMax() * 0.25;
75 action_data.m_MainItem.SetQuantity(qnt);
76 }
77 else
78 {
79 action_data.m_MainItem.Delete();
80 }
81 }
82 }
83
84 override ActionData CreateActionData()
85 {
86 RepairVehiclePartActionData actionData = new RepairVehiclePartActionData();
87 return actionData;
88 }
89
90 override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
91 {
92 super.WriteToContext(ctx, action_data);
93 RepairVehiclePartActionData repairActionData;
94
95 if (HasTarget() && Class.CastTo(repairActionData, action_data))
96 {
97 repairActionData.m_DamageZone = m_CurrentDamageZone;
98 ctx.Write(repairActionData.m_DamageZone);
99 }
100 }
101
102 override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
103 {
104 if (!action_recive_data)
105 {
106 action_recive_data = new RepairVehiclePartActionReciveData();
107 }
108
109 super.ReadFromContext(ctx, action_recive_data);
110 RepairVehiclePartActionReciveData recieveDataRepair = RepairVehiclePartActionReciveData.Cast(action_recive_data);
111
112 if (HasTarget())
113 {
114 string zone;
115 if (!ctx.Read(zone))
116 {
117 return false;
118 }
119
120 recieveDataRepair.m_DamageZoneRecived = zone;
121 }
122
123 return true;
124 }
125
126 override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
127 {
128 super.HandleReciveData(action_recive_data, action_data);
129
130 RepairVehiclePartActionReciveData recieveDataRepair = RepairVehiclePartActionReciveData.Cast(action_recive_data);
131 RepairVehiclePartActionData.Cast(action_data).m_DamageZone = recieveDataRepair.m_DamageZoneRecived;
132 }
133};
RepairTentActionReciveData m_DamageZone
ActionData m_ActionData
bool HasTarget()
Definition actionbase.c:244
ref CCIBase m_ConditionItem
Definition actionbase.c:64
ref CCTBase m_ConditionTarget
Definition actionbase.c:65
override void OnFinishProgressServer(ActionData action_data)
void AdjustItemQuantityServer(ActionData action_data)
override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
void AdjustVehicleHealthServer(ActionData action_data)
override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_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
Native class for boats - handles physics simulation.
Definition boat.c:28
proto native CGame GetGame()