Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionrepaircarengine.c
Go to the documentation of this file.
1 class RepairCarEngineActionReciveData : ActionReciveData
2 {
3  string m_DamageZoneRecived;
4 }
5 
6 class RepairCarEngineActionData : 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  typename m_LastValidType;
22  string m_CurrentDamageZone = "";
24 
26  {
27  m_CallbackClass = ActionRepairTentPartCB;
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  }
35 
36  override void CreateConditionComponents()
37  {
40  }
41 
42  override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
43  {
44  if (player.GetBrokenLegs() == eBrokenLegs.BROKEN_LEGS)
45  return false;
46 
47  Object targetObject = target.GetObject();
48  Object targetParent = target.GetParent();
49  CarScript car = CarScript.Cast(targetObject);
50  EntityAI carEntity = EntityAI.Cast(targetObject);
51 
52  if (!car || !player)
53  return false;
54 
55  if (car.EngineIsOn())
56  return false;
57 
58  if (GetGame().IsMultiplayer() && GetGame().IsServer())
59  return true;
60 
61  if (m_LastValidType != target.Type() || m_LastValidComponentIndex != target.GetComponentIndex() || m_CurrentDamageZone == "")
62  {
63  string damageZone = "";
64  array<string> selections = new array<string>();
65  targetObject.GetActionComponentNameList(target.GetComponentIndex(), selections, LOD.NAME_VIEW);
66 
67  foreach (string selection : selections)
68  {
69  //NOTE: relevant fire geometry and view geometry selection names MUST match in order to get a valid damage zone
70  if (carEntity && DamageSystem.GetDamageZoneFromComponentName(carEntity, selection, damageZone))
71  {
72  if (damageZone == "Engine")
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  return true;
81  }
82  }
83  }
84  }
85  }
86 
87  return false;
88  }
89 
90  override void OnFinishProgressServer(ActionData action_data)
91  {
92  Object tgObject = action_data.m_Target.GetObject();
93 
94  string damageZone = RepairCarPartActionData.Cast(action_data).m_DamageZone;
95  if (!GetGame().IsMultiplayer())
96  damageZone = m_CurrentDamageZone;
97 
98  if (tgObject && damageZone != "")
99  {
100  CarScript car = CarScript.Cast(tgObject);
101  if (car)
102  {
103  int newDmgLevel = Math.Clamp(car.GetHealthLevel(damageZone) - 1, GameConstants.STATE_WORN, GameConstants.STATE_RUINED);
104  float zoneMax = car.GetMaxHealth(damageZone, "");
105  float randomValue = Math.RandomFloatInclusive(zoneMax * 0.05, zoneMax * 0.15);
106 
107  switch (newDmgLevel)
108  {
109  case GameConstants.STATE_BADLY_DAMAGED:
110  car.SetHealth(damageZone, "", (zoneMax * GameConstants.DAMAGE_RUINED_VALUE) + randomValue);
111  break;
112 
113  case GameConstants.STATE_DAMAGED:
114  car.SetHealth(damageZone, "", (zoneMax * GameConstants.DAMAGE_BADLY_DAMAGED_VALUE) + randomValue);
115  break;
116 
117  case GameConstants.STATE_WORN:
118  car.SetHealth(damageZone, "", (zoneMax * GameConstants.DAMAGE_DAMAGED_VALUE) + randomValue);
119  break;
120 
121  default:
122  break;
123  }
124 
125  MiscGameplayFunctions.DealAbsoluteDmg(action_data.m_MainItem, UADamageApplied.BUILD);
126  }
127  }
128  }
129 
131  {
132  RepairCarPartActionData actionData = new RepairCarPartActionData();
133  return actionData;
134  }
135 
136  override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
137  {
138  super.WriteToContext(ctx, action_data);
139  RepairCarPartActionData repairActionData;
140 
141  if (HasTarget() && Class.CastTo(repairActionData, action_data))
142  {
143  repairActionData.m_DamageZone = m_CurrentDamageZone;
144  ctx.Write(repairActionData.m_DamageZone);
145  }
146  }
147 
148  override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
149  {
150  if (!action_recive_data)
151  action_recive_data = new RepairCarPartActionReciveData();
152 
153  super.ReadFromContext(ctx, action_recive_data);
154  RepairCarPartActionReciveData reciveDataRepair = RepairCarPartActionReciveData.Cast(action_recive_data);
155 
156  if (HasTarget())
157  {
158  string zone;
159  if (!ctx.Read(zone))
160  return false;
161 
162  reciveDataRepair.m_DamageZoneRecived = zone;
163  }
164 
165  return true;
166  }
167 
168  override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
169  {
170  super.HandleReciveData(action_recive_data, action_data);
171 
172  RepairCarPartActionReciveData reciveDataRepair = RepairCarPartActionReciveData.Cast(action_recive_data);
173  RepairCarPartActionData.Cast(action_data).m_DamageZone = reciveDataRepair.m_DamageZoneRecived;
174  }
175 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
ActionCondition
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
Definition: actionrepaircarengine.c:42
UADamageApplied
Definition: actionconstants.c:130
CAContinuousTime
Definition: cacontinuoustime.c:1
ActionRepairCarEngineCB
Definition: actionrepaircarengine.c:11
ActionRepairCarEngine
void ActionRepairCarEngine()
Definition: actionrepaircarengine.c:25
UASoftSkillsWeight
Definition: actionconstants.c:118
RepairCarPartActionReciveData
Definition: actionrepaircarpart.c:1
m_LastValidType
ActionRepairCarEngineCB m_LastValidType
CarScript
Definition: civiliansedan.c:1
LOD
LOD class.
Definition: gameplay.c:202
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
RepairCarEngineActionReciveData
Definition: actionrepaircarengine.c:1
PlayerBase
Definition: playerbaseclient.c:1
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
WriteToContext
override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
Definition: actionrepaircarengine.c:136
CreateConditionComponents
override void CreateConditionComponents()
Definition: actionrepaircarengine.c:36
Object
Definition: objecttyped.c:1
ActionRepairTentPartCB
Definition: actionrepairtentpart.c:11
CreateActionData
override ActionData CreateActionData()
Definition: actionrepaircarengine.c:130
CCTCursor
Definition: cctcursor.c:1
UATimeSpent
Definition: actionconstants.c:26
ActionContinuousBaseCB
Definition: actioncontinuousbase.c:1
m_LockTargetOnUse
protected bool m_LockTargetOnUse
Definition: actionbase.c:51
array< string >
m_DamageZone
RepairCarEngineActionReciveData m_DamageZone
ReadFromContext
override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
Definition: actionrepaircarengine.c:148
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
OnFinishProgressServer
override void OnFinishProgressServer(ActionData action_data)
Definition: actionrepaircarengine.c:90
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
HandleReciveData
override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
Definition: actionrepaircarengine.c:168
m_SpecialtyWeight
protected float m_SpecialtyWeight
Definition: actionbase.c:68
m_StanceMask
protected int m_StanceMask
Definition: actionbase.c:53
EntityAI
Definition: building.c:5