public void Update() { RemoveLoggedOutPlayers(); if (m_LeaveTimers.Count > 0) { List <LeaveTimer> toRemove = new List <LeaveTimer>(); foreach (LeaveTimer t in m_LeaveTimers) { if (t.IsExpired()) { m_CommandListener.AddCommand("sub", AddToSubList); Chat.SendMessage(">> Leaver Detected: " + t.Leaver.Name); Chat.SendMessage(">> Type /sub to join."); m_SubSearches.Add(new SubSearch(t.Leaver)); toRemove.Add(t); } else if (m_Context.GetPlayer(t.Leaver.Name) != null) { //player rejoined m_Context.AddPlayerToTeam(t.Leaver.Name, t.Leaver.TeamLeft); toRemove.Add(t); } } m_LeaveTimers.RemoveAll(x => toRemove.Contains(x)); } if (m_SubSearches.Count > 0) { List <SubSearch> done = new List <SubSearch>(); bool sentNoSubMessage = false; foreach (SubSearch s in m_SubSearches) { if (s.IsExpired()) { if (m_PotentialSubs.Count > 0) { RankedPlayer p = s.ClosestElo(m_PotentialSubs); m_Context.RemovePlayerFromTeam(p.Name); m_Context.AddPlayerToTeam(p.Name, s.Team); Chat.SendMessage(">> " + p.Name + " added to " + s.Team.ToString() + " team."); done.Add(s); } else { if (!sentNoSubMessage) { Chat.SendMessage(">> No Sub Found."); Chat.SendMessage(">> Type /sub to join."); sentNoSubMessage = true; } s.ResetSearchTime(); } } } m_SubSearches.RemoveAll(x => done.Contains(x)); if (m_SubSearches.Count == 0) { m_PotentialSubs = new List <RankedPlayer>(); m_CommandListener.RemoveCommand("sub"); } } }
//TODO: clean this up private void CreateTeams() { List <string> redTeam = new List <string>(); List <string> blueTeam = new List <string>(); //give prio to people who didn't play last game List <RankedPlayer> players = new List <RankedPlayer>(); List <RankedPlayer> others = new List <RankedPlayer>(); foreach (RankedPlayer p in m_Context.LoggedInPlayers) { if (m_LastGamePlayers.Contains(p.Name)) { others.Add(p); } else if (players.Count < 10) { players.Add(p); } } Random r = new Random(); while (players.Count < Math.Min(10, m_Context.LoggedInPlayers.Count)) { RankedPlayer newPlayer = others[r.Next(others.Count)]; others.Remove(newPlayer); players.Add(newPlayer); } List <RankedPlayer> SortedRankedPlayers = players.OrderByDescending(x => x.Rating).ToList(); /*split up goalies * List<RankedPlayer> goalies = SortedRankedPlayers.Where(x => x.PlayerStruct.Role == HQMRole.G).ToList(); * if(goalies.Count >= 2) * { * RedTeam.Add(goalies[0].Name); * goalies[0].AssignedTeam = HQMTeam.Red; * BlueTeam.Add(goalies[1].Name); * goalies[1].AssignedTeam = HQMTeam.Blue; * SortedRankedPlayers.Remove(goalies[0]); * SortedRankedPlayers.Remove(goalies[1]); * }*/ double half_max = Math.Ceiling((double)SortedRankedPlayers.Count() / 2); for (int i = 0; i < SortedRankedPlayers.Count; i++) { RankedPlayer p = SortedRankedPlayers[i]; if (TotalRating(redTeam) < TotalRating(blueTeam) && redTeam.Count < half_max) { redTeam.Add(p.Name); } else if (blueTeam.Count < half_max) { blueTeam.Add(p.Name); } else { redTeam.Add(p.Name); } } m_Context.ClearTeams(); redTeam.ForEach(x => m_Context.AddPlayerToTeam(x, HQMTeam.Red)); blueTeam.ForEach(x => m_Context.AddPlayerToTeam(x, HQMTeam.Blue)); //auto join while (players.Where(p => p.PlayerStruct.Team == HQMTeam.NoTeam).Count() > 0) { foreach (RankedPlayer p in players.Where(p => p.PlayerStruct.Team == HQMTeam.NoTeam)) { p.PlayerStruct.LockoutTime = 0; if (redTeam.Contains(p.Name)) { p.PlayerStruct.LegState = 4; } else if (blueTeam.Contains(p.Name)) { p.PlayerStruct.LegState = 8; } } } }