DayZ 1.24
Loading...
Searching...
No Matches
PluginRepairing.c
Go to the documentation of this file.
1class PluginRepairing extends PluginBase
2{
4 {
5 switch (item.GetHealthLevel(damage_zone))
6 {
8 break;
10#ifdef DEVELOPER
11 Debug.Log("repairing from GameConstants.STATE_RUINED");
12#endif
14 break;
16 if (CanRepairToPristine(player) || CanBeRepairedToPristine(item))
17 CalculateHealth(player, repair_kit, item, specialty_weight,/* GameConstants.DAMAGE_PRISTINE_VALUE,*/ damage_zone, use_kit_qty);
18 break;
19 default:
21 break;
22 }
23
24 return true;
25 }
26
28 {
31
32 if (entity != null)
33 entity.SetAllowDamage(true);
34
35 bool kit_has_quantity = kit.HasQuantity();
36 int health_levels_count = item.GetNumberOfHealthLevels(damage_zone);
37 float cur_kit_quantity = kit.GetQuantity();
38 float kit_repair_cost_per_level = GetKitRepairCost(kit, item);
39 float kit_repair_cost_adjusted; //used with specialty_weight, disconnected
40 float new_quantity;
41
42 int target_level = Math.Clamp(item.GetHealthLevel(damage_zone) - 1, 0, health_levels_count - 1);
43 float health_coef;
44 if (!CanRepairToPristine(player) && !CanBeRepairedToPristine(item))
46 health_coef = item.GetHealthLevelValue(target_level, damage_zone);
47
48 //handles kit depletion; TODO: move to separate method.
50 {
51 kit_repair_cost_adjusted = kit_repair_cost_per_level; //TODO: removed speciality weight for now, it should affect speed only (?).
52 //kit_repair_cost_adjusted = player.GetSoftSkillsManager().SubtractSpecialtyBonus( kit_repair_cost_per_level, specialty_weight );
54 if (use_kit_qty)
55 {
57 kit.SetQuantity(new_quantity);
58 }
59 }
60 else if (!kit_has_quantity) //"kit" without quantity (hammers and such) for your every day repairing needs
61 {
62 }
63 else
64 {
65 if (use_kit_qty)
66 kit.SetQuantity(0);
67 }
68
69 if (item.GetHealth01(damage_zone, "Health") < health_coef)
70 item.SetHealth01(damage_zone, "Health", health_coef);
71
72 if (entity != null)
73 entity.ProcessInvulnerabilityCheck(entity.GetInvulnerabilityTypeString());
74 }
75
77 {
78 int state = item.GetHealthLevel(damage_zone);
79
80 if (state != GameConstants.STATE_RUINED && (item.CanBeRepairedToPristine() && state >= GameConstants.STATE_WORN) || (!item.CanBeRepairedToPristine() && state >= GameConstants.STATE_DAMAGED))
81 {
82 int repair_kit_type = repair_kit.ConfigGetInt("repairKitType");
83
85 item.ConfigGetIntArray("repairableWithKits", repairable_with_types);
86
87 for (int i = 0; i < repairable_with_types.Count(); i++)
88 {
90
91 if (IsRepairValid(repair_kit_type, repairable_with_type))
92 return true;
93 }
94 }
95 return false;
96
97 }
98
100 {
103
104 return false;
105 }
106
109 {
110 return false;
111 }
112
115 {
116 return item.CanBeRepairedToPristine();
117 }
118
120 {
123
124 item.ConfigGetIntArray("repairableWithKits", allowedRepairKitTypes);
125 item.ConfigGetFloatArray("repairCosts", repairKitCosts);
126
127 int repairKitType = repair_kit.ConfigGetInt("repairKitType");
128
129 foreach (int i, int allowedKitType : allowedRepairKitTypes)
130 {
132 return repairKitCosts.Get(i);
133 }
134
135 return 0;
136 }
137}
Super root of all classes in Enforce script.
Definition EnScript.c:11
Definition Debug.c:14
static void Log(string message=LOG_DEFAULT, string plugin=LOG_DEFAULT, string author=LOG_DEFAULT, string label=LOG_DEFAULT, string entity=LOG_DEFAULT)
Prints debug message with normal prio.
Definition Debug.c:133
Definition EnMath.c:7
bool CanRepairToPristine(PlayerBase player)
Player can repair items to 100%; currently unused.
void CalculateHealth(PlayerBase player, ItemBase kit, Object item, float specialty_weight, string damage_zone="", bool use_kit_qty=true)
float GetKitRepairCost(ItemBase repair_kit, Object item)
bool CanRepair(ItemBase repair_kit, Object item, string damage_zone="")
bool Repair(PlayerBase player, ItemBase repair_kit, Object item, float specialty_weight, string damage_zone="", bool use_kit_qty=true)
bool CanBeRepairedToPristine(Object item)
Item can be repaired to 100%.
bool IsRepairValid(int repair_kit_type, int repairable_with_type)
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
const int STATE_RUINED
Definition constants.c:757
const int STATE_WORN
Definition constants.c:760
const int STATE_DAMAGED
Definition constants.c:759
const int STATE_PRISTINE
Definition constants.c:761
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'.