diff --git a/ValheimPlus/Configurations/Sections/StructuralIntegrityConfiguration.cs b/ValheimPlus/Configurations/Sections/StructuralIntegrityConfiguration.cs index 6c34ad48..d0297642 100644 --- a/ValheimPlus/Configurations/Sections/StructuralIntegrityConfiguration.cs +++ b/ValheimPlus/Configurations/Sections/StructuralIntegrityConfiguration.cs @@ -6,6 +6,7 @@ public class StructuralIntegrityConfiguration : ServerSyncConfig - /// Disable weather damage - /// + /// + /// Disable weather damage + /// [HarmonyPatch(typeof(WearNTear), "HaveRoof")] public static class RemoveWearNTear { @@ -19,42 +19,42 @@ private static void Postfix(ref bool __result) } } - /// - /// Disable weather damage under water - /// - [HarmonyPatch(typeof(WearNTear), "IsUnderWater")] - public static class RemoveWearNTearFromUnderWater - { - private static void Postfix(ref bool __result) - { - if (Configuration.Current.Building.IsEnabled && Configuration.Current.Building.noWeatherDamage) - { - __result = false; - } - } - } + /// + /// Disable weather damage under water + /// + [HarmonyPatch(typeof(WearNTear), "IsUnderWater")] + public static class RemoveWearNTearFromUnderWater + { + private static void Postfix(ref bool __result) + { + if (Configuration.Current.Building.IsEnabled && Configuration.Current.Building.noWeatherDamage) + { + __result = false; + } + } + } - /// - /// Removes the integrity check for having a connected piece to the ground. - /// - [HarmonyPatch(typeof(WearNTear), "HaveSupport")] - public static class WearNTear_HaveSupport_Patch - { - private static void Postfix(ref bool __result) - { - if (Configuration.Current.Building.IsEnabled && Configuration.Current.StructuralIntegrity.disableStructuralIntegrity) - { - __result = true; - } - } - } + /// + /// Removes the integrity check for having a connected piece to the ground. + /// + [HarmonyPatch(typeof(WearNTear), "HaveSupport")] + public static class WearNTear_HaveSupport_Patch + { + private static void Postfix(ref bool __result) + { + if (Configuration.Current.Building.IsEnabled && Configuration.Current.StructuralIntegrity.disableStructuralIntegrity) + { + __result = true; + } + } + } - /// - /// Disable damage to player structures - /// - [HarmonyPatch(typeof(WearNTear), "ApplyDamage")] - public static class WearNTear_ApplyDamage_Patch - { + /// + /// Disable damage to player structures + /// + [HarmonyPatch(typeof(WearNTear), "ApplyDamage")] + public static class WearNTear_ApplyDamage_Patch + { private static bool Prefix(ref WearNTear __instance, ref float damage) { // Gets the name of the method calling the ApplyDamage method @@ -66,11 +66,11 @@ private static bool Prefix(ref WearNTear __instance, ref float damage) if (__instance.m_piece.m_name.StartsWith("$ship")) { - if (Configuration.Current.StructuralIntegrity.disableDamageToPlayerBoats || - (Configuration.Current.StructuralIntegrity.disableWaterDamageToPlayerBoats && - stackTrace.GetFrame(15).GetMethod().Name == "UpdateWaterForce")) return false; - - return true; + if (Configuration.Current.StructuralIntegrity.disableDamageToPlayerBoats || + (Configuration.Current.StructuralIntegrity.disableWaterDamageToPlayerBoats && + stackTrace.GetFrame(15).GetMethod().Name == "UpdateWaterForce")) return false; + + return true; } if (__instance.m_piece.m_name.StartsWith("$tool_cart")) { @@ -82,102 +82,115 @@ private static bool Prefix(ref WearNTear __instance, ref float damage) } return !Configuration.Current.StructuralIntegrity.disableDamageToPlayerStructures; } - } + } - /// - /// Disable structural integrity - /// - [HarmonyPatch(typeof(WearNTear), "GetMaterialProperties")] + /// + /// Disable structural integrity + /// + [HarmonyPatch(typeof(WearNTear), nameof(WearNTear.GetMaterialProperties))] public static class RemoveStructualIntegrity { private static bool Prefix(ref WearNTear __instance, out float maxSupport, out float minSupport, out float horizontalLoss, out float verticalLoss) { - if (Configuration.Current.StructuralIntegrity.IsEnabled && Configuration.Current.StructuralIntegrity.disableStructuralIntegrity) - { - maxSupport = 1500f; - minSupport = 20f; - verticalLoss = 0f; - horizontalLoss = 0f; - return false; - } - if (Configuration.Current.StructuralIntegrity.IsEnabled) - { - // This handling is choosen because we subtract from a value thats reduced by distance from ground contact. - Configuration.Current.StructuralIntegrity.wood = (Configuration.Current.StructuralIntegrity.wood >= 100 ? 100 : Configuration.Current.StructuralIntegrity.wood); - Configuration.Current.StructuralIntegrity.stone = (Configuration.Current.StructuralIntegrity.wood >= 100 ? 100 : Configuration.Current.StructuralIntegrity.stone); - Configuration.Current.StructuralIntegrity.iron = (Configuration.Current.StructuralIntegrity.wood >= 100 ? 100 : Configuration.Current.StructuralIntegrity.iron); - Configuration.Current.StructuralIntegrity.hardWood = (Configuration.Current.StructuralIntegrity.wood >= 100 ? 100 : Configuration.Current.StructuralIntegrity.hardWood); + if (Configuration.Current.StructuralIntegrity.IsEnabled && Configuration.Current.StructuralIntegrity.disableStructuralIntegrity) + { + maxSupport = 1500f; + minSupport = 20f; + verticalLoss = 0f; + horizontalLoss = 0f; + return false; + } + if (Configuration.Current.StructuralIntegrity.IsEnabled) + { + // This handling is choosen because we subtract from a value thats reduced by distance from ground contact. + Configuration.Current.StructuralIntegrity.wood = Helper.Clamp(Configuration.Current.StructuralIntegrity.wood, 0, 100); + Configuration.Current.StructuralIntegrity.stone = Helper.Clamp(Configuration.Current.StructuralIntegrity.stone, 0, 100); + Configuration.Current.StructuralIntegrity.iron = Helper.Clamp(Configuration.Current.StructuralIntegrity.iron, 0, 100); + Configuration.Current.StructuralIntegrity.hardWood = Helper.Clamp(Configuration.Current.StructuralIntegrity.hardWood, 0, 100); + Configuration.Current.StructuralIntegrity.marble = Helper.Clamp(Configuration.Current.StructuralIntegrity.marble, 0, 100); - switch (__instance.m_materialType) - { - case WearNTear.MaterialType.Wood: - maxSupport = 100f; - minSupport = 10f; - verticalLoss = 0.125f - ((0.125f / 100) * Configuration.Current.StructuralIntegrity.wood); - horizontalLoss = 0.2f - ((0.125f / 100) * Configuration.Current.StructuralIntegrity.wood); - return false; - case WearNTear.MaterialType.Stone: - maxSupport = 1000f; - minSupport = 100f; - verticalLoss = 0.125f - ((0.125f / 100) * Configuration.Current.StructuralIntegrity.stone); - horizontalLoss = 1f - ((1f / 100) * Configuration.Current.StructuralIntegrity.stone); - return false; - case WearNTear.MaterialType.Iron: - maxSupport = 1500f; - minSupport = 20f; - verticalLoss = 0.07692308f - ((0.07692308f / 100) * Configuration.Current.StructuralIntegrity.iron); - horizontalLoss = 0.07692308f - ((0.07692308f / 100) * Configuration.Current.StructuralIntegrity.iron); - return false; - case WearNTear.MaterialType.HardWood: - maxSupport = 140f; - minSupport = 10f; - verticalLoss = 0.1f - ((0.1f / 100) * Configuration.Current.StructuralIntegrity.hardWood); - horizontalLoss = 0.16666667f - ((0.16666667f / 100) * Configuration.Current.StructuralIntegrity.hardWood); - return false; - default: - maxSupport = 0f; - minSupport = 0f; - verticalLoss = 0f; - horizontalLoss = 0f; - return false; - } - } - else - { - switch (__instance.m_materialType) - { - case WearNTear.MaterialType.Wood: - maxSupport = 100f; - minSupport = 10f; - verticalLoss = 0.125f; - horizontalLoss = 0.2f; - return false; - case WearNTear.MaterialType.Stone: - maxSupport = 1000f; - minSupport = 100f; - verticalLoss = 0.125f; - horizontalLoss = 1f; - return false; - case WearNTear.MaterialType.Iron: - maxSupport = 1500f; - minSupport = 20f; - verticalLoss = 0.07692308f; - horizontalLoss = 0.07692308f; - return false; - case WearNTear.MaterialType.HardWood: - maxSupport = 140f; - minSupport = 10f; - verticalLoss = 0.1f; - horizontalLoss = 0.16666667f; - return false; - default: - maxSupport = 0f; - minSupport = 0f; - verticalLoss = 0f; - horizontalLoss = 0f; - return false; - } - } + switch (__instance.m_materialType) + { + case WearNTear.MaterialType.Wood: + maxSupport = 100f; + minSupport = 10f; + verticalLoss = 0.125f - ((0.125f / 100) * Configuration.Current.StructuralIntegrity.wood); + horizontalLoss = 0.2f - ((0.125f / 100) * Configuration.Current.StructuralIntegrity.wood); + return false; + case WearNTear.MaterialType.Stone: + maxSupport = 1000f; + minSupport = 100f; + verticalLoss = 0.125f - ((0.125f / 100) * Configuration.Current.StructuralIntegrity.stone); + horizontalLoss = 1f - ((1f / 100) * Configuration.Current.StructuralIntegrity.stone); + return false; + case WearNTear.MaterialType.Iron: + maxSupport = 1500f; + minSupport = 20f; + verticalLoss = 0.07692308f - ((0.07692308f / 100) * Configuration.Current.StructuralIntegrity.iron); + horizontalLoss = 0.07692308f - ((0.07692308f / 100) * Configuration.Current.StructuralIntegrity.iron); + return false; + case WearNTear.MaterialType.HardWood: + maxSupport = 140f; + minSupport = 10f; + verticalLoss = 0.1f - ((0.1f / 100) * Configuration.Current.StructuralIntegrity.hardWood); + horizontalLoss = 0.16666667f - ((0.16666667f / 100) * Configuration.Current.StructuralIntegrity.hardWood); + return false; + case WearNTear.MaterialType.Marble: + maxSupport = 1500f; + minSupport = 100f; + verticalLoss = 0.125f - ((0.125f / 100) * Configuration.Current.StructuralIntegrity.marble); + horizontalLoss = 0.5f - ((0.5f / 100) * Configuration.Current.StructuralIntegrity.marble); + return false; + default: + maxSupport = 0f; + minSupport = 0f; + verticalLoss = 0f; + horizontalLoss = 0f; + return false; + } + } + else + { + switch (__instance.m_materialType) + { + case WearNTear.MaterialType.Wood: + maxSupport = 100f; + minSupport = 10f; + verticalLoss = 0.125f; + horizontalLoss = 0.2f; + return false; + case WearNTear.MaterialType.Stone: + maxSupport = 1000f; + minSupport = 100f; + verticalLoss = 0.125f; + horizontalLoss = 1f; + return false; + case WearNTear.MaterialType.Iron: + maxSupport = 1500f; + minSupport = 20f; + verticalLoss = 0.07692308f; + horizontalLoss = 0.07692308f; + return false; + case WearNTear.MaterialType.HardWood: + maxSupport = 140f; + minSupport = 10f; + verticalLoss = 0.1f; + horizontalLoss = 0.16666667f; + return false; + case WearNTear.MaterialType.Marble: + maxSupport = 1500f; + minSupport = 100f; + verticalLoss = 0.125f; + horizontalLoss = 0.5f; + return false; + default: + maxSupport = 0f; + minSupport = 0f; + verticalLoss = 0f; + horizontalLoss = 0f; + return false; + } + } } } }