Server writes item condition at full accuracy instead of just using 8 bits. The more inaccurate condition caused issues when the value was just above some specific threshold (e.g. minimum condition for a fabricator ingredient) server-side and below it client-side. Closes #616

This commit is contained in:
Joonas Rikkonen
2018-08-09 12:39:14 +03:00
parent 45939a9144
commit 7a7c92a2ce
2 changed files with 2 additions and 6 deletions
@@ -381,8 +381,7 @@ namespace Barotrauma
(components[containerIndex] as ItemContainer).Inventory.ClientRead(type, msg, sendingTime); (components[containerIndex] as ItemContainer).Inventory.ClientRead(type, msg, sendingTime);
break; break;
case NetEntityEvent.Type.Status: case NetEntityEvent.Type.Status:
condition = msg.ReadRangedSingle(0.0f, prefab.Health, 8); condition = msg.ReadSingle();
if (FixRequirements.Count > 0) if (FixRequirements.Count > 0)
{ {
if (Condition <= 0.0f) if (Condition <= 0.0f)
@@ -1375,10 +1375,7 @@ namespace Barotrauma
(components[containerIndex] as ItemContainer).Inventory.ServerWrite(msg, c); (components[containerIndex] as ItemContainer).Inventory.ServerWrite(msg, c);
break; break;
case NetEntityEvent.Type.Status: case NetEntityEvent.Type.Status:
//clamp to (MaxHealth / 255.0f) if condition > 0.0f msg.Write(condition);
//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, prefab.Health / 255.0f) : 0.0f, 0.0f, prefab.Health, 8);
if (condition <= 0.0f && FixRequirements.Count > 0) if (condition <= 0.0f && FixRequirements.Count > 0)
{ {
for (int i = 0; i < FixRequirements.Count; i++) for (int i = 0; i < FixRequirements.Count; i++)