protected async Task Start()
        {
            Debug.Log("start called");

            _stateManager = new GameStateManager(_connection);
            _stateManager.OnCardRequested        += OnCardRequested;
            _stateManager.OnCardPlayed           += OnCardPlayed;
            _stateManager.OnStartingHandReceived += OnStartingHandReceived;

            _unitsManager = new UnitsManager(_connection, _stateManager);

            _localHandPanel.OnCardPlayed += OnCardRequested;
            _localHandPanel.Init(_connection, _stateManager);

            Debug.Log("post local hand panel init");

            _summary.SetBackButtonHandler(() =>
            {
                _summary.Hide();
                _stateManager.LeaveGame();
            });

            await _localHand.Init(_connection);

            await _opponentHand.Init(_connection);

            Debug.Log("post hand init");

            _unitsManager.OnAfterUnitInstantiated += HandleAfterUnitInstantiated;

            IMatch match = await _connection.Socket.JoinMatchAsync(_connection.BattleConnection.Matched);

            _connection.BattleConnection.MatchId = match.Id;



            if (match.Presences.Count() == 1)
            {
                Debug.Log("count is 1");

                string opponentId = match.Presences.First().UserId;
                _connection.BattleConnection.OpponentId = opponentId;
                _connection.BattleConnection.HostId     = opponentId;
                SetInitialPlayerState();
            }
            else
            {
                Debug.Log("count is 0");
                _connection.BattleConnection.HostId       = _connection.Session.UserId;
                _connection.Socket.ReceivedMatchPresence += HandleOtherPlayerJoin;
            }

            _spellsManager = new SpellsManager(_stateManager, _unitsManager, _connection.BattleConnection.HostId == _connection.Session.UserId);
        }
Example #2
0
        protected async void Start()
        {
            IMatch match = await _connection.Socket.JoinMatchAsync(_connection.BattleConnection.Matched);

            _connection.BattleConnection.MatchId = match.Id;

            if (match.Presences.Count() == 1)
            {
                string opponentId = match.Presences.First().UserId;
                _connection.BattleConnection.OpponentId = opponentId;
                _connection.BattleConnection.HostId     = opponentId;
                SetInitialPlayerState();
            }
            else
            {
                _connection.BattleConnection.HostId       = _connection.Session.UserId;
                _connection.Socket.ReceivedMatchPresence += HandleOtherPlayerJoin;
            }

            _spellsManager = new SpellsManager(_stateManager, _unitsManager, _connection.BattleConnection.HostId == _connection.Session.UserId);
        }