From f7c618c0cac19d104ca63f04f705ef4be4feb081 Mon Sep 17 00:00:00 2001 From: chudders1231 Date: Sun, 2 Jul 2023 20:36:14 +0100 Subject: [PATCH] Added a new item + changed recipe for the blade. --- ConfigOptions.cs | 13 ----- CureBladeOptions.cs | 25 ++++++++ Items/Consumables/BrineBottleItem.cs | 39 +++++++++++++ Items/Equipment/CureBladeItem.cs | 33 ++++++++--- Patches/CreatureDeathPatch.cs | 1 - Patches/FiltrationMachinePatch.cs | 86 ++++++++++++++++++++++++++++ Plugin.cs | 15 ++++- Utilities.cs | 1 + 8 files changed, 191 insertions(+), 22 deletions(-) delete mode 100644 ConfigOptions.cs create mode 100644 CureBladeOptions.cs create mode 100644 Items/Consumables/BrineBottleItem.cs create mode 100644 Patches/FiltrationMachinePatch.cs diff --git a/ConfigOptions.cs b/ConfigOptions.cs deleted file mode 100644 index e37d1a0..0000000 --- a/ConfigOptions.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Nautilus.Options; - -namespace CureBlade -{ - public class CureBladeOptions : ModOptions - { - public CureBladeOptions() : base("Cure Blade Options") - { - AddItem(Plugin.cureKnifeRange.ToModSliderOption(minValue: 0.1f, maxValue: 2.0f, step: 0.01f, floatFormat: "{0:F2}x")); - AddItem(Plugin.cureKnifeDamage.ToModSliderOption(minValue: 0.1f, maxValue: 5.0f, step: 0.1f, floatFormat: "{0:F1}x")); - } - } -} \ No newline at end of file diff --git a/CureBladeOptions.cs b/CureBladeOptions.cs new file mode 100644 index 0000000..3a06420 --- /dev/null +++ b/CureBladeOptions.cs @@ -0,0 +1,25 @@ +using BepInEx.Configuration; +using Nautilus.Options; +using UnityEngine; + +namespace CureBlade +{ + public class CureBladeOptions : ModOptions + { + public CureBladeOptions() : base("Cure Blade Options") + { + + AddItem(Plugin.cureKnifeRange.ToModSliderOption(minValue: 0.1f, maxValue: 2.0f, step: 0.01f, floatFormat: "{0:F2}x")); + AddItem(Plugin.cureKnifeDamage.ToModSliderOption(minValue: 0.1f, maxValue: 5.0f, step: 0.1f, floatFormat: "{0:F1}x")); + + ModSliderOption emissionStrength = Plugin.cureKnifeEmissionStrength.ToModSliderOption(minValue: 0.1f, maxValue: 2.0f, step: 0.01f, floatFormat: "{0:F2}x"); + emissionStrength.OnChanged += emissionStrengthChanged; + AddItem(emissionStrength); + } + + public void emissionStrengthChanged( object sender, SliderChangedEventArgs e) + { + Object.FindObjectsOfType().ForEach(x => x.Refresh()); + } + } +} \ No newline at end of file diff --git a/Items/Consumables/BrineBottleItem.cs b/Items/Consumables/BrineBottleItem.cs new file mode 100644 index 0000000..2312636 --- /dev/null +++ b/Items/Consumables/BrineBottleItem.cs @@ -0,0 +1,39 @@ +using Nautilus.Assets; +using Nautilus.Assets.Gadgets; +using Nautilus.Assets.PrefabTemplates; +using Nautilus.Crafting; +using Ingredient = CraftData.Ingredient; +using UnityEngine; +using System.Collections.Generic; + +namespace CureBlade.Items.Consumables +{ + internal class BrineBottleItem + { + public static PrefabInfo Info { get; private set; } + public static void Patch() + { + Info = Utilities.CreatePrefabInfo("BrineSolution", "Concentrated Brine", "Usually used in curing meat, however using this high a concentration could potentially poison the consumer!", Utilities.GetSprite("brine_bottle_sprite"), 1, 1); + + var prefab = new CustomPrefab(Info); + + var clonePrefab = new CloneTemplate(Info, TechType.FilteredWater); + + clonePrefab.ModifyPrefab += obj => + { + var eatable = obj.GetComponent(); + + eatable.waterValue = -50; + + var renderer = obj.GetComponentInChildren(true); + obj.GetComponentsInChildren(true).ForEach(x => x.material.mainTexture = Utilities.GetTexture("brine_bottle")); + }; + + prefab.SetGameObject(clonePrefab); + prefab.SetUnlock(TechType.HeatBlade).CompoundTechsForUnlock = new List() { TechType.FiltrationMachine }; + + prefab.Register(); + + } + } +} diff --git a/Items/Equipment/CureBladeItem.cs b/Items/Equipment/CureBladeItem.cs index 324cbf2..861c8b9 100644 --- a/Items/Equipment/CureBladeItem.cs +++ b/Items/Equipment/CureBladeItem.cs @@ -6,12 +6,13 @@ using UnityEngine; using Ingredient = CraftData.Ingredient; using CureBlade; +using CureBlade.Items.Consumables; namespace CureBlade.Items.Equipment { public static class CureBladeItem { - public static PrefabInfo Info; + public static PrefabInfo Info { get; private set; } public static void Patch() { @@ -26,13 +27,16 @@ public static void Patch() var cureKnife = obj.AddComponent().CopyComponent(heatBlade); Object.DestroyImmediate(heatBlade); - + cureKnife.damageType = Plugin.dehydrationDamageType; cureKnife.vfxEventType = VFXEventTypes.diamondBlade; var renderer = obj.GetComponentInChildren(true); obj.GetComponentsInChildren(true).ForEach(x => x.material.mainTexture = Utilities.GetTexture("brine_blade")); - obj.GetComponentsInChildren(true).ForEach(x => x.material.SetTexture("_Illum", Utilities.GetTexture("brine_blade_illum"))); + obj.GetComponentsInChildren(true).ForEach(x => { + x.material.SetTexture("_Illum", Utilities.GetTexture("brine_blade_illum")); + }); + }; @@ -42,8 +46,7 @@ public static void Patch() Ingredients = { new Ingredient(TechType.Knife, 1), - new Ingredient(TechType.Battery, 1), - new Ingredient(TechType.Salt, 4) + new Ingredient(BrineBottleItem.Info.TechType, 2) } }; @@ -53,8 +56,8 @@ public static void Patch() prefab.AddGadget(new EquipmentGadget(prefab, EquipmentType.Hand)).WithQuickSlotType(QuickSlotType.Selectable); prefab.SetRecipe(recipe) - .WithFabricatorType(CraftTree.Type.Fabricator) - .WithStepsToFabricatorTab("Personal", "Tools") + .WithFabricatorType(CraftTree.Type.Workbench) + .WithStepsToFabricatorTab("Tools") .WithCraftingTime(5.5f); prefab.Register(); @@ -65,6 +68,7 @@ public static void Patch() public class CureBladeComp : HeatBlade { public override string animToolName { get; } = TechType.HeatBlade.AsString(true); + public float emissionStrength; public override void OnToolUseAnim(GUIHand hand) { @@ -78,4 +82,19 @@ public override void OnToolUseAnim(GUIHand hand) UWE.Utils.TraceFPSTargetPosition(Player.main.gameObject, attackDist * Plugin.cureKnifeRange.Value, ref hitObj, ref hitPosition); } + public override void OnDraw(Player p) + { + base.OnDraw(p); + + Refresh(); + } + + public void Refresh() + { + emissionStrength = Plugin.cureKnifeEmissionStrength.Value; + + this.GetComponentsInChildren(true).ForEach(x => { + x.material.SetColor("_GlowColor", Color.white * emissionStrength); + }); + } } \ No newline at end of file diff --git a/Patches/CreatureDeathPatch.cs b/Patches/CreatureDeathPatch.cs index 4f70dee..77c51a6 100644 --- a/Patches/CreatureDeathPatch.cs +++ b/Patches/CreatureDeathPatch.cs @@ -17,7 +17,6 @@ internal static void OnKillAsyncPrefix(CreatureDeath __instance) TechType curedData = Utilities.curedCreatureList.GetOrDefault(CraftData.GetTechType(__instance.gameObject), TechType.None); - Plugin.logger.LogInfo($"Last Damage Type: {creatureData.lastDamageType}"); if(curedData != TechType.None && creatureData.lastDamageType == Plugin.dehydrationDamageType) { UWE.CoroutineHost.StartCoroutine(SpawnCuredFish(gameObject, curedData)); diff --git a/Patches/FiltrationMachinePatch.cs b/Patches/FiltrationMachinePatch.cs new file mode 100644 index 0000000..ec40bd9 --- /dev/null +++ b/Patches/FiltrationMachinePatch.cs @@ -0,0 +1,86 @@ +using CureBlade.Items.Consumables; +using HarmonyLib; +using System.Collections; +using System.Collections.Generic; +using System.Reflection.Emit; +using UnityEngine; + +namespace CureBlade.Patches +{ + [HarmonyPatch(typeof(FiltrationMachine))] + internal class FiltrationMachinePatch + { + [HarmonyPatch(typeof(FiltrationMachine), nameof(FiltrationMachine.TryFilterWater))] + [HarmonyTranspiler] + static IEnumerable TranspilerWater(IEnumerable instructions) + { + return new CodeMatcher(instructions).MatchForward(true, + new CodeMatch(OpCodes.Callvirt), + new CodeMatch(OpCodes.Ldc_I4, (int)TechType.BigFilteredWater)) + .InsertAndAdvance( new CodeInstruction(OpCodes.Ldarg_0) ) + .SetInstruction( new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(FiltrationMachinePatch), "GetBiomeForWater", parameters: new[] { typeof(FiltrationMachine) })) ) + .InstructionEnumeration(); + } + + static TechType GetBiomeForWater(FiltrationMachine __instance) { + // Get Biome code goes here + string biome = LargeWorld.main.GetBiome(__instance.transform.position); + + // Check if biome returns true -> return new techtype + if(biome.Contains("LostRiver")) + { + UWE.CoroutineHost.StartCoroutine(SetInstanceWaterPrefab(__instance, TechType.FilteredWater)); + return TechType.FilteredWater; + } + // Else -> return old techtype + + UWE.CoroutineHost.StartCoroutine(SetInstanceWaterPrefab(__instance, TechType.BigFilteredWater)); + return TechType.BigFilteredWater; + } + public static IEnumerator SetInstanceWaterPrefab(FiltrationMachine __instance, TechType waterTechType) + { + TaskResult result = new TaskResult(); + yield return CraftData.GetPrefabForTechTypeAsync(waterTechType, false, result); + var gameObject = result.Get(); + + __instance.waterPrefab = gameObject; + } + + [HarmonyPatch(typeof(FiltrationMachine), nameof(FiltrationMachine.TryFilterSalt))] + [HarmonyTranspiler] + static IEnumerable TranspilerSalt(IEnumerable instructions) + { + return new CodeMatcher(instructions).MatchForward(true, + new CodeMatch(OpCodes.Callvirt), + new CodeMatch(OpCodes.Ldc_I4_S, (sbyte)TechType.Salt)) + .InsertAndAdvance(new CodeInstruction(OpCodes.Ldarg_0)) + .SetInstruction(new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(FiltrationMachinePatch), "GetBiomeForSalt", parameters: new[] { typeof(FiltrationMachine) }))) + .InstructionEnumeration(); + } + + static TechType GetBiomeForSalt(FiltrationMachine __instance) + { + // Get Biome code goes here + string biome = LargeWorld.main.GetBiome(__instance.transform.position); + + // Check if biome returns true -> return new techtype + if (biome.Contains("LostRiver")) + { + UWE.CoroutineHost.StartCoroutine(SetInstanceSaltPrefab(__instance, BrineBottleItem.Info.TechType)); + return TechType.FilteredWater; + } + // Else -> return old techtype + + UWE.CoroutineHost.StartCoroutine(SetInstanceSaltPrefab(__instance, TechType.Salt)); + return TechType.Salt; + } + public static IEnumerator SetInstanceSaltPrefab(FiltrationMachine __instance, TechType saltTechType) + { + TaskResult result = new TaskResult(); + yield return CraftData.GetPrefabForTechTypeAsync(saltTechType, false, result); + var gameObject = result.Get(); + + __instance.waterPrefab = gameObject; + } + } +} diff --git a/Plugin.cs b/Plugin.cs index d85be0b..22aa0eb 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -4,6 +4,8 @@ using BepInEx; using CureBlade.Items.Equipment; using BepInEx.Configuration; +using System.Collections.Generic; +using CureBlade.Items.Consumables; namespace CureBlade; @@ -14,11 +16,12 @@ public class Plugin : BaseUnityPlugin // Config Stuff public static ConfigEntry cureKnifeRange; public static ConfigEntry cureKnifeDamage; + public static ConfigEntry cureKnifeEmissionStrength; // Plugin Setup private const string myGUID = "com.chadlymasterson.cureblade"; private const string pluginName = "Cure Blade"; - private const string versionString = "1.0.2"; + private const string versionString = "1.0.3"; public static readonly Harmony harmony = new Harmony(myGUID); public static ManualLogSource logger; @@ -61,11 +64,21 @@ private void SetupBepinexConfigs() ) ); + cureKnifeEmissionStrength = Config.Bind("Cure Blade Options", + "Cure Knife Emission Strength", + 1.0f, + new ConfigDescription( + "Changes the strength of the glow.", + new AcceptableValueRange(0.1f, 2.0f) + ) + ); + OptionsPanelHandler.RegisterModOptions(new CureBladeOptions()); } private void InitializePrefabs() { + BrineBottleItem.Patch(); CureBladeItem.Patch(); } } \ No newline at end of file diff --git a/Utilities.cs b/Utilities.cs index f84fa67..0f3399f 100644 --- a/Utilities.cs +++ b/Utilities.cs @@ -1,4 +1,5 @@ using Nautilus.Assets; +using Nautilus.Handlers; using Nautilus.Utility; using System; using System.Collections.Generic;