예제 #1
0
        /// <summary>
        /// Start the round
        /// </summary>
        public virtual void StartRound()
        {
            Logger.LogFormat("Starting {0} round!", Category.GameMode, Name);

            List <PlayerSpawnRequest> playerSpawnRequests;
            List <PlayerSpawnRequest> antagSpawnRequests;
            int antagsToSpawn = CalculateAntagCount(PlayerList.Instance.ReadyPlayers.Count);
            var jobAllocator  = new JobAllocator();
            var playerPool    = PlayerList.Instance.ReadyPlayers;

            if (AllocateJobsToAntags)
            {
                // Allocate jobs to all players first then choose antags
                playerSpawnRequests = jobAllocator.DetermineJobs(playerPool);
                var antagCandidates = playerSpawnRequests.Where(p =>
                                                                !NonAntagJobTypes.Contains(p.RequestedOccupation.JobType) &&
                                                                HasPossibleAntagEnabled(ref p.CharacterSettings.AntagPreferences) && HasPossibleAntagNotBanned(p.UserID));
                antagSpawnRequests = antagCandidates.PickRandom(antagsToSpawn).ToList();
                // Player and antag spawn requests are kept separate to stop players being spawned twice
                playerSpawnRequests.RemoveAll(antagSpawnRequests.Contains);
            }
            else
            {
                // Choose antags first then allocate jobs to all other players
                var antagCandidates = playerPool.Where(p =>
                                                       HasPossibleAntagEnabled(ref p.CharacterSettings.AntagPreferences) && HasPossibleAntagNotBanned(p.UserId));
                var chosenAntags = antagCandidates.PickRandom(antagsToSpawn).ToList();
                // Player and antag spawn requests are kept separate to stop players being spawned twice
                playerPool.RemoveAll(chosenAntags.Contains);
                playerSpawnRequests = jobAllocator.DetermineJobs(playerPool);
                antagSpawnRequests  = chosenAntags.Select(player =>
                                                          PlayerSpawnRequest.RequestOccupation(player, null)).ToList();
            }

            // Spawn all players and antags
            foreach (var spawnReq in playerSpawnRequests)
            {
                PlayerSpawn.ServerSpawnPlayer(spawnReq);
            }
            foreach (var spawnReq in antagSpawnRequests)
            {
                SpawnAntag(spawnReq);
            }

            var msg =
                $"{PlayerList.Instance.ReadyPlayers.Count} players ready, {antagsToSpawn} antags to spawn. {playerSpawnRequests.Count} players spawned (excludes antags), {antagSpawnRequests.Count} antags spawned";

            DiscordWebhookMessage.Instance.AddWebHookMessageToQueue(DiscordWebhookURLs.DiscordWebhookAdminLogURL,
                                                                    msg,
                                                                    "[GameMode]");

            StationObjectiveManager.Instance.ServerChooseObjective();
            GameManager.Instance.CurrentRoundState = RoundState.Started;
            EventManager.Broadcast(Event.RoundStarted, true);
        }
예제 #2
0
    /// <summary>
    /// Start the round
    /// </summary>
    public virtual void StartRound()
    {
        Logger.LogFormat("Starting {0} round!", Category.GameMode, Name);

        List <PlayerSpawnRequest> playerSpawnRequests;
        List <PlayerSpawnRequest> antagSpawnRequests;
        int antagsToSpawn = CalculateAntagCount(PlayerList.Instance.ReadyPlayers.Count);
        var jobAllocator  = new JobAllocator();
        var playerPool    = PlayerList.Instance.ReadyPlayers;

        if (AllocateJobsToAntags)
        {
            // Allocate jobs to all players first then choose antags
            playerSpawnRequests = jobAllocator.DetermineJobs(playerPool);
            var antagCandidates = playerSpawnRequests.Where(p =>
                                                            !NonAntagJobTypes.Contains(p.RequestedOccupation.JobType) &&
                                                            HasPossibleAntagEnabled(ref p.CharacterSettings.AntagPreferences));
            antagSpawnRequests = antagCandidates.PickRandom(antagsToSpawn).ToList();
            // Player and antag spawn requests are kept separate to stop players being spawned twice
            playerSpawnRequests.RemoveAll(antagSpawnRequests.Contains);
        }
        else
        {
            // Choose antags first then allocate jobs to all other players
            var antagCandidates = playerPool.Where(p =>
                                                   HasPossibleAntagEnabled(ref p.CharacterSettings.AntagPreferences));
            var chosenAntags = antagCandidates.PickRandom(antagsToSpawn).ToList();
            // Player and antag spawn requests are kept separate to stop players being spawned twice
            playerPool.RemoveAll(chosenAntags.Contains);
            playerSpawnRequests = jobAllocator.DetermineJobs(playerPool);
            antagSpawnRequests  = chosenAntags.Select(player =>
                                                      PlayerSpawnRequest.RequestOccupation(player, null)).ToList();
        }

        // Spawn all players and antags
        foreach (var spawnReq in playerSpawnRequests)
        {
            PlayerSpawn.ServerSpawnPlayer(spawnReq);
        }
        foreach (var spawnReq in antagSpawnRequests)
        {
            SpawnAntag(spawnReq);
        }
    }