Skip to content

Commit

Permalink
- fixed jewel bug with class spells by unequipping them before abilit…
Browse files Browse the repository at this point in the history
…y is swapped then equipping them again after

- legacy experience back to feed kills only
  • Loading branch information
mfoltz committed Sep 21, 2024
1 parent 87d518d commit ef4fae8
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 29 deletions.
11 changes: 7 additions & 4 deletions Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ public static void Initialize()
if (ConfigService.ExtraRecipes) RecipeUtilities.ExtraRecipes();
if (ConfigService.StarterKit) ConfigUtilities.StarterKit();
if (ConfigService.PrestigeSystem) BuffUtilities.PrestigeBuffs();
if (ConfigService.SoftSynergies || ConfigService.HardSynergies) ConfigUtilities.CreateClassSpellCooldowns();
if (ConfigService.SoftSynergies || ConfigService.HardSynergies)
{
ConfigUtilities.CreateClassSpellCooldowns();
ClassUtilities.GenerateAbilityJewelMap();
}

if (ConfigService.LevelingSystem) DeathEventListenerSystemPatch.OnDeathEvent += LevelingSystem.OnUpdate;
if (ConfigService.BloodSystem) DeathEventListenerSystemPatch.OnDeathEvent += BloodSystem.OnUpdate;
//if (ConfigService.BloodSystem) DeathEventListenerSystemPatch.OnDeathEvent += BloodSystem.OnUpdate;
if (ConfigService.ExpertiseSystem) DeathEventListenerSystemPatch.OnDeathEvent += WeaponSystem.OnUpdate;
if (ConfigService.QuestSystem)
{
Expand Down Expand Up @@ -80,8 +84,7 @@ public static void Initialize()
}
Core.Log.LogInfo("=============================");
}
*/

*/

