Add ghost role raffles (#26629)
* Add ghost role raffles * GRR: Fix dialogue sizing, fix merge * GRR: Add raffle deciders (winner picker) * GRR: Make settings prototype based with option to override * GRR: Use Raffles folder and namespace * GRR: DataFieldify and TimeSpanify * GRR: Don't actually DataFieldify HashSet<ICommonSession>s * GRR: add GetGhostRoleCount() + docs * update engine on branch * Ghost role raffles: docs, fix window size, cleanup, etc * GRR: Admin UI * GRR: Admin UI: Display initial/max/ext of selected raffle settings proto * GRR: Make a ton of roles raffled
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user