示例#1
0
 public League(string status, string name, string host,
               LeagueSettings settings, string key, List <LeaguePlayerStats> playerList)
 {
     Status     = status;
     Name       = name;
     Settings   = settings;
     Host       = host;
     Key        = key;
     PlayerList = playerList;
 }
示例#2
0
        private void GetLeagueDataFromServer()
        {
            var leagueId = TitleDescriptionButtonLinkData.LinkID;

            // keys that must exist for valid league
            List <string> validLeagueKeys = new List <string>()
            {
                "Status",
                "Name",
                "HostName",
                "Settings",
            };

            PlayFabClientAPI.ExecuteCloudScript(new ExecuteCloudScriptRequest()
            {
                FunctionName      = "GetLeague",
                FunctionParameter = new
                {
                    leagueKey = leagueId
                },
                GeneratePlayStreamEvent = true,
            },
                                                result =>
            {
                // update player stats
                PlayerManager.UpdatePlayerStats();

                // 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("League data received from server");

                    // get list of players
                    string playerListJSON = RPSCommon.InterpretCloudScriptData(jsonResult, "Players");
                    var playerArray       = JsonHelper.getJsonArray <LeaguePlayerStats>(playerListJSON);
                    var playerList        = new List <LeaguePlayerStats>();
                    foreach (LeaguePlayerStats player in playerArray)
                    {
                        playerList.Add(player);
                    }
                    // order them WLD
                    playerList.Sort(
                        delegate(LeaguePlayerStats c1, LeaguePlayerStats c2)
                    {
                        return(c1.WLDScore.CompareTo(c2.WLDScore));
                    }
                        );
                    playerList.Reverse();

                    // create instance of league
                    LeagueManager.league = new League(
                        RPSCommon.InterpretCloudScriptData(jsonResult, "Status"),
                        RPSCommon.InterpretCloudScriptData(jsonResult, "Name"),
                        RPSCommon.InterpretCloudScriptData(jsonResult, "HostName"),
                        LeagueSettings.CreateFromJSON(RPSCommon.InterpretCloudScriptData(jsonResult, "Settings")),
                        leagueId,
                        playerList
                        );

                    // interpret schedule as object and save in league object
                    if (LeagueManager.league.Status != "Open")
                    {
                        string scheduleJSON = RPSCommon.InterpretCloudScriptData(jsonResult, "Schedule");
                        Debug.Log(scheduleJSON);
                        if (scheduleJSON != "null")
                        {
                            scheduleJSON       = scheduleJSON.Trim(']');
                            scheduleJSON       = scheduleJSON.Trim('[');
                            scheduleJSON       = scheduleJSON.Replace("\"", string.Empty);
                            var matchDataArray = scheduleJSON.Split(',');

                            foreach (string matchString in matchDataArray)
                            {
                                if (matchString == "null")
                                {
                                    LeagueManager.league.Schedule.Add(null);
                                }
                                else
                                {
                                    LeagueManager.league.Schedule.Add(new MatchBrief(matchString));
                                }
                            }
                        }
                    }
                }

                // determine type of UI we need to set up, OPEN league or CLOSED
                // Open means it is still recruiting, otherwise it has started or completed
                if (LeagueManager.league.Status == "Open")
                {
                    LeagueViewOpenUI();
                }
                else
                {
                    LeagueViewClosedUI();
                }
            },
                                                RPSCommon.OnPlayFabError
                                                );
        }
示例#3
0
 public static void NewLeague(LeagueType leagueType)
 {
     leagueSettings = new LeagueSettings(leagueType);
 }