diff --git a/BloodRefill/BloodRefill.csproj b/BloodRefill/BloodRefill.csproj
index c686144..c808393 100644
--- a/BloodRefill/BloodRefill.csproj
+++ b/BloodRefill/BloodRefill.csproj
@@ -4,7 +4,7 @@
VMods.BloodRefill
VMods.BloodRefill
Allows a player to refill his/her blood pool
- 1.0.0
+ 1.0.1
true
latest
False
@@ -18,7 +18,16 @@
+
+
+
+
+
+
+
+
+
diff --git a/BloodRefill/Configs/BloodRefillConfig.cs b/BloodRefill/Configs/BloodRefillConfig.cs
index 62171be..8bb0508 100644
--- a/BloodRefill/Configs/BloodRefillConfig.cs
+++ b/BloodRefill/Configs/BloodRefillConfig.cs
@@ -26,6 +26,8 @@ public static class BloodRefillConfig
public static ConfigEntry BloodRefillMultiplier { get; private set; }
+ public static ConfigEntry BloodRefillSendRefillMessage { get; private set; }
+
#endregion
#region Public Methods
@@ -42,6 +44,7 @@ public static void Initialize(ConfigFile config)
BloodRefillAmount = config.Bind(nameof(BloodRefillConfig), nameof(BloodRefillAmount), 2.0f, "The maximum amount of blood to refill with no level difference, a matching blood type and quality (Expressed in Litres of blood).");
BloodRefillMultiplier = config.Bind(nameof(BloodRefillConfig), nameof(BloodRefillMultiplier), 1.0f, $"The multiplier used in the blood refill calculation. [Formula: (('Enemy Level' / 'Player Level') * ((100 - ('Player Blood Quality %' - 'Enemy Blood Quality %')) / 100)) * '{nameof(BloodRefillAmount)}' * '(If applicable) {nameof(BloodRefillDifferentBloodTypeMultiplier)}' * '{nameof(BloodRefillMultiplier)}']");
BloodRefillDifferentBloodTypeMultiplier = config.Bind(nameof(BloodRefillConfig), nameof(BloodRefillDifferentBloodTypeMultiplier), 0.1f, $"The multiplier used in the blood refill calculation as a penalty for feeding on a different blood type (only works when {nameof(BloodRefillRequiresSameBloodType)} is disabled).");
+ BloodRefillSendRefillMessage = config.Bind(nameof(BloodRefillConfig), nameof(BloodRefillSendRefillMessage), true, $"When enabled, a refill chat message is sent to the player.");
}
#endregion
diff --git a/BloodRefill/Plugin.cs b/BloodRefill/Plugin.cs
index 18db1f2..a0754b0 100644
--- a/BloodRefill/Plugin.cs
+++ b/BloodRefill/Plugin.cs
@@ -29,8 +29,10 @@ public sealed override void Load()
}
Utils.Initialize(Log, PluginInfo.PLUGIN_NAME);
+ CommandSystemConfig.Initialize(Config);
BloodRefillConfig.Initialize(Config);
+ CommandSystem.Initialize();
BloodRefillSystem.Initialize();
_hooks = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly());
@@ -44,8 +46,11 @@ public sealed override bool Unload()
{
return true;
}
+ VModStorage.SaveAll();
+
_hooks?.UnpatchSelf();
BloodRefillSystem.Deinitialize();
+ CommandSystem.Deinitialize();
Config.Clear();
Utils.Deinitialize();
return true;
diff --git a/BloodRefill/Systems/BloodRefillSystem.cs b/BloodRefill/Systems/BloodRefillSystem.cs
index 1c51c67..bb380e3 100644
--- a/BloodRefill/Systems/BloodRefillSystem.cs
+++ b/BloodRefill/Systems/BloodRefillSystem.cs
@@ -1,6 +1,7 @@
using ProjectM;
using ProjectM.Network;
using System;
+using System.Collections.Generic;
using Unity.Entities;
using VMods.Shared;
using Wetstone.API;
@@ -10,16 +11,37 @@ namespace VMods.BloodRefill
{
public static class BloodRefillSystem
{
+ #region Consts
+
+ private const string BloodRefillFileName = "BloodRefill.json";
+
+ #endregion
+
+ #region Variables
+
+ private static Dictionary _bloodRefills;
+
+ #endregion
+
#region Public Methods
public static void Initialize()
{
+ _bloodRefills = VModStorage.Load(BloodRefillFileName, () => new Dictionary());
+
+ VModStorage.SaveEvent += Save;
DeathHook.DeathEvent += OnDeath;
}
public static void Deinitialize()
{
DeathHook.DeathEvent -= OnDeath;
+ VModStorage.SaveEvent -= Save;
+ }
+
+ public static void Save()
+ {
+ VModStorage.Save(BloodRefillFileName, _bloodRefills);
}
#endregion
@@ -146,6 +168,8 @@ private static void OnDeath(DeathEvent deathEvent)
refillAmount *= BloodRefillConfig.BloodRefillMultiplier.Value;
+ bool sendMessage = BloodRefillConfig.BloodRefillSendRefillMessage.Value && (!_bloodRefills.TryGetValue(user.PlatformId, out var bloodRefillData) || bloodRefillData.ShowRefillMessages);
+
if(refillAmount > 0f)
{
int roundedRefillAmount = (int)Math.Ceiling(refillAmount);
@@ -156,18 +180,87 @@ private static void OnDeath(DeathEvent deathEvent)
Utils.Logger.LogMessage($"New Blood Amount: {playerBlood.Value + roundedRefillAmount}");
#endif
- float newTotalBlood = Math.Min(playerBlood.MaxBlood, playerBlood.Value + roundedRefillAmount);
- float actualBloodGained = newTotalBlood - playerBlood.Value;
- float refillAmountInLitres = (int)(actualBloodGained * 10f) / 100f;
- float newTotalBloodInLitres = (int)Math.Round(newTotalBlood) / 10f;
- Utils.SendMessage(userEntity, $"+{refillAmountInLitres}L Blood ({newTotalBloodInLitres}L)", ServerChatMessageType.Lore);
+ if(sendMessage)
+ {
+ float newTotalBlood = Math.Min(playerBlood.MaxBlood, playerBlood.Value + roundedRefillAmount);
+ float actualBloodGained = newTotalBlood - playerBlood.Value;
+ float refillAmountInLitres = (int)(actualBloodGained * 10f) / 100f;
+ float newTotalBloodInLitres = (int)Math.Round(newTotalBlood) / 10f;
+ Utils.SendMessage(userEntity, $"+{refillAmountInLitres}L Blood ({newTotalBloodInLitres}L)", ServerChatMessageType.Lore);
+ }
playerBloodType.ApplyToPlayer(user, playerBlood.Quality, roundedRefillAmount);
return;
}
}
- Utils.SendMessage(userEntity, $"No blood gained from the enemy.", ServerChatMessageType.Lore);
+ if(sendMessage)
+ {
+ Utils.SendMessage(userEntity, $"No blood gained from the enemy.", ServerChatMessageType.Lore);
+ }
+ }
+
+ [Command("toggle-blood-refill-messages,toggle-blood-messages,toggle-blood-refill-msgs,togglebloodrefillmessages,togglebloodrefillmsgs", "toggle-blood-refill-messages [on/off]", "Toggles the Blood Refill chat messages (on/off)")]
+ private static void OnToggleBloodRefillMessages(Command command)
+ {
+ var platformId = command.VModCharacter.PlatformId;
+ BloodRefillData bloodRefillData = null;
+
+ bool? showRefillMessages = null;
+ if(command.Args.Length >= 1)
+ {
+ switch(command.Args[0])
+ {
+ case "on":
+ case "true":
+ case "1":
+ showRefillMessages = true;
+ break;
+
+ case "off":
+ case "false":
+ case "0":
+ showRefillMessages = false;
+ break;
+
+ default:
+ command.VModCharacter.SendSystemMessage($"Invalid toggle options. Options are: on, off");
+ break;
+ }
+ }
+ else
+ {
+ if(_bloodRefills.TryGetValue(platformId, out bloodRefillData))
+ {
+ showRefillMessages = !bloodRefillData.ShowRefillMessages;
+ }
+ else
+ {
+ showRefillMessages = false;
+ }
+ }
+
+ if(showRefillMessages.HasValue)
+ {
+ if(bloodRefillData == null && !_bloodRefills.TryGetValue(platformId, out bloodRefillData))
+ {
+ bloodRefillData = new BloodRefillData();
+ _bloodRefills[platformId] = bloodRefillData;
+ }
+
+ bloodRefillData.ShowRefillMessages = showRefillMessages.Value;
+
+ command.VModCharacter.SendSystemMessage($"Blood Refill messages have now been turned {(showRefillMessages.Value ? "on" : "off")}");
+ }
+ }
+
+ #endregion
+
+ #region Nested
+
+ public class BloodRefillData
+ {
+ public bool ShowRefillMessages { get; set; }
}
#endregion
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 028a5e2..4e902fb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,7 +1,9 @@
# VMods Change Log
## Blood Refill
-### Next Release
+### v1.0.1
+* Added a config option to globally enable/disable the sending of blood refill messages
+* Added a new '!toggle-blood-refill-messages [on/off]' command for players to turn on/off the blood refill messages for themselves
* Moved the `!setblood` command to the Generic Chat Commands VMod
* Made the `BloodType` enum generic and usable across multiple VMods
diff --git a/README.md b/README.md
index 2e7bd7d..e492ac2 100644
--- a/README.md
+++ b/README.md
@@ -45,6 +45,7 @@ The amount of blood regained is based on the level difference, blood type and bl
* Switch between having V-Blood act as diluted or pure blood, or have V-Blood completely refill your blood pool
* The options to make refilling random between 0.1L and the calculated amount (which then acts as a max refill amount)
* A global refill multiplier (applied after picking a random refill value)
+* Enable/disable blood refill chat messages for everyone
diff --git a/Shared/VModCharacter.cs b/Shared/VModCharacter.cs
index 72c0a83..c4b65bc 100644
--- a/Shared/VModCharacter.cs
+++ b/Shared/VModCharacter.cs
@@ -18,6 +18,8 @@ public readonly struct VModCharacter
#region Properties
+ public ulong PlatformId => User.PlatformId;
+
public bool IsAdmin => User.IsAdmin;
public AdminLevel AdminLevel { get; }
diff --git a/Thunderstone/BloodRefill/README.md b/Thunderstone/BloodRefill/README.md
index 448ee07..9e9bd9e 100644
--- a/Thunderstone/BloodRefill/README.md
+++ b/Thunderstone/BloodRefill/README.md
@@ -14,6 +14,7 @@ The amount of blood regained is based on the level difference, blood type and bl
* Switch between having V-Blood act as diluted or pure blood, or have V-Blood completely refill your blood pool
* The options to make refilling random between 0.1L and the calculated amount (which then acts as a max refill amount)
* A global refill multiplier (applied after picking a random refill value)
+* Enable/disable blood refill chat messages for everyone
diff --git a/Thunderstone/BloodRefill/manifest.json b/Thunderstone/BloodRefill/manifest.json
index 88371e3..da7e6ab 100644
--- a/Thunderstone/BloodRefill/manifest.json
+++ b/Thunderstone/BloodRefill/manifest.json
@@ -1,7 +1,7 @@
{
"name": "VMods_Blood_Refill",
"description": "A mod that allows players to refill their blood pool.",
- "version_number": "1.0.0",
+ "version_number": "1.0.1",
"dependencies": [
"BepInEx-BepInExPack_V_Rising-1.0.0",
"molenzwiebel-Wetstone-1.1.0"