From dcd566f2dc6171eeeb9cb8801174a2784cf1ae2e Mon Sep 17 00:00:00 2001 From: Regalis Date: Tue, 21 Mar 2017 17:31:22 +0200 Subject: [PATCH] Clients can't set the condition of an item unless the server says so, fixed low item condition being rounded down to zero when writing into a network msg --- Subsurface/Source/Items/Item.cs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Subsurface/Source/Items/Item.cs b/Subsurface/Source/Items/Item.cs index 07d9fae0b..46232e02a 100644 --- a/Subsurface/Source/Items/Item.cs +++ b/Subsurface/Source/Items/Item.cs @@ -181,6 +181,7 @@ namespace Barotrauma get { return condition; } set { + if (GameMain.Client != null) return; if (!MathUtils.IsValid(value)) return; float prev = condition; @@ -1722,12 +1723,14 @@ namespace Barotrauma ownInventory.ServerWrite(msg, c, extraData); break; case NetEntityEvent.Type.Status: - msg.WriteRangedSingle(condition, 0.0f, 100.0f, 8); + //clamp above 0.5f if condition > 0.0f + //to prevent condition from being rounded down to 0.0 even if the item is not broken + msg.WriteRangedSingle(condition > 0.0f ? Math.Max(condition, 0.5f) : 0.0f, 0.0f, 100.0f, 8); if (condition <= 0.0f && FixRequirements.Count > 0) { - for (int i = 0; i 0) {