Exemple #1
0
        public void UpdatePlayerUI(PlayerStats playerStats)
        {
            titleText.text = playerStats.PlayerName;
            if (LeagueManager.league == null || LeagueManager.league.Status == "Open")
            {
                statsText.text = playerStats.GetReadout();
            }
            else
            {
                LeaguePlayerStats leagueStats     = new LeaguePlayerStats(null, null);
                string            currentPlayerId = TitleDescriptionButtonLinkData.LinkID;
                foreach (var player in LeagueManager.league.PlayerList)
                {
                    if (player.PlayerId == currentPlayerId)
                    {
                        leagueStats = player;
                        break;
                    }
                }

                string leagueStatsText = "League Record\n" + LeagueManager.league.Name + "\n" +
                                         "Wins\t\t" + leagueStats.Wins.ToString() + "\n" +
                                         "Losses\t\t" + leagueStats.Losses.ToString() + "\n" +
                                         "Draws\t\t" + leagueStats.Draws.ToString() + "\n" +
                                         "Points\t\t" + leagueStats.WLDScore.ToString();
                statsText.text = playerStats.GetReadout() + "\n\n" + leagueStatsText;
            }
        }
Exemple #2
0
        private void GetMatchFromServer()
        {
            PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()
            {
                FunctionName      = "GetMatch",
                FunctionParameter = new
                {
                    leagueId   = TitleDescriptionButtonLinkData.LinkID,
                    matchIndex = TitleDescriptionButtonLinkData.DataIndex
                },
                GeneratePlayStreamEvent = true,
            },
                                                result =>
            {
                // update player stats
                PlayerManager.UpdatePlayerStats();

                // get Json object representing the host's schedule out of FunctionResult
                JsonObject jsonResult = (JsonObject)result.FunctionResult;

                // check if data exists
                if (jsonResult == null)
                {
                    Debug.Log("get match failed... missing data");
                    return;
                }

                // data successfully received
                // interpret data
                string matchJSON = RPSCommon.InterpretCloudScriptData(jsonResult, "matchTurn");
                string statsJSON = RPSCommon.InterpretCloudScriptData(jsonResult, "opponentStats");
                matchBrief       = new MatchBrief(RPSCommon.InterpretCloudScriptData(jsonResult, "matchBrief"));
                matchTurn        = MatchTurn.CreateFromJSON(matchJSON);
                opponentStats    = LeaguePlayerStats.CreateFromJSON(statsJSON);
                opponentRating   = Int32.Parse(RPSCommon.InterpretCloudScriptData(jsonResult, "opponentRating"));

                UpdateMatchUI();
            },
                                                RPSCommon.OnPlayFabError
                                                );
        }
Exemple #3
0
        private void JoinLeague()
        {
            string            leagueKey        = TitleDescriptionButtonLinkData.LinkID;
            LeaguePlayerStats leaguePlayerData = new LeaguePlayerStats(
                PlayerManager.PlayerName,
                PlayerPrefs.GetString("playFabId"));

            PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()
            {
                FunctionName      = "JoinLeague",
                FunctionParameter = new
                {
                    playerData = leaguePlayerData.ToJSON(),
                    leagueId   = leagueKey,
                    playerName = PlayerManager.PlayerName
                },
                GeneratePlayStreamEvent = true,
            },
                                                result =>
            {
                // get Json object representing the Game State out of FunctionResult
                JsonObject jsonResult = (JsonObject)result.FunctionResult;

                // check if data exists
                if (jsonResult == null)
                {
                    ShowLeagueCancelledAlert();
                    Debug.Log("server failed to return data");
                }
                else
                {
                    Debug.Log("Joined League");
                    GetLeagueDataFromServer(); // TODO: skip this by using the data returned from joining
                }
            },
                                                RPSCommon.OnPlayFabError
                                                );
        }
Exemple #4
0
        public void OnCreateLeagueButtonPress()
        {
            // Manage UI
            SetAllButtonsInteractable(false);

            // Save input from league settings input fields
            LeagueManager.SetMatchCount(Int32.Parse(matchCountInputField.text));
            // * 3600 is hours to seconds conversion
            LeagueManager.SetRoundDuration(Int32.Parse(roundDurationInputField.text) * 3600);
            LeaguePlayerStats leaguePlayerData = new LeaguePlayerStats(
                PlayerManager.PlayerName,
                PlayerPrefs.GetString("playFabId")
                );

            // call to Playfab cloud script function called "CreateNewLeague"
            PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()
            {
                FunctionName      = "CreateNewLeague",
                FunctionParameter = new
                {
                    status         = "Open",
                    leagueName     = leagueNameInput.text,
                    hostName       = PlayerManager.PlayerName,
                    playerData     = leaguePlayerData.ToJSON(),
                    leagueSettings = LeagueManager.leagueSettings.ToJSON()
                },
                GeneratePlayStreamEvent = true,
            },
                                                result =>
            {
                // get Json object representing the Game State out of FunctionResult
                JsonObject jsonResult = (JsonObject)result.FunctionResult;

                // check if data exists
                if (jsonResult == null)
                {
                    Debug.Log("server failed to return data");
                }
                else
                {
                    Debug.Log("New League created");

                    // save key for accessing the league from server
                    TitleDescriptionButtonLinkData.LinkID =
                        RPSCommon.InterpretCloudScriptData(jsonResult, "leagueKey");

                    // reselect UI element from league dashboard
                    EventSystem.current.SetSelectedGameObject(prevUISelection);

                    // Load league view for displaying new league
                    SceneManager.UnloadSceneAsync("NewLeague");
                    SceneManager.LoadScene("LeagueView", LoadSceneMode.Additive);
                }
            },
                                                errorCallback =>
            {
                Debug.Log(errorCallback.ErrorMessage + "error creating new League.");

                // TODO: more specific error messages to help with league creation.
                alertPanelText.text =
                    "Oops! According to the server, The league could not be created.";
                alertPanel.SetActive(true);

                // let player interact again
                SetAllButtonsInteractable(true);
            }
                                                );
        }