I have an enum indicating the eligibility of a spawn.
protected enum SpawnEligibility
{
Worst,
Ok,
Optimal
}
Then, I have a function to return the eligibility.
protected virtual SpawnEligibility GetEligibility(Vector3 spawn)
{
var players = _instance.FindPlayersInRadius(spawn, 10).ToList();
if (!players.Any())
return SpawnEligibility.Optimal;
return players.Any(x => _instance.CanSeeLocation(x, spawn))
? SpawnEligibility.Worst
: SpawnEligibility.Ok;
}
When selecting a spawn I'd like to pick a random spawn from those that have the highest level of eligibility, though they may all be Worst
, Ok
, Optimal
, or a mix. This is my code which I was using to select a spawn.
public virtual Vector3 FindSpawn(BasePlayer player) =>
_spawns.OrderByDescending(GetEligibility).First();
How can I either make a dictionary with a Spawn key and SpawnEligibility value OR return a random element from my list without calling the GetEligibility function again?