Exemplo n.º 1
0
        public async void Update()
        {
            if (_selfPage == null)
            {
                return;
            }

            if (!_selfPage.activeInHierarchy ||
                GameClient.Get <IAppStateManager>().AppState != Enumerators.AppState.APP_INIT)
            {
                return;
            }

            if (!_isLoaded)
            {
                _percentage          += 1f;
                _loaderBar.fillAmount = Mathf.Clamp(_percentage / 100f, 0.03f, 1f);
                if (_percentage >= 100)
                {
                    _isLoaded = true;
                    _progressBar.gameObject.SetActive(false);
                    _pressAnyText.gameObject.SetActive(true);
                }
            }
            else
            {
                if (!Input.anyKey)
                {
                    return;
                }

                if (!_pressAnyText.gameObject.activeSelf)
                {
                    return;
                }

                _pressAnyText.gameObject.SetActive(false);

                if (_backendDataControlMediator.LoadUserDataModel() &&
                    _backendDataControlMediator.UserDataModel.IsValid)
                {
                    ConnectionPopup connectionPopup = _uiManager.GetPopup <ConnectionPopup>();

                    Func <Task> connectFunc = async() =>
                    {
                        bool success = true;
                        try
                        {
                            await _backendDataControlMediator.LoginAndLoadData();
                        }
                        catch (GameVersionMismatchException e)
                        {
                            success = false;
                            _uiManager.DrawPopup <LoginPopup>();
                            _uiManager.GetPopup <LoginPopup>().Show(e);
                        }
                        catch (Exception e)
                        {
                            // HACK: ignore to allow offline mode
                            Debug.LogWarning(e);
                        }

                        connectionPopup.Hide();

                        if (success)
                        {
                            GameClient.Get <IAppStateManager>().ChangeAppState(Enumerators.AppState.MAIN_MENU);
                        }
                    };
                    _uiManager.DrawPopup <ConnectionPopup>();
                    connectionPopup.ConnectFunc = connectFunc;
                    await connectionPopup.ExecuteConnection();
                }
                else
                {
                    _uiManager.DrawPopup <LoginPopup>();
                }
            }
        }
Exemplo n.º 2
0
        public void StartGame()
        {
            if (_battlegroundController == null)
            {
                _battlegroundController = _gameplayManager.GetController <BattlegroundController>();

                _battlegroundController.PlayerGraveyardUpdated   += PlayerGraveyardUpdatedHandler;
                _battlegroundController.OpponentGraveyardUpdated += OpponentGraveyardUpdatedHandler;
            }

            _gameplayManager.PlayerDeckId = CurrentDeckId;

            OpponentDeck randomOpponentDeck =
                _dataManager.CachedOpponentDecksData.Decks[
                    Random.Range(0, _dataManager.CachedOpponentDecksData.Decks.Count)];

            _gameplayManager.OpponentDeckId = randomOpponentDeck.Id;

            //Debug.Log(_tutorialManager.CurrentTutorial.SpecificBattlegroundInfo);
            //Debug.Log(_tutorialManager.CurrentTutorial.SpecificBattlegroundInfo.OpponentInfo);
            //Debug.Log(_tutorialManager.CurrentTutorial.SpecificBattlegroundInfo.OpponentInfo.HeroId);
            int heroId         = 0; //Constants.TutorialPlayerHeroId; // TUTORIAL
            int opponentHeroId = 0;

            if (!_gameplayManager.IsTutorial)
            {
                heroId         = _dataManager.CachedDecksData.Decks.First(o => o.Id == CurrentDeckId).HeroId;
                opponentHeroId = randomOpponentDeck.HeroId;
            }
            else
            {
                heroId         = _tutorialManager.CurrentTutorial.SpecificBattlegroundInfo.PlayerInfo.HeroId;
                opponentHeroId = _tutorialManager.CurrentTutorial.SpecificBattlegroundInfo.OpponentInfo.HeroId;
            }


            Hero currentPlayerHero   = _dataManager.CachedHeroesData.HeroesParsed[heroId];
            Hero currentOpponentHero = _dataManager.CachedHeroesData.HeroesParsed[opponentHeroId];

            _playerDeckStatusTexture   = GameObject.Find("Player/Deck_Illustration/Deck").GetComponent <SpriteRenderer>();
            _opponentDeckStatusTexture =
                GameObject.Find("Opponent/Deck_Illustration/Deck").GetComponent <SpriteRenderer>();
            _playerGraveyardStatusTexture = GameObject.Find("Player/Graveyard_Illustration/Graveyard")
                                            .GetComponent <SpriteRenderer>();
            _opponentGraveyardStatusTexture = GameObject.Find("Opponent/Graveyard_Illustration/Graveyard")
                                              .GetComponent <SpriteRenderer>();

            _playerHealthText   = GameObject.Find("Player/Avatar/LivesCircle/DefenceText").GetComponent <TextMeshPro>();
            _opponentHealthText =
                GameObject.Find("Opponent/Avatar/LivesCircle/DefenceText").GetComponent <TextMeshPro>();

            _playerManaBar = new PlayerManaBarItem(GameObject.Find("PlayerManaBar"), "GooOverflowPlayer",
                                                   new Vector3(-3.55f, 0, -6.07f));
            _opponentManaBar = new PlayerManaBarItem(GameObject.Find("OpponentManaBar"), "GooOverflowOpponent",
                                                     new Vector3(9.77f, 0, 4.75f));

            // improve find to get it from OBJECTS ON BOARD!!
            _playerNameText   = GameObject.Find("Player/NameBoard/NameText").GetComponent <TextMeshPro>();
            _opponentNameText = GameObject.Find("Opponent/NameBoard/NameText").GetComponent <TextMeshPro>();

            _playerCardDeckCountText   = GameObject.Find("Player/CardDeckText").GetComponent <TextMeshPro>();
            _opponentCardDeckCountText = GameObject.Find("Opponent/CardDeckText").GetComponent <TextMeshPro>();

            _endTurnButton = GameObject.Find("EndTurnButton");

            PlayerPrimarySkillHandler =
                GameObject.Find("Player").transform.Find("Object_SpellPrimary").GetComponent <OnBehaviourHandler>();
            PlayerSecondarySkillHandler =
                GameObject.Find("Player").transform.Find("Object_SpellSecondary").GetComponent <OnBehaviourHandler>();

            OpponentPrimarySkillHandler =
                GameObject.Find("Opponent").transform.Find("Object_SpellPrimary").GetComponent <OnBehaviourHandler>();
            OpponentSecondarySkillHandler =
                GameObject.Find("Opponent").transform.Find("Object_SpellSecondary").GetComponent <OnBehaviourHandler>();

            if (currentPlayerHero != null)
            {
                SetHeroInfo(currentPlayerHero, "Player", PlayerPrimarySkillHandler.gameObject,
                            PlayerSecondarySkillHandler.gameObject);
                string playerNameText = currentPlayerHero.FullName;
                if (_backendDataControlMediator.LoadUserDataModel())
                {
                    playerNameText = _backendDataControlMediator.UserDataModel.UserId;
                }

                _playerNameText.text = playerNameText;
            }

            if (currentOpponentHero != null)
            {
                SetHeroInfo(currentOpponentHero, "Opponent", OpponentPrimarySkillHandler.gameObject,
                            OpponentSecondarySkillHandler.gameObject);
                _opponentNameText.text = currentOpponentHero.FullName;
            }

            _isPlayerInited = true;
        }