Beispiel #1
0
 public void PlayerScoreUpdated(LeaderboardType lbType, int score)
 {
     if (this.OnPlayerScoreUpdated != null)
     {
         this.OnPlayerScoreUpdated(lbType, score);
     }
 }
Beispiel #2
0
 public static LeaderboardType GetNext(LeaderboardType value)
 {
     return((from LeaderboardType val in System.Enum.GetValues(typeof(LeaderboardType))
             where val > value
             orderby val
             select val).DefaultIfEmpty().First());
 }
        public async Task <List <VLeaderboard> > GetTop(LeaderboardType type, LeaderboardTimeType timeType, DateTime date, int page, int records)
        {
            switch (timeType)
            {
            case LeaderboardTimeType.AllTime:
                date = DateTime.MinValue;
                break;

            case LeaderboardTimeType.Yearly:
                date = new DateTime(date.Year, 1, 1);
                break;

            case LeaderboardTimeType.Monthly:
                date = new DateTime(date.Year, date.Month, 1);
                break;

            case LeaderboardTimeType.Daily:
                date = date.Date;
                break;

            default:
                date = date.Date;
                break;
            }
            var list = await _vset.AsQueryable().Where(p => p.Type == type && p.TimeType == timeType && p.Date == date).Skip(page * records).Take(records).ToListAsync();

            return(list);
        }
Beispiel #4
0
 public async Task <List <VLeaderboard> > GetTop(LeaderboardType type, LeaderboardTimeType timeType, DateTime date, int page, int records)
 {
     using (var ctx = _db.GetDbContext())
     {
         return(await ctx.Leaderboards.GetTop(type, timeType, date, page, records));
     }
 }
Beispiel #5
0
 public async Task <bool> AddAsync(ulong userId, LeaderboardType type, LeaderboardTimeType timeType, long scoreIncrease)
 {
     using (var ctx = _db.GetDbContext())
     {
         return(await ctx.Leaderboards.AddAsync(userId, type, timeType, scoreIncrease));
     }
 }
