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));
            }
        }