public IHttpActionResult SaveMatch(List <Match> matches) { matches = matches.OrderBy(x => x.TimeStampUtc).ToList(); //Sat i AddMatch java foreach (var match in matches) { if (match.TimeStampUtc == DateTime.MinValue) { match.TimeStampUtc = DateTime.UtcNow; } LeaderboardView currentLeaderboard = _leaderboardService.GetLatestLeaderboardView(); _leaderboardService.AddMatchToLeaderboard(currentLeaderboard, match); _matchRepository.SaveMatch(match); _leaderboardViewRepository.SaveLeaderboardView(currentLeaderboard); } //TODO Run validation return(Ok()); }
private void ChangeView(LeaderboardView newView, string newTitle = "") { UnityEngine.Debug.LogWarning("[LeaderboardDialog] ChangeView(" + newView.ToString() + ")"); this.loadingView = LeaderboardDialog.LeaderboardView.Loading; this.previousTitle = this.currentTitle; this.previousView = this.currentView; if (!string.IsNullOrEmpty(newTitle)) { this.currentTitle = newTitle; } this.currentView = newView; if (this.viewContainers == null) { return; } int num = (int)this.currentView; for (int i = 0; i < this.viewContainers.Length; i++) { if (this.viewContainers[i] != null) { this.viewContainers[i].SetActive(num == i); } } if (!string.IsNullOrEmpty(newTitle)) { this.SetTitle(newTitle); } this.cupButton.SetActive(this.currentView != LeaderboardDialog.LeaderboardView.CupInfo && this.currentView != LeaderboardDialog.LeaderboardView.Loading); }
public void ChangeView(LeaderboardView leaderboardView, Action onFinished) { if (this.Reading) { onFinished(); } else if (this.leaderboard == null) { this.onLeaderboardFound = (Action)(() => this.ChangeView(leaderboardView, onFinished)); } else { this.Reading = true; this.View = leaderboardView; this.callback = onFinished; switch (this.View) { case LeaderboardView.Friends: this.leaderboard.RequestFriendLeaderboardEntries(0, (OnLeaderboardEntriesRetrieved)(e => this.CacheEntries(e, 0))); this.CanChangePage = false; break; case LeaderboardView.MyScore: this.leaderboard.RequestLeaderboardEntriesAroundCurrentUser(50, 50, 0, (OnLeaderboardEntriesRetrieved)(e => this.CacheEntries(e, 0))); this.CanChangePage = true; break; case LeaderboardView.Overall: this.leaderboard.RequestLeaderboardEntries(0, 100, 0, (OnLeaderboardEntriesRetrieved)(e => this.CacheEntries(e, 0))); this.CanChangePage = true; break; } } }
/// <summary> /// Converts a Leaderboard model into a Ranking View Model. /// </summary> /// <param name="leaderboard">Leaderboard model you are converting.</param> private LeaderboardView ConvertLeaderboardToLeaderboardView(Leaderboard leaderboard) { LeaderboardView leaderboardView = new LeaderboardView(); leaderboardView.LeaderboardName = leaderboard.LeaderboardName; return(leaderboardView); }
// When the Leaderboard button is clicked private void leaderboardButton_Click(object sender, EventArgs e) { // Create new leaderboard form view LeaderboardView leaderboardView = new LeaderboardView(); // Show the form leaderboardView.Show(); }
public void GoToLeaderboardPage() { _activePageForward(this._leaderBoardPage); LeaderboardView Script = _leaderBoardPage.GetComponent <LeaderboardView> (); DataStore.List <Leaderboard> (Settings.application.UserID.ToString(), list => { Script.EnterPage(list as List <Leaderboard>); }); }
/// <summary> /// Converts an enumerable set of Leaderboard models into a Leaderboard View Models. /// </summary> /// <param name="leaderboards">Leaderboards models you are converting.</param> private IEnumerable <LeaderboardView> ConvertLeaderboardsToLeaderboardViews(IEnumerable <Leaderboard> leaderboards) { IList <LeaderboardView> leaderboardViews = new List <LeaderboardView>(); foreach (Leaderboard leaderboard in leaderboards) { LeaderboardView leaderboardView = ConvertLeaderboardToLeaderboardView(leaderboard); leaderboardViews.Add(leaderboardView); } return(leaderboardViews); }
public LeaderboardView RecalculateLeaderboard() { var matches = _matchRepository.GetMatches().OrderBy(x => x.TimeStampUtc); var leaderboardView = new LeaderboardView(); foreach (var match in matches) { AddMatchToLeaderboard(leaderboardView, match); _matchRepository.SaveMatch(match); } leaderboardView.Entries = leaderboardView.Entries.OrderByDescending(x => x.EloRating).ToList(); _leaderboardViewRepository.SaveLeaderboardView(leaderboardView); return(leaderboardView); }
public LeaderboardView RecalculateLeaderboard(string season) { var matches = _matchRepository.GetMatches(season).OrderBy(x => x.TimeStampUtc); var leaderboardView = new LeaderboardView { SeasonName = season }; foreach (var match in matches) { AddMatchToLeaderboard(leaderboardView, match); _matchRepository.Upsert(match); } leaderboardView.Entries = leaderboardView.Entries.OrderByDescending(x => x.EloRating).ToList(); _leaderboardViewRepository.Upsert(leaderboardView); return(leaderboardView); }
public async Task GetLeaderboard() { ulong userId = Context.User.Id; List <SocketGuildUser> users = Context.Guild?.Users?.ToList() ?? new List <SocketGuildUser>(); LeaderboardView leaderboard = await _service.GetLeaderboard(userId, users); if (leaderboard == null) { await ReplyAsync("Records are lost. I'll find them, come back later."); return; } SocketRole rich = Context.Guild?.Roles?.FirstOrDefault(role => role.Name == "Rich"); if (rich != null) { var richMembers = rich.Members ?? new List <SocketGuildUser>(); var newRichMembers = leaderboard.TopUsers.Where(newRich => !richMembers.Any(c => c.Id == newRich.User.Id)); await Task.WhenAll(newRichMembers.Select(m => { var guidUser = Context.Guild?.GetUser(m.User.Id); if (guidUser == null) { return(Task.CompletedTask); } return(guidUser.AddRoleAsync(rich)); })); var oldRichToRemove = richMembers.Where(currently => !leaderboard.TopUsers.Any(c => c.User.Id == currently.Id)); await Task.WhenAll(oldRichToRemove.Select(u => { var guidUser = Context.Guild?.GetUser(u.Id); if (guidUser == null) { return(Task.CompletedTask); } return(guidUser.RemoveRoleAsync(rich)); })); } leaderboard.TheInfinite = Context.Client.GetUser(698910396093825065); await Context.Channel.SendMessageAsync("", false, EmbedViews.Leaderboard(leaderboard)); }
public override void Initialize() { base.Initialize(); this.IsDynamic = true; this.OnClose = (Action) (() => { if (this.leaderboard == null) return; this.GameState.LiveConnectionChanged -= new Action(this.ChangeView); this.leaderboard = (CachedLeaderboard) null; }); this.XButtonAction = (Action) (() => { ++this.view; if (this.view > LeaderboardView.Overall) this.view = LeaderboardView.Friends; this.ChangeView(); }); }
public override void Initialize() { base.Initialize(); this.IsDynamic = true; this.OnClose = (Action)(() => { if (this.leaderboard == null) { return; } this.GameState.LiveConnectionChanged -= new Action(this.ChangeView); this.leaderboard = (CachedLeaderboard)null; }); this.XButtonAction = (Action)(() => { ++this.view; if (this.view > LeaderboardView.Overall) { this.view = LeaderboardView.Friends; } this.ChangeView(); }); }
public bool AddMatchToLeaderboard(LeaderboardView leaderboardView, Match match) { var existingPointsOnMatch = match.Points; var leaderboardEntries = leaderboardView.Entries; //Team1 var player1 = match.PlayerList[0]; var existingPlayer1 = leaderboardEntries.SingleOrDefault(x => x.UserName == player1); var player2 = match.PlayerList[1]; var existingPlayer2 = leaderboardEntries.SingleOrDefault(x => x.UserName == player2); var team1AvgElo = existingPlayer1?.EloRating ?? 1500; team1AvgElo += existingPlayer2?.EloRating ?? 1500; //Team2 var player3 = match.PlayerList[2]; var existingPlayer3 = leaderboardEntries.SingleOrDefault(x => x.UserName == player3); var player4 = match.PlayerList[3]; var existingPlayer4 = leaderboardEntries.SingleOrDefault(x => x.UserName == player4); var team2AvgElo = existingPlayer3?.EloRating ?? 1500; team2AvgElo += existingPlayer4?.EloRating ?? 1500; var elo = new EloRating(); var result = elo.CalculateRating(team1AvgElo / 2, team2AvgElo / 2, match.MatchResult.Team1Won); match.Points = (int)result; if (existingPlayer1 == null) { leaderboardEntries.Add(CreatePlayer(player1, match, result, match.MatchResult.Team1Won)); } else { UpdateExistingLeaderboardEntry(existingPlayer1.UserName, leaderboardEntries, match, result, match.MatchResult.Team1Won); } if (existingPlayer2 == null) { leaderboardEntries.Add(CreatePlayer(player2, match, result, match.MatchResult.Team1Won)); } else { UpdateExistingLeaderboardEntry(existingPlayer2.UserName, leaderboardEntries, match, result, match.MatchResult.Team1Won); } if (existingPlayer3 == null) { leaderboardEntries.Add(CreatePlayer(player3, match, result, !match.MatchResult.Team1Won)); } else { UpdateExistingLeaderboardEntry(existingPlayer3.UserName, leaderboardEntries, match, result, !match.MatchResult.Team1Won); } if (existingPlayer4 == null) { leaderboardEntries.Add(CreatePlayer(player4, match, result, !match.MatchResult.Team1Won)); } else { UpdateExistingLeaderboardEntry(existingPlayer4.UserName, leaderboardEntries, match, result, !match.MatchResult.Team1Won); } return(existingPointsOnMatch != match.Points); }
public LeaderboardPresenter(LeaderboardView view) { leaderboardModel = new LeaderboardModel(); this.view = view; }
public void ChangeView(LeaderboardView leaderboardView, Action onFinished) { if (this.Reading) onFinished(); else if (this.leaderboard == null) { this.onLeaderboardFound = (Action) (() => this.ChangeView(leaderboardView, onFinished)); } else { this.Reading = true; this.View = leaderboardView; this.callback = onFinished; switch (this.View) { case LeaderboardView.Friends: this.leaderboard.RequestFriendLeaderboardEntries(0, (OnLeaderboardEntriesRetrieved) (e => this.CacheEntries(e, 0))); this.CanChangePage = false; break; case LeaderboardView.MyScore: this.leaderboard.RequestLeaderboardEntriesAroundCurrentUser(50, 50, 0, (OnLeaderboardEntriesRetrieved) (e => this.CacheEntries(e, 0))); this.CanChangePage = true; break; case LeaderboardView.Overall: this.leaderboard.RequestLeaderboardEntries(0, 100, 0, (OnLeaderboardEntriesRetrieved) (e => this.CacheEntries(e, 0))); this.CanChangePage = true; break; } } }
private void _leaveLeaderboardPage() { LeaderboardView Script = _leaderBoardPage.GetComponent <LeaderboardView> (); Script.LeavePage(); }