DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
PluginRepairing.c
См. документацию.
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 {
8 break;
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;
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
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.
Определения EnScript.c:11
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.
Определения Debug.c:122
Определения Debug.c:2
Определения Building.c:6
Определения constants.c:659
override bool SetQuantity(float value, bool destroy_config=true, bool destroy_forced=false, bool allow_client=false, bool clamp_to_stack_max=true)
Определения PileOfWoodenPlanks.c:88
Определения InventoryItem.c:731
Определения EnMath.c:7
Определения ObjectTyped.c:2
Определения PlayerBaseClient.c:2
bool CanRepairToPristine(PlayerBase player)
Player can repair items to 100%; currently unused.
Определения PluginRepairing.c:132
void CalculateHealth(PlayerBase player, ItemBase kit, Object item, float specialty_weight, string damage_zone="", bool use_kit_qty=true)
Определения PluginRepairing.c:29
float GetKitRepairCost(ItemBase repair_kit, Object item)
Определения PluginRepairing.c:143
bool CanRepair(ItemBase repair_kit, Object item, string damage_zone="")
Определения PluginRepairing.c:92
bool Repair(PlayerBase player, ItemBase repair_kit, Object item, float specialty_weight, string damage_zone="", bool use_kit_qty=true)
Определения PluginRepairing.c:3
bool CanBeRepairedToPristine(Object item)
Item can be repaired to 100%.
Определения PluginRepairing.c:138
bool IsRepairValid(int repair_kit_type, int repairable_with_type)
Определения PluginRepairing.c:121
Определения PluginBase.c:2
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
const int STATE_RUINED
Определения constants.c:846
const int STATE_WORN
Определения constants.c:849
const int STATE_DAMAGED
Определения constants.c:848
const int STATE_PRISTINE
Определения constants.c:850
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'.