Exemplo n.º 1
0
        public void PostScore(int score, Tournament target)
        {
            if (target != null && TacoManager.UserLoggedIn())
            {
                Action <string> success = (string data) => {
                    ScoreResult r         = JsonUtility.FromJson <ScoreResult>(data);
                    string      modalBody = TacoConfig.TacoPlayEndedModalBody;
                    string      modal     = TacoConfig.TacoPlayEndedWinnerModalBody;
                    modalBody = modalBody.Replace("&gameEndScore", r.score.ToString());
                    if (r.tournament.typeCurrency == 0)
                    {
                        modal = modal.Replace("&prize", " $ " + Math.Round((Decimal)r.tournament.prize, 2, MidpointRounding.AwayFromZero));
                        modal = modal.Replace("&point", "P " + (int)Math.Round(r.tournament.prize * 50, 0, MidpointRounding.AwayFromZero) + " and ");
                    }
                    else
                    {
                        modal = modal.Replace("&point", string.Empty);
                        modal = modal.Replace("&prize", " T " + r.tournament.prize);
                    }

                    if (r.winner)
                    {
                        TacoManager.CloseAllModals();
                        TacoManager.SetToMainMenu();
                        TacoManager.ShowPanel(PanelNames.MyLeaderboardPanelFromEndGame);
                    }
                    else
                    {
                        TacoManager.CloseAllModals();
                        TacoManager.SetToMainMenu();
                        TacoManager.ShowPanel(PanelNames.MyLeaderboardPanelFromEndGame);
                    }
                    TacoManager.GameToken = null;
                    if (r.updated)
                    {
                        TacoManager.UpdateFundsWithToken(r.funds, r.gTokens.ToString(), r.ticket.ToString());
                    }
                };

                Action <string, string> fail = (string data, string error) => {
                    if (Application.internetReachability == NetworkReachability.NotReachable)
                    {
                        TacoManager.CloseMessage();
                        TacoManager.OpenModalConnectionErrorPanel(TacoConfig.ErrorStatusNoInternet);
                    }
                    else
                    {
                        var r = JsonUtility.FromJson <StartGameResult>(data);
                        TacoManager.CloseAllModals();
                        TacoManager.OpenModalGeneralResultPanel(false, TacoConfig.TacoPlayError, r.message);
                    }
                    TacoManager.GameToken = null;
                };

                StartCoroutine(ApiManager.Instance.EndGame(score, target.id, target.gameId, TacoManager.GameToken, TacoManager.User.token, success, fail));
            }
        }
Exemplo n.º 2
0
        public void PostScore(int score, Tournament target)
        {
            TacoConfig.print(" Game Ended with score : " + score);

            PlayerPrefs.SetInt(TacoConfig.TacoHighScoresType, 0);
            PlayerPrefs.SetFloat(TacoConfig.TacoHighScoresPerhapsText, 0);
            Highscore.Instance.highscore = PlayerPrefs.GetFloat("highscoreArcade");
            Highscore.Instance.UpdateManually();

            if (target != null && TacoManager.UserLoggedIn())
            {
                //StartCoroutine(endGame(score));

                Action <string> success = (string data) => {
                    ScoreResult r = JsonUtility.FromJson <ScoreResult>(data);
                    TacoConfig.print("Result complete = " + r.success + " - " + r.score + " - " + r.message);
                    string modalBody = string.Empty;
                    //If user play again so token can't verify
                    if (r.success)
                    {
                        modalBody = TacoConfig.TacoPlayEndedModalBody;

                        modalBody = modalBody.Replace("&gameEndScore", r.score.ToString());
                    }
                    else
                    {
                        modalBody = TacoConfig.TacoPlayEndedAgainModalBody;
                    }

                    TacoManager.CloseAllModals();
                    TacoManager.OpenModal(TacoConfig.TacoPlayEndedModalHeader, modalBody, null, ModalFunctions.TournamentGamePosted);

                    // set the status text
                    TacoManager.StatusText.text = "";

                    // game is over : release token
                    TacoManager.GameToken = null;
                    if (r.updated)
                    {
                        TacoManager.UpdateFundsWithToken(r.funds, r.gTokens.ToString());
                    }
                };

                Action <string, string> fail = (string data, string error) => {
                    var msg = data + ((string.IsNullOrEmpty(error)) ? "" : " : " + error);
                    TacoConfig.print("Error starting game - " + msg);

                    var r = JsonUtility.FromJson <StartGameResult>(data);

                    TacoManager.CloseAllModals();
                    TacoManager.OpenModal(TacoConfig.TacoPlayError, r.message);
                };

                StartCoroutine(ApiManager.Instance.EndGame(score, target.id, target.gameId, TacoManager.GameToken, TacoManager.User.token, success, fail));
            }
        }