Beispiel #6
0
        public async Task RichestCommandAsync(CommandContext ctx, LeaderboardType type)
        {
            List <Wallet> wallets;

            wallets = this._model.Wallets
                      .AsNoTracking()
                      .OrderByDescending(x => x.Balance)
                      .ToList();

            if (type == LeaderboardType.Server)
            {
                var users = await ctx.Guild.GetAllMembersAsync();

                wallets = wallets.Where(x => users.Any(y => y.Id == x.UserId)).ToList();
            }

            int total = 0;

            var totalCalc = Task.Run(() => total = wallets.AsParallel().Sum(x => x.Balance));

            var interact = ctx.Client.GetInteractivity();

            string data = "";

            int c = 1;

            foreach (var user in wallets)
            {
                data += $"{c++}. {Formatter.Bold(user.Username == "" ? user.UserId.ToString() : user.Username)} - {user.Balance.ToMoney()}\n";
            }

            if (data.Count() > 0)
            {
                data = data[..(data.Count() - 1)];
Beispiel #7
0
        public async Task ShowLeaderboard(LeaderboardType type = LeaderboardType.Global)
        {
            if (type == LeaderboardType.Global)
            {
                var top = _leaderboard.GetTopRank(15);
                await ReplyAsync(embed : await FormatLeaderboard(top));
            }
            else if (type == LeaderboardType.Current)
            {
                var challenge = await _challenges.GetCurrentChallenge();

                if (challenge == null)
                {
                    await ReplyAsync("There is no currently running challenge");

                    return;
                }

                await DisplayChallengeLeaderboard(challenge);
            }
            else if (type == LeaderboardType.Trueskill)
            {
                var top = _skills.GetTopRanks(15);
                await ReplyAsync(embed : await FormatLeaderboard(top));
            }
            else
            {
                throw new InvalidOperationException("Unknown leaderboard type");
            }
        }
Beispiel #8
0
 public void LeaderboardLoaded(LeaderboardType lbType)
 {
     if (this.OnLeaderboardLoaded != null)
     {
         this.OnLeaderboardLoaded(lbType);
     }
 }
Beispiel #9
0
 public LeaderboardVO(LeaderboardType type, int totalEntries)
 {
     this.type           = type;
     this.HasPlayerEntry = false;
     this.playerScore    = null;
     this.totalEntries   = totalEntries;
     this.entries        = new List <LeaderboardEntryVO>();
 }
Beispiel #10
0
 private Leaderboard(ulong guildId, LeaderboardType type, DiscordBot bot, DateTimeOffset creationTime, TimeSpan timePeriod = default(TimeSpan))
 {
     TimeGenerated = creationTime;
     GuildId       = guildId;
     Type          = type;
     TimePeriod    = timePeriod;
     this.bot      = bot;
 }
Beispiel #11
0
    public void ChangeLeaderboardType(LeaderboardType newType)
    {
        leaderboardType = newType;

        title.text = leaderboardType.ToString();

        UpdateLeaderboard(leaderboardType);
    }
        public async Task <IActionResult> Get(string name)
        {
            var gamertag = User.GetGamerTag();

            _appMonitor.LogEvent("Leaderboard", properties: new Dictionary <string, string> {
                { "Name", name }
            });

            LeaderboardConfig config = _leaderboardProvider.GetByName(name);

            if (config == null)
            {
                return(NotFound());
            }
            LeaderboardType  type = config.Type;
            List <GameScore> scores;

            switch (type)
            {
            case LeaderboardType.AroundMe:
                if (gamertag == null)
                {
                    return(this.ValidationFailed(new ErrorDetail("gamertag", "Must be signed in as a player with a gamertag to retrive this leaderboard")));
                }
                scores = await _store.GetScoresAroundMeAsync(gamertag, config.Radius);

                break;

            case LeaderboardType.Top:
                scores = await _store.GetTopHighScoresAsync(config.Top);

                break;

            default:
                scores = await _store.GetAllHighScoresAsync();

                break;
            }

            GameScore currentPlayer = null;

            if (config.IncludeCurrentPlayer && gamertag != null)
            {
                currentPlayer = (await _store.GetScoresAroundMeAsync(gamertag, 0)).FirstOrDefault();
            }

            // Format response model
            var resultModel = new LeaderboardGetResponseModel
            {
                Entries = scores
                          ?.Select(s => LeaderboardGetResponseModel.LeaderboardEntry.Map(s, gamertag))
                          ?.ToList(),
                CurrentPlayer = LeaderboardGetResponseModel.LeaderboardEntry.Map(currentPlayer, null)
            };

            // Return result
            return(Ok(resultModel));
        }
        public void CanGetGameDataByLeaderboardType(EvaluationDataType dataType, LeaderboardType leaderboardType, string expectedValue)
        {
            var loggedInAccount = Helpers.CreateAndLoginGlobal(Fixture.SUGARClient, GameDataClientTestsLeaderboardKey);
            var game            = Helpers.GetGame(Fixture.SUGARClient.Game, GameDataClientTestsLeaderboardKey);

            var get = Fixture.SUGARClient.GameData.GetByLeaderboardType(loggedInAccount.User.Id, game.Id, GameDataClientTestsLeaderboardKey, dataType, leaderboardType);

            Assert.Equal(expectedValue, get.Value);
        }
        private void onLeaderboardOutperformed(LeaderboardType leaderboardType)
        {
            Player player = GameLogic.Binder.GameState.Player;

            if ((leaderboardType == LeaderboardType.Royal) && !player.TrackingData.PerSessionWasOutperformed)
            {
                player.TrackingData.PerSessionWasOutperformed = true;
                this.sendCrmEvent(player, "crm_leaderboard_beaten");
            }
        }
Beispiel #15
0
        public Leaderboard(string id = "leaderboard", int amount = 100, LeaderboardType type = LeaderboardType.HIGH_TO_LOW, bool persistOnInstantiate = true)
        {
            _id   = id;
            _type = type;
            Initialize(amount);

            if (persistOnInstantiate)
            {
                Save();
            }
        }
        public async Task <IActionResult> Get(string name)
        {
            var gamertag = User.GetGamerTag();

            LeaderboardConfig config = _leaderboardConfiguration.GetByName(name);

            if (config == null)
            {
                return(NotFound());
            }
            LeaderboardType  type = config.Type;
            List <GameScore> scores;

            switch (type)
            {
            case LeaderboardType.AroundMe:
                if (gamertag == null)
                {
                    return(BadRequest());    // need a gamertag to get scores!
                }
                scores = await _store.GetScoresAroundMeAsync(gamertag, config.Radius);

                break;

            case LeaderboardType.Top:
                scores = await _store.GetTopHighScoresAsync(config.Top);

                break;

            default:
                scores = await _store.GetAllHighScoresAsync();

                break;
            }

            GameScore currentPlayer = null;

            if (config.IncludeCurrentPlayer && gamertag != null)
            {
                currentPlayer = (await _store.GetScoresAroundMeAsync(gamertag, 0)).FirstOrDefault();
            }

            // Format response model
            var resultModel = new LeaderboardGetResponseModel
            {
                Entries = scores
                          ?.Select(s => LeaderboardGetResponseModel.LeaderboardEntry.Map(s, gamertag))
                          ?.ToList(),
                CurrentPlayer = LeaderboardGetResponseModel.LeaderboardEntry.Map(currentPlayer, null)
            };

            // Return result
            return(Ok(resultModel));
        }
 /// <summary>
 /// Posts a score to the specified leaderboard.
 /// </summary>
 /// <param name="score">The score to post.</param>
 /// <param name="leaderboard">The leaderboard to post to.</param>
 /// <param name="reportScoreFinishedDelegate">The event handler for when report score finishes.</param>
 public void PostScoreToLeaderboard(int score, LeaderboardType leaderboard, System.Action <bool> reportScoreFinishedDelegate)
 {
     if (leaderboard == LeaderboardType.SIZE)
     {
         return;
     }
     if (!IsSignedInToGoogle)
     {
         return;
     }
     Social.ReportScore(score, m_leaderboards.GetID(leaderboard), reportScoreFinishedDelegate);
 }
Beispiel #18
0
        private static Dictionary <string, LeaderboardConfig> GetLeaderboardConfiguration(IConfigurationSection configuration)
        {
            Dictionary <string, LeaderboardConfig> leaderboards = new Dictionary <string, LeaderboardConfig>();

            // go over all leaderboards under "Leaderboard:Leaderboards"
            foreach (var config in configuration.GetChildren())
            {
                string            name = config.Key;
                bool              includeCurrentPlayer = bool.Parse(config["IncludeCurrentPlayer"] ?? "false");
                LeaderboardType   type = (LeaderboardType)Enum.Parse(typeof(LeaderboardType), config["Type"]);
                LeaderboardConfig leaderboardConfig = new LeaderboardConfig
                {
                    Name = name,
                    Type = type,
                    IncludeCurrentPlayer = includeCurrentPlayer
                };

                switch (type)
                {
                case LeaderboardType.Top:
                    string top = config["Top"];
                    if (top == null)
                    {
                        throw new Exception($"Leaderboard type Top must have Top value set. Leaderboard name: '{name}'");
                    }
                    else
                    {
                        leaderboardConfig.Top = int.Parse(top);
                    }
                    break;

                case LeaderboardType.AroundMe:
                    string radius = config["Radius"];
                    if (radius == null)
                    {
                        throw new Exception($"Leaderboard type AroundMe must have Radius value set. Leaderboard name: '{name}'");
                    }
                    else
                    {
                        leaderboardConfig.Radius = int.Parse(radius);
                    }
                    break;

                case LeaderboardType.All:
                    break;
                }

                leaderboards.Add(name, leaderboardConfig);
            }

            return(leaderboards);
        }
Beispiel #19
0
        public async Task TestLeaderboard(GameMode mode, LeaderboardType type, uint expectedUser, uint pages = 1)
        {
            OsuUserLeaderboard leaderboard = null;

            do
            {
                leaderboard = await Client.GetLeaderboard(mode, type, last : leaderboard);

                pages--;
            } while (pages > 0);

            Assert.IsTrue(leaderboard.Ranking.Select(x => x.User?.Id).Contains(expectedUser));
        }
 /// <summary>
 /// Shows the UI for the specified leaderboard.
 /// </summary>
 /// <param name="leaderboard">The leaderboard.</param>
 /// <returns>Whether leaderboard UI was shown</returns>
 public bool ShowLeaderboardUI(LeaderboardType leaderboard)
 {
     if (leaderboard == LeaderboardType.SIZE)
     {
         return(false);
     }
     if (!IsSignedInToGoogle)
     {
         return(false);
     }
     PlayGamesPlatform.Instance.ShowLeaderboardUI(m_leaderboards.GetID(leaderboard));
     return(true);
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            LeaderboardType leaderboardType = (Session["LeaderboardType"] != null ? (LeaderboardType)Session["LeaderboardType"] : LeaderboardType.Monthly);
            PlaylistType    playlistType    = (Session["PlaylistType"] != null ? (PlaylistType)Session["PlaylistType"] : PlaylistType.Standard);

            SqlDataSource source = (leaderboardType == LeaderboardType.AllTime ? AllTimeDataSource : MonthlyDataSource);
            source.ConnectionString = Database.GetSqlConnection().ConnectionString;
            source.SelectParameters.Add("Playlist", ((int)playlistType).ToString());
            gvLeaderboard.DataSource = source;
            gvLeaderboard.DataBind();
        }
    }
    public void LoadLeaderboard(LeaderboardType type)
    {
        SortLeaderboards();

        string leaderboard = "";

        switch (type)
        {
        case LeaderboardType.MostWins:
            leaderboard = "<b><size=50>Most Wins</size></b>\n";
            for (int i = 0; i < 10; i++)
            {
                leaderboard += (i + 1) + ". ";
                if (mostWins.Count > i)
                {
                    string id          = mostWins.ElementAt(i).Key;
                    string displayName = tc.GetDisplayName(id).Result;
                    leaderboard += displayName + " - " + mostWins[id];
                }
                if (i != 10)
                {
                    leaderboard += "\n";
                }
            }
            break;

        case LeaderboardType.MostGuesses:
            leaderboard = "<b><size=50>Most Guesses</size></b>\n";
            for (int i = 0; i < 10; i++)
            {
                leaderboard += (i + 1) + ". ";
                if (mostGuesses.Count > i)
                {
                    string id          = mostGuesses.ElementAt(i).Key;
                    string displayName = tc.GetDisplayName(id).Result;
                    leaderboard += displayName + " - " + mostGuesses[id];
                }
                if (i != 10)
                {
                    leaderboard += "\n";
                }
            }
            break;

        case LeaderboardType.MostAccurate:
            break;
        }

        StartCoroutine(changeLeaderboardInfoText(leaderboard, type));
    }
Beispiel #23
0
        private static Dictionary <string, LeaderboardConfig> GetLeaderboardconfiguraion(IEnumerable <IConfigurationSection> enumerable)
        {
            Dictionary <string, LeaderboardConfig> leaderboards = new Dictionary <string, LeaderboardConfig>();

            // go over all leaderboards under "Leaderboard:Leaderboards"
            foreach (var config in enumerable)
            {
                string            name = config["Name"];
                LeaderboardType   type = (LeaderboardType)Enum.Parse(typeof(LeaderboardType), config["Type"]);
                LeaderboardConfig leaderboardConfig = new LeaderboardConfig
                {
                    Name = name,
                    Type = type
                };

                switch (type)
                {
                case LeaderboardType.Top:
                    string top = config["Top"];
                    if (top == null)
                    {
                        throw new Exception($"Leaderboard type Top must have Top value set. Leaderboard name: '{name}'");
                    }
                    else
                    {
                        leaderboardConfig.Top = int.Parse(top);
                    }
                    break;

                case LeaderboardType.AroundMe:
                    string radius = config["Radius"];
                    if (radius == null)
                    {
                        throw new Exception($"Leaderboard type AroundMe must have Radius value set. Leaderboard name: '{name}'");
                    }
                    else
                    {
                        leaderboardConfig.Radius = int.Parse(radius);
                    }
                    break;

                case LeaderboardType.All:
                    break;
                }

                leaderboards.Add(name, leaderboardConfig);
            }

            return(leaderboards);
        }
Beispiel #24
0
        /// <summary>
        /// Get the top count players/clubs/brawlers.
        /// </summary>
        /// <param name="type">Type of leaderboard.</param>
        /// <param name="count">The number of top players or clubs to fetch. If count > 200, it will return a ValueError.</param>
        public async Task <Leaderboard[]> GetLeaderboardAsync(LeaderboardType type, int count)
        {
            string s         = Utils.LeaderboardToString(type);
            bool   isbrawler = (int)type > 1;
            string req       = $"{Utils.Leaderboard}/{(isbrawler ? "players" : s)}?count={count}{(isbrawler ? "&brawler=" + type : "")}";

            HttpResponseMessage response = await client.GetAsync(req);

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                return(Leaderboard.FromJson(json));
            }
            return(null);
        }
