示例#1
0
        private bool FillTeam(Team team, TeamCompositionRules compositionRules, int maxPlayers, int maxBots, ref List <LobbyServerConnection> availablePlayers, ref LobbyTeamInfo teamInfo)
        {
            Log.Print(LogType.Debug, $"Filling Team {team.ToString()}");
            int usedPlayers = 0;
            int usedBots    = 0;

            List <LobbyPlayerInfo> playerInfo = new List <LobbyPlayerInfo>();

            for (int slot = 1; slot <= 5; slot++)
            {
                //Log.Print(LogType.Debug, "fillteam:: slot "+slot);
                FreelancerSet botSet = new FreelancerSet()
                {
                    Roles = new List <CharacterRole>(), Types = new List <CharacterType>()
                };
                bool filled = false;

                if (usedPlayers != maxPlayers)
                {
                    foreach (LobbyServerConnection player in availablePlayers)
                    {
                        bool matchedAny = false;
                        bool matched    = true;

                        //Log.Print(LogType.Debug, "matching rules with " + player.UserName);

                        foreach (TeamCompositionRules.SlotTypes slotType in compositionRules.Rules.Keys)
                        {
                            if (compositionRules.MatchesSlotType(slotType, team, slot))
                            {
                                matchedAny = true;
                                //Log.Print(LogType.Debug, "Matched slotType " + slotType.ToString());

                                /*if (!CharacterUtils.MatchesCharacter(player.PlayerInfo.GetCharacterType(), compositionRules.Rules[slotType]))
                                 * {
                                 *  //Log.Print(LogType.Debug, "not matched rule");
                                 *  matched = false;
                                 *
                                 *  if (usedBots == maxBots)
                                 *  {
                                 *      break;
                                 *  }
                                 *  else
                                 *  {
                                 *      FreelancerSet tempSet = compositionRules.Rules[slotType];
                                 *      if (tempSet.Roles != null)
                                 *          botSet.Roles.AddRange(tempSet.Roles);
                                 *      if (tempSet.Types != null)
                                 *          botSet.Types.AddRange(tempSet.Types);
                                 *  }
                                 * }*/
                            }
                        }

                        if (matchedAny && matched)
                        {
                            //Log.Print(LogType.Debug, "Adding player");
                            LobbyPlayerInfo info = player.GetLobbyPlayerInfo().Clone();
                            info.TeamId = team;
                            playerInfo.Add(info);

                            filled = true;
                            usedPlayers++;
                            availablePlayers.Remove(player);
                            break;
                        }
                    }
                }

                if (!filled)
                {
                    // try fill with bots
                    if (usedBots != maxBots) // Bots remaining to fill
                    {
                        // create bot
                        //Log.Print(LogType.Debug, "creating bot");
                        LobbyPlayerInfo botInfo = CharacterUtils.CreateBotCharacterFromFreelancerSet(botSet);
                        botInfo.TeamId = team;
                        playerInfo.Add(botInfo);
                        usedBots++;
                    }
                }
            }

            //Log.Print(LogType.Debug, "For finished");

            if (usedPlayers != maxPlayers)
            {
                //Log.Print(LogType.Debug, "Bot overflow");
                QueueInfo.QueueStatus = QueueStatus.QueueDoesntHaveEnoughHumans;
                return(false);
            }

            //Log.Print(LogType.Debug, "Filling team info");
            foreach (LobbyPlayerInfo playerinfo in playerInfo)
            {
                teamInfo.TeamPlayerInfo.Add(playerinfo);
            }
            //Log.Print(LogType.Debug, "TeamFilled!");

            return(true);
        }