fix RangeNumberSelector to actually be inclusive (#36155)

* fix RangeNumberSelector to actually be inclusive

* Convert all random number stuff to randomint and prune unused code

* another heisentest???

* another heisentest after a heisentest. im going to lose it.
This commit is contained in:
ArtisticRoomba
2025-04-14 14:02:49 -07:00
committed by GitHub
parent 0de0ef6065
commit 6c2c5935ed
5 changed files with 11 additions and 18 deletions

View File

@@ -20,7 +20,7 @@ public sealed partial class EntSelector : EntityTableSelector
IEntityManager entMan,
IPrototypeManager proto)
{
var num = (int) Math.Round(Amount.Get(rand, entMan, proto));
var num = Amount.Get(rand);
for (var i = 0; i < num; i++)
{
yield return Id;

View File

@@ -30,7 +30,7 @@ public abstract partial class EntityTableSelector
IEntityManager entMan,
IPrototypeManager proto)
{
var rolls = Rolls.Get(rand, entMan, proto);
var rolls = Rolls.Get(rand);
for (var i = 0; i < rolls; i++)
{
if (!rand.Prob(Prob))

View File

@@ -1,5 +1,3 @@
using Robust.Shared.Prototypes;
namespace Content.Shared.EntityTable.ValueSelector;
/// <summary>
@@ -8,14 +6,14 @@ namespace Content.Shared.EntityTable.ValueSelector;
public sealed partial class ConstantNumberSelector : NumberSelector
{
[DataField]
public float Value = 1;
public int Value = 1;
public ConstantNumberSelector(float value)
public ConstantNumberSelector(int value)
{
Value = value;
}
public override float Get(System.Random rand, IEntityManager entMan, IPrototypeManager proto)
public override int Get(System.Random rand)
{
return Value;
}

View File

@@ -1,6 +1,5 @@
using Content.Shared.EntityTable.EntitySelectors;
using JetBrains.Annotations;
using Robust.Shared.Prototypes;
namespace Content.Shared.EntityTable.ValueSelector;
@@ -10,7 +9,5 @@ namespace Content.Shared.EntityTable.ValueSelector;
[ImplicitDataDefinitionForInheritors, UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)]
public abstract partial class NumberSelector
{
public abstract float Get(System.Random rand,
IEntityManager entMan,
IPrototypeManager proto);
public abstract int Get(System.Random rand);
}

View File

@@ -1,7 +1,3 @@
using System.Numerics;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
namespace Content.Shared.EntityTable.ValueSelector;
/// <summary>
@@ -10,10 +6,12 @@ namespace Content.Shared.EntityTable.ValueSelector;
public sealed partial class RangeNumberSelector : NumberSelector
{
[DataField]
public Vector2 Range = new(1, 1);
public Vector2i Range = new(1, 1);
public override float Get(System.Random rand, IEntityManager entMan, IPrototypeManager proto)
public override int Get(System.Random rand)
{
return rand.NextFloat(Range.X, Range.Y + 1);
// rand.Next() is inclusive on the first number and exclusive on the second number,
// so we add 1 to the second number.
return rand.Next(Range.X, Range.Y + 1);
}
}