private void ProcessWelcomeReceivedPacket(int playerId, Packet packet)
        {
            int    packetPlayerId = packet.ReadInt();
            string userName       = packet.ReadString();
            string userApiVersion = packet.ReadString();

            if (userApiVersion != GameConfiguration.ApiVersion)
            {
                playersManager.clients.Remove(playerId);
                Logger.LogError(LoggerSection.Connection, $"Unable to add a client with old version ({userApiVersion}) to the game");
                return;
            }

            if (playerId != packetPlayerId)
            {
                throw new Exception($"Bad playerId {playerId} received");
            }

            if (userName.Equals(""))
            {
                Logger.LogError(LoggerSection.Connection, $"Bad user name passed from player {playerId}");
                return;
            }

            Logger.LogEvent(LoggerSection.Connection, $"{playersManager.clients[playerId].GetTcpEndPoint()} connected successfully and is now a player {playerId}");

            lobbyGamePhase.ConnectPlayer(playerId, userName);
        }
Exemple #2
0
        public void TryToScheduleGameStart(int calledPlayerId)
        {
            if (!PlayersManager.IsLobbyHost(calledPlayerId))
            {
                Logger.LogNotice(SharedLoggerSection.GameStart, $"Player {calledPlayerId} tries to schedule game start, but he's not the host");
                return;
            }

            if (playersManager.clients.Count < GameConfiguration.MinRequiredPlayersAmountForGame)
            {
                Logger.LogError(SharedLoggerSection.GameStart, "Attempt to start a game with too few players in it");
                return;
            }

            if (GameStarts)
            {
                Logger.LogError(SharedLoggerSection.GameStart, "Attempt to start a game which is already starting");
                return;
            }

            GameStarts = true;
            metaMonoBehaviours.coroutines.StartCoroutine(StartGame());

            Logger.LogEvent(SharedLoggerSection.GameStart, "Game starts");
        }
Exemple #3
0
        private void InitializeScene(UnityEngine.SceneManagement.Scene scene, LoadSceneMode loadSceneMode)
        {
            switch (scene.name)
            {
            case Scene.MainMenu:
                mainMenuGamePhase.Initialize();
                break;

            case Scene.Lobby:
                lobbyGamePhase.Initialize();
                break;

            case Scene.RoleReveal:
                roleRevealGamePhase.Initialize();
                break;

            case Scene.Skeld:
                playGamePhase.Initialize();
                break;

            default:
                Logger.LogError(SharedLoggerSection.ScenesManager, $"No game phase initializer found for the scene {scene.name}");
                break;
            }
        }
        public void Remove(int playerId)
        {
            lockedPlayerIds.Remove(playerId);

            BasePlayer basePlayer = basePlayersManager.players[playerId];

            if (!basePlayer.movable.isDisabled)
            {
                Logger.LogError(SharedLoggerSection.Interactions, $"Unable to unlock the not disabled player {playerId}");
                return;
            }

            basePlayer.movable.isDisabled = false;
        }
        public void Add(int playerId)
        {
            lockedPlayerIds.Add(playerId);

            BasePlayer basePlayer = basePlayersManager.players[playerId];

            if (basePlayer.movable.isDisabled)
            {
                Logger.LogError(SharedLoggerSection.Interactions, $"Unable to lock the disabled player {playerId}");
                return;
            }

            basePlayer.movable.isDisabled = true;
        }
        private Sprite GetSprite(PlayerColor playerColor)
        {
            switch (playerColor)
            {
            case PlayerColor.Red:
                return(minimapIconSprites.redSprite);

            case PlayerColor.Blue:
                return(minimapIconSprites.blueSprite);

            case PlayerColor.Green:
                return(minimapIconSprites.greenSprite);

            case PlayerColor.Yellow:
                return(minimapIconSprites.yellowSprite);

            case PlayerColor.Pink:
                return(minimapIconSprites.pinkSprite);

            case PlayerColor.Orange:
                return(minimapIconSprites.orangeSprite);

            case PlayerColor.Purple:
                return(minimapIconSprites.purpleSprite);

            case PlayerColor.Black:
                return(minimapIconSprites.blackSprite);

            case PlayerColor.Brown:
                return(minimapIconSprites.brownSprite);

            case PlayerColor.Cyan:
                return(minimapIconSprites.cyanSprite);

            case PlayerColor.Lime:
                return(minimapIconSprites.limeSprite);

            case PlayerColor.White:
                return(minimapIconSprites.whiteSprite);

            default:
                Logger.LogError(SharedLoggerSection.PlayerColors, $"Undefined sprite for color {Shared.Helpers.GetEnumName(playerColor)}");
                return(minimapIconSprites.redSprite);
            }
        }
        private void UpdateAnimatorController()
        {
            RuntimeAnimatorController animatorController;

            switch (clientPlayer.basePlayer.colorable.color)
            {
            case PlayerColor.Red:
                animatorController = astronautAnimatorControllersRepository.redAnimatorController;
                break;

            case PlayerColor.Blue:
                animatorController = astronautAnimatorControllersRepository.blueAnimatorController;
                break;

            case PlayerColor.Green:
                animatorController = astronautAnimatorControllersRepository.greenAnimatorController;
                break;

            case PlayerColor.Yellow:
                animatorController = astronautAnimatorControllersRepository.yellowAnimatorController;
                break;

            case PlayerColor.Pink:
                animatorController = astronautAnimatorControllersRepository.pinkAnimatorController;
                break;

            case PlayerColor.Orange:
                animatorController = astronautAnimatorControllersRepository.orangeAnimatorController;
                break;

            case PlayerColor.Purple:
                animatorController = astronautAnimatorControllersRepository.purpleAnimatorController;
                break;

            case PlayerColor.Black:
                animatorController = astronautAnimatorControllersRepository.blackAnimatorController;
                break;

            case PlayerColor.Brown:
                animatorController = astronautAnimatorControllersRepository.brownAnimatorController;
                break;

            case PlayerColor.Cyan:
                animatorController = astronautAnimatorControllersRepository.cyanAnimatorController;
                break;

            case PlayerColor.Lime:
                animatorController = astronautAnimatorControllersRepository.limeAnimatorController;
                break;

            case PlayerColor.White:
                animatorController = astronautAnimatorControllersRepository.whiteAnimatorController;
                break;

            default:
                Logger.LogError(SharedLoggerSection.PlayerColors, "Undefined player color");
                return;
            }

            animator.runtimeAnimatorController = animatorController;
        }