Пример #1
0
 /// <summary>
 /// Logs the data being passed through the aggregate
 /// </summary>
 /// <param name="prefix">The prefix to the log, defualts to empty</param>
 public static IAggregator <T> Debug <T>(this IAggregator <T> aggregator, string prefix = "")
 {
     return(new Aggregator <T>
     {
         getData = () =>
         {
             var data = aggregator.GetData();
             UnityEngine.Debug.Log(prefix + ": " + data);
             return data;
         }
     });
 }
Пример #2
0
        /// <summary>
        /// Returns the majority team's id. 0 represents unclaimed and -1 represents contested
        /// </summary>
        /// <returns>The team identifier.</returns>
        public static IAggregator <int> MajorityTeamId <T>(this IAggregator <IEnumerable <T> > aggregator) where T : ITeamOwned
        {
            return(new Aggregator <int>
            {
                getData = () =>
                {
                    var teamOwnedList = aggregator.GetData();

                    if (!teamOwnedList.Any())                       // If there is nothing in the of team owned objects, then it is unclaimed
                    {
                        return CapturePoint.UnclaimedId;
                    }

                    var teams = teamOwnedList                       // Gets the list of teams
                                .Select(teamOwned => teamOwned.GetTeamId())
                                .Distinct();

                    int winningTeamId = CapturePoint.UnclaimedId;
                    int winningCount = -1;

                    foreach (var team in teams)
                    {
                        if (team < 1)                               // Filter out contested and unclaimed team
                        {
                            continue;
                        }

                        int teamCount = teamOwnedList
                                        .Count(teamOwned => teamOwned.GetTeamId() == team);

                        if (teamCount > winningCount)
                        {
                            winningTeamId = team;
                            winningCount = teamCount;
                        }
                        else if (teamCount == winningCount)         // If there are more than one objects with a winning count, then it is contested
                        {
                            winningTeamId = CapturePoint.ContestedId;
                            winningCount = teamCount;
                        }
                    }

                    return winningTeamId;
                }
            });
        }