예제 #1
0
 private void OnRegisteredPlayerDisconnectedEvent(RegisteredPlayer player)
 {
     if (_turnSystem.CurrentTurnTicket == player.PlayerIndex)
     {
         _turnSystem.EndTurnForCurrentTicket();
     }
 }
예제 #2
0
    private void OnFactionRequestEvent(int deviceId, FactionType factionType, bool selectType)
    {
        PlayerFactionLinkItem ft         = _conPlayerFactions.GetLinkItemForFaction(factionType);
        RegisteredPlayer      playerOfId = _conPlayers.GetRegisteredPlayerById(deviceId);

        if (selectType)
        {
            if (ft.Player != null)
            {
                return;
            }
            _conPlayerFactions.UnassignPlayerFromItsFaction(playerOfId);
            _conPlayerFactions.AssignPlayerToFaction(playerOfId, factionType);
        }
        else
        {
            if (ft.Player != playerOfId)
            {
                return;
            }
            _conPlayerFactions.UnassignPlayerFromItsFaction(playerOfId);
        }

        if (_conPlayerFactions.GetTakenFactions().Length == _conPlayers.GetCurrentlyRegisteredPlayers(false).Length)
        {
            GoToGameScene();
            return;
        }
        SendUpdateFactions();
    }
예제 #3
0
파일: Lobby.cs 프로젝트: Darkfafi/P_PVB
    /// <summary>
    /// When a player is unregisterd, it will unlink the player from his or her JoinTab.
    /// </summary>
    /// <param name="player">The unregistered player</param>
    private void OnPlayerUnregisteredEvent(RegisteredPlayer player)
    {
        bool replacingPlayers = false;

        for (int i = 0; i < _joinTabs.Length; i++)
        {
            if (!replacingPlayers)
            {
                if (_joinTabs[i].DisplayingPlayer == player)
                {
                    _joinTabs[i].DisplayPlayer(null);
                    replacingPlayers = true;
                    i = -1;
                }
            }
            else
            {
                if (_joinTabs[i].DisplayingPlayer == null)
                {
                    for (int j = i; j < _joinTabs.Length; j++)
                    {
                        if (_joinTabs[j].DisplayingPlayer != null)
                        {
                            _joinTabs[i].DisplayPlayer(_joinTabs[j].DisplayingPlayer);
                            _joinTabs[j].DisplayPlayer(null);
                            break;
                        }
                    }
                }
            }
        }
        SetGlobalText();
        SetAllPlayersReadyValue(false); // All players are set unready when a person leaves so the game cannot accidentally start without a friend.
    }
예제 #4
0
        public override void Use(Player player)
        {
            CanUseAndCheckError(player);

            var x = _registeredPlayers.FirstOrDefault(r => r.player == player);

            x.ThrowIfNotNull(ErrorCodes.MissionAlarmAlreadyStarted, gex =>
            {
                /*
                 * gex.SetData( k.timeOut, (int) AlarmPeriod.TotalMilliseconds);
                 * gex.SetData( k.started, registeredPlayer.registerTime);
                 * gex.SetData( k.now, (long)GlobalTimer.Elapsed.TotalMilliseconds);
                 */
            });

            var rp = new RegisteredPlayer(player, _alarmPeriod);

            ImmutableInterlocked.Update(ref _registeredPlayers, p =>
            {
                return(p.Add(rp));
            });

            CreateInteractionBeam(player);

            player.SendStartProgressBar(this, _alarmPeriod, _elapsed);
        }
예제 #5
0
    public void DisplayPlayer(RegisteredPlayer player)
    {
        ToggleReady(false);

        if (player != null)
        {
            // Player to show
            _usernameText.text  = AirConsole.instance.GetNickname(player.DeviceID);
            _usernameText.color = _userInTabTextColor;
            _playerImage.gameObject.SetActive(true);
            _playerImage.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
            this.transform.DOScale(0.88f, 0.6f);
            _playerImage.sprite = _guestProfileImage;
            StartCoroutine(SetSprite(player.DeviceID));
        }
        else
        {
            // No player to show
            _usernameText.text  = "Open";
            _usernameText.color = _noUserInTabTextColor;
            _playerImage.gameObject.SetActive(false);
        }

        DisplayingPlayer = player;
    }
 public static void Log(this RegisteredPlayer registeredPlayer)
 {
     Console.WriteLine(registeredPlayer.GetType().FullName);
     Console.WriteLine(registeredPlayer.Id);
     Console.WriteLine(registeredPlayer.Name);
     Console.WriteLine(registeredPlayer.Url);
     Console.WriteLine();
 }
예제 #7
0
 public FactionType GetFactionTypeOfPlayer(RegisteredPlayer player)
 {
     for (int i = 0; i < PlayerFactionLinks.Length; i++)
     {
         if (PlayerFactionLinks[i].Player == player)
             return PlayerFactionLinks[i].FactionType;
     }
     return FactionType.None;
 }
