From ea7f5a3b824369e768748a96d3e032b02b338af7 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Sat, 30 Mar 2019 21:44:51 +0200 Subject: [PATCH] (0835d92e6) More reliable throw StatusEffect (= grenade explosion) syncing. Previously the clients would simply apply the statuseffects themselves when a client throws something, which most of the time didn't work because character inputs are sent unreliably and the item may have already been taken out from the character's inventory by a reliable NetEntityEvent by the time the throw input arrives. --- .../Source/Items/Components/Holdable/Throwable.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs index 7fb161dfa..b1634a6b7 100644 --- a/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs +++ b/Barotrauma/BarotraumaShared/Source/Items/Components/Holdable/Throwable.cs @@ -104,8 +104,8 @@ namespace Barotrauma.Items.Components #if SERVER GameServer.Log(picker.LogName + " threw " + item.Name, ServerLog.MessageType.ItemInteraction); #endif - - item.Drop(picker, createNetworkEvent: GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer); + Character thrower = picker; + item.Drop(thrower, createNetworkEvent: GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer); item.body.ApplyLinearImpulse(throwVector * throwForce * item.body.Mass * 3.0f); ac.GetLimb(LimbType.Head).body.ApplyLinearImpulse(throwVector*10.0f); @@ -115,7 +115,15 @@ namespace Barotrauma.Items.Components item.body.AngularVelocity = rightHand.body.AngularVelocity; throwPos = 0; throwDone = true; - ApplyStatusEffects(ActionType.OnSecondaryUse, deltaTime, picker); //Stun grenades, flares, etc. all have their throw-related things handled in "onSecondaryUse" + + if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsServer) + { + GameMain.NetworkMember.CreateEntityEvent(item, new object[] { NetEntityEvent.Type.ApplyStatusEffect, ActionType.OnSecondaryUse, this, thrower.ID }); + } + if (GameMain.NetworkMember == null || GameMain.NetworkMember.IsServer) + { + ApplyStatusEffects(ActionType.OnSecondaryUse, deltaTime, thrower); //Stun grenades, flares, etc. all have their throw-related things handled in "onSecondaryUse" + } throwing = false; } }