private void CmdRequestJob(JobType jobType, string jsonCharSettings) { var characterSettings = JsonConvert.DeserializeObject <CharacterSettings>(jsonCharSettings); if (GameManager.Instance.CurrentRoundState != RoundState.Started) { Logger.LogWarningFormat("Round hasn't started yet, can't request job {0} for {1}", Category.Jobs, jobType, characterSettings); return; } int slotsTaken = GameManager.Instance.GetOccupationsCount(jobType); int slotsMax = GameManager.Instance.GetOccupationMaxCount(jobType); if (slotsTaken >= slotsMax) { return; } var spawnRequest = PlayerSpawnRequest.RequestOccupation(this, GameManager.Instance.GetRandomFreeOccupation(jobType), characterSettings); //regardless of their chosen occupation, they might spawn as an antag instead. //If they do, bypass the normal spawn logic. if (GameManager.Instance.TrySpawnAntag(spawnRequest)) { return; } PlayerSpawn.ServerSpawnPlayer(spawnRequest); }
private void CmdRequestJob(JobType jobType, string jsonCharSettings) { var characterSettings = JsonConvert.DeserializeObject <CharacterSettings>(jsonCharSettings); if (GameManager.Instance.CurrentRoundState != RoundState.Started) { Logger.LogWarningFormat("Round hasn't started yet, can't request job {0} for {1}", Category.Jobs, jobType, characterSettings); return; } int slotsTaken = GameManager.Instance.GetOccupationsCount(jobType); int slotsMax = GameManager.Instance.GetOccupationMaxCount(jobType); if (slotsTaken >= slotsMax) { return; } var spawnRequest = PlayerSpawnRequest.RequestOccupation(this, GameManager.Instance.GetRandomFreeOccupation(jobType), characterSettings); GameManager.Instance.SpawnPlayerRequestQueue.Enqueue(spawnRequest); GameManager.Instance.ProcessSpawnPlayerQueue(); }
public bool Initiate(TestRunSO TestRunSO) { CharacterSettings characterSettings; if (string.IsNullOrEmpty(SerialisedCharacterSettings)) { characterSettings = new CharacterSettings(); } else { characterSettings = JsonConvert.DeserializeObject <CharacterSettings>(SerialisedCharacterSettings); } var Connectedplayer = PlayerList.Instance.Get(PlayerManager.LocalPlayer); var Request = PlayerSpawnRequest.RequestOccupation(PlayerManager.LocalViewerScript, Occupation, characterSettings, Connectedplayer.UserId); PlayerSpawn.ServerSpawnPlayer(Request, PlayerManager.LocalViewerScript, Occupation, characterSettings, spawnPos: PositionToSpawn.RoundToInt(), existingMind: PlayerManager.LocalPlayerScript.mind, conn: Connectedplayer.Connection); return(true); }
private void AcceptRequest(NetMessage msg) { var characterSettings = JsonConvert.DeserializeObject <CharacterSettings>(msg.JsonCharSettings); var spawnRequest = PlayerSpawnRequest.RequestOccupation( SentByPlayer.ViewerScript, GameManager.Instance.GetRandomFreeOccupation(msg.JobType), characterSettings, SentByPlayer.UserId); GameManager.Instance.TrySpawnPlayer(spawnRequest); }
private void AcceptRequest() { var characterSettings = JsonConvert.DeserializeObject <CharacterSettings>(JsonCharSettings); var spawnRequest = PlayerSpawnRequest.RequestOccupation( SentByPlayer.ViewerScript, GameManager.Instance.GetRandomFreeOccupation(JobType), characterSettings, SentByPlayer.UserId); GameManager.Instance.SpawnPlayerRequestQueue.Enqueue(spawnRequest); GameManager.Instance.ProcessSpawnPlayerQueue(); }
/// <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); }
/// <summary> /// Allocates a job to players. Updates _determinedPlayers and _playersLeft. /// </summary> /// <param name="players">Players to allocate jobs to</param> /// <param name="job">The job to allocate</param> private void AllocateJobs(IReadOnlyCollection <ConnectedPlayer> players, Occupation job) { // Update determined players and players left determinedPlayers.AddRange(players.Select(player => PlayerSpawnRequest.RequestOccupation(player.ViewerScript, job, player.CharacterSettings, player.UserId))); playersLeft.RemoveAll(players.Contains); missedOutPlayers.RemoveAll(players.Contains); // Update occupation counts occupationCount.TryGetValue(job, out int currentCount); occupationCount[job] = currentCount + 1; }
public override void Process() { // Server stuff here if (SentByPlayer == null || SentByPlayer.ViewerScript == null) { return; } if (SentByPlayer.UserId == null) { SentByPlayer.ViewerScript.NotifyJobRequestFailed(JobRequestError.InvalidUserID); Logger.Log("User ID was null, cant spawn job.", Category.Admin); return; } if (SentByPlayer.UserId != PlayerID) { SentByPlayer.ViewerScript.NotifyJobRequestFailed(JobRequestError.InvalidPlayerID); Logger.Log($"User: {SentByPlayer.Username} ID: {SentByPlayer.UserId} used a different ID: {PlayerID} to request a job.", Category.Admin); return; } var characterSettings = JsonConvert.DeserializeObject <CharacterSettings>(JsonCharSettings); if (GameManager.Instance.CurrentRoundState != RoundState.Started) { SentByPlayer.ViewerScript.NotifyJobRequestFailed(JobRequestError.RoundNotReady); Logger.LogWarningFormat("Round hasn't started yet, can't request job {0} for {1}", Category.Jobs, JobType, characterSettings); return; } if (PlayerList.Instance.FindPlayerJobBanEntryServer(PlayerID, JobType, true) != null) { SentByPlayer.ViewerScript.NotifyJobRequestFailed(JobRequestError.JobBanned); return; } int slotsTaken = GameManager.Instance.GetOccupationsCount(JobType); int slotsMax = GameManager.Instance.GetOccupationMaxCount(JobType); if (slotsTaken >= slotsMax) { SentByPlayer.ViewerScript.NotifyJobRequestFailed(JobRequestError.PositionsFilled); return; } var spawnRequest = PlayerSpawnRequest.RequestOccupation( SentByPlayer.ViewerScript, GameManager.Instance.GetRandomFreeOccupation(JobType), characterSettings, SentByPlayer.UserId); GameManager.Instance.SpawnPlayerRequestQueue.Enqueue(spawnRequest); GameManager.Instance.ProcessSpawnPlayerQueue(); }
public void CmdRequestJob(JobType jobType, CharacterSettings characterSettings) { var spawnRequest = PlayerSpawnRequest.RequestOccupation(this, GameManager.Instance.GetRandomFreeOccupation(jobType), characterSettings); //regardless of their chosen occupation, they might spawn as an antag instead. //If they do, bypass the normal spawn logic. if (GameManager.Instance.TrySpawnAntag(spawnRequest)) { return; } PlayerSpawn.ServerSpawnPlayer(spawnRequest.JoinedViewer, spawnRequest.RequestedOccupation, characterSettings); }
/// <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); } }