Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cultist knife poison #244

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}
Loading