예제 #8
0
    /// <summary>
    /// To create a GamePlayer, there must be a RegisteredPlayer linked to it. This player will not change as long as the GamePlayer lives.
    /// </summary>
    /// <param name="linkedPlayer">Registered player (The seat) for the GamePlayer</param>
    public GamePlayer(RegisteredPlayer linkedPlayer)
    {
        _linkedPlayer          = linkedPlayer;
        SkillPouch             = new SkillPouch(this);
        _playfieldSceneTracker = Ramses.SceneTrackers.SceneTrackersFinder.Instance.GetSceneTracker <PlayfieldST>();

        _playfieldSceneTracker.Playfield.CoinPile.VisualObjectArrivedEvent += OnCoinArrivedToPlayerEvent;

        _playfieldSceneTracker.Playfield.CardPile.VisualObjectArrivedEvent += OnCardArrivedToPlayerEvent;
        _playfieldSceneTracker.Playfield.CardPile.AllObjectsArrivedEvent   += OnAllCardsArrivedEvent;
    }
예제 #9
0
파일: Lobby.cs 프로젝트: Darkfafi/P_PVB
 /// <summary>
 /// When a player is registered, it will link the player to a JoinTab.
 /// </summary>
 /// <param name="player">The registered player</param>
 private void OnPlayerRegisteredEvent(RegisteredPlayer player)
 {
     for (int i = 0; i < _joinTabs.Length; i++)
     {
         if (_joinTabs[i].DisplayingPlayer == null)
         {
             _joinTabs[i].DisplayPlayer(player);
             break;
         }
     }
     SetGlobalText();
     StopCountDown();
 }
예제 #10
0
 public void UnassignPlayerFromItsFaction(RegisteredPlayer player)
 {
     for (int i = 0; i < PlayerFactionLinks.Length; i++)
     {
         if (PlayerFactionLinks[i].Player == player)
         {
             PlayerFactionLinks[i].Player = null;
             if(PlayerFactionAssignedEvent != null)
             {
                 PlayerFactionAssignedEvent(PlayerFactionLinks[i]);
             }
             break;
         }
     }
 }
예제 #11
0
 public void AssignPlayerToFaction(RegisteredPlayer player, FactionType faction)
 {
     for (int i = 0; i < PlayerFactionLinks.Length; i++)
     {
         if (PlayerFactionLinks[i].FactionType == faction)
         {
             PlayerFactionLinks[i].Player = player;
             if(PlayerFactionAssignedEvent != null)
             {
                 PlayerFactionAssignedEvent(PlayerFactionLinks[i]);
             }
             break;
         }
     }
 }
예제 #12
0
    private void OnConnectEvent(int device_id)
    {
        RegisteredPlayer rd = GetRegisteredPlayerById(device_id);

        if (rd != null)
        {
            // Same device came back for player
            rd.DeviceConnectedAction(device_id);
            if (RegisteredPlayerReconnectedEvent != null)
            {
                RegisteredPlayerReconnectedEvent(rd);
            }
            return;
        }
        else if (AllowsPlayerRegistration)
        {
            for (int i = 0; i < _registeredPlayers.Length; i++)
            {
                if (_registeredPlayers[i] == null)
                {
                    // new register player item made
                    _registeredPlayers[i] = new RegisteredPlayer(i, device_id);
                    if (PlayerRegisteredEvent != null)
                    {
                        PlayerRegisteredEvent(_registeredPlayers[i]);
                    }
                    return;
                }
            }
        }

        // If the device was not registered as a new or reconnected as a lost device -
        // -> then find disconnected player and register the new user as him
        for (int i = 0; i < _registeredPlayers.Length; i++)
        {
            if (_registeredPlayers[i] != null && !_registeredPlayers[i].IsConnected)
            {
                // Other device came to replace player
                _registeredPlayers[i].LinkDeviceToPlayer(device_id);
                if (RegisteredPlayerReconnectedEvent != null)
                {
                    RegisteredPlayerReconnectedEvent(_registeredPlayers[i]);
                }
                return;
            }
        }
    }
예제 #13
0
    private void OnDisconnectEvent(int device_id)
    {
        RegisteredPlayer rd = GetRegisteredPlayerById(device_id);

        if (rd != null)
        {
            rd.DeviceDisconnectAction(device_id);
        }

        if (RegisteredPlayerDisconnectedEvent != null)
        {
            RegisteredPlayerDisconnectedEvent(rd);
        }

        if (AllowsDeleteRegisteredPlayerOnLeave)
        {
            CleanRegisteredPlayers(true);
        }
    }
