Skip to content

Commit

Permalink
Added a new item + changed recipe for the blade.
Browse files Browse the repository at this point in the history
  • Loading branch information
chudders1231 committed Jul 2, 2023
1 parent 34804b2 commit f7c618c
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 22 deletions.
13 changes: 0 additions & 13 deletions ConfigOptions.cs

This file was deleted.

25 changes: 25 additions & 0 deletions CureBladeOptions.cs
Original file line number Diff line number Diff line change
@@ -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<CureBladeComp>().ForEach(x => x.Refresh());
}
}
}
39 changes: 39 additions & 0 deletions Items/Consumables/BrineBottleItem.cs
Original file line number Diff line number Diff line change
@@ -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>();

eatable.waterValue = -50;

var renderer = obj.GetComponentInChildren<MeshRenderer>(true);
obj.GetComponentsInChildren<MeshRenderer>(true).ForEach(x => x.material.mainTexture = Utilities.GetTexture("brine_bottle"));
};

prefab.SetGameObject(clonePrefab);
prefab.SetUnlock(TechType.HeatBlade).CompoundTechsForUnlock = new List<TechType>() { TechType.FiltrationMachine };

prefab.Register();

}
}
}
33 changes: 26 additions & 7 deletions Items/Equipment/CureBladeItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand All @@ -26,13 +27,16 @@ public static void Patch()
var cureKnife = obj.AddComponent<CureBladeComp>().CopyComponent(heatBlade);

Object.DestroyImmediate(heatBlade);

cureKnife.damageType = Plugin.dehydrationDamageType;
cureKnife.vfxEventType = VFXEventTypes.diamondBlade;

var renderer = obj.GetComponentInChildren<MeshRenderer>(true);
obj.GetComponentsInChildren<MeshRenderer>(true).ForEach(x => x.material.mainTexture = Utilities.GetTexture("brine_blade"));
obj.GetComponentsInChildren<MeshRenderer>(true).ForEach(x => x.material.SetTexture("_Illum", Utilities.GetTexture("brine_blade_illum")));
obj.GetComponentsInChildren<MeshRenderer>(true).ForEach(x => {
x.material.SetTexture("_Illum", Utilities.GetTexture("brine_blade_illum"));
});

};


Expand All @@ -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)
}
};

Expand All @@ -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();
Expand All @@ -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)
{
Expand All @@ -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<MeshRenderer>(true).ForEach(x => {
x.material.SetColor("_GlowColor", Color.white * emissionStrength);
});
}
}
1 change: 0 additions & 1 deletion Patches/CreatureDeathPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
86 changes: 86 additions & 0 deletions Patches/FiltrationMachinePatch.cs
Original file line number Diff line number Diff line change
@@ -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<CodeInstruction> TranspilerWater(IEnumerable<CodeInstruction> 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<GameObject> result = new TaskResult<GameObject>();
yield return CraftData.GetPrefabForTechTypeAsync(waterTechType, false, result);
var gameObject = result.Get();

__instance.waterPrefab = gameObject;
}

[HarmonyPatch(typeof(FiltrationMachine), nameof(FiltrationMachine.TryFilterSalt))]
[HarmonyTranspiler]
static IEnumerable<CodeInstruction> TranspilerSalt(IEnumerable<CodeInstruction> 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<GameObject> result = new TaskResult<GameObject>();
yield return CraftData.GetPrefabForTechTypeAsync(saltTechType, false, result);
var gameObject = result.Get();

__instance.waterPrefab = gameObject;
}
}
}
15 changes: 14 additions & 1 deletion Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using BepInEx;
using CureBlade.Items.Equipment;
using BepInEx.Configuration;
using System.Collections.Generic;
using CureBlade.Items.Consumables;

namespace CureBlade;

Expand All @@ -14,11 +16,12 @@ public class Plugin : BaseUnityPlugin
// Config Stuff
public static ConfigEntry<float> cureKnifeRange;
public static ConfigEntry<float> cureKnifeDamage;
public static ConfigEntry<float> 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;

Expand Down Expand Up @@ -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<float>(0.1f, 2.0f)
)
);

OptionsPanelHandler.RegisterModOptions(new CureBladeOptions());
}

private void InitializePrefabs()
{
BrineBottleItem.Patch();
CureBladeItem.Patch();
}
}
1 change: 1 addition & 0 deletions Utilities.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Nautilus.Assets;
using Nautilus.Handlers;
using Nautilus.Utility;
using System;
using System.Collections.Generic;
Expand Down

0 comments on commit f7c618c

Please sign in to comment.