94 lines
4.2 KiB
C#
94 lines
4.2 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace Harmony.VehiclePartPatches
|
|
{
|
|
[HarmonyPatch(typeof(VehiclePart))]
|
|
[HarmonyPatch("IsBroken")]
|
|
public class DamageVehiclePartPatch
|
|
{
|
|
public static bool Prefix(VehiclePart __instance, ref bool __result,
|
|
Vehicle ___vehicle
|
|
)
|
|
{
|
|
__result = false;
|
|
|
|
//Log.Out("VehiclePartPatches-IsBroken START");
|
|
|
|
if (___vehicle.GetHealth() <= 0)
|
|
{
|
|
//Log.Out("VehiclePartPatches-IsBroken 1");
|
|
__result = true;
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
//Log.Out("VehiclePartPatches-IsBroken 2");
|
|
|
|
if (___vehicle.entity.HasDriver && ___vehicle.entity is global::EntityVehicleRebirth)
|
|
{
|
|
//Log.Out("VehiclePartPatches-IsBroken 3");
|
|
global::EntityVehicleRebirth entityVehicle = (global::EntityVehicleRebirth)___vehicle.entity;
|
|
|
|
if (___vehicle.entity.EntityClass.Properties.Values.ContainsKey("VehicleType"))
|
|
{
|
|
string vehicleType = ___vehicle.entity.EntityClass.Properties.Values["VehicleType"];
|
|
|
|
//Log.Out("VehiclePartPatches-IsBroken 4, vehicleType: " + vehicleType);
|
|
|
|
int currentPart = 0;
|
|
|
|
foreach (string vehicleTypeKey in RebirthVariables.localVehicleTypes.Keys)
|
|
{
|
|
if (vehicleType == vehicleTypeKey)
|
|
{
|
|
//Log.Out("VehiclePartPatches-IsBroken 5");
|
|
|
|
List<RepairableVehicleSlotsEnum> partsList = RebirthVariables.localVehicleTypes[vehicleTypeKey];
|
|
|
|
//Log.Out("VehiclePartPatches-IsBroken 6, partsList.Count: " + partsList.Count);
|
|
|
|
for (int i = 0; i < partsList.Count; i++)
|
|
{
|
|
RepairableVehicleSlotsEnum partName = partsList[i];
|
|
|
|
//Log.Out("VehiclePartPatches-IsBroken 7, partName: " + partName);
|
|
|
|
foreach (RepairableVehicleSlotsEnum key in RebirthVariables.localVehicleParts.Keys)
|
|
{
|
|
if (key == partName && RebirthVariables.localVehicleParts[key].requiredToOperate)
|
|
{
|
|
//Log.Out("VehiclePartPatches-IsBroken 6");
|
|
if (entityVehicle.itemValues[i].type == ItemValue.None.type)
|
|
{
|
|
//Log.Out("VehiclePartPatches-IsBroken MISSING OR BROKEN: " + partName);
|
|
__result = true;
|
|
return false;
|
|
}
|
|
else
|
|
{
|
|
int maxUSerTimes = entityVehicle.itemValues[i].MaxUseTimes;
|
|
int useTimes = (int)entityVehicle.itemValues[i].UseTimes;
|
|
|
|
bool flag = entityVehicle.itemValues[i].MaxUseTimes - entityVehicle.itemValues[i].UseTimes == 0;
|
|
|
|
if (flag)
|
|
{
|
|
//Log.Out("VehiclePartPatches-IsBroken MISSING OR BROKEN: " + partName);
|
|
__result = true;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
}
|