Entity Tables (EntitySpawnEntry replacement) (#30579)

* Entity table code

* entity table examples

* fix dat shit

* access

* tests tests tests

* sloth review
This commit is contained in:
Nemanja
2024-08-09 22:12:40 -04:00
committed by GitHub
parent b692ab1850
commit 437c861622
19 changed files with 1198 additions and 566 deletions

View File

@@ -108,6 +108,27 @@ namespace Content.Shared.Random.Helpers
return true;
}
public static T Pick<T>(Dictionary<T, float> weights, System.Random random)
where T : notnull
{
var sum = weights.Values.Sum();
var accumulated = 0f;
var rand = random.NextFloat() * sum;
foreach (var (key, weight) in weights)
{
accumulated += weight;
if (accumulated >= rand)
{
return key;
}
}
throw new InvalidOperationException("Invalid weighted pick");
}
public static (string reagent, FixedPoint2 quantity) Pick(this WeightedRandomFillSolutionPrototype prototype, IRobustRandom? random = null)
{
var randomFill = prototype.PickRandomFill(random);