Skip to content

Commit

Permalink
fix: Fixes negative weight issue (#1621)
Browse files Browse the repository at this point in the history
Closes #73
  • Loading branch information
kamronbatman authored Nov 26, 2023
1 parent 4f6afad commit 130a567
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions Projects/Server/Items/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public double Weight
{
var info = LookupCompactInfo();

return info != null && info.m_Weight != -1 ? info.m_Weight : DefaultWeight;
return info is { m_Weight: >= 0 } ? info.m_Weight : DefaultWeight;
}
set
{
Expand All @@ -458,7 +458,7 @@ public double Weight

info.m_Weight = value;

if (info.m_Weight == -1)
if (info.m_Weight < 0)
{
VerifyCompactInfo();
}
Expand Down Expand Up @@ -883,26 +883,23 @@ public virtual void Serialize(IGenericWriter writer)
}
}

if (info == null || info.m_Weight == -1.0)
if (info == null || info.m_Weight < 0)
{
flags |= SaveFlag.NullWeight;
}
else
else if (info.m_Weight == 0.0)
{
flags |= SaveFlag.WeightIs0;
}
else if (info.m_Weight > 0)
{
if (info.m_Weight == 0.0)
if (info.m_Weight == (int)info.m_Weight)
{
flags |= SaveFlag.WeightIs0;
flags |= SaveFlag.IntWeight;
}
else if (info.m_Weight != 1.0)
else
{
if (info.m_Weight == (int)info.m_Weight)
{
flags |= SaveFlag.IntWeight;
}
else
{
flags |= SaveFlag.WeightNot1or0;
}
flags |= SaveFlag.WeightNot1or0;
}
}

Expand Down Expand Up @@ -1607,7 +1604,7 @@ public ExpandFlag GetExpandFlags()
flags |= ExpandFlag.TempFlag;
}

if (info.m_Weight != -1)
if (info.m_Weight >= 0)
{
flags |= ExpandFlag.Weight;
}
Expand Down Expand Up @@ -1642,7 +1639,7 @@ private void VerifyCompactInfo()
|| info.m_Spawner != null
|| info.m_TempFlags != 0
|| info.m_SavedFlags != 0
|| info.m_Weight != -1;
|| info.m_Weight >= 0;

if (!isValid)
{
Expand Down

0 comments on commit 130a567

Please sign in to comment.