RngGhostRoleRaffleDecider.cs 842 B

123456789101112131415161718192021222324252627
  1. using System.Linq;
  2. using JetBrains.Annotations;
  3. using Robust.Shared.Player;
  4. using Robust.Shared.Random;
  5. namespace Content.Server.Ghost.Roles.Raffles;
  6. /// <summary>
  7. /// Chooses the winner of a ghost role raffle entirely randomly, without any weighting.
  8. /// </summary>
  9. [UsedImplicitly(ImplicitUseTargetFlags.WithMembers)]
  10. public sealed partial class RngGhostRoleRaffleDecider : IGhostRoleRaffleDecider
  11. {
  12. public void PickWinner(IEnumerable<ICommonSession> candidates, Func<ICommonSession, bool> tryTakeover)
  13. {
  14. var random = IoCManager.Resolve<IRobustRandom>();
  15. var choices = candidates.ToList();
  16. random.Shuffle(choices); // shuffle the list so we can pick a lucky winner!
  17. foreach (var candidate in choices)
  18. {
  19. if (tryTakeover(candidate))
  20. return;
  21. }
  22. }
  23. }