hasInitialized = true;
}
Expand Down
2 changes: 2 additions & 0 deletions Patches/DeathEventSystemPatch.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Bloodcraft.Services;
using Bloodcraft.Systems.Legacies;
using Bloodcraft.Systems.Professions;
using Bloodcraft.Utilities;
using HarmonyLib;
Expand Down Expand Up @@ -47,6 +48,7 @@ static void OnUpdatePostfix(DeathEventListenerSystem __instance)
Target = deathEvent.Died
};
if (deathArgs.Source != deathArgs.Target) RaiseDeathEvent(deathArgs);
if (deathEvent.StatChangeReason.Equals(StatChangeReason.HandleGameplayEventsBase_11)) BloodSystem.ProcessLegacy(deathArgs.Source, deathArgs.Target);
}
}
else if (ConfigService.ProfessionSystem && deathEvent.Killer.IsPlayer())
Expand Down
2 changes: 2 additions & 0 deletions Systems/Legacies/BloodSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,12 @@ internal static class BloodSystem
{ BloodType.Immortal, new PrefabGUID(55100532) }, // CHAR_Dracula_BloodSoul_heart
{ BloodType.Brute, new PrefabGUID(2005508157) } // CHAR_Militia_Heavy
};
/*
public static void OnUpdate(object sender, DeathEventArgs deathEvent)
{
ProcessLegacy(deathEvent.Source, deathEvent.Target);
}
*/
public static void ProcessLegacy(Entity Killer, Entity Victim)
{
if (!Victim.Has<BloodConsumeSource>()) return;
Expand Down
14 changes: 0 additions & 14 deletions Systems/Leveling/LevelingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,6 @@ static void NotifyPlayer(Entity userEntity, Entity victim, ulong steamId, int ga
LocalizationService.HandleServerReply(EntityManager, user, message);
}

if (victim.Equals(Entity.Null)) return;

/*
if (PlayerUtilities.GetPlayerBool(steamId, "ScrollingText"))
{
Expand All @@ -356,18 +354,6 @@ static void NotifyPlayer(Entity userEntity, Entity victim, ulong steamId, int ga
}
*/
}
static float3 GetRandomPositionAroundEntity(float3 entityPosition, float radius)
{
// Generate a random angle in radians (0 to 2 * Pi for a full circle)
float randomAngle = UnityEngine.Random.Range(0f, 2f * Mathf.PI);

// Calculate the X and Z offsets using trigonometry (we assume Y remains the same)
float offsetX = Mathf.Cos(randomAngle) * radius;
float offsetZ = Mathf.Sin(randomAngle) * radius;

// Return the new position, keeping the Y axis (height) unchanged
return new float3(entityPosition.x + offsetX, entityPosition.y, entityPosition.z + offsetZ);
}
public static int ConvertXpToLevel(float xp)
{
return (int)(EXPConstant * Math.Sqrt(xp));
Expand Down
53 changes: 42 additions & 11 deletions Utilities/ClassUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
using ProjectM.Scripting;
using ProjectM.Shared;
using Stunlock.Core;
using Unity.Collections;
using Unity.Entities;
using UnityEngine.TextCore.Text;
using VampireCommandFramework;
using static Bloodcraft.Systems.Leveling.LevelingSystem;
using static ProjectM.Tiles.TileConstants;

namespace Bloodcraft.Utilities;

internal static class ClassUtilities
{
static EntityManager EntityManager => Core.EntityManager;

static EntityManager EntityManagerRef = Core.EntityManager;
static ServerGameManager ServerGameManager => Core.ServerGameManager;
static SystemService SystemService => Core.SystemService;
static EntityCommandBufferSystem EntityCommandBufferSystem => SystemService.EntityCommandBufferSystem;
Expand All @@ -26,6 +27,18 @@ internal static class ClassUtilities

static readonly PrefabGUID VBloodAbilityBuff = new(1171608023);

static NativeParallelHashMap<PrefabGUID, ItemData> itemLookup = SystemService.GameDataSystem.ItemHashLookupMap;
static PrefabLookupMap PrefabLookupMap = PrefabCollectionSystem._PrefabLookupMap;

static readonly ComponentType[] JewelComponents =
[
ComponentType.ReadOnly(Il2CppType.Of<JewelInstance>()),
ComponentType.ReadOnly(Il2CppType.Of<JewelLevelSource>())
];

static EntityQuery JewelQuery;

static readonly Dictionary<PrefabGUID, List<Entity>> AbilityJewelMap = [];
public static List<int> GetClassBuffs(ulong steamId)
{
if (steamId.TryGetPlayerClasses(out var classes) && classes.Keys.Count > 0)
Expand Down Expand Up @@ -186,7 +199,12 @@ public static void UpdateShift(Entity character, PrefabGUID spellPrefabGUID)
{
if (PrefabCollectionSystem._PrefabGuidToEntityMap.TryGetValue(spellPrefabGUID, out Entity ability) && ability.TryGetComponent(out VBloodAbilityData vBloodAbilityData))
{
bool tryEquip = false;

Entity inventoryEntity = Entity.Null;
Entity equippedJewelEntity = Entity.Null;
Entity abilityGroup = ServerGameManager.GetAbilityGroup(character, 3);

if (abilityGroup.Exists() && ServerGameManager.TryGetBuffer<VBloodAbilityBuffEntry>(character, out var firstBuffer))
{
Entity buffEntity = Entity.Null;
Expand All @@ -200,11 +218,26 @@ public static void UpdateShift(Entity character, PrefabGUID spellPrefabGUID)
{
buffEntity = vBloodAbilityBuffEntry.ActiveBuff;
index = i;
//Core.Log.LogInfo("Found old shift ability...");
break;
}
}

if (InventoryUtilities.TryGetInventoryEntity(EntityManager, character, out inventoryEntity))
{
foreach (Entity jewel in AbilityJewelMap[oldAbility])
{
if (JewelEquipUtilitiesServer.TryGetEquippedJewel(EntityManager, character, jewel, out equippedJewelEntity) && equippedJewelEntity.Exists())
{
break;
}
}

if (JewelEquipUtilitiesServer.TryUnequipJewel(EntityManager, ref itemLookup, inventoryEntity, abilityGroup))
{
tryEquip = true;
}
}

if (firstBuffer.IsIndexWithinRange(index) && buffEntity.Exists())
{
firstBuffer.RemoveAt(index);
Expand All @@ -219,7 +252,6 @@ public static void UpdateShift(Entity character, PrefabGUID spellPrefabGUID)
{
if (abilityEntry.ActiveAbility.Equals(spellPrefabGUID))
{
//Core.Log.LogInfo("Set correct ability type for shift...");
abilityEntry.ActiveBuff.With((ref VBloodAbilityReplaceBuff vBloodAbilityReplaceBuff) =>
{
vBloodAbilityReplaceBuff.AbilityType = vBloodAbilityData.AbilityType;
Expand All @@ -230,6 +262,11 @@ public static void UpdateShift(Entity character, PrefabGUID spellPrefabGUID)
}

ReplaceAbilityOnSlotSystem.OnUpdate();

if (tryEquip && InventoryUtilities.TryGetItemSlot(EntityManager, character, equippedJewelEntity, out int slot))
{
JewelEquipUtilitiesServer.TryEquipJewel(ref EntityManagerRef, ref PrefabLookupMap, character, slot);
}
}
else if (spellPrefabGUID.HasValue())
{
Expand Down Expand Up @@ -273,7 +310,6 @@ public static void UpdateShift(Entity character, PrefabGUID spellPrefabGUID)
ReplaceAbilityOnSlotSystem.OnUpdate();
}
}
/*
public static void GenerateAbilityJewelMap()
{
JewelQuery = EntityManager.CreateEntityQuery(new EntityQueryDesc
Expand All @@ -296,20 +332,15 @@ public static void GenerateAbilityJewelMap()
}

string prefabName = entity.Read<PrefabGUID>().LookupName().Split(" ", 2)[0];

if (prefabName.EndsWith("T01") || prefabName.EndsWith("T02") || prefabName.EndsWith("T03") || prefabName.EndsWith("T04")) continue;
else AbilityJewelMap[jewelInstance.OverrideAbilityType].Add(entity);
}
}
foreach(var kvp in AbilityJewelMap)
{
//Core.Log.LogInfo($"Ability {kvp.Key.LookupName()} has {kvp.Value.Count} jewel(s): {string.Join(", ", kvp.Value.Select(e => e.Read<PrefabGUID>().LookupName()))}");
}
}
finally
{
JewelQuery.Dispose();
}
}
*/
}

0 comments on commit ef4fae8

Please sign in to comment.