Skip to content

Commit

Permalink
Add WearNTear.MaterialType.Marble to structural integrity check
Browse files Browse the repository at this point in the history
  • Loading branch information
healiha committed Dec 6, 2022
1 parent cf058f9 commit d425e17
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class StructuralIntegrityConfiguration : ServerSyncConfig<StructuralInteg
public float stone { get; internal set; } = 0;
public float iron { get; internal set; } = 0;
public float hardWood { get; internal set; } = 0;
public float marble { get; internal set; } = 0;
public bool disableStructuralIntegrity { get; internal set; } = false;
public bool disableDamageToPlayerStructures { get; internal set; } = false;
public bool disableDamageToPlayerBoats { get; internal set; } = false;
Expand Down
277 changes: 145 additions & 132 deletions ValheimPlus/GameClasses/WearNTear.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace ValheimPlus.GameClasses
{
/// <summary>
/// Disable weather damage
/// </summary>
/// <summary>
/// Disable weather damage
/// </summary>
[HarmonyPatch(typeof(WearNTear), "HaveRoof")]
public static class RemoveWearNTear
{
Expand All @@ -19,42 +19,42 @@ private static void Postfix(ref bool __result)
}
}

/// <summary>
/// Disable weather damage under water
/// </summary>
[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;
}
}
}
/// <summary>
/// Disable weather damage under water
/// </summary>
[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;
}
}
}

/// <summary>
/// Removes the integrity check for having a connected piece to the ground.
/// </summary>
[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;
}
}
}
/// <summary>
/// Removes the integrity check for having a connected piece to the ground.
/// </summary>
[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;
}
}
}

/// <summary>
/// Disable damage to player structures
/// </summary>
[HarmonyPatch(typeof(WearNTear), "ApplyDamage")]
public static class WearNTear_ApplyDamage_Patch
{
/// <summary>
/// Disable damage to player structures
/// </summary>
[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
Expand All @@ -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"))
{
Expand All @@ -82,102 +82,115 @@ private static bool Prefix(ref WearNTear __instance, ref float damage)
}
return !Configuration.Current.StructuralIntegrity.disableDamageToPlayerStructures;
}
}
}

/// <summary>
/// Disable structural integrity
/// </summary>
[HarmonyPatch(typeof(WearNTear), "GetMaterialProperties")]
/// <summary>
/// Disable structural integrity
/// </summary>
[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;
}
}
}
}
}

0 comments on commit d425e17

Please sign in to comment.