From 83c94a6cd0256789ad42bbe79074c2bec5df0b4b Mon Sep 17 00:00:00 2001 From: Kevin nX_ J Date: Sat, 6 Mar 2021 08:35:23 +0100 Subject: [PATCH] Changelog - Added a option to remove structure damage to buildings built by players - Added a option to disable portals - Added no weather damage to objects placed in water - Added a option to the Gathering to increase drop chances of resources from resource nodes - Fixed iron scrap not being affected by gathering rates - Fixed issues from crop notifications --- README.md | 4 +++ .../Sections/GameConfiguration.cs | 1 + .../Sections/GatherConfiguration.cs | 1 + .../StructuralIntegrityConfiguration.cs | 1 + ValheimPlus/GameClasses/DropTable.cs | 24 +++++++++++-- ValheimPlus/GameClasses/ItemDrop.cs | 3 -- ValheimPlus/GameClasses/Player.cs | 7 +++- ValheimPlus/GameClasses/TeleportWorld.cs | 25 ++++++++++++++ ValheimPlus/GameClasses/WearNTear.cs | 34 +++++++++++++++++-- ValheimPlus/ValheimPlus.cs | 2 +- ValheimPlus/ValheimPlus.csproj | 1 + valheim_plus.cfg | 13 ++++++- 12 files changed, 106 insertions(+), 10 deletions(-) create mode 100644 ValheimPlus/GameClasses/TeleportWorld.cs diff --git a/README.md b/README.md index f754866a..23a95605 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ All of these features can be adjusted by a configuration file. This also allows * Iron * Hardwood * Disable structural integrity entirely, allowing you to place objects in free air. +* Disable all damage to player built structures/objects. ## Player Hud * Show the experience you gained for a skill in the top left corner @@ -83,12 +84,14 @@ All of these features can be adjusted by a configuration file. This also allows ## Gathering * Modify the amount of resources dropped on destruction of objects. *This includes all types of wood (inc. elderbark), stone, iron/bronze/tin/silver/copper and chitin.* +* Modify the drop chance of resources from destroyed objects. ## Game Difficulty * Modify the game difficulty multipliers applied to health and damage of enemies based on the amount of connected players. * Change the range of where the game considers other players to be nearby. * Add a additional amount of Players to the player count for the difficulty calculation. * Set the difficulty calculation to a specific player count. +* Option to disable the use of portals ## Skill Experience * Modify each skill's experience gain seperately by percent. @@ -134,6 +137,7 @@ Prevents players on the server from making themselves invisible on the map. # Building * Remove Building "Invalid Placement" restriction * Remove Building Object deterioration by weather. +* Remove Building Object deterioration by water. * Advanced Building Mode * Advanced Editing Mode * Structural Integrity modification system diff --git a/ValheimPlus/Configurations/Sections/GameConfiguration.cs b/ValheimPlus/Configurations/Sections/GameConfiguration.cs index e03d3994..6ab8f565 100644 --- a/ValheimPlus/Configurations/Sections/GameConfiguration.cs +++ b/ValheimPlus/Configurations/Sections/GameConfiguration.cs @@ -7,5 +7,6 @@ public class GameConfiguration : ServerSyncConfig public int extraPlayerCountNearby { get; internal set; } = 0; public int setFixedPlayerCountTo { get; internal set; } = 0; public int difficultyScaleRange { get; internal set; } = 200; + public bool disablePortals { get; set; } = false; } } diff --git a/ValheimPlus/Configurations/Sections/GatherConfiguration.cs b/ValheimPlus/Configurations/Sections/GatherConfiguration.cs index b85aecce..14991874 100644 --- a/ValheimPlus/Configurations/Sections/GatherConfiguration.cs +++ b/ValheimPlus/Configurations/Sections/GatherConfiguration.cs @@ -12,5 +12,6 @@ public class GatherConfiguration : ServerSyncConfig public float copperOre { get; internal set; } = 0; public float silverOre { get; internal set; } = 0; public float chitin { get; internal set; } = 0; + public float dropChance { get; internal set; } = 0; } } diff --git a/ValheimPlus/Configurations/Sections/StructuralIntegrityConfiguration.cs b/ValheimPlus/Configurations/Sections/StructuralIntegrityConfiguration.cs index c6647ec3..c2dbb4c5 100644 --- a/ValheimPlus/Configurations/Sections/StructuralIntegrityConfiguration.cs +++ b/ValheimPlus/Configurations/Sections/StructuralIntegrityConfiguration.cs @@ -7,5 +7,6 @@ public class StructuralIntegrityConfiguration : ServerSyncConfig __result, int amount) + + static float originalDropChance = 0; + private static void Prefix(ref DropTable __instance, ref List __result, int amount) { + originalDropChance = __instance.m_dropChance; // we have to save the original to change it back after the function + if (Configuration.Current.Gathering.IsEnabled && Configuration.Current.Gathering.dropChance != 0) + { + float newDropChance = Helper.applyModifierValue(__instance.m_dropChance, Configuration.Current.Gathering.dropChance); + if (newDropChance >= 1) + newDropChance = 1; + if (newDropChance <= 0) + newDropChance = 0; + + if (__instance.m_dropChance != 1) + __instance.m_dropChance = newDropChance; + } + } + + private static void Postfix(ref DropTable __instance, ref List __result, int amount) + { + __instance.m_dropChance = originalDropChance; // Apply the original drop chance in case modified + if (!Configuration.Current.Gathering.IsEnabled) return; @@ -65,7 +85,7 @@ private static void Postfix(ref DropTable __instance, ref List __res stone += 1; stoneObject = toDrop; break; - case "ScrapIron": // Iron + case "IronScrap": // Iron scrapIron += 1; scrapIronObject = toDrop; break; diff --git a/ValheimPlus/GameClasses/ItemDrop.cs b/ValheimPlus/GameClasses/ItemDrop.cs index 3f794311..3bd1c639 100644 --- a/ValheimPlus/GameClasses/ItemDrop.cs +++ b/ValheimPlus/GameClasses/ItemDrop.cs @@ -63,9 +63,6 @@ private static bool Prefix(ref ItemDrop.ItemData __instance, ref int quality, re if (!Configuration.Current.Durability.IsEnabled) return true; - - - // Tools: Axe, How, Cultivator, Hammer, Pickaxe string itemName = __instance.m_shared.m_name.Replace("$item_", ""); string itemType = itemName.Split(new char[] { '_' })[0]; diff --git a/ValheimPlus/GameClasses/Player.cs b/ValheimPlus/GameClasses/Player.cs index bb67b896..289b6796 100644 --- a/ValheimPlus/GameClasses/Player.cs +++ b/ValheimPlus/GameClasses/Player.cs @@ -392,9 +392,14 @@ private static void Postfix(ref Player __instance) } } - + + if (Configuration.Current.Player.IsEnabled && Configuration.Current.Player.cropNotifier) { + + if (__instance.m_placementGhost == null) + return; + // Check to see if the current placement ghost is has a plant component Plant plantComponent = __instance.m_placementGhost.GetComponent(); if (plantComponent != null && __instance.m_placementStatus == Player.PlacementStatus.Valid) diff --git a/ValheimPlus/GameClasses/TeleportWorld.cs b/ValheimPlus/GameClasses/TeleportWorld.cs new file mode 100644 index 00000000..65210882 --- /dev/null +++ b/ValheimPlus/GameClasses/TeleportWorld.cs @@ -0,0 +1,25 @@ +using HarmonyLib; +using ValheimPlus.Configurations; +using UnityEngine; + +namespace ValheimPlus +{ + + /// + /// Disable portals + /// + [HarmonyPatch(typeof(TeleportWorld), "Teleport", new System.Type[] { typeof(Player) })] + public static class TeleportWorld_Teleport_Patch + { + private static bool Prefix(ref TeleportWorld __instance, ref Player player) + { + if (Configuration.Current.Game.IsEnabled && Configuration.Current.Game.disablePortals) + { + MessageHud.instance.ShowMessage(MessageHud.MessageType.Center, "Portals have been disabled on this Server."); + return false; + } + + return true; + } + } +} diff --git a/ValheimPlus/GameClasses/WearNTear.cs b/ValheimPlus/GameClasses/WearNTear.cs index ecce493e..60799c86 100644 --- a/ValheimPlus/GameClasses/WearNTear.cs +++ b/ValheimPlus/GameClasses/WearNTear.cs @@ -17,11 +17,41 @@ 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 damage to player structures + /// + [HarmonyPatch(typeof(WearNTear), "ApplyDamage")] + public static class WearNTear_ApplyDamage_Patch + { + private static bool Prefix(ref WearNTear __instance,ref float damage) + { + if (Configuration.Current.StructuralIntegrity.IsEnabled && Configuration.Current.StructuralIntegrity.disableDamageToPlayerStructures && __instance.m_piece && __instance.m_piece.IsPlacedByPlayer()) + return false; + + return true; + } + } + /// /// Disable structural integrity /// - [HarmonyPatch(typeof(WearNTear), "GetMaterialProperties")] + [HarmonyPatch(typeof(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) diff --git a/ValheimPlus/ValheimPlus.cs b/ValheimPlus/ValheimPlus.cs index d83a35e0..b08a2ea1 100644 --- a/ValheimPlus/ValheimPlus.cs +++ b/ValheimPlus/ValheimPlus.cs @@ -12,7 +12,7 @@ namespace ValheimPlus [BepInPlugin("org.bepinex.plugins.valheim_plus", "Valheim Plus", version)] public class ValheimPlusPlugin : BaseUnityPlugin { - public const string version = "0.9.3"; + public const string version = "0.9.4"; public static string newestVersion = ""; public static bool isUpToDate = false; diff --git a/ValheimPlus/ValheimPlus.csproj b/ValheimPlus/ValheimPlus.csproj index 1822c340..f526a229 100644 --- a/ValheimPlus/ValheimPlus.csproj +++ b/ValheimPlus/ValheimPlus.csproj @@ -368,6 +368,7 @@ + diff --git a/valheim_plus.cfg b/valheim_plus.cfg index 8162107f..5e5ffdbd 100644 --- a/valheim_plus.cfg +++ b/valheim_plus.cfg @@ -181,6 +181,9 @@ setFixedPlayerCountTo=0 ; The range in meters at which other players count towards nearby players for the difficulty scale difficultyScaleRange=200 +; If you set this to true, all portals will be disabled +disablePortals=false + [Hotkeys] ; https://docs.unity3d.com/ScriptReference/KeyCode.html <- a list of keycodes @@ -232,6 +235,11 @@ removeDamageFlash=false ; Change false to true to enable this section enabled=false +; Modify the chance to drop resources from resource nodes affected by this category +; This only works on resource nodes that do not have garuanteed drops +; As example by default scrap piles in dungeons have a 20% chance to drop a item, if you set this option to 200, you will then have a 60% chance to drop iron. +dropChance=0 + ; Each of these values increase or reduce the dropped items from destroyed objects with tools (Stones, Trees, Resource nodes, etc.) by % ; The value 50 will increase the dropped wood from trees from 10 to 15. The value -50 will reduce the amount of dropped wood from 10 to 5. wood=0 @@ -352,7 +360,7 @@ dataRate=60 [Stamina] -; Each of these values allow for - values, 50% will increase the stamina cost by 50, -50 will reduce the stamina cost by 50% +; Each of these values allow for - values, 50 will increase the stamina cost by 50%, -50 will reduce the stamina cost by 50% ; Change false to true to enable this section enabled=false @@ -409,6 +417,9 @@ enabled=false ; Disables the entire structural integrity system and allows for placement in free air, does not prevent building damage. disableStructuralIntegrity=false +; Disables any damage from anything to all player built structures +disableDamageToPlayerStructures=false + ; Each of these values reduce the loss of structural integrity by % less. The value 100 would result in disabled structural integrity and allow placement in free air. wood=0 stone=0