From 20b326d396fd4d1bdc9052612bd09563cec008ca Mon Sep 17 00:00:00 2001 From: Sardelka Date: Tue, 12 Jul 2022 17:15:54 +0800 Subject: [PATCH] Check before breaking a door --- RageCoop.Client/Util/VehicleExtensions.cs | 116 +++++++++++----------- 1 file changed, 60 insertions(+), 56 deletions(-) diff --git a/RageCoop.Client/Util/VehicleExtensions.cs b/RageCoop.Client/Util/VehicleExtensions.cs index ddd0e62b..3bd30110 100644 --- a/RageCoop.Client/Util/VehicleExtensions.cs +++ b/RageCoop.Client/Util/VehicleExtensions.cs @@ -139,6 +139,66 @@ public static VehicleDamageModel GetVehicleDamageModel(this Vehicle veh) RightHeadLightBroken = (byte)(veh.IsRightHeadLightBroken ? 1 : 0) }; } + + public static void SetDamageModel(this Vehicle veh, VehicleDamageModel model, bool leavedoors = true) + { + for (int i = 0; i < 8; i++) + { + var door = veh.Doors[(VehicleDoorIndex)i]; + if ((model.BrokenDoors & (byte)(1 << i)) != 0) + { + if (!door.IsBroken) + { + door.Break(leavedoors); + } + } + else if (door.IsBroken) + { + // The vehicle can only fix a door if the vehicle was completely fixed + veh.Repair(); + return; + } + if ((model.OpenedDoors & (byte)(1 << i)) != 0) + { + if ((!door.IsOpen)&&(!door.IsBroken)) + { + door.Open(); + } + } + else if (door.IsOpen) + { + if (!door.IsBroken) { door.Close(); } + } + + if ((model.BrokenWindows & (byte)(1 << i)) != 0) + { + veh.Windows[(VehicleWindowIndex)i].Smash(); + } + else if (!veh.Windows[(VehicleWindowIndex)i].IsIntact) + { + veh.Windows[(VehicleWindowIndex)i].Repair(); + } + } + + foreach (VehicleWheel wheel in veh.Wheels) + { + if ((model.BurstedTires & (short)(1 << (int)wheel.BoneId)) != 0) + { + if (!wheel.IsBursted) + { + wheel.Puncture(); + wheel.Burst(); + } + } + else if (wheel.IsBursted) + { + wheel.Fix(); + } + } + + veh.IsLeftHeadLightBroken = model.LeftHeadLightBroken > 0; + veh.IsRightHeadLightBroken = model.RightHeadLightBroken > 0; + } public static Dictionary GetPassengers(this Vehicle veh) { @@ -207,62 +267,6 @@ public static void SetNozzleAngel(this Vehicle plane, float ratio) { Function.Call(Hash.SET_VEHICLE_FLIGHT_NOZZLE_POSITION, plane, ratio); } - public static void SetDamageModel(this Vehicle veh, VehicleDamageModel model, bool leavedoors = true) - { - for (int i = 0; i < 8; i++) - { - var door = veh.Doors[(VehicleDoorIndex)i]; - if ((model.BrokenDoors & (byte)(1 << i)) != 0) - { - door.Break(leavedoors); - } - else if (door.IsBroken) - { - // The vehicle can only fix a door if the vehicle was completely fixed - veh.Repair(); - return; - } - if ((model.OpenedDoors & (byte)(1 << i)) != 0) - { - if ((!door.IsOpen)&&(!door.IsBroken)) - { - door.Open(); - } - } - else if (door.IsOpen) - { - if (!door.IsBroken) { door.Close(); } - } - - if ((model.BrokenWindows & (byte)(1 << i)) != 0) - { - veh.Windows[(VehicleWindowIndex)i].Smash(); - } - else if (!veh.Windows[(VehicleWindowIndex)i].IsIntact) - { - veh.Windows[(VehicleWindowIndex)i].Repair(); - } - } - - foreach (VehicleWheel wheel in veh.Wheels) - { - if ((model.BurstedTires & (short)(1 << (int)wheel.BoneId)) != 0) - { - if (!wheel.IsBursted) - { - wheel.Puncture(); - wheel.Burst(); - } - } - else if (wheel.IsBursted) - { - wheel.Fix(); - } - } - - veh.IsLeftHeadLightBroken = model.LeftHeadLightBroken > 0; - veh.IsRightHeadLightBroken = model.RightHeadLightBroken > 0; - } #endregion }