Skip to content

Commit

Permalink
[BloodRefill] Added a new config option and command to toggle blood r…
Browse files Browse the repository at this point in the history
…efill messages; Bumped version to v1.0.1
  • Loading branch information
WhiteFang5 committed Aug 6, 2022
1 parent b2f0d98 commit c9f08e9
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 9 deletions.
11 changes: 10 additions & 1 deletion BloodRefill/BloodRefill.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AssemblyName>VMods.BloodRefill</AssemblyName>
<RootNamespace>VMods.BloodRefill</RootNamespace>
<Description>Allows a player to refill his/her blood pool</Description>
<Version>1.0.0</Version>
<Version>1.0.1</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>False</GeneratePackageOnBuild>
Expand All @@ -18,7 +18,16 @@

<ItemGroup>
<Compile Include="..\Shared\BloodType.cs" Link="Shared\BloodType.cs" />
<Compile Include="..\Shared\CommandSystem\Command.cs" Link="Shared\Command.cs" />
<Compile Include="..\Shared\CommandSystem\CommandAttribute.cs" Link="Shared\CommandAttribute.cs" />
<Compile Include="..\Shared\CommandSystem\CommandExtensions.cs" Link="Shared\CommandExtensions.cs" />
<Compile Include="..\Shared\CommandSystem\CommandSystem.cs" Link="Shared\CommandSystem.cs" />
<Compile Include="..\Shared\CommandSystem\CommandSystemConfig.cs" Link="Shared\CommandSystemConfig.cs" />
<Compile Include="..\Shared\ExtensionMethods.cs" Link="Shared\ExtensionMethods.cs" />
<Compile Include="..\Shared\SaveHook.cs" Link="Shared\SaveHook.cs" />
<Compile Include="..\Shared\Utils.cs" Link="Shared\Utils.cs" />
<Compile Include="..\Shared\VModCharacter.cs" Link="Shared\VModCharacter.cs" />
<Compile Include="..\Shared\VModStorage.cs" Link="Shared\VModStorage.cs" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions BloodRefill/Configs/BloodRefillConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public static class BloodRefillConfig

public static ConfigEntry<float> BloodRefillMultiplier { get; private set; }

public static ConfigEntry<bool> BloodRefillSendRefillMessage { get; private set; }

#endregion

#region Public Methods
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions BloodRefill/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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;
Expand Down
105 changes: 99 additions & 6 deletions BloodRefill/Systems/BloodRefillSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ProjectM;
using ProjectM.Network;
using System;
using System.Collections.Generic;
using Unity.Entities;
using VMods.Shared;
using Wetstone.API;
Expand All @@ -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<ulong, BloodRefillData> _bloodRefills;

#endregion

#region Public Methods

public static void Initialize()
{
_bloodRefills = VModStorage.Load(BloodRefillFileName, () => new Dictionary<ulong, BloodRefillData>());

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
Expand Down Expand Up @@ -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);
Expand All @@ -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($"<color=#ff0000>Invalid toggle options. Options are: on, off</color>");
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 <color=#{(showRefillMessages.Value ? "00ff00" : "ff0000")}>{(showRefillMessages.Value ? "on" : "off")}</color>");
}
}

#endregion

#region Nested

public class BloodRefillData
{
public bool ShowRefillMessages { get; set; }
}

#endregion
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

</details>

Expand Down
2 changes: 2 additions & 0 deletions Shared/VModCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public readonly struct VModCharacter

#region Properties

public ulong PlatformId => User.PlatformId;

public bool IsAdmin => User.IsAdmin;

public AdminLevel AdminLevel { get; }
Expand Down
1 change: 1 addition & 0 deletions Thunderstone/BloodRefill/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

</details>

Expand Down
2 changes: 1 addition & 1 deletion Thunderstone/BloodRefill/manifest.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit c9f08e9

Please sign in to comment.