Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Wisp Spawner #797

Open
wants to merge 4 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## How to setup your environment for V+ development
How to setup the development enviroment to compile ValheimPlus yourself.

1. Download the [BepInEx for Valheim package](https://valheim.thunderstore.io/package/download/denikson/BepInExPack_Valheim/5.4.1901/).
1. Download the [BepInEx for Valheim package](https://valheim.thunderstore.io/package/download/denikson/BepInExPack_Valheim/5.4.2100/).
- Extract zip contents and copy the contents inside `/BepInExPack_Valheim/` and paste them in your Valheim root folder and overwrite every file when asked.
- This package sets up your Valheim game with BepInEx configurations specifically for mod devs. Created by [BepInEx](https://github.com/BepInEx).
1. Copy over all the DLLs from Valheim/unstripped_corlib to Valheim/valheim_Data/Managed *(overwrite when asked)*
Expand Down
1 change: 1 addition & 0 deletions ValheimPlus/Configurations/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ public class Configuration
public GameClockConfiguration GameClock { get; set; }
public BrightnessConfiguration Brightness { get; set; }
public ChatConfiguration Chat { get; set; }
public WispSpawnerConfiguration WispSpawner { get; set; }
}
}
10 changes: 10 additions & 0 deletions ValheimPlus/Configurations/Sections/WispSpawnerConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace ValheimPlus.Configurations.Sections
{
public class WispSpawnerConfiguration : ServerSyncConfig<WispSpawnerConfiguration>
{
public int maximumWisps { get; set; } = 3;
public bool onlySpawnAtNight { get; internal set; } = true;
public float wispSpawnIntervalMultiplier { get; internal set; } = 0;
public float wispSpawnChanceMultiplier { get; internal set; } = 0;
}
}
8 changes: 4 additions & 4 deletions ValheimPlus/GameClasses/Chat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace ValheimPlus.GameClasses
/// <summary>
/// Change Ping and global message behavior
/// </summary>
[HarmonyPatch(typeof(Chat), nameof(Chat.OnNewChatMessage), new System.Type[] { typeof(GameObject), typeof(long), typeof(Vector3), typeof(Talker.Type), typeof(string), typeof(string), typeof(string) })]
[HarmonyPatch(typeof(Chat), nameof(Chat.OnNewChatMessage), new System.Type[] { typeof(GameObject), typeof(long), typeof(Vector3), typeof(Talker.Type), typeof(UserInfo), typeof(string), typeof(string) })]
public static class Chat_AddInworldText_Patch
{
private static bool Prefix(ref Chat __instance, GameObject go, long senderID, Vector3 pos, Talker.Type type, string user, string text, string senderNetworkUserId)
private static bool Prefix(ref Chat __instance, GameObject go, long senderID, Vector3 pos, Talker.Type type, UserInfo user, string text, string senderNetworkUserId)
{

if (Configuration.Current.Chat.IsEnabled)
Expand Down Expand Up @@ -50,7 +50,7 @@ private static bool Prefix(ref Chat __instance, GameObject go, long senderID, Ve
{
// Only add string to chat window and show no ping
if (Configuration.Current.Chat.outOfRangeShoutsDisplayInChatWindow)
__instance.AddString(user, text, Talker.Type.Shout);
__instance.AddString(user.GetDisplayName(senderNetworkUserId), text, Talker.Type.Shout);
return false;
}
}
Expand All @@ -64,7 +64,7 @@ private static bool Prefix(ref Chat __instance, GameObject go, long senderID, Ve



[HarmonyPatch(typeof(Chat), nameof(Chat.AddInworldText), new System.Type[] { typeof(GameObject), typeof(long), typeof(Vector3), typeof(Talker.Type), typeof(string), typeof(string) })]
[HarmonyPatch(typeof(Chat), nameof(Chat.AddInworldText), new System.Type[] { typeof(GameObject), typeof(long), typeof(Vector3), typeof(Talker.Type), typeof(UserInfo), typeof(string) })]
public static class Chat_AddInworldText_Transpiler
{
/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions ValheimPlus/GameClasses/FejdStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ private static void Postfix(ref FejdStartup __instance)

// version text for bottom right of startup
__instance.m_versionLabel.fontSize = 14;
__instance.m_versionLabel.GetComponent<RectTransform>().sizeDelta = new Vector2(300, 30);
__instance.m_versionLabel.GetComponent<RectTransform>().sizeDelta = new Vector2(600, 30);
string gameVersion = Version.CombineVersion(global::Version.m_major, global::Version.m_minor, global::Version.m_patch);
__instance.m_versionLabel.text = "version " + gameVersion + "\n" + "ValheimPlus " + ValheimPlusPlugin.version;
__instance.m_versionLabel.text = "version " + gameVersion + "\n" + "ValheimPlus " + ValheimPlusPlugin.version + " (Grantapher Temporary)";


if (Configuration.Current.ValheimPlus.IsEnabled && Configuration.Current.ValheimPlus.serverBrowserAdvertisement)
Expand Down
5 changes: 3 additions & 2 deletions ValheimPlus/GameClasses/InventoryGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,8 @@ public static IEnumerable<CodeInstruction> Transpile(IEnumerable<CodeInstruction

private static ItemDrop.ItemData GetFirstRequiredItemFromInventoryOrChest(Player player, Recipe recipe, int quality, out int quantity)
{
ItemDrop.ItemData found = player.GetFirstRequiredItem(player.GetInventory(), recipe, quality, out quantity);
int extraAmount;
ItemDrop.ItemData found = player.GetFirstRequiredItem(player.GetInventory(), recipe, quality, out quantity, out extraAmount);
if (found != null) return found;

GameObject pos = player.GetCurrentCraftingStation()?.gameObject;
Expand All @@ -271,7 +272,7 @@ private static ItemDrop.ItemData GetFirstRequiredItemFromInventoryOrChest(Player

foreach (Container chest in nearbyChests)
{
found = player.GetFirstRequiredItem(chest.GetInventory(), recipe, quality, out quantity);
found = player.GetFirstRequiredItem(chest.GetInventory(), recipe, quality, out quantity, out extraAmount);
if (found != null)
{
return found;
Expand Down
29 changes: 29 additions & 0 deletions ValheimPlus/GameClasses/LuredWisp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using HarmonyLib;
using System;
using System.Reflection;
using System.Runtime.Remoting.Messaging;
using UnityEngine;
using ValheimPlus.Configurations;
using ValheimPlus.Utility;
using static HarmonyLib.AccessTools;

namespace ValheimPlus.GameClasses
{
class LuredWispModification
{
[HarmonyPatch(typeof(LuredWisp), "Awake")]
public static class LuredWispPatch
{

[HarmonyPrefix]
static void Prefix(LuredWisp __instance)
{
if (Configuration.Current.WispSpawner.IsEnabled)
{
FieldRef<LuredWisp, bool> m_despawnInDaylight = FieldRefAccess<LuredWisp, bool>("m_despawnInDaylight");
m_despawnInDaylight(__instance) = Configuration.Current.WispSpawner.onlySpawnAtNight;
}
}
}
}
}
31 changes: 31 additions & 0 deletions ValheimPlus/GameClasses/WispSpawner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using HarmonyLib;
using System;
using System.Runtime.Remoting.Messaging;
using UnityEngine;
using ValheimPlus.Configurations;
using ValheimPlus.Utility;
using static HarmonyLib.AccessTools;

namespace ValheimPlus.GameClasses
{
[HarmonyPatch(typeof(WispSpawner), "Start")]
static class WispSpawnerModification
{
[HarmonyPrefix]
static void Prefix(WispSpawner __instance)
{
if (Configuration.Current.WispSpawner.IsEnabled)
{
FieldRef<WispSpawner, int> m_maxSpawned = FieldRefAccess<WispSpawner, int>("m_maxSpawned");
FieldRef<WispSpawner, float> m_spawnChance = FieldRefAccess<WispSpawner, float>("m_spawnChance");
FieldRef<WispSpawner, float> m_spawnInterval = FieldRefAccess<WispSpawner, float>("m_spawnInterval");
FieldRef<WispSpawner, bool> m_onlySpawnAtNight = FieldRefAccess<WispSpawner, bool>("m_onlySpawnAtNight");

m_onlySpawnAtNight(__instance) = Configuration.Current.WispSpawner.onlySpawnAtNight;
m_maxSpawned(__instance) = Configuration.Current.WispSpawner.maximumWisps;
m_spawnChance(__instance) = Helper.applyModifierValue(m_spawnChance(__instance), Configuration.Current.WispSpawner.wispSpawnChanceMultiplier);
m_spawnInterval(__instance) = Helper.applyModifierValue(m_spawnInterval(__instance), Configuration.Current.WispSpawner.wispSpawnIntervalMultiplier);
}
}
}
}
8 changes: 4 additions & 4 deletions ValheimPlus/ValheimPlus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace ValheimPlus
[BepInPlugin("org.bepinex.plugins.valheim_plus", "Valheim Plus", version)]
public class ValheimPlusPlugin : BaseUnityPlugin
{
public const string version = "0.9.9.11";
public const string version = "0.9.9.12";
public static string newestVersion = "";
public static bool isUpToDate = false;

Expand All @@ -29,11 +29,11 @@ public class ValheimPlusPlugin : BaseUnityPlugin
public static Harmony harmony = new Harmony("mod.valheim_plus");

// Project Repository Info
public static string Repository = "https://github.com/valheimPlus/ValheimPlus";
public static string ApiRepository = "https://api.github.com/repos/valheimPlus/valheimPlus/tags";
public static string Repository = "https://github.com/grantapher/ValheimPlus";
public static string ApiRepository = "https://api.github.com/repos/grantapher/valheimPlus/tags";

// Website INI for auto update
public static string iniFile = "https://raw.githubusercontent.com/valheimPlus/ValheimPlus/" + version + "/valheim_plus.cfg";
public static string iniFile = "https://raw.githubusercontent.com/grantapher/ValheimPlus/" + version + "/valheim_plus.cfg";

// Awake is called once when both the game and the plug-in are loaded
void Awake()
Expand Down
3 changes: 3 additions & 0 deletions ValheimPlus/ValheimPlus.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@
<Compile Include="Configurations\Sections\TameableConfiguration.cs" />
<Compile Include="Configurations\Sections\ValheimPlusConfiguration.cs" />
<Compile Include="Configurations\Sections\WindmillConfiguration.cs" />
<Compile Include="Configurations\Sections\WispSpawnerConfiguration.cs" />
<Compile Include="Deconstruct.cs" />
<Compile Include="FirstPerson\VPlusFirstPerson.cs" />
<Compile Include="FreePlacementRotation.cs" />
Expand Down Expand Up @@ -396,6 +397,7 @@
<Compile Include="Configurations\Sections\StaminaUsageConfiguration.cs" />
<Compile Include="Configurations\Sections\StaminaConfiguration.cs" />
<Compile Include="GameClasses\Character.cs" />
<Compile Include="GameClasses\LuredWisp.cs" />
<Compile Include="GameClasses\SEMan.cs" />
<Compile Include="GameClasses\Talker.cs" />
<Compile Include="GameClasses\Container.cs" />
Expand All @@ -405,6 +407,7 @@
<Compile Include="GameClasses\Fireplace.cs" />
<Compile Include="GameClasses\GameCamera.cs" />
<Compile Include="GameClasses\Chat.cs" />
<Compile Include="GameClasses\WispSpawner.cs" />
<Compile Include="RPC\VPlusMapPinSync.cs" />
<Compile Include="UI\HotkeyBar.cs" />
<Compile Include="GameClasses\Hud.cs" />
Expand Down
17 changes: 17 additions & 0 deletions valheim_plus.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1110,3 +1110,20 @@ defaultNormalDistance = 15

; This value determines the range in meters that you can see shout text messages by default.
defaultShoutDistance = 70

[WispSpawner]

; Change false to true to enable this section.
enabled = false

; This value determines the maximum amount of Wisp per spawner.
maximumWisps = 3

; This value determines if the Wisps can spawn during the day.
onlySpawnAtNight = true

; This value determines the rate at which the Wisps try to spawn. A multiplier of -50 will result in a wisp trying to spawn every 2.5 seconds (5 seconds by default).
wispSpawnIntervalMultiplier = 0

; This value determines the chance of a Wisp to spawn. A multiplier of 200 will result in a 100% wisp spawn chance.
wispSpawnChanceMultiplier = 0