(1.4.0) Door auto close
This commit is contained in:
@@ -15,7 +15,7 @@ public class MxValheimMod : BaseUnityPlugin
|
||||
|
||||
private const string ModGUID = "ovh.mxdev.mxvalheim";
|
||||
private const string ModName = "MxValheim";
|
||||
private const string ModVersion = "1.3.0";
|
||||
private const string ModVersion = "1.4.0";
|
||||
|
||||
public static ConfigEntry<bool> Config_Locked;
|
||||
public static ConfigEntry<int> Config_OreMultiplier;
|
||||
@@ -23,6 +23,8 @@ public class MxValheimMod : BaseUnityPlugin
|
||||
public static ConfigEntry<float> Config_bowDrawSpeedBonusPerLevel;
|
||||
public static ConfigEntry<bool> Config_rainDamage;
|
||||
public static ConfigEntry<float> Config_boatSpeed;
|
||||
public static ConfigEntry<bool> Config_autoDoorCloseEnabled;
|
||||
public static ConfigEntry<float> Config_autoDoorClose;
|
||||
|
||||
private static string WeightConfigPath => Path.Combine(Paths.ConfigPath, "mxvalheim.custom_weights.json");
|
||||
public static Dictionary<string, float> WeightSettings = new Dictionary<string, float>();
|
||||
@@ -36,6 +38,8 @@ public class MxValheimMod : BaseUnityPlugin
|
||||
Config_bowDrawSpeedBonusPerLevel = Config.Bind("General", "BowDrawSpeedBonusPercentPerLevel", 1.0f, "Shorten the bow draw speed by this percent for every bow upgrade level.");
|
||||
Config_rainDamage = Config.Bind("General", "RainDamage", true, "Set to true to stop rain damage, false to return to vanilla behavior.");
|
||||
Config_boatSpeed = Config.Bind("General", "BoatSpeedMultiplier", 2.0f, "Your boat/raft will move without wind at a speed multiplied by this value.");
|
||||
Config_autoDoorCloseEnabled = Config.Bind("General", "AutoDoorCloseEnabled", true, "Your doors will auto close if enabled. See AutoDoorCloseTimer for the desired time.");
|
||||
Config_autoDoorClose = Config.Bind("General", "AutoDoorCloseTimer", 5.0f, "Your doors will auto close after the specified timer duration.");
|
||||
|
||||
LoadJsonConfig();
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@
|
||||
<Compile Include="MxValheim.cs" />
|
||||
<Compile Include="Patch\Bow.cs" />
|
||||
<Compile Include="Patch\CraftingStation.cs" />
|
||||
<Compile Include="Patch\Doors.cs" />
|
||||
<Compile Include="Patch\Items.cs" />
|
||||
<Compile Include="Patch\Ores.cs" />
|
||||
<Compile Include="Patch\WearNTear.cs" />
|
||||
|
||||
45
MxValheim/Patch/Doors.cs
Normal file
45
MxValheim/Patch/Doors.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using BepInEx;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
|
||||
namespace MxValheim.Patch
|
||||
{
|
||||
internal class Doors
|
||||
{
|
||||
[HarmonyPatch(typeof(Door), nameof(Door.Interact))]
|
||||
static class Door_Interact_Patch
|
||||
{
|
||||
static void Postfix(Door __instance, Humanoid character, bool hold, bool alt, ZNetView ___m_nview)
|
||||
{
|
||||
if (hold || alt || ___m_nview == null || !___m_nview.IsValid()) return;
|
||||
|
||||
// Get state: 0 is closed
|
||||
int state = ___m_nview.GetZDO().GetInt("state");
|
||||
|
||||
if (state != 0)
|
||||
{
|
||||
// Start coroutine on the door object itself
|
||||
__instance.StartCoroutine(CloseDoorAfterDelay(__instance, ___m_nview));
|
||||
}
|
||||
}
|
||||
|
||||
static IEnumerator CloseDoorAfterDelay(Door door, ZNetView nview)
|
||||
{
|
||||
yield return new WaitForSeconds(MxValheimMod.Config_autoDoorClose.Value);
|
||||
|
||||
// Verify the door still exists and is still open before closing
|
||||
if (door != null && nview != null && nview.IsValid())
|
||||
{
|
||||
if (nview.GetZDO().GetInt("state") != 0)
|
||||
{
|
||||
// Directly invoke the RPC with '0' (closed).
|
||||
// This avoids the 'Null' player error in Door.Interact
|
||||
ZDO zd0 = nview.GetZDO();
|
||||
zd0.Set("state", 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,14 +17,12 @@ namespace MxValheim.Patch
|
||||
{
|
||||
if (ObjectDB.instance == null) return;
|
||||
|
||||
int count = 0;
|
||||
foreach (GameObject item in ObjectDB.instance.m_items)
|
||||
{
|
||||
ItemDrop itemDrop = item.GetComponent<ItemDrop>();
|
||||
if (itemDrop != null && MxValheimMod.WeightSettings.TryGetValue(item.name, out float newWeight))
|
||||
{
|
||||
itemDrop.m_itemData.m_shared.m_weight = newWeight;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user