void st_NewHighscoreFound(object sender, HighscoreEventArgs e) { /* Whenever a new highscore is found/added, this event is called. */ PrintEvent(String.Format("NewHighscoreFound {0} {1} {2} {3} {4} {5}", e.FromNetwork, e.Score.Gamertag, e.Score.Score, e.Score.Gametype, e.RankInGametype, e.RankInGamertag)); /* Re-build the display text if I'm currently viewing the highscores tables. */ if (isHighscores) { BuildHighscoreTexts(); } }
/* I got some new highscore. Sort it into my tables, and kick off an * auto-save if necessary. Make sure I don't save too many scores. There's * one allowance for "network" scores, and another allowance for "non-network" * scores, on the theory that players want to see their own scores even if * they are worse than the worst network score received. */ protected virtual void HighscoreReceived(Highscore data, bool fromNetwork) { int nGamertag = 0; int nGametype = 0; int nGamertagGametype = 0; int rankInGamertag = 0; int rankInGametype = 0; int rankInGamertagGametype = 0; Highscore lowestGamertag = null; Highscore lowestGametype = null; Highscore lowestGamertagGametype = null; Highscore oldestDate = null; lock (highscores) { gametypes.Add(data.Gametype); foreach (Highscore hs in highscores) { if (oldestDate == null || oldestDate.Date > hs.Date) { oldestDate = hs; } if (hs.Gamertag == data.Gamertag) { if (hs.Score > data.Score) { rankInGamertag++; } if (lowestGamertag == null || lowestGamertag.Score > hs.Score) { lowestGamertag = hs; } ++nGamertag; } if (hs.Gametype == data.Gametype) { if (hs.Score > data.Score) { rankInGametype++; } if (lowestGametype == null || lowestGametype.Score > hs.Score) { lowestGametype = hs; } ++nGametype; } if (hs.Gamertag == data.Gamertag && hs.Gametype == data.Gametype) { if (hs.Score > data.Score) { rankInGamertagGametype++; } if (lowestGamertagGametype == null || lowestGamertagGametype.Score > hs.Score) { lowestGamertagGametype = hs; } ++nGamertagGametype; } } if (lowestGamertag == null || data.Score > lowestGamertag.Score || lowestGametype == null || data.Score > lowestGametype.Score || lowestGamertagGametype == null || data.Score > lowestGamertagGametype.Score) { highscores.Add(data); if (nGamertag == MaxHighscoresPerGamertag) { highscores.Remove(lowestGamertag); } if (nGamertagGametype == MaxHighscoresPerGamertagPerGametype) { if (lowestGamertag != lowestGamertagGametype) { highscores.Remove(lowestGamertagGametype); } } Queue(delegate() { MaybeAutosave(); if (NewHighscoreFound != null) { HighscoreEventArgs h = new HighscoreEventArgs(); h.FromNetwork = fromNetwork; h.RankInGamertag = rankInGamertag; h.RankInGamertagAndGametype = rankInGamertagGametype; h.RankInGametype = rankInGametype; h.Score = data; NewHighscoreFound(this, h); } }, mainActions); } if (highscores.Count >= MaxHighscoreCountTotal) { MaybeAutosave(); highscores.Remove(oldestDate); } } }