diff --git a/Commands/ClassCommands.cs b/Commands/ClassCommands.cs index b661c02..b64927c 100644 --- a/Commands/ClassCommands.cs +++ b/Commands/ClassCommands.cs @@ -82,6 +82,12 @@ public static void ChooseClassSpell(ChatCommandContext ctx, int choice) if (choice == 0) // set default for all classes { + if (prestigeLevel < ConfigUtilities.ParseConfigString(ConfigService.PrestigeLevelsToUnlockClassSpells)[choice]) + { + LocalizationService.HandleReply(ctx, "You do not have the required prestige level for that spell."); + return; + } + if (steamId.TryGetPlayerSpells(out var data)) { if (ConfigService.DefaultClassSpell == 0) @@ -99,7 +105,7 @@ public static void ChooseClassSpell(ChatCommandContext ctx, int choice) } } - if (prestigeLevel < ConfigUtilities.ParseConfigString(ConfigService.PrestigeLevelsToUnlockClassSpells)[choice - 1]) + if (prestigeLevel < ConfigUtilities.ParseConfigString(ConfigService.PrestigeLevelsToUnlockClassSpells)[choice]) { LocalizationService.HandleReply(ctx, "You do not have the required prestige level for that spell."); return; diff --git a/Patches/BuffSystemSpawnServerPatch.cs b/Patches/BuffSystemSpawnServerPatch.cs index 541e22f..ed409e0 100644 --- a/Patches/BuffSystemSpawnServerPatch.cs +++ b/Patches/BuffSystemSpawnServerPatch.cs @@ -13,7 +13,7 @@ namespace Bloodcraft.Patches; [HarmonyPatch] -internal static class BuffSpawnSystemPatches +internal static class BuffSystemSpawnPatches { static EntityManager EntityManager => Core.EntityManager; static ServerGameManager ServerGameManager => Core.ServerGameManager; diff --git a/Patches/DealDamageSystemPatch.cs b/Patches/DealDamageSystemPatch.cs index f1d3f86..ccb517e 100644 --- a/Patches/DealDamageSystemPatch.cs +++ b/Patches/DealDamageSystemPatch.cs @@ -44,9 +44,10 @@ static void OnUpdatePrefix(DealDamageSystem __instance) foreach (Entity entity in entities) { if (!entity.TryGetComponent(out DealDamageEvent dealDamageEvent)) continue; - else if (!dealDamageEvent.Target.Exists() || !dealDamageEvent.SpellSource.Exists()) continue; + else if (!dealDamageEvent.Target.Exists() || !dealDamageEvent.SpellSource.Exists()) continue; // checks are kind of excessive here but null entities in this system can reeeeally mess things up for a save so leaving them for safety >_> else if (dealDamageEvent.MainType != MainDamageType.Physical && dealDamageEvent.MainType != MainDamageType.Spell) continue; // skip if source isn't phys/spell else if (dealDamageEvent.SpellSource.TryGetComponent(out PrefabGUID sourcePrefabGUID) && (sourcePrefabGUID.Equals(silverDebuff) || sourcePrefabGUID.Equals(garlicDebuff))) continue; // skip if source is silver or garlic + else if (!dealDamageEvent.SpellSource.Has()) continue; // not really sure why this would be the case but seems to be popping up in console so okay I guess if (dealDamageEvent.Target.Has() && dealDamageEvent.SpellSource.GetOwner().TryGetPlayer(out Entity player)) { diff --git a/Patches/InteractValidateAndStopSystemPatch.cs b/Patches/InteractValidateAndStopSystemPatch.cs index 098f400..8033db9 100644 --- a/Patches/InteractValidateAndStopSystemPatch.cs +++ b/Patches/InteractValidateAndStopSystemPatch.cs @@ -14,6 +14,7 @@ namespace Bloodcraft.Patches; [HarmonyPatch] internal static class InteractValidateAndStopSystemPatch { + static EntityManager EntityManager => Core.EntityManager; static ServerGameManager ServerGameManager => Core.ServerGameManager; static readonly PrefabGUID dominateBuff = new(-1447419822); @@ -33,7 +34,7 @@ static void OnUpdatePrefix(InteractValidateAndStopSystemServer __instance) { if (!entity.Has()) continue; if (!entity.TryGetComponent(out PrefabGUID prefabGUID)) continue; - + if (entity.GetOwner().TryGetPlayer(out Entity player) && !ServerGameManager.HasBuff(player, dominateBuff.ToIdentifier())) { if (prefabGUID.GuidHash.Equals(-986064531) || prefabGUID.GuidHash.Equals(985937733)) // player using world or castle waygate diff --git a/Patches/ReactToInventoryChangedSystemPatch.cs b/Patches/ReactToInventoryChangedSystemPatch.cs index 047bfcd..25f5162 100644 --- a/Patches/ReactToInventoryChangedSystemPatch.cs +++ b/Patches/ReactToInventoryChangedSystemPatch.cs @@ -45,6 +45,7 @@ static void OnUpdatePrefix(ReactToInventoryChangedSystem __instance) else if (DealDamageSystemPatch.LastDamageTime.TryGetValue(steamId, out DateTime lastDamageTime) && (DateTime.UtcNow - lastDamageTime).TotalSeconds < 0.10f) { if (steamId.TryGetPlayerQuests(out var quests)) QuestSystem.ProcessQuestProgress(quests, inventoryChangedEvent.Item, inventoryChangedEvent.Amount, user); + continue; } diff --git a/Patches/ReplaceAbilityOnSlotSystemPatch.cs b/Patches/ReplaceAbilityOnSlotSystemPatch.cs index 3df77eb..5d6eda9 100644 --- a/Patches/ReplaceAbilityOnSlotSystemPatch.cs +++ b/Patches/ReplaceAbilityOnSlotSystemPatch.cs @@ -4,7 +4,6 @@ using ProjectM; using ProjectM.Gameplay.Systems; using ProjectM.Scripting; -using ProjectM.Shared; using Stunlock.Core; using Unity.Collections; using Unity.Entities; @@ -51,7 +50,7 @@ static void OnUpdatePrefix(ReplaceAbilityOnSlotSystem __instance) } else if (ConfigService.ShiftSlot && shiftSpell && steamId.TryGetPlayerSpells(out spells)) { - //HandleShiftSpell(entity, character, spells, PlayerUtilities.GetPlayerBool(steamId, "ShiftLock")); + HandleShiftSpell(entity, character, spells, PlayerUtilities.GetPlayerBool(steamId, "ShiftLock")); } else if (!entity.Has() && steamId.TryGetPlayerSpells(out spells)) { @@ -94,58 +93,14 @@ static void HandleExtraSpells(Entity entity, Entity character, ulong steamId, (i buffer.Add(buff); } - //HandleShiftSpell(entity, character, spells, PlayerUtilities.GetPlayerBool(steamId, "ShiftLock")); + HandleShiftSpell(entity, character, spells, PlayerUtilities.GetPlayerBool(steamId, "ShiftLock")); } static void HandleShiftSpell(Entity entity, Entity character, (int FirstSlot, int SecondSlot, int ShiftSlot) spells, bool shiftLock) { PrefabGUID spellPrefabGUID = new(spells.ShiftSlot); if (!shiftLock) return; - else if (PrefabCollectionSystem._PrefabGuidToEntityMap.TryGetValue(spellPrefabGUID, out Entity ability) && ability.TryGetComponent(out VBloodAbilityData vBloodAbilityData)) - { - Entity abilityGroup = ServerGameManager.GetAbilityGroup(character, 3); - if (abilityGroup.Exists() && ServerGameManager.TryGetBuffer(character, out var firstBuffer)) - { - Entity buffEntity = Entity.Null; - PrefabGUID oldAbility = abilityGroup.Read(); - int index = -1; - - for (int i = 0; i < firstBuffer.Length; i++) - { - VBloodAbilityBuffEntry vBloodAbilityBuffEntry = firstBuffer[i]; - if (vBloodAbilityBuffEntry.ActiveAbility.Equals(oldAbility) && vBloodAbilityBuffEntry.SlotId == 3) - { - buffEntity = vBloodAbilityBuffEntry.ActiveBuff; - index = i; - //Core.Log.LogInfo("Found old shift ability..."); - break; - } - } - - if (firstBuffer.IsIndexWithinRange(index) && buffEntity.Exists()) - { - firstBuffer.RemoveAt(index); - DestroyUtility.Destroy(EntityManager, buffEntity, DestroyDebugReason.TryRemoveBuff); - } - } - - VBloodAbilityUtilities.InstantiateBuff(EntityManager, ActivateVBloodAbilitySystem._BuffSpawnerSystemData, character, PrefabCollectionSystem._PrefabGuidToEntityMap[VBloodAbilityBuff], spellPrefabGUID, 3); - if (ServerGameManager.TryGetBuffer(character, out var secondBuffer)) - { - foreach(VBloodAbilityBuffEntry abilityEntry in secondBuffer) - { - if (abilityEntry.ActiveAbility.Equals(spellPrefabGUID)) - { - //Core.Log.LogInfo("Set correct ability type for shift..."); - abilityEntry.ActiveBuff.With((ref VBloodAbilityReplaceBuff vBloodAbilityReplaceBuff) => - { - vBloodAbilityReplaceBuff.AbilityType = vBloodAbilityData.AbilityType; - }); - break; - } - } - } - } + else if (PrefabCollectionSystem._PrefabGuidToEntityMap.TryGetValue(spellPrefabGUID, out Entity ability) && ability.Has()) return; else if (spellPrefabGUID.HasValue()) { var buffer = entity.ReadBuffer(); diff --git a/Patches/ScriptSpawnServerPatch.cs b/Patches/ScriptSpawnServerPatch.cs index d00cadc..b850fef 100644 --- a/Patches/ScriptSpawnServerPatch.cs +++ b/Patches/ScriptSpawnServerPatch.cs @@ -1,5 +1,4 @@ using Bloodcraft.Services; -using Bloodcraft.Systems.Familiars; using Bloodcraft.Systems.Legacies; using Bloodcraft.Systems.Leveling; using Bloodcraft.Utilities; @@ -7,16 +6,10 @@ using ProjectM; using ProjectM.Gameplay.Scripting; using ProjectM.Scripting; -using ProjectM.Shared; using ProjectM.Shared.Systems; using Stunlock.Core; -using System.Collections; using Unity.Collections; using Unity.Entities; -using Unity.Mathematics; -using Unity.Transforms; -using UnityEngine; -using Random = System.Random; namespace Bloodcraft.Patches; diff --git a/Patches/UpdateBuffsBufferDestroyPatch.cs b/Patches/UpdateBuffsBufferDestroyPatch.cs index cc8f26f..1bc36ad 100644 --- a/Patches/UpdateBuffsBufferDestroyPatch.cs +++ b/Patches/UpdateBuffsBufferDestroyPatch.cs @@ -3,6 +3,7 @@ using Bloodcraft.Utilities; using HarmonyLib; using ProjectM; +using ProjectM.Scripting; using Stunlock.Core; using Unity.Collections; using Unity.Entities; @@ -12,7 +13,11 @@ namespace Bloodcraft.Patches; [HarmonyPatch] internal static class UpdateBuffsBufferDestroyPatch { + static EntityManager EntityManager => Core.EntityManager; + static ServerGameManager ServerGameManager => Core.ServerGameManager; + static readonly PrefabGUID CombatBuff = new(581443919); + static readonly PrefabGUID ExternalInventory = new(1183666186); public static readonly List PrestigeBuffs = []; public static readonly Dictionary> ClassBuffs = []; @@ -30,8 +35,9 @@ static void OnUpdatePostix(UpdateBuffsBuffer_Destroy __instance) { foreach (Entity entity in entities) { - if (!entity.TryGetComponent(out PrefabGUID prefabGUID)) continue; - else if (ConfigService.FamiliarSystem && prefabGUID.Equals(CombatBuff)) + if (!entity.TryGetComponent(out PrefabGUID prefabGUID)) continue; + + if (ConfigService.FamiliarSystem && prefabGUID.Equals(CombatBuff)) { if (entity.GetBuffTarget().TryGetPlayer(out Entity character)) { @@ -69,7 +75,6 @@ static void OnUpdatePostix(UpdateBuffsBuffer_Destroy __instance) LevelingSystem.PlayerClasses playerClass = ClassUtilities.GetPlayerClass(steamId); List classBuffs = ClassBuffs.ContainsKey(playerClass) ? ClassBuffs[playerClass] : []; - //Core.Log.LogInfo($"UpdateBuffsBuffer_Destroy {steamId} | {playerClass} | {prefabGUID.LookupName()}"); if (classBuffs.Contains(prefabGUID)) BuffUtilities.HandlePermaBuff(player, prefabGUID); } } diff --git a/Patches/VBloodSystemPatch.cs b/Patches/VBloodSystemPatch.cs index b56a19e..c12b7a0 100644 --- a/Patches/VBloodSystemPatch.cs +++ b/Patches/VBloodSystemPatch.cs @@ -32,7 +32,6 @@ static void OnUpdatePrefix(VBloodSystem __instance) { foreach (VBloodConsumed vBloodConsumed in events) { - Entity player = vBloodConsumed.Target; User user = player.Read().UserEntity.Read(); ulong steamId = user.PlatformId; diff --git a/Services/ConfigService.cs b/Services/ConfigService.cs index 45fba4c..e6c1c49 100644 --- a/Services/ConfigService.cs +++ b/Services/ConfigService.cs @@ -455,20 +455,28 @@ static ConfigEntry InitConfigEntry(string section, string key, T defaultVa // Try to convert the string value to the expected type try { + //initialValue = (T)Convert.ChangeType(configValue, typeof(T)); var convertedValue = (T)Convert.ChangeType(configValue, typeof(T)); entry.Value = convertedValue; - //Plugin.LogInstance.LogInfo(line); - //Plugin.LogInstance.LogInfo($"Loaded existing config entry: {section} - {key} = {entry.Value} | {configKey}:{configValue}"); } catch (Exception ex) { Plugin.LogInstance.LogError($"Failed to convert config value for {key}: {ex.Message}"); } + break; // Stop searching once the key is found } } } } + + // Create ConfigDefinition and ConfigDescription with the actual default value + //var configDef = new ConfigDefinition(section, key); + //var configDesc = new ConfigDescription(description, null, null, defaultValue); + + // Add setting to config file with the initial value and the actual default value + //var configEntry = Plugin.Instance.Config.Bind(configDef, initialValue, configDesc); + return entry; } static void CreateDirectory(string path) diff --git a/Systems/Leveling/LevelingSystem.cs b/Systems/Leveling/LevelingSystem.cs index 41b0615..318331e 100644 --- a/Systems/Leveling/LevelingSystem.cs +++ b/Systems/Leveling/LevelingSystem.cs @@ -1,14 +1,12 @@ using Bloodcraft.Services; using Bloodcraft.Utilities; using ProjectM; -using ProjectM.Gameplay.Scripting; using ProjectM.Network; using ProjectM.Scripting; using Stunlock.Core; using Unity.Entities; using Unity.Mathematics; using Unity.Transforms; -using UnityEngine; using VampireCommandFramework; using static Bloodcraft.Patches.DeathEventListenerSystemPatch; using static Bloodcraft.Services.PlayerService; diff --git a/Systems/Leveling/PrestigeSystem.cs b/Systems/Leveling/PrestigeSystem.cs index c660b1b..d9a8ff9 100644 --- a/Systems/Leveling/PrestigeSystem.cs +++ b/Systems/Leveling/PrestigeSystem.cs @@ -14,8 +14,6 @@ internal static class PrestigeSystem static EntityManager EntityManager => Core.EntityManager; static ServerGameManager ServerGameManager => Core.ServerGameManager; static SystemService SystemService => Core.SystemService; - static DebugEventsSystem DebugEventsSystem => SystemService.DebugEventsSystem; - static EntityCommandBufferSystem EntityCommandBufferSystem => SystemService.EntityCommandBufferSystem; public static readonly Dictionary Data)>> TryGetExtensionMap = new() { @@ -486,7 +484,7 @@ static void RemoveBuff(Entity character, int buffId) var buffPrefab = new PrefabGUID(buffId); if (ServerGameManager.TryGetBuff(character, buffPrefab.ToIdentifier(), out Entity buffEntity)) { - Core.Log.LogInfo($"Removing buff {buffPrefab.LookupName()}..."); + //Core.Log.LogInfo($"Removing buff {buffPrefab.LookupName()}..."); DestroyUtility.Destroy(EntityManager, buffEntity, DestroyDebugReason.TryRemoveBuff); } } diff --git a/Utilities/ClassUtilities.cs b/Utilities/ClassUtilities.cs index 9621691..23e871c 100644 --- a/Utilities/ClassUtilities.cs +++ b/Utilities/ClassUtilities.cs @@ -259,6 +259,7 @@ public static void UpdateShift(ChatCommandContext ctx, Entity character, PrefabG Entity inventoryEntity = Entity.Null; Entity equippedJewelEntity = Entity.Null; Entity abilityGroup = ServerGameManager.GetAbilityGroup(character, 3); + string spellName = spellPrefabGUID.GetPrefabName(); if (abilityGroup.Exists() && ServerGameManager.TryGetBuffer(character, out var firstBuffer)) { @@ -266,7 +267,11 @@ public static void UpdateShift(ChatCommandContext ctx, Entity character, PrefabG PrefabGUID oldAbility = abilityGroup.Read(); int index = -1; - if (spellPrefabGUID.Equals(oldAbility)) return; + if (spellPrefabGUID.Equals(oldAbility)) + { + LocalizationService.HandleReply(ctx, $"Shift spell: {spellName}"); + return; + } for (int i = 0; i < firstBuffer.Length; i++) { VBloodAbilityBuffEntry vBloodAbilityBuffEntry = firstBuffer[i]; @@ -325,7 +330,6 @@ public static void UpdateShift(ChatCommandContext ctx, Entity character, PrefabG JewelEquipUtilitiesServer.TryEquipJewel(ref EntityManagerRef, ref PrefabLookupMap, character, slot); } - string spellName = spellPrefabGUID.GetPrefabName(); LocalizationService.HandleReply(ctx, $"Shift spell: {spellName}"); } else if (spellPrefabGUID.HasValue()) @@ -343,7 +347,11 @@ public static void UpdateShift(ChatCommandContext ctx, Entity character, PrefabG PrefabGUID oldAbility = abilityGroup.Read(); int index = -1; - if (spellPrefabGUID.Equals(oldAbility)) return; + if (spellPrefabGUID.Equals(oldAbility)) + { + LocalizationService.HandleReply(ctx, $"Shift spell: {spellName}"); + return; + } for (int i = 0; i < firstBuffer.Length; i++) { VBloodAbilityBuffEntry vBloodAbilityBuffEntry = firstBuffer[i]; diff --git a/Utilities/EntityUtilities.cs b/Utilities/EntityUtilities.cs index 1718dbf..6986382 100644 --- a/Utilities/EntityUtilities.cs +++ b/Utilities/EntityUtilities.cs @@ -66,7 +66,10 @@ internal static class EntityUtilities "GarlicResistance" ]; - static readonly HashSet FilteredResources = []; + static readonly HashSet FilteredResources = + [ + "Item_Ingredient_Crystal", + ]; public static IEnumerable GetEntitiesEnumerable(EntityQuery entityQuery, int targetType = -1) // not sure if need to actually check for empty buff buffer for quest targets but don't really want to find out { JobHandle handle = GetEntities(entityQuery, out NativeArray entities, Allocator.TempJob); @@ -86,12 +89,20 @@ internal static class EntityUtilities } else if (targetType == 1) { - if (entity.TryGetComponent(out PrefabGUID unitPrefab)) + if (entity.TryGetComponent(out PrefabGUID craftPrefab)) { - string prefabName = unitPrefab.LookupName(); + string prefabName = craftPrefab.LookupName(); if (!FilteredCrafts.Any(part => prefabName.Contains(part))) yield return entity; } } + else if (targetType == 2) + { + if (entity.TryGetComponent(out PrefabGUID resourcePrefab)) + { + string prefabName = resourcePrefab.LookupName(); + if (!FilteredResources.Any(part => prefabName.Contains(part))) yield return entity; + } + } else if (EntityManager.Exists(entity)) { yield return entity;