diff --git a/BloodRefill/BloodRefill.csproj b/BloodRefill/BloodRefill.csproj
index 2482ca2..c686144 100644
--- a/BloodRefill/BloodRefill.csproj
+++ b/BloodRefill/BloodRefill.csproj
@@ -17,13 +17,8 @@
-
-
-
-
-
+
-
diff --git a/BloodRefill/Plugin.cs b/BloodRefill/Plugin.cs
index 8c1ccd9..18db1f2 100644
--- a/BloodRefill/Plugin.cs
+++ b/BloodRefill/Plugin.cs
@@ -29,10 +29,8 @@ 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());
@@ -48,7 +46,6 @@ public sealed override bool Unload()
}
_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 ac6cf30..1c51c67 100644
--- a/BloodRefill/Systems/BloodRefillSystem.cs
+++ b/BloodRefill/Systems/BloodRefillSystem.cs
@@ -1,7 +1,6 @@
using ProjectM;
using ProjectM.Network;
using System;
-using System.Linq;
using Unity.Entities;
using VMods.Shared;
using Wetstone.API;
@@ -163,7 +162,7 @@ private static void OnDeath(DeathEvent deathEvent)
float newTotalBloodInLitres = (int)Math.Round(newTotalBlood) / 10f;
Utils.SendMessage(userEntity, $"+{refillAmountInLitres}L Blood ({newTotalBloodInLitres}L)", ServerChatMessageType.Lore);
- ChangeBloodType(user, playerBloodType, playerBlood.Quality, roundedRefillAmount);
+ playerBloodType.ApplyToPlayer(user, playerBlood.Quality, roundedRefillAmount);
return;
}
}
@@ -171,72 +170,6 @@ private static void OnDeath(DeathEvent deathEvent)
Utils.SendMessage(userEntity, $"No blood gained from the enemy.", ServerChatMessageType.Lore);
}
- private static void ChangeBloodType(User user, BloodType bloodType, float quality, int addAmount)
- {
- ChangeBloodDebugEvent bloodChangeEvent = new()
- {
- Source = bloodType.ToPrefabGUID(),
- Quality = quality,
- Amount = addAmount,
- };
- VWorld.Server.GetExistingSystem().ChangeBloodEvent(user.Index, ref bloodChangeEvent);
- }
-
- [Command("setblood", "setblood []", "Sets your blood type to the specified blood-type and blood-quality, and optionally adds a given amount of blood (in Litres).", true)]
- private static void OnSetBloodCommand(Command command)
- {
- var vmodCharacter = command.VModCharacter;
- var argCount = command.Args.Length;
- if(argCount >= 2)
- {
- var searchBloodType = command.Args[0];
- var validBloodTypes = BloodTypeExtensions.BloodTypeToPrefabGUIDMapping.Keys.ToList();
- if(Enum.TryParse(searchBloodType.ToLowerInvariant(), true, out BloodType bloodType) && validBloodTypes.Contains(bloodType))
- {
- var searchBloodQuality = command.Args[1];
- if(int.TryParse(searchBloodQuality.Replace("%", string.Empty), out var bloodQuality) && bloodQuality >= 1 && bloodQuality <= 100)
- {
- float? addBloodAmount = null;
- if(argCount >= 3)
- {
- var searchLitres = command.Args[2];
- if(float.TryParse(searchLitres.Replace("L", string.Empty), out float parsedAddBloodAmount) && parsedAddBloodAmount >= -10f && parsedAddBloodAmount <= 10f)
- {
- addBloodAmount = parsedAddBloodAmount;
- }
- else
- {
- vmodCharacter.SendSystemMessage($"Invalid gain-amount '{searchBloodQuality}'. Should be between -10 and 10");
- }
- }
- else
- {
- addBloodAmount = 10f;
- }
-
- if(addBloodAmount.HasValue)
- {
- ChangeBloodType(vmodCharacter.User, bloodType, bloodQuality, (int)(addBloodAmount.Value * 10f));
- vmodCharacter.SendSystemMessage($"Changed blood type to {bloodQuality}% {searchBloodType} and added {addBloodAmount.Value}L");
- }
- }
- else
- {
- vmodCharacter.SendSystemMessage($"Invalid blood-quality '{searchBloodQuality}'. Should be between 1 and 100");
- }
- }
- else
- {
- vmodCharacter.SendSystemMessage($"Invalid blood-type '{searchBloodType}'. Options are: {string.Join(", ", validBloodTypes.Select(x => x.ToString()))}");
- }
- }
- else
- {
- CommandSystem.SendInvalidCommandMessage(command);
- }
- command.Use();
- }
-
#endregion
}
}
diff --git a/BloodRefill/Systems/BloodType.cs b/BloodRefill/Systems/BloodType.cs
deleted file mode 100644
index 1ca1aa2..0000000
--- a/BloodRefill/Systems/BloodType.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-using ProjectM;
-using System;
-using System.Collections.Generic;
-
-namespace VMods.BloodRefill
-{
- public enum BloodType
- {
- Frailed = -899826404,
- Creature = -77658840,
- Warrior = -1094467405,
- Rogue = 793735874,
- Brute = 581377887,
- Scholar = -586506765,
- Worker = -540707191,
- VBlood = 1557174542,
- }
-
- public static class BloodTypeExtensions
- {
- #region Consts
-
- public static readonly Dictionary BloodTypeToPrefabGUIDMapping = new()
- {
- [BloodType.Creature] = new PrefabGUID(1897056612),
- [BloodType.Warrior] = new PrefabGUID(-1128238456),
- [BloodType.Rogue] = new PrefabGUID(-1030822544),
- [BloodType.Brute] = new PrefabGUID(-1464869978),
- [BloodType.Scholar] = new PrefabGUID(-700632469),
- [BloodType.Worker] = new PrefabGUID(-1342764880),
- };
-
- #endregion
-
- #region Public Methods
-
- public static bool ParseBloodType(this PrefabGUID prefabGUID, out BloodType bloodType)
- {
- int guidHash = prefabGUID.GuidHash;
- if(!Enum.IsDefined(typeof(BloodType), guidHash))
- {
- bloodType = BloodType.Frailed;
- return false;
- }
- bloodType = (BloodType)guidHash;
- return true;
- }
-
- public static BloodType? ToBloodType(this PrefabGUID prefabGUID)
- {
- int guidHash = prefabGUID.GuidHash;
- if(!Enum.IsDefined(typeof(BloodType), guidHash))
- {
- return null;
- }
- return (BloodType)guidHash;
- }
-
- public static PrefabGUID ToPrefabGUID(this BloodType bloodType) => BloodTypeToPrefabGUIDMapping[bloodType];
-
- #endregion
- }
-}
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2f2e3a3..6e94ad3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,10 @@
# VMods Change Log
## Blood Refill
+### Next Release
+* Moved the `!setblood` command to the Generic Chat Commands VMod
+* Made the `BloodType` enum generic and usable across multiple VMods
+
### v1.0.0
* Initial release
diff --git a/Shared/BloodType.cs b/Shared/BloodType.cs
new file mode 100644
index 0000000..0367c9f
--- /dev/null
+++ b/Shared/BloodType.cs
@@ -0,0 +1,76 @@
+using ProjectM;
+using ProjectM.Network;
+using System;
+using System.Collections.Generic;
+using Wetstone.API;
+
+namespace VMods.Shared
+{
+ public enum BloodType
+ {
+ Frailed = -899826404,//(UnitBloodType) BloodType_None
+ Creature = -77658840,//(UnitBloodType) BloodType_Creature
+ Warrior = -1094467405,//(UnitBloodType) BloodType_Warrior
+ Rogue = 793735874,//(UnitBloodType) BloodType_Rogue
+ Brute = 581377887,//(UnitBloodType) BloodType_Brute
+ Scholar = -586506765,//(UnitBloodType) BloodType_Scholar
+ Worker = -540707191,//(UnitBloodType) BloodType_Worker
+ VBlood = 1557174542,//(UnitBloodType) BloodType_VBlood
+ }
+
+ public static class BloodTypeExtensions
+ {
+ #region Consts
+
+ public static readonly Dictionary BloodTypeToPrefabGUIDMapping = new()
+ {
+ [BloodType.Creature] = new PrefabGUID(1897056612),//CHAR_Wildlife_Deer
+ [BloodType.Warrior] = new PrefabGUID(-1128238456),//CHAR_Bandit_Bomber
+ [BloodType.Rogue] = new PrefabGUID(-1030822544),//CHAR_Bandit_Deadeye
+ [BloodType.Brute] = new PrefabGUID(-1464869978),//CHAR_Town_Cleric
+ [BloodType.Scholar] = new PrefabGUID(-700632469),//CHAR_Farmlands_Nun
+ [BloodType.Worker] = new PrefabGUID(-1342764880),//CHAR_Farmlands_Farmer
+ };
+
+ #endregion
+
+ #region Public Methods
+
+ public static bool ParseBloodType(this PrefabGUID prefabGUID, out BloodType bloodType)
+ {
+ int guidHash = prefabGUID.GuidHash;
+ if(!Enum.IsDefined(typeof(BloodType), guidHash))
+ {
+ bloodType = BloodType.Frailed;
+ return false;
+ }
+ bloodType = (BloodType)guidHash;
+ return true;
+ }
+
+ public static BloodType? ToBloodType(this PrefabGUID prefabGUID)
+ {
+ int guidHash = prefabGUID.GuidHash;
+ if(!Enum.IsDefined(typeof(BloodType), guidHash))
+ {
+ return null;
+ }
+ return (BloodType)guidHash;
+ }
+
+ public static PrefabGUID ToPrefabGUID(this BloodType bloodType) => BloodTypeToPrefabGUIDMapping[bloodType];
+
+ public static void ApplyToPlayer(this BloodType bloodType, User user, float quality, int addAmount)
+ {
+ ChangeBloodDebugEvent bloodChangeEvent = new()
+ {
+ Source = bloodType.ToPrefabGUID(),
+ Quality = quality,
+ Amount = addAmount,
+ };
+ VWorld.Server.GetExistingSystem().ChangeBloodEvent(user.Index, ref bloodChangeEvent);
+ }
+
+ #endregion
+ }
+}