5 switch (item.GetHealthLevel(damage_zone))
11 Debug.Log(
"repairing from GameConstants.STATE_RUINED");
13 CalculateHealth( player, repair_kit, item, specialty_weight, damage_zone, use_kit_qty );
16 if (CanRepairToPristine(player) || CanBeRepairedToPristine(item))
18 CalculateHealth( player, repair_kit, item, specialty_weight, damage_zone, use_kit_qty );
22 CalculateHealth( player, repair_kit, item, specialty_weight, damage_zone, use_kit_qty );
29 void CalculateHealth(
PlayerBase player,
ItemBase kit,
Object item,
float specialty_weight,
string damage_zone =
"",
bool use_kit_qty =
true )
32 Class.CastTo(entity,item);
36 entity.SetAllowDamage(
true);
39 bool kit_has_quantity = kit.HasQuantity();
40 int health_levels_count = item.GetNumberOfHealthLevels(damage_zone);
41 float cur_kit_quantity = kit.GetQuantity();
42 float kit_repair_cost_per_level = GetKitRepairCost( kit, item );
43 float kit_repair_cost_adjusted;
46 int target_level =
Math.Clamp(item.GetHealthLevel(damage_zone) - 1, 0, health_levels_count - 1);
48 if ( !CanRepairToPristine( player ) && !CanBeRepairedToPristine( item ) )
50 target_level =
Math.Clamp(target_level,
GameConstants.STATE_WORN, health_levels_count - 1);
52 health_coef = item.GetHealthLevelValue(target_level,damage_zone);
55 if ( cur_kit_quantity > kit_repair_cost_per_level )
57 kit_repair_cost_adjusted = kit_repair_cost_per_level;
59 kit_repair_cost_adjusted =
Math.Clamp( kit_repair_cost_adjusted, 0, 100 );
62 new_quantity = kit.GetQuantity() - kit_repair_cost_adjusted;
63 kit.SetQuantity( new_quantity );
66 else if (!kit_has_quantity)
77 if (item.GetHealth01(damage_zone,
"Health") < health_coef)
79 item.SetHealth01(damage_zone,
"Health",health_coef);
84 entity.ProcessInvulnerabilityCheck(entity.GetInvulnerabilityTypeString());
90 int state = item.GetHealthLevel(damage_zone);
92 if ( state !=
GameConstants.STATE_RUINED && (item.CanBeRepairedToPristine() && state >=
GameConstants.STATE_WORN) || (!item.CanBeRepairedToPristine() && state >=
GameConstants.STATE_DAMAGED ) )
94 int repair_kit_type = repair_kit.ConfigGetInt(
"repairKitType" );
97 item.ConfigGetIntArray(
"repairableWithKits", repairable_with_types );
99 for (
int i = 0; i < repairable_with_types.Count(); i++ )
101 int repairable_with_type = repairable_with_types.Get(i);
103 if ( IsRepairValid( repair_kit_type, repairable_with_type ) )
113 private bool IsRepairValid(
int repair_kit_type,
int repairable_with_type)
115 if (repair_kit_type > 0 && repairable_with_type > 0)
117 return repair_kit_type == repairable_with_type;
124 private bool CanRepairToPristine(
PlayerBase player)
130 private bool CanBeRepairedToPristine(
Object item)
132 return item.CanBeRepairedToPristine();
140 item.ConfigGetIntArray(
"repairableWithKits", allowedRepairKitTypes);
141 item.ConfigGetFloatArray(
"repairCosts", repairKitCosts);
143 int repairKitType = repair_kit.ConfigGetInt(
"repairKitType");
145 foreach (
int i,
int allowedKitType : allowedRepairKitTypes)
147 if (allowedKitType == repairKitType)
149 return repairKitCosts.Get(i);