Skip to content

Commit

Permalink
- fixed indexing for class spells
Browse files Browse the repository at this point in the history
- fixed default spell bypassing prestige level requirement if not left at 0
- NPC spells should stay as chosen and not get reset when ReplaceAbiltiyOnSlotSystem from game fires
  • Loading branch information
mfoltz committed Sep 29, 2024
1 parent bad7b35 commit 5468ecc
Show file tree
Hide file tree
Showing 14 changed files with 60 additions and 76 deletions.
8 changes: 7 additions & 1 deletion Commands/ClassCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Patches/BuffSystemSpawnServerPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion Patches/DealDamageSystemPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EntityOwner>()) 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<YieldResourcesOnDamageTaken>() && dealDamageEvent.SpellSource.GetOwner().TryGetPlayer(out Entity player))
{
Expand Down
3 changes: 2 additions & 1 deletion Patches/InteractValidateAndStopSystemPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -33,7 +34,7 @@ static void OnUpdatePrefix(InteractValidateAndStopSystemServer __instance)
{
if (!entity.Has<EntityOwner>()) 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
Expand Down
1 change: 1 addition & 0 deletions Patches/ReactToInventoryChangedSystemPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
51 changes: 3 additions & 48 deletions Patches/ReplaceAbilityOnSlotSystemPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<WeaponLevel>() && steamId.TryGetPlayerSpells(out spells))
{
Expand Down Expand Up @@ -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<VBloodAbilityBuffEntry>(character, out var firstBuffer))
{
Entity buffEntity = Entity.Null;
PrefabGUID oldAbility = abilityGroup.Read<PrefabGUID>();
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<VBloodAbilityBuffEntry>(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<VBloodAbilityData>()) return;
else if (spellPrefabGUID.HasValue())
{
var buffer = entity.ReadBuffer<ReplaceAbilityOnSlotBuff>();
Expand Down
7 changes: 0 additions & 7 deletions Patches/ScriptSpawnServerPatch.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
using Bloodcraft.Services;
using Bloodcraft.Systems.Familiars;
using Bloodcraft.Systems.Legacies;
using Bloodcraft.Systems.Leveling;
using Bloodcraft.Utilities;
using HarmonyLib;
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;

Expand Down
11 changes: 8 additions & 3 deletions Patches/UpdateBuffsBufferDestroyPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Bloodcraft.Utilities;
using HarmonyLib;
using ProjectM;
using ProjectM.Scripting;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
Expand All @@ -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<PrefabGUID> PrestigeBuffs = [];
public static readonly Dictionary<LevelingSystem.PlayerClasses, List<PrefabGUID>> ClassBuffs = [];
Expand All @@ -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))
{
Expand Down Expand Up @@ -69,7 +75,6 @@ static void OnUpdatePostix(UpdateBuffsBuffer_Destroy __instance)
LevelingSystem.PlayerClasses playerClass = ClassUtilities.GetPlayerClass(steamId);
List<PrefabGUID> classBuffs = ClassBuffs.ContainsKey(playerClass) ? ClassBuffs[playerClass] : [];

//Core.Log.LogInfo($"UpdateBuffsBuffer_Destroy {steamId} | {playerClass} | {prefabGUID.LookupName()}");
if (classBuffs.Contains(prefabGUID)) BuffUtilities.HandlePermaBuff(player, prefabGUID);
}
}
Expand Down
1 change: 0 additions & 1 deletion Patches/VBloodSystemPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ static void OnUpdatePrefix(VBloodSystem __instance)
{
foreach (VBloodConsumed vBloodConsumed in events)
{

Entity player = vBloodConsumed.Target;
User user = player.Read<PlayerCharacter>().UserEntity.Read<User>();
ulong steamId = user.PlatformId;
Expand Down
12 changes: 10 additions & 2 deletions Services/ConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,20 +455,28 @@ static ConfigEntry<T> InitConfigEntry<T>(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)
Expand Down
2 changes: 0 additions & 2 deletions Systems/Leveling/LevelingSystem.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 1 addition & 3 deletions Systems/Leveling/PrestigeSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PrestigeType, Func<ulong, (bool Success, KeyValuePair<int, float> Data)>> TryGetExtensionMap = new()
{
Expand Down Expand Up @@ -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);
}
}
Expand Down
14 changes: 11 additions & 3 deletions Utilities/ClassUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,14 +259,19 @@ 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<VBloodAbilityBuffEntry>(character, out var firstBuffer))
{
Entity buffEntity = Entity.Null;
PrefabGUID oldAbility = abilityGroup.Read<PrefabGUID>();
int index = -1;

if (spellPrefabGUID.Equals(oldAbility)) return;
if (spellPrefabGUID.Equals(oldAbility))
{
LocalizationService.HandleReply(ctx, $"Shift spell: <color=#CBC3E3>{spellName}</color>");
return;
}
for (int i = 0; i < firstBuffer.Length; i++)
{
VBloodAbilityBuffEntry vBloodAbilityBuffEntry = firstBuffer[i];
Expand Down Expand Up @@ -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: <color=#CBC3E3>{spellName}</color>");
}
else if (spellPrefabGUID.HasValue())
Expand All @@ -343,7 +347,11 @@ public static void UpdateShift(ChatCommandContext ctx, Entity character, PrefabG
PrefabGUID oldAbility = abilityGroup.Read<PrefabGUID>();
int index = -1;

if (spellPrefabGUID.Equals(oldAbility)) return;
if (spellPrefabGUID.Equals(oldAbility))
{
LocalizationService.HandleReply(ctx, $"Shift spell: <color=#CBC3E3>{spellName}</color>");
return;
}
for (int i = 0; i < firstBuffer.Length; i++)
{
VBloodAbilityBuffEntry vBloodAbilityBuffEntry = firstBuffer[i];
Expand Down
17 changes: 14 additions & 3 deletions Utilities/EntityUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ internal static class EntityUtilities
"GarlicResistance"
];

static readonly HashSet<string> FilteredResources = [];
static readonly HashSet<string> FilteredResources =
[
"Item_Ingredient_Crystal",
];
public static IEnumerable<Entity> 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<Entity> entities, Allocator.TempJob);
Expand All @@ -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;
Expand Down

0 comments on commit 5468ecc

Please sign in to comment.