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
This commit is contained in:
@@ -181,6 +181,7 @@ namespace Barotrauma
|
|||||||
get { return condition; }
|
get { return condition; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
if (GameMain.Client != null) return;
|
||||||
if (!MathUtils.IsValid(value)) return;
|
if (!MathUtils.IsValid(value)) return;
|
||||||
|
|
||||||
float prev = condition;
|
float prev = condition;
|
||||||
@@ -1722,12 +1723,14 @@ namespace Barotrauma
|
|||||||
ownInventory.ServerWrite(msg, c, extraData);
|
ownInventory.ServerWrite(msg, c, extraData);
|
||||||
break;
|
break;
|
||||||
case NetEntityEvent.Type.Status:
|
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)
|
if (condition <= 0.0f && FixRequirements.Count > 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i<FixRequirements.Count; i++)
|
for (int i = 0; i < FixRequirements.Count; i++)
|
||||||
msg.Write(FixRequirements[i].Fixed);
|
msg.Write(FixRequirements[i].Fixed);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case NetEntityEvent.Type.ApplyStatusEffect:
|
case NetEntityEvent.Type.ApplyStatusEffect:
|
||||||
@@ -1761,7 +1764,7 @@ namespace Barotrauma
|
|||||||
ownInventory.ClientRead(type, msg, sendingTime);
|
ownInventory.ClientRead(type, msg, sendingTime);
|
||||||
break;
|
break;
|
||||||
case NetEntityEvent.Type.Status:
|
case NetEntityEvent.Type.Status:
|
||||||
Condition = msg.ReadRangedSingle(0.0f, 100.0f, 8);
|
condition = msg.ReadRangedSingle(0.0f, 100.0f, 8);
|
||||||
|
|
||||||
if (FixRequirements.Count > 0)
|
if (FixRequirements.Count > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user