Skip to content

Commit

Permalink
- fixed some bugs with blood
Browse files Browse the repository at this point in the history
  • Loading branch information
mfoltz committed Sep 21, 2024
1 parent ef4fae8 commit bf24a6f
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 8 deletions.
3 changes: 3 additions & 0 deletions Commands/WeaponCommands.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -126,6 +128,7 @@ public static void ChooseWeaponStat(ChatCommandContext ctx, string weaponType, s
if (ChooseStat(steamID, WeaponType, StatType))
{
LocalizationService.HandleReply(ctx, $"<color=#00FFFF>{StatType}</color> has been chosen for <color=#c0c0c0>{WeaponType}</color> and will apply after reequiping.");
//UpdateWeaponStats(ctx.Event.SenderCharacterEntity);
}
else
{
Expand Down
1 change: 1 addition & 0 deletions Patches/StatChangeMutationSystemPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
103 changes: 103 additions & 0 deletions Systems/Expertise/WeaponManager.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
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;

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<FromCharacter>()),
ComponentType.ReadOnly(Il2CppType.Of<ReceiveNetworkEventTag>()),
ComponentType.ReadOnly(Il2CppType.Of<NetworkEventType>()),
ComponentType.ReadOnly(Il2CppType.Of<UnequipItemEvent>())
];

static readonly NetworkEventType UnequipEventType = new()
{
IsAdminEvent = false,
EventId = NetworkEvents.EventId_UnequipItemEvent,
IsDebugEvent = false
};

static readonly ComponentType[] EquipNetworkEventComponents =
[
ComponentType.ReadOnly(Il2CppType.Of<FromCharacter>()),
ComponentType.ReadOnly(Il2CppType.Of<ReceiveNetworkEventTag>()),
ComponentType.ReadOnly(Il2CppType.Of<NetworkEventType>()),
ComponentType.ReadOnly(Il2CppType.Of<EquipItemEvent>())
];

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))
Expand Down Expand Up @@ -148,6 +183,74 @@ public static WeaponType GetCurrentWeaponType(Entity character)
Entity weapon = character.Read<Equipment>().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<Equipment>();
Entity weaponEntity = equipment.WeaponSlot.SlotEntity.GetEntityOnServer();
int slot = -1;

EquipItemEvent equipItemEvent = new();
FromCharacter fromCharacter = new();
Entity networkEntity = Entity.Null;

if (!weaponEntity.Exists() && ServerGameManager.TryGetBuffer<InventoryBuffer>(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<PlayerCharacter>().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<PlayerCharacter>().UserEntity
};

networkEntity = EntityManager.CreateEntity(EquipNetworkEventComponents);

networkEntity.Write(fromCharacter);
networkEntity.Write(EquipEventType);
networkEntity.Write(equipItemEvent);
}
public class WeaponStats
{
public enum WeaponStatType
Expand Down
9 changes: 4 additions & 5 deletions Systems/Legacies/BloodManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Blood>();

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))
Expand All @@ -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]
};
Expand Down
1 change: 0 additions & 1 deletion Systems/Legacies/BloodSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions Utilities/ClassUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit bf24a6f

Please sign in to comment.