6
StarHorizon_Public/Content.Server/Ghost/Roles/Raffles/RngGhostRoleRaffleDecider.cs
2026-01-24 12:49:55 +03:00

28 lines
842 B
C#

using System.Linq;
using JetBrains.Annotations;
using Robust.Shared.Player;
using Robust.Shared.Random;
namespace Content.Server.Ghost.Roles.Raffles;
/// <summary>
/// Chooses the winner of a ghost role raffle entirely randomly, without any weighting.
/// </summary>
[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
public sealed partial class RngGhostRoleRaffleDecider : IGhostRoleRaffleDecider
{
public void PickWinner(IEnumerable<ICommonSession> candidates, Func<ICommonSession, bool> tryTakeover)
{
var random = IoCManager.Resolve<IRobustRandom>();
var choices = candidates.ToList();
random.Shuffle(choices); // shuffle the list so we can pick a lucky winner!
foreach (var candidate in choices)
{
if (tryTakeover(candidate))
return;
}
}
}