From bf24a6ffaa45f24c9c3e00b05bbe621db9827719 Mon Sep 17 00:00:00 2001 From: mfoltz Date: Sat, 21 Sep 2024 11:41:52 -0500 Subject: [PATCH] - fixed some bugs with blood --- Commands/WeaponCommands.cs | 3 + Patches/StatChangeMutationSystemPatch.cs | 1 + Systems/Expertise/WeaponManager.cs | 103 +++++++++++++++++++++++ Systems/Legacies/BloodManager.cs | 9 +- Systems/Legacies/BloodSystem.cs | 1 - Utilities/ClassUtilities.cs | 3 +- 6 files changed, 112 insertions(+), 8 deletions(-) diff --git a/Commands/WeaponCommands.cs b/Commands/WeaponCommands.cs index 802caca..85f09f5 100644 --- a/Commands/WeaponCommands.cs +++ b/Commands/WeaponCommands.cs @@ -1,7 +1,9 @@ using Bloodcraft.Services; using Bloodcraft.Systems.Expertise; using Bloodcraft.Utilities; +using Il2CppInterop.Runtime; using ProjectM; +using ProjectM.Network; using ProjectM.Scripting; using ProjectM.Shared; using Stunlock.Core; @@ -126,6 +128,7 @@ public static void ChooseWeaponStat(ChatCommandContext ctx, string weaponType, s if (ChooseStat(steamID, WeaponType, StatType)) { LocalizationService.HandleReply(ctx, $"{StatType} has been chosen for {WeaponType} and will apply after reequiping."); + //UpdateWeaponStats(ctx.Event.SenderCharacterEntity); } else { diff --git a/Patches/StatChangeMutationSystemPatch.cs b/Patches/StatChangeMutationSystemPatch.cs index 15ed0df..7859d1b 100644 --- a/Patches/StatChangeMutationSystemPatch.cs +++ b/Patches/StatChangeMutationSystemPatch.cs @@ -43,6 +43,7 @@ static void OnUpdatePrefix(StatChangeMutationSystem __instance) if (ConfigService.PrestigeSystem && steamID.TryGetPlayerPrestiges(out var prestiges) && prestiges.TryGetValue(BloodSystem.BloodTypeToPrestigeMap[bloodType], out var bloodPrestige)) { float qualityPercentBonus = ConfigService.PrestigeBloodQuality > 1f ? ConfigService.PrestigeBloodQuality : ConfigService.PrestigeBloodQuality * 100f; + Core.Log.LogInfo($"Prestige blood quality bonus in StatChangeMutationSystem: {qualityPercentBonus}"); quality = (float)bloodPrestige * qualityPercentBonus; if (quality > 0) diff --git a/Systems/Expertise/WeaponManager.cs b/Systems/Expertise/WeaponManager.cs index 3a8df3d..04bf9c0 100644 --- a/Systems/Expertise/WeaponManager.cs +++ b/Systems/Expertise/WeaponManager.cs @@ -1,6 +1,10 @@ using Bloodcraft.Services; using Bloodcraft.Utilities; +using Il2CppInterop.Runtime; using ProjectM; +using ProjectM.Network; +using ProjectM.Scripting; +using Stunlock.Core; using Unity.Entities; using static Bloodcraft.Systems.Expertise.WeaponManager.WeaponStats; @@ -8,8 +12,39 @@ namespace Bloodcraft.Systems.Expertise; internal static class WeaponManager { static EntityManager EntityManager => Core.EntityManager; + static ServerGameManager ServerGameManager => Core.ServerGameManager; static readonly bool Classes = ConfigService.SoftSynergies || ConfigService.HardSynergies; + + static readonly ComponentType[] UnequipNetworkEventComponents = + [ + ComponentType.ReadOnly(Il2CppType.Of()), + ComponentType.ReadOnly(Il2CppType.Of()), + ComponentType.ReadOnly(Il2CppType.Of()), + ComponentType.ReadOnly(Il2CppType.Of()) + ]; + + static readonly NetworkEventType UnequipEventType = new() + { + IsAdminEvent = false, + EventId = NetworkEvents.EventId_UnequipItemEvent, + IsDebugEvent = false + }; + + static readonly ComponentType[] EquipNetworkEventComponents = + [ + ComponentType.ReadOnly(Il2CppType.Of()), + ComponentType.ReadOnly(Il2CppType.Of()), + ComponentType.ReadOnly(Il2CppType.Of()), + ComponentType.ReadOnly(Il2CppType.Of()) + ]; + + static readonly NetworkEventType EquipEventType = new() + { + IsAdminEvent = false, + EventId = NetworkEvents.EventId_EquipItemEvent, + IsDebugEvent = false + }; public static bool ChooseStat(ulong steamId, WeaponType weaponType, WeaponStatType statType) { if (steamId.TryGetPlayerWeaponStats(out var weaponStats) && weaponStats.TryGetValue(weaponType, out var Stats)) @@ -148,6 +183,74 @@ public static WeaponType GetCurrentWeaponType(Entity character) Entity weapon = character.Read().WeaponSlot.SlotEntity._Entity; return WeaponSystem.GetWeaponTypeFromSlotEntity(weapon); } + public static void UpdateWeaponStats(Entity character) + { + if (!InventoryUtilities.TryGetInventoryEntity(EntityManager, character, out Entity inventoryEntity)) return; + + Equipment equipment = character.Read(); + Entity weaponEntity = equipment.WeaponSlot.SlotEntity.GetEntityOnServer(); + int slot = -1; + + EquipItemEvent equipItemEvent = new(); + FromCharacter fromCharacter = new(); + Entity networkEntity = Entity.Null; + + if (!weaponEntity.Exists() && ServerGameManager.TryGetBuffer(inventoryEntity, out var inventoryBuffer)) + { + // iterate through inventory and find first equipbuff_weapon? + for (int i = 0; i < inventoryBuffer.Length; i++) + { + var item = inventoryBuffer[i]; + if (item.ItemEntity.GetEntityOnServer().TryGetComponent(out Equippable equippable)) + { + slot = equippable.EquipBuff.TryGetComponent(out PrefabGUID itemPrefab) && itemPrefab.LookupName().StartsWith("EquipBuff_Weapon") ? i : -1; + if (slot != -1) break; + } + } + + equipItemEvent = new() + { + IsCosmetic = false, + SlotIndex = slot, + }; + + fromCharacter = new() + { + Character = character, + User = character.Read().UserEntity + }; + + networkEntity = EntityManager.CreateEntity(EquipNetworkEventComponents); + + networkEntity.Write(fromCharacter); + networkEntity.Write(EquipEventType); + networkEntity.Write(equipItemEvent); + + equipment.UnequipItem(EntityManager, character, EquipmentType.Weapon); + return; + } + else if (!InventoryUtilities.TryGetItemSlot(EntityManager, character, weaponEntity, out slot)) return; + + equipment.UnequipItem(EntityManager, character, EquipmentType.Weapon); + + equipItemEvent = new() + { + IsCosmetic = false, + SlotIndex = slot, + }; + + fromCharacter = new() + { + Character = character, + User = character.Read().UserEntity + }; + + networkEntity = EntityManager.CreateEntity(EquipNetworkEventComponents); + + networkEntity.Write(fromCharacter); + networkEntity.Write(EquipEventType); + networkEntity.Write(equipItemEvent); + } public class WeaponStats { public enum WeaponStatType diff --git a/Systems/Legacies/BloodManager.cs b/Systems/Legacies/BloodManager.cs index 54d4f8a..07b2b30 100644 --- a/Systems/Legacies/BloodManager.cs +++ b/Systems/Legacies/BloodManager.cs @@ -149,12 +149,10 @@ public static float CalculateScaledBloodBonus(IBloodHandler handler, ulong steam } public static void UpdateBloodStats(Entity player, User user, BloodType bloodType) { - ulong steamId = user.PlatformId; Blood blood = player.Read(); - - float amount = blood.Value; float quality = blood.Quality; + /* if (ConfigService.BloodQualityBonus) // unless accounted for this will stack, we don't want that here. subtract what will be added in StatMutationSystemPatch { if (ConfigService.PrestigeSystem && steamId.TryGetPlayerPrestiges(out var prestigeData) && prestigeData.TryGetValue(BloodTypeToPrestigeMap[bloodType], out var bloodPrestige)) @@ -171,12 +169,13 @@ public static void UpdateBloodStats(Entity player, User user, BloodType bloodTyp quality -= (float)handler.GetLegacyData(steamId).Key; } } - } + } // might just need to comment this out if the debug event below doesn't actually fire the statChangeMutation system as expected + */ // applying same blood to player again and letting game handle the ModifyUnitStatDOTS is much easier than trying to handle it manually ConsumeBloodDebugEvent consumeBloodDebugEvent = new() { - Amount = (int)amount, + Amount = 0, Quality = quality, Source = BloodTypeToConsumeSourceMap[bloodType] }; diff --git a/Systems/Legacies/BloodSystem.cs b/Systems/Legacies/BloodSystem.cs index 40556a9..dec618d 100644 --- a/Systems/Legacies/BloodSystem.cs +++ b/Systems/Legacies/BloodSystem.cs @@ -5,7 +5,6 @@ using ProjectM.Network; using Stunlock.Core; using Unity.Entities; -using static Bloodcraft.Patches.DeathEventListenerSystemPatch; using static Bloodcraft.Systems.Legacies.BloodManager; namespace Bloodcraft.Systems.Legacies; diff --git a/Utilities/ClassUtilities.cs b/Utilities/ClassUtilities.cs index be98354..8b57aa9 100644 --- a/Utilities/ClassUtilities.cs +++ b/Utilities/ClassUtilities.cs @@ -261,8 +261,7 @@ public static void UpdateShift(Entity character, PrefabGUID spellPrefabGUID) } } - ReplaceAbilityOnSlotSystem.OnUpdate(); - + ReplaceAbilityOnSlotSystem.OnUpdate(); if (tryEquip && InventoryUtilities.TryGetItemSlot(EntityManager, character, equippedJewelEntity, out int slot)) { JewelEquipUtilitiesServer.TryEquipJewel(ref EntityManagerRef, ref PrefabLookupMap, character, slot);