Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
pluginrepairing.c
Go to the documentation of this file.
1class PluginRepairing extends PluginBase
2{
3 bool Repair(PlayerBase player, ItemBase repair_kit, Object item, float specialty_weight, string damage_zone = "", bool use_kit_qty = true)
4 {
5 switch (item.GetHealthLevel(damage_zone))
6 {
7 case GameConstants.STATE_PRISTINE:
8 break;
9 case GameConstants.STATE_RUINED:
10 #ifdef DEVELOPER
11 Debug.Log("repairing from GameConstants.STATE_RUINED");
12 #endif
13 CalculateHealth(player, repair_kit, item, specialty_weight, damage_zone, use_kit_qty);
14 break;
15 case GameConstants.STATE_WORN:
16 if (CanRepairToPristine(player) || CanBeRepairedToPristine(item))
17 {
18 CalculateHealth(player, repair_kit, item, specialty_weight,/* GameConstants.DAMAGE_PRISTINE_VALUE,*/ damage_zone, use_kit_qty);
19 }
20 break;
21 default:
22 CalculateHealth(player, repair_kit, item, specialty_weight, damage_zone, use_kit_qty);
23 break;
24 }
25
26 return true;
27 }
28
29 void CalculateHealth(PlayerBase player, ItemBase kit, Object item, float specialty_weight, string damage_zone = "", bool use_kit_qty = true)
30 {
31 EntityAI entity;
32 Class.CastTo(entity,item);
33
34 if (entity != null)
35 {
36 entity.SetAllowDamage(true);
37 }
38
39 int health_levels_count = item.GetNumberOfHealthLevels(damage_zone);
40 float kit_repair_cost_adjusted; //used with specialty_weight, disconnected
41 float new_quantity;
42
43 int target_level = Math.Clamp(item.GetHealthLevel(damage_zone) - 1, 0, health_levels_count - 1);
44 float health_coef;
45 if (!CanRepairToPristine(player) && !CanBeRepairedToPristine(item))
46 {
47 target_level = Math.Clamp(target_level, GameConstants.STATE_WORN, health_levels_count - 1);
48 }
49 health_coef = item.GetHealthLevelValue(target_level,damage_zone);
50
51 //handles kit depletion; TODO: move to separate method.
52 if (kit && kit.ConfigGetInt("repairKitType"))
53 {
54 bool kit_has_quantity = kit.HasQuantity();
55 float cur_kit_quantity = kit.GetQuantity();
56 float kit_repair_cost_per_level = GetKitRepairCost(kit, item);
57
58 if (cur_kit_quantity > kit_repair_cost_per_level)
59 {
60 kit_repair_cost_adjusted = kit_repair_cost_per_level; //TODO: removed speciality weight for now, it should affect speed only (?).
61 //kit_repair_cost_adjusted = player.GetSoftSkillsManager().SubtractSpecialtyBonus(kit_repair_cost_per_level, specialty_weight);
62 kit_repair_cost_adjusted = Math.Clamp(kit_repair_cost_adjusted, 0, 100);
63 if (use_kit_qty)
64 {
65 new_quantity = kit.GetQuantity() - kit_repair_cost_adjusted;
66 kit.SetQuantity(new_quantity);
67 }
68 }
69 else if (!kit_has_quantity) //"kit" without quantity (hammers and such) for your every day repairing needs
70 {
71 }
72 else
73 {
74 if (use_kit_qty)
75 {
76 kit.SetQuantity(0);
77 }
78 }
79 }
80
81 if (item.GetHealth01(damage_zone,"Health") < health_coef)
82 {
83 item.SetHealth01(damage_zone,"Health",health_coef);
84 }
85
86 if (entity != null)
87 {
88 entity.ProcessInvulnerabilityCheck(entity.GetInvulnerabilityTypeString());
89 }
90 }
91
92 bool CanRepair(ItemBase repair_kit, Object item, string damage_zone = "")
93 {
94 int state = item.GetHealthLevel(damage_zone);
95
96 if (state != GameConstants.STATE_RUINED && (item.CanBeRepairedToPristine() && state >= GameConstants.STATE_WORN) || (!item.CanBeRepairedToPristine() && state >= GameConstants.STATE_DAMAGED))
97 {
98 int repair_kit_type = repair_kit.ConfigGetInt("repairKitType");
99 if (!repair_kit_type) //outside of regular repair kit logic for some reason, bypass check
100 {
101 return true;
102 }
103
104 array<int> repairable_with_types = new array<int>;
105 item.ConfigGetIntArray("repairableWithKits", repairable_with_types);
106
107 for (int i = 0; i < repairable_with_types.Count(); i++)
108 {
109 int repairable_with_type = repairable_with_types.Get(i);
110
111 if (IsRepairValid(repair_kit_type, repairable_with_type))
112 {
113 return true;
114 }
115 }
116 }
117 return false;
118
119 }
120
121 private bool IsRepairValid(int repair_kit_type, int repairable_with_type)
122 {
123 if (repair_kit_type > 0 && repairable_with_type > 0)
124 {
125 return repair_kit_type == repairable_with_type;
126 }
127
128 return false;
129 }
130
132 private bool CanRepairToPristine(PlayerBase player)
133 {
134 return false;
135 }
136
138 private bool CanBeRepairedToPristine(Object item)
139 {
140 return item.CanBeRepairedToPristine();
141 }
142
143 private float GetKitRepairCost(ItemBase repair_kit, Object item)
144 {
145 array<int> allowedRepairKitTypes = new array<int>();
146 array<float> repairKitCosts = new array<float>();
147
148 item.ConfigGetIntArray("repairableWithKits", allowedRepairKitTypes);
149 item.ConfigGetFloatArray("repairCosts", repairKitCosts);
150
151 int repairKitType = repair_kit.ConfigGetInt("repairKitType");
152
153 foreach (int i, int allowedKitType : allowedRepairKitTypes)
154 {
155 if (allowedKitType == repairKitType)
156 {
157 return repairKitCosts.Get(i);
158 }
159 }
160
161 return 0;
162 }
163}
Super root of all classes in Enforce script.
Definition enscript.c:11
Definition debug.c:2
Definition enmath.c:7
Plugin interface for controlling of agent pool system.
Definition pluginbase.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
bool CanRepair(ItemBase item_repair_kit)
Definition itembase.c:7493
bool Repair(PlayerBase player, ItemBase item_repair_kit, float specialty_weight)
Definition itembase.c:7500