Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
actionrepaircarpart.c
Go to the documentation of this file.
1 class RepairCarPartActionReciveData : ActionReciveData
2 {
3  string m_DamageZoneRecived;
4 }
5 
6 class RepairCarPartActionData : 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 = ActionRepairCarPartCB;
29 
30  m_CommandUID = DayZPlayerConstants.CMD_ACTIONFB_INTERACT;
31  m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT;
32  m_FullBody = true;
33  m_LockTargetOnUse = false;
34  m_Text = "#repair";
35  }
36 
37  override void CreateConditionComponents()
38  {
41  }
42 
43  override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
44  {
45  if (player.GetBrokenLegs() == eBrokenLegs.BROKEN_LEGS)
46  return false;
47 
48  Object targetObject = target.GetObject();
49  Object targetParent = target.GetParent();
50  CarDoor carDoor = CarDoor.Cast(targetObject);
51 
52  if (!carDoor || !player)
53  return false;
54 
55  if (GetGame().IsMultiplayer() && GetGame().IsServer())
56  return true;
57 
58  if (carDoor)
59  {
60  //Check if item is attached to car -> If so, block repair if door is closed
61  if (targetParent != null)
62  {
64  bool isPresent = carDoor.GetInventory().GetCurrentInventoryLocation(loc);
65 
66  if (!isPresent || loc.GetSlot() == -1)
67  return false;
68 
69  string slotName = InventorySlots.GetSlotName(loc.GetSlot());
70  if (slotName && CarScript.Cast(targetParent).GetCarDoorsState(slotName) != CarDoorState.DOORS_OPEN)
71  return false;
72  }
73 
74  //Check health level of door
75  int zoneHP = carDoor.GetHealthLevel("");
76  return zoneHP > GameConstants.STATE_WORN && zoneHP < GameConstants.STATE_RUINED);
77  }
78 
79  return false;
80  }
81 
82  override void OnFinishProgressServer(ActionData action_data)
83  {
84  Object tgObject = action_data.m_Target.GetObject();
85 
86  string damageZone = RepairCarPartActionData.Cast(action_data).m_DamageZone;
87  if (!GetGame().IsMultiplayer())
88  damageZone = m_CurrentDamageZone;
89 
90  if (tgObject)
91  {
92  CarDoor carDoor = CarDoor.Cast(tgObject);
93  if (carDoor)
94  {
95  int newDmgLevel = Math.Clamp(carDoor.GetHealthLevel(damageZone) - 1, GameConstants.STATE_WORN, GameConstants.STATE_RUINED);
96  float zoneMax = carDoor.GetMaxHealth("", "");
97  float randomValue = Math.RandomFloatInclusive(zoneMax * 0.05, zoneMax * 0.15);
98 
99  switch (newDmgLevel)
100  {
101  case GameConstants.STATE_BADLY_DAMAGED:
102  carDoor.SetHealth("", "", (zoneMax * GameConstants.DAMAGE_RUINED_VALUE) + randomValue);
103  break;
104 
105  case GameConstants.STATE_DAMAGED:
106  carDoor.SetHealth("", "", (zoneMax * GameConstants.DAMAGE_BADLY_DAMAGED_VALUE) + randomValue);
107  break;
108 
109  case GameConstants.STATE_WORN:
110  carDoor.SetHealth("", "", (zoneMax * GameConstants.DAMAGE_DAMAGED_VALUE) + randomValue);
111  break;
112 
113  default:
114  break;
115  }
116 
117  if (action_data.m_MainItem.HasQuantity())
118  {
119  if (action_data.m_MainItem.GetQuantity() > 1)
120  {
121  int qnt = action_data.m_MainItem.GetQuantity();
122  qnt -= action_data.m_MainItem.GetQuantityMax() * 0.25;
123  action_data.m_MainItem.SetQuantity(qnt);
124  }
125  else
126  action_data.m_MainItem.Delete();
127  }
128  }
129  }
130  }
131 
133  {
134  RepairCarPartActionData actionData = new RepairCarPartActionData();
135  return actionData;
136  }
137 
138  override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
139  {
140  super.WriteToContext(ctx, action_data);
141  RepairCarPartActionData repairActionData;
142 
143  if (HasTarget() && Class.CastTo(repairActionData, action_data))
144  {
145  repairActionData.m_DamageZone = m_CurrentDamageZone;
146  ctx.Write(repairActionData.m_DamageZone);
147  }
148  }
149 
150  override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
151  {
152  if (!action_recive_data)
153  action_recive_data = new RepairCarPartActionReciveData();
154 
155  super.ReadFromContext(ctx, action_recive_data);
156  RepairCarPartActionReciveData reciveDataRepair = RepairCarPartActionReciveData.Cast(action_recive_data);
157 
158  if (HasTarget())
159  {
160  string zone;
161  if (!ctx.Read(zone))
162  return false;
163 
164  reciveDataRepair.m_DamageZoneRecived = zone;
165  }
166 
167  return true;
168  }
169 
170  override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
171  {
172  super.HandleReciveData(action_recive_data, action_data);
173 
174  RepairCarPartActionReciveData reciveDataRepair = RepairCarPartActionReciveData.Cast(action_recive_data);
175  RepairCarPartActionData.Cast(action_data).m_DamageZone = reciveDataRepair.m_DamageZoneRecived;
176  }
177 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
CarDoor
Definition: inventoryitem.c:496
CAContinuousTime
Definition: cacontinuoustime.c:1
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
WriteToContext
override void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
Definition: actionrepaircarpart.c:138
UASoftSkillsWeight
Definition: actionconstants.c:118
RepairCarPartActionReciveData
Definition: actionrepaircarpart.c:1
CarScript
Definition: civiliansedan.c:1
m_LastValidType
ActionRepairCarPartCB m_LastValidType
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
m_CurrentDamageZone
string m_CurrentDamageZone
Definition: actionrepaircarpart.c:22
m_DamageZone
RepairCarPartActionReciveData m_DamageZone
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
ActionCondition
override bool ActionCondition(PlayerBase player, ActionTarget target, ItemBase item)
Definition: actionrepaircarpart.c:43
ActionTarget
class ActionTargets ActionTarget
ActionData
Definition: actionbase.c:20
DayZPlayerConstants
DayZPlayerConstants
defined in C++
Definition: dayzplayer.c:601
CarDoorState
CarDoorState
Definition: carscript.c:1
ReadFromContext
override bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data)
Definition: actionrepaircarpart.c:150
Object
Definition: objecttyped.c:1
slotName
PlayerSpawnPreset slotName
ActionRepairCarPart
void ActionRepairCarPart()
Definition: actionrepaircarpart.c:25
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
CreateConditionComponents
override void CreateConditionComponents()
Definition: actionrepaircarpart.c:37
m_LastValidComponentIndex
int m_LastValidComponentIndex
Definition: actionrepaircarpart.c:23
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
ActionRepairCarPartCB
Definition: actionrepaircarpart.c:11
CreateActionData
override ActionData CreateActionData()
Definition: actionrepaircarpart.c:132
ActionContinuousBase
Definition: actioncontinuousbase.c:132
CCINonRuined
Definition: ccinonruined.c:1
HandleReciveData
override void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
Definition: actionrepaircarpart.c:170
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
OnFinishProgressServer
override void OnFinishProgressServer(ActionData action_data)
Definition: actionrepaircarpart.c:82
m_SpecialtyWeight
protected float m_SpecialtyWeight
Definition: actionbase.c:68
m_StanceMask
protected int m_StanceMask
Definition: actionbase.c:53