Skip to content

Commit

Permalink
Merge pull request #244 from project-fika/fix-knife-poison
Browse files Browse the repository at this point in the history
Fix cultist knife poison
  • Loading branch information
Lacyway authored Dec 18, 2024
2 parents 7f46bd0 + 5ba7e33 commit 8d4d47e
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 4 deletions.
39 changes: 35 additions & 4 deletions Fika.Core/Coop/Players/CoopPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item> itemResult = FindItemById(lastWeaponId, false, false);
Item item = itemResult.Value;
if (!itemResult.Succeeded)
{
foreach (ThrowWeapItemClass grenadeClass in Singleton<IFikaNetworkManager>.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,
Expand Down Expand Up @@ -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++)
Expand Down
5 changes: 5 additions & 0 deletions Fika.Core/Coop/Players/ObservedCoopPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,11 @@ public void InitObservedPlayer(bool isDedicatedHost)
}
}

public override void OnSideEffectApplied(SideEffectComponent sideEffect)
{
// Do nothing
}

private IEnumerator CreateHealthBar()
{
CoopGame coopGame = (CoopGame)Singleton<IFikaGame>.Instance;
Expand Down
25 changes: 25 additions & 0 deletions Fika.Core/Networking/FikaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -158,6 +159,7 @@ public async void Init()
packetProcessor.SubscribeNetSerializable<LootSyncPacket>(OnLootSyncPacketReceived);
packetProcessor.SubscribeNetSerializable<LoadingProfilePacket>(OnLoadingProfilePacketReceived);
packetProcessor.SubscribeNetSerializable<CorpsePositionPacket>(OnCorpsePositionPacketReceived);
packetProcessor.SubscribeNetSerializable<SideEffectPacket>(OnSideEffectPacketReceived);

#if DEBUG
AddDebugPackets();
Expand Down Expand Up @@ -209,6 +211,29 @@ public async void Init()
FikaEventDispatcher.DispatchEvent(new FikaNetworkManagerCreatedEvent(this));
}

private void OnSideEffectPacketReceived(SideEffectPacket packet)
{
GameWorld gameWorld = Singleton<GameWorld>.Instance;
if (gameWorld == null)
{
logger.LogError("OnSideEffectPacketReceived: GameWorld was null!");
return;
}

GStruct448<Item> 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<GameWorld>.Instance;
Expand Down
26 changes: 26 additions & 0 deletions Fika.Core/Networking/FikaServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public async Task Init()
packetProcessor.SubscribeNetSerializable<PingPacket, NetPeer>(OnPingPacketReceived);
packetProcessor.SubscribeNetSerializable<LootSyncPacket, NetPeer>(OnLootSyncPacketReceived);
packetProcessor.SubscribeNetSerializable<LoadingProfilePacket, NetPeer>(OnLoadingProfilePacketReceived);
packetProcessor.SubscribeNetSerializable<SideEffectPacket, NetPeer>(OnSideEffectPacketReceived);

#if DEBUG
AddDebugPackets();
Expand Down Expand Up @@ -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<GameWorld>.Instance;
if (gameWorld == null)
{
logger.LogError("OnSideEffectPacketReceived: GameWorld was null!");
return;
}

GStruct448<Item> 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)
Expand Down
22 changes: 22 additions & 0 deletions Fika.Core/Networking/Packets/Player/SideEffectPacket.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}

0 comments on commit 8d4d47e

Please sign in to comment.