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:
Tayrtahn
2024-07-13 00:14:30 -04:00
committed by GitHub
parent de2ab29f34
commit 3388c0dcaa
5 changed files with 184 additions and 18 deletions

View File

@@ -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);