Skip to content

Commit e6d88a8

Browse files
committed
GetRandomIndex should ignore items with 0 weight
1 parent e254141 commit e6d88a8

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

LabExtended/LabExtended.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
</PropertyGroup>
2626

2727
<ItemGroup>
28-
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.2" PrivateAssets="all" />
29-
<PackageReference Include="Lib.Harmony" Version="2.3.3" />
30-
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
31-
<PackageReference Include="System.Drawing.Common" Version="10.0.0-preview.2.25163.9" />
28+
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.3" PrivateAssets="all" />
29+
<PackageReference Include="Lib.Harmony" Version="2.4.2" />
30+
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
31+
<PackageReference Include="System.Drawing.Common" Version="10.0.1" />
3232
<PackageReference Include="System.Drawing.Primitives" Version="4.3.0" />
3333
</ItemGroup>
3434

LabExtended/Utilities/WeightUtils.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,18 @@ public static int GetRandomIndex(float total, int size, Func<int, float> picker)
265265
{
266266
var weight = picker(i);
267267

268+
if (weight <= 0f)
269+
continue;
270+
271+
if (weight >= 100f)
272+
return i;
273+
268274
for (float x = sum; x < weight + sum; x++)
269275
{
270276
if (x >= rnd)
277+
{
271278
return i;
279+
}
272280
}
273281

274282
sum += weight;

0 commit comments

Comments
 (0)