Beispiel #25
0
        /// <inheritdoc />
        /// <summary>
        /// </summary>
        /// <param name="type"></param>
        /// <param name="text"></param>
        public LeaderboardSelectorItemRankings(LeaderboardType type, string text) :
            base(text, type == ConfigManager.LeaderboardSection.Value)
        {
            Type = type;
            ConfigManager.LeaderboardSection.ValueChanged += OnLeaderboardSectionChange;

            Clicked += (sender, args) =>
            {
                if (ConfigManager.LeaderboardSection.Value == Type)
                {
                    return;
                }

                ConfigManager.LeaderboardSection.Value = Type;
            };
        }
 private void GetByLeaderboardType(string key, EvaluationDataType dataType, LeaderboardType type, Action <EvaluationDataResponse> onComplete)
 {
     if (SUGARManager.UserSignedIn)
     {
         SUGARManager.client.GameData.GetByLeaderboardTypeAsync(SUGARManager.CurrentUser.Id, SUGARManager.GameId, key, dataType, type,
                                                                onComplete,
                                                                exception =>
         {
             Debug.LogError(exception);
             onComplete(null);
         });
     }
     else
     {
         onComplete(null);
     }
 }
        public void GetLeaderboardByType(LeaderboardType type, int numberOfEntries)
        {
            switch (type)
            {
            case LeaderboardType.GLOBAL:
                GetGlobalLeaderboard(numberOfEntries);
                break;

            case LeaderboardType.AROUND_ME:
                GetAroundMeLeaderboard(numberOfEntries);
                break;

            case LeaderboardType.FRIENDS:
                GetFriendsLeaderboard(numberOfEntries);
                break;
            }
        }
    IEnumerator changeLeaderboardInfoText(string newtext, LeaderboardType type)
    {
        if (leaderboardType == type)
        {
            Leaderboard.text = newtext;
        }
        else
        {
            leaderboardType = type;
            var start       = -835;
            var destination = -1605;
            yield return(moveGui(destination));

            Leaderboard.text = newtext;
            yield return(moveGui(start));
        }
    }
    public void ChangeLeaderBoardType(int index)
    {
        leaderboardType = (LeaderboardType)index;

        for (int i = 0; i < leaderBoardTypeList.Count; i++)
        {
            if (i == index)
            {
                leaderBoardTypeList[i].DOFade(1, 0.3f);
            }
            else
            {
                leaderBoardTypeList[i].DOFade(0.6f, 0.2f);
            }
        }

        ShowHighScore();
    }
Beispiel #30
0
        public static string LeaderboardToString(LeaderboardType type)
        {
            int t = (int)type;
            int i = t - 2;

            if (i >= 0)
            {
                return(Brawlers[i]);
            }
            else if (t >= 0 && t <= 1)
            {
                return(type.ToString().ToLower());
            }
            else
            {
                return(null);
            }
        }