private async Task ReportMatchResult(MatchResult result) { if (currentBucket == "") { currentBucket = await UpdateBucketMetadata(currentEntityToken); } PlayFabLeaderboardsAPI.UpdateStatistics(new UpdateStatisticsRequest() { Statistics = new System.Collections.Generic.List <PlayFab.LeaderboardsModels.StatisticUpdate>() { new PlayFab.LeaderboardsModels.StatisticUpdate() { Name = "TimeToFindPair", ChildName = currentBucket, Value = result.matchTime, Metadata = result.cardIndex.ToString() //Metadata = $"{currentPlayer}:{result.cardIndex}" } } }, (response) => { }, (error) => { PlayFabErrorHandler(error); } ); return; }
//private bool isRefreshing = false; public void RefreshPlayerList() { PlayFabLeaderboardsAPI.GetLeaderboard( new GetEntityLeaderboardRequest() { EntityType = "title_player_account", StatisticName = "Bucket", MaxResults = 100 }, (result) => { foreach (PlayerListEntry playerEntry in playerListLocation.transform.GetComponentsInChildren <PlayerListEntry>()) { playerEntry.transform.parent = null; UnityEngine.Object.DestroyImmediate(playerEntry.gameObject); } if (result.Rankings != null) { foreach (EntityLeaderboardEntry ranking in result.Rankings) { AddPlayerToList(ranking.DisplayName, ranking.Metadata, ranking.Entity.Id); } } SetStatus(""); }, (error) => { Debug.LogError(error.GenerateErrorReport()); } ); }
public static async Task <string> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req, ILogger log) { string response = ""; string titleToken = await AzureFunctions.ExecuteFunction.GetTitleEntityToken(); var deleteBucketDef = await PlayFabLeaderboardsAPI.DeleteStatisticDefinitionAsync(new DeleteStatisticDefinitionRequest() { Name = "Bucket" }); response += JsonConvert.SerializeObject(deleteBucketDef, Formatting.Indented); var bucketDef = await PlayFabLeaderboardsAPI.CreateStatisticDefinitionAsync(new CreateStatisticDefinitionRequest() { Name = "Bucket", AggregationMethod = StatisticAggregationMethod.Max, LeaderboardDefinition = new LeaderboardDefinition() { SortDirection = LeaderboardSortDirection.Descending, ProvisionLeaderboard = true } }); response += JsonConvert.SerializeObject(bucketDef.Result, Formatting.Indented); var deleteTimeToFindDef = await PlayFabLeaderboardsAPI.DeleteStatisticDefinitionAsync(new DeleteStatisticDefinitionRequest() { Name = "TimeToFindPair" }); response += JsonConvert.SerializeObject(deleteTimeToFindDef.Result, Formatting.Indented); var timeToFindDef = await PlayFabLeaderboardsAPI.CreateStatisticDefinitionAsync(new CreateStatisticDefinitionRequest() { Name = "TimeToFindPair", AggregationMethod = StatisticAggregationMethod.Last, LeaderboardDefinition = new LeaderboardDefinition() { SortDirection = LeaderboardSortDirection.Ascending, ProvisionLeaderboard = true, DynamicChildLeaderboardMaxSize = 5 } }); response += JsonConvert.SerializeObject(timeToFindDef.Result, Formatting.Indented); return(response); }
public void ReloadLeaderboardData() { for (int i = 1; i <= 5; i++) { LeaderboardListEntry le = leaderboardList.transform.Find($"Entry{i}").GetComponent <LeaderboardListEntry>(); le.Player = ""; le.Time = ""; le.Card.gameObject.SetActive(false); le.Card.allowsSelection = false; } if (string.IsNullOrEmpty(currentBucket)) { LeaderboardPanel.transform.Find("Header/Title").GetComponent <TextMeshProUGUI>().text = "Leaderboard: Bucket Unknown"; return; } else { LeaderboardPanel.transform.Find("Header/Title").GetComponent <TextMeshProUGUI>().text = $"Leaderboard: Bucket {currentBucket}"; } PlayFabLeaderboardsAPI.GetLeaderboard( new GetEntityLeaderboardRequest() { EntityType = "title_player_account", StatisticName = "TimeToFindPair", ChildName = currentBucket, MaxResults = 5 }, (result) => { if (result.Rankings != null) { foreach (EntityLeaderboardEntry ranking in result.Rankings) { LeaderboardListEntry entry = leaderboardList.transform.Find($"Entry{ranking.Rank}").GetComponent <LeaderboardListEntry>(); entry.Player = ranking.DisplayName; float time = ranking.Score / 1000f; entry.Time = $"{time.ToString("0.0")}s"; //entry.Card.Id = int.Parse(ranking.Metadata.Substring(ranking.Metadata.IndexOf(':') + 1)); entry.Card.Id = int.Parse(ranking.Metadata); entry.Card.cardImage = images[entry.Card.Id]; entry.Card.gameObject.SetActive(true); } } }, (error) => { Debug.LogError(error.GenerateErrorReport()); } ); }
public static async Task <string> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] EntityRequest req, ILogger log) { log.LogInformation("Attempting to get TitleEntityToken"); var titleToken = await AzureFunctions.ExecuteFunction.GetTitleEntityToken(); var name = req.FunctionParameter.ToString(); log.LogInformation($"Connected to PlayFab [{titleToken}]"); if ((req.EntityProfile.Statistics != null) && req.EntityProfile.Statistics.ContainsKey("Bucket")) { if (req.EntityProfile.Statistics["Bucket"].Metadata != null) { log.LogInformation($"{name} already had bucket statistic but no assignment"); return(await UpdateBucketMetadata(req, log)); } else { log.LogInformation($"{name} already had bucket assigned {req.EntityProfile.Statistics["Bucket"].Metadata}"); return(req.EntityProfile.Statistics["Bucket"].Metadata); } } else { await PlayFabLeaderboardsAPI.UpdateStatisticsAsync(new UpdateStatisticsRequest() { Entity = new PlayFab.LeaderboardsModels.EntityKey() { Id = req.RequestorEntity.Id, Type = req.RequestorEntity.Type }, EntityLeaderboardMetadata = name, Statistics = new System.Collections.Generic.List <StatisticUpdate>() { new StatisticUpdate() { Name = "Bucket", Value = 1 } } }); return(await UpdateBucketMetadata(req, log)); } }
private Task <string> UpdateBucketMetadata(EntityTokenResponse entityToken) { var t = new TaskCompletionSource <string>(); PlayFabLeaderboardsAPI.GetLeaderboardAroundEntity(new GetLeaderboardAroundEntityRequest() { Entity = new PlayFab.LeaderboardsModels.EntityKey() { Type = entityToken.Entity.Type, Id = entityToken.Entity.Id }, StatisticName = "Bucket", Offset = 0 }, (result) => { int entityRank = result.Rankings[0].Rank; int bucket = (entityRank - 1) / 5; PlayFabLeaderboardsAPI.UpdateStatistics(new UpdateStatisticsRequest() { EntityLeaderboardMetadata = currentPlayer, Statistics = new List <PlayFab.LeaderboardsModels.StatisticUpdate>() { new PlayFab.LeaderboardsModels.StatisticUpdate() { Name = "Bucket", Value = 1, Metadata = bucket.ToString() } } }, (response) => t.SetResult(bucket.ToString()), PlayFabErrorHandler); }, PlayFabErrorHandler ); return(t.Task); }
private Task <bool> SetBucket(EntityTokenResponse entityToken, string metadata) { var t = new TaskCompletionSource <bool>(); PlayFabLeaderboardsAPI.UpdateStatistics(new UpdateStatisticsRequest() { EntityLeaderboardMetadata = metadata, Statistics = new List <PlayFab.LeaderboardsModels.StatisticUpdate>() { new PlayFab.LeaderboardsModels.StatisticUpdate() { Name = "Bucket", Value = 1 } } }, (response) => t.SetResult(true), PlayFabErrorHandler); return(t.Task); }
private static async Task <string> UpdateBucketMetadata(EntityRequest req, ILogger log) { var rankings = await PlayFabLeaderboardsAPI.GetLeaderboardAroundEntityAsync(new GetLeaderboardAroundEntityRequest() { Entity = new PlayFab.LeaderboardsModels.EntityKey() { Id = req.RequestorEntity.Id, Type = req.RequestorEntity.Type }, StatisticName = "Bucket", Offset = 0 }); int entityRank = rankings.Result.Rankings[0].Rank; int bucket = entityRank / 5; await PlayFabLeaderboardsAPI.UpdateStatisticsAsync(new UpdateStatisticsRequest() { Entity = new PlayFab.LeaderboardsModels.EntityKey() { Id = req.RequestorEntity.Id, Type = req.RequestorEntity.Type }, EntityLeaderboardMetadata = (string)req.FunctionParameter, Statistics = new System.Collections.Generic.List <StatisticUpdate>() { new StatisticUpdate() { Name = "Bucket", Value = 1, Metadata = bucket.ToString() } } }); log.LogInformation($"{req.FunctionParameter.ToString()} assigned bucket {bucket}"); return(bucket.ToString()); }