예제 #14
0
        public async Task GameSocket(string id)
        {
            if (!HttpContext.WebSockets.IsWebSocketRequest)
            {
                HttpContext.Response.StatusCode = 418;
                return;
            }

            WebSocket ws = await HttpContext.WebSockets.AcceptWebSocketAsync();

            GamePlayer client;
            int?       userId = loginHandler.LoggedInUserId(HttpContext);

            if (userId.HasValue)
            {
                client = new RegisteredPlayer()
                {
                    UserId = userId.Value
                };
            }
            else
            {
                if (HttpContext.Session.GetString("anonymousIdentifier") == null)
                {
                    HttpContext.Response.StatusCode = 400;
                    return;
                }
                client = new AnonymousPlayer()
                {
                    AnonymousIdentifier = HttpContext.Session.GetString("anonymousIdentifier")
                };
            }
            GameSocketHandler handler = new GameSocketHandler(ws, client, gameRepoForSocketHandlers, gameSocketHandlerRepository, moveCollectionTransformer, userRepository, randomProvider, id);

            if (!handler.GameExists)
            {
                HttpContext.Response.StatusCode = 400;
                return;
            }
            gameSocketHandlerRepository.Add(handler);
            await handler.LobbyLoop();
        }
        public async Task LobbySocket()
        {
            if (!HttpContext.WebSockets.IsWebSocketRequest)
            {
                HttpContext.Response.StatusCode = 418;
                return;
            }

            WebSocket ws = await HttpContext.WebSockets.AcceptWebSocketAsync();

            GamePlayer client;
            int?       userId = await loginHandler.LoggedInUserIdAsync(HttpContext);

            if (userId.HasValue)
            {
                client = new RegisteredPlayer()
                {
                    UserId = userId.Value
                };
            }
            else
            {
                if (HttpContext.Session.GetString("anonymousIdentifier") == null)
                {
                    HttpContext.Response.StatusCode = 400;
                    return;
                }
                client = new AnonymousPlayer()
                {
                    AnonymousIdentifier = HttpContext.Session.GetString("anonymousIdentifier")
                };
            }
            LobbySocketHandler handler = new LobbySocketHandler(ws, client, lobbySocketHandlerRepository, seekRepository, gameRepository, randomProvider, userRepository, gameConstructor);

            lobbySocketHandlerRepository.Add(handler);
            await handler.LobbyLoop();
        }
예제 #16
0
    private void SetActive(RegisteredPlayer player)
    {
        _selectionIcon.transform.DOComplete();

        if (player == null)
        {
            // Inactive
            _selectionIcon.transform.DOScale(0, 0.5f).SetEase(Ease.InBack);

            _characterImage.color = Color.white;
            _nameText.color       = _conPlayerFactions.FactionsLibrary.GetItemByFactionType(FactionType).FactionColor;
            _nameText.text        = Enum.GetName(typeof(FactionType), FactionType);
        }
        else
        {
            // Active
            _selectionIcon.transform.localScale = Vector3.zero;
            _selectionIcon.transform.DOScale(1, 0.5f).SetEase(Ease.OutBack);

            _characterImage.color = _activeColor;
            _nameText.color       = _conPlayerFactions.FactionsLibrary.GetItemByFactionType(FactionType).FactionColor + _activeColor;
            _nameText.text        = AirConsole.instance.GetNickname(player.DeviceID);
        }
    }
예제 #17
0
 /// <summary>
 /// Displays the active player locally.
 /// </summary>
 /// <param name="player"></param>
 private void DisplayActivePlayer(RegisteredPlayer player)
 {
     ToggleActivePlayerDisplay(true);
     _nameText.text = AirConsole.instance.GetNickname(player.DeviceID);
 }
예제 #18
0
 private void OnRegisteredPlayerDisconnectedEvent(RegisteredPlayer player)
 {
     DisplayInactivePlayer();
 }
예제 #19
0
 private void OnRegisteredPlayerConnectedEvent(RegisteredPlayer player)
 {
     DisplayActivePlayer(player);
 }
예제 #20
0
 /// <summary>
 /// Returns a GamePlayer by its linked RegisteredPlayer
 /// </summary>
 /// <param name="player"></param>
 /// <returns></returns>
 public GamePlayer GetGamePlayerBy(RegisteredPlayer player)
 {
     return(GetGamePlayerByDeviceId(player.DeviceID));
 }
예제 #21
0
 public PlayerFactionLinkItem(FactionType factionType)
 {
     Player = null;
     FactionType = factionType;
 }
예제 #22
0
 private void OnRegisteredPlayerReconnectedEvent(RegisteredPlayer player)
 {
     SendUpdateFactions();
 }
예제 #23
0
 [HttpPost("Register")] public RegistrationErrors Register([FromBody] RegisteredPlayer player) => player.N?.Trim() switch
 {
     null or {
예제 #24
0
 RegistrationErrors DoRegistration(RegisteredPlayer player)
 {
     game_creator.Register(player.G, player.N.Trim(), Password.FromPassword(player.P.Trim()), player.S);
     return(RegistrationErrors.Ok);
 }
예제 #25
0
 private void UpdatePhaseInfoForPlayer(RegisteredPlayer player)
 {
     _phasesTranslator.UpdateOnCurrentPhase(CurrentGamePhase, player.DeviceID);
 }