From 5ba7e333e86fc31ee3a8cf24a502117a1822c25e Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:28:21 +0100 Subject: [PATCH] Fix cultist knife poison --- Fika.Core/Coop/Players/CoopPlayer.cs | 39 +++++++++++++++++-- Fika.Core/Coop/Players/ObservedCoopPlayer.cs | 5 +++ Fika.Core/Networking/FikaClient.cs | 25 ++++++++++++ Fika.Core/Networking/FikaServer.cs | 26 +++++++++++++ .../Packets/Player/SideEffectPacket.cs | 22 +++++++++++ 5 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 Fika.Core/Networking/Packets/Player/SideEffectPacket.cs diff --git a/Fika.Core/Coop/Players/CoopPlayer.cs b/Fika.Core/Coop/Players/CoopPlayer.cs index e6c2c84c..dabea03d 100644 --- a/Fika.Core/Coop/Players/CoopPlayer.cs +++ b/Fika.Core/Coop/Players/CoopPlayer.cs @@ -434,26 +434,37 @@ public override void OnBeenKilledByAggressor(IPlayer aggressor, DamageInfoStruct } } - protected void FindKillerWeapon() + protected Item FindWeapon() { #if DEBUG FikaPlugin.Instance.FikaLogger.LogWarning($"Finding weapon '{lastWeaponId}'!"); #endif GStruct448 itemResult = FindItemById(lastWeaponId, false, false); + Item item = itemResult.Value; if (!itemResult.Succeeded) { foreach (ThrowWeapItemClass grenadeClass in Singleton.Instance.CoopHandler.LocalGameInstance.ThrownGrenades) { if (grenadeClass.Id == lastWeaponId) { - LastDamageInfo.Weapon = grenadeClass; + item = grenadeClass; break; } } - return; } - LastDamageInfo.Weapon = itemResult.Value; + return item; + } + + protected void FindKillerWeapon() + { + Item item = FindWeapon(); + if (item == null) + { + FikaPlugin.Instance.FikaLogger.LogError($"Could not find killer weapon: {lastWeaponId}!"); + return; + } + LastDamageInfo.Weapon = item; } public void HandleTeammateKill(ref DamageInfoStruct damage, EBodyPart bodyPart, @@ -1327,11 +1338,31 @@ public virtual void HandleDamagePacket(ref DamagePacket packet) lastWeaponId = packet.WeaponId; } + if (damageInfo.DamageType == EDamageType.Melee && !string.IsNullOrEmpty(lastWeaponId)) + { + Item item = FindWeapon(); + if (item != null) + { + damageInfo.Weapon = item; + } + } + ShotReactions(damageInfo, packet.BodyPartType); ReceiveDamage(damageInfo.Damage, packet.BodyPartType, damageInfo.DamageType, packet.Absorbed, packet.Material); base.ApplyDamageInfo(damageInfo, packet.BodyPartType, packet.ColliderType, packet.Absorbed); } + public override void OnSideEffectApplied(SideEffectComponent sideEffect) + { + SideEffectPacket packet = new() + { + ItemId = sideEffect.Item.Id, + Value = sideEffect.Value + }; + + PacketSender.SendPacket(ref packet); + } + public void HandleArmorDamagePacket(ref ArmorDamagePacket packet) { for (int i = 0; i < packet.ItemIds.Length; i++) diff --git a/Fika.Core/Coop/Players/ObservedCoopPlayer.cs b/Fika.Core/Coop/Players/ObservedCoopPlayer.cs index b9a8b934..0e88a788 100644 --- a/Fika.Core/Coop/Players/ObservedCoopPlayer.cs +++ b/Fika.Core/Coop/Players/ObservedCoopPlayer.cs @@ -1112,6 +1112,11 @@ public void InitObservedPlayer(bool isDedicatedHost) } } + public override void OnSideEffectApplied(SideEffectComponent sideEffect) + { + // Do nothing + } + private IEnumerator CreateHealthBar() { CoopGame coopGame = (CoopGame)Singleton.Instance; diff --git a/Fika.Core/Networking/FikaClient.cs b/Fika.Core/Networking/FikaClient.cs index d7f0e014..91bc7400 100644 --- a/Fika.Core/Networking/FikaClient.cs +++ b/Fika.Core/Networking/FikaClient.cs @@ -8,6 +8,7 @@ using EFT.Communications; using EFT.GlobalEvents; using EFT.Interactive; +using EFT.InventoryLogic; using EFT.SynchronizableObjects; using EFT.UI; using EFT.Vehicle; @@ -158,6 +159,7 @@ public async void Init() packetProcessor.SubscribeNetSerializable(OnLootSyncPacketReceived); packetProcessor.SubscribeNetSerializable(OnLoadingProfilePacketReceived); packetProcessor.SubscribeNetSerializable(OnCorpsePositionPacketReceived); + packetProcessor.SubscribeNetSerializable(OnSideEffectPacketReceived); #if DEBUG AddDebugPackets(); @@ -209,6 +211,29 @@ public async void Init() FikaEventDispatcher.DispatchEvent(new FikaNetworkManagerCreatedEvent(this)); } + private void OnSideEffectPacketReceived(SideEffectPacket packet) + { + GameWorld gameWorld = Singleton.Instance; + if (gameWorld == null) + { + logger.LogError("OnSideEffectPacketReceived: GameWorld was null!"); + return; + } + + GStruct448 gstruct2 = gameWorld.FindItemById(packet.ItemId); + if (gstruct2.Failed) + { + logger.LogError("OnSideEffectPacketReceived: " + gstruct2.Error); + return; + } + Item item = gstruct2.Value; + if (item.TryGetItemComponent(out SideEffectComponent sideEffectComponent)) + { + sideEffectComponent.Value = packet.Value; + item.RaiseRefreshEvent(false, false); + } + } + private void OnCorpsePositionPacketReceived(CorpsePositionPacket packet) { GameWorld gameWorld = Singleton.Instance; diff --git a/Fika.Core/Networking/FikaServer.cs b/Fika.Core/Networking/FikaServer.cs index 7190118b..b0ebccf9 100644 --- a/Fika.Core/Networking/FikaServer.cs +++ b/Fika.Core/Networking/FikaServer.cs @@ -188,6 +188,7 @@ public async Task Init() packetProcessor.SubscribeNetSerializable(OnPingPacketReceived); packetProcessor.SubscribeNetSerializable(OnLootSyncPacketReceived); packetProcessor.SubscribeNetSerializable(OnLoadingProfilePacketReceived); + packetProcessor.SubscribeNetSerializable(OnSideEffectPacketReceived); #if DEBUG AddDebugPackets(); @@ -295,6 +296,31 @@ public async Task Init() FikaEventDispatcher.DispatchEvent(new FikaNetworkManagerCreatedEvent(this)); } + private void OnSideEffectPacketReceived(SideEffectPacket packet, NetPeer peer) + { + SendDataToAll(ref packet, DeliveryMethod.ReliableOrdered, peer); + + GameWorld gameWorld = Singleton.Instance; + if (gameWorld == null) + { + logger.LogError("OnSideEffectPacketReceived: GameWorld was null!"); + return; + } + + GStruct448 gstruct2 = gameWorld.FindItemById(packet.ItemId); + if (gstruct2.Failed) + { + logger.LogError("OnSideEffectPacketReceived: " + gstruct2.Error); + return; + } + Item item = gstruct2.Value; + if (item.TryGetItemComponent(out SideEffectComponent sideEffectComponent)) + { + sideEffectComponent.Value = packet.Value; + item.RaiseRefreshEvent(false, false); + } + } + private void OnLoadingProfilePacketReceived(LoadingProfilePacket packet, NetPeer peer) { if (packet.Profiles == null) diff --git a/Fika.Core/Networking/Packets/Player/SideEffectPacket.cs b/Fika.Core/Networking/Packets/Player/SideEffectPacket.cs new file mode 100644 index 00000000..d679b873 --- /dev/null +++ b/Fika.Core/Networking/Packets/Player/SideEffectPacket.cs @@ -0,0 +1,22 @@ +using LiteNetLib.Utils; + +namespace Fika.Core.Networking +{ + public class SideEffectPacket : INetSerializable + { + public string ItemId; + public float Value; + + public void Deserialize(NetDataReader reader) + { + ItemId = reader.GetString(); + Value = reader.GetFloat(); + } + + public void Serialize(NetDataWriter writer) + { + writer.Put(ItemId); + writer.Put(Value); + } + } +}