Fix antag objectives always overshooting MaxDifficulty (and kill tries20) (#29830)
* The death of try20 * Add integration test for traitor gamerule * Fix max difficulty being overshot * Check at least one objective is assigned * EntProtoId
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using Content.Shared.Dataset;
|
||||
using Content.Shared.FixedPoint;
|
||||
@@ -87,6 +88,26 @@ namespace Content.Shared.Random.Helpers
|
||||
throw new InvalidOperationException("Invalid weighted pick");
|
||||
}
|
||||
|
||||
public static T PickAndTake<T>(this IRobustRandom random, Dictionary<T, float> weights)
|
||||
where T : notnull
|
||||
{
|
||||
var pick = Pick(random, weights);
|
||||
weights.Remove(pick);
|
||||
return pick;
|
||||
}
|
||||
|
||||
public static bool TryPickAndTake<T>(this IRobustRandom random, Dictionary<T, float> weights, [NotNullWhen(true)] out T? pick)
|
||||
where T : notnull
|
||||
{
|
||||
if (weights.Count == 0)
|
||||
{
|
||||
pick = default;
|
||||
return false;
|
||||
}
|
||||
pick = PickAndTake(random, weights);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static (string reagent, FixedPoint2 quantity) Pick(this WeightedRandomFillSolutionPrototype prototype, IRobustRandom? random = null)
|
||||
{
|
||||
var randomFill = prototype.PickRandomFill(random);
|
||||
|
||||
Reference in New Issue
Block a user