public async Task SendCase([Remainder] string item) { if (PermissionManager.GetPerms(Context.Message.Author.Id) < PermissionConfig.User) { await Context.Channel.SendMessageAsync("Not authorised to run this command."); return; } StringBuilder sb = new StringBuilder(); int count = 0; SSRPItems.Case c = await SSRPItems.GetCase(item); if (c == null) { await Context.Channel.SendMessageAsync("Specified case not found. You can request for it to be added by contacting an Admin."); return; } foreach (string i in c.items) { sb.Append($"Item: {i} | Odds: {c.odds[count]}%\n"); count++; } await Context.Channel.SendMessageAsync($"{Context.Message.Author.Mention}\n```--- The {c.caseName} Case ---\n{sb.ToString()}```"); await Utilities.StatusMessage("case", Context); }
static int TotalOdds(SSRPItems.Case c) { int total = 0; foreach (int odd in c.odds) { total += odd; } return(total); }
static string SelectItem(SSRPItems.Case c) { int totalOdds = TotalOdds(c); for (int i = 0; i < c.items.Count(); i++) { double add = c.odds[i] * 100; for (int j = 0; j < add; j++) { items.Add(c.items[i]); } } var rand = new Random(); int num = rand.Next(0, items.Count()); return(items[num]); }
public async Task SendCaseSimulation(string casE, int amount = 1) { if (PermissionManager.GetPerms(Context.Message.Author.Id) < PermissionConfig.User) { await Context.Channel.SendMessageAsync("Not authorised to run this command."); return; } if (amount > 3000 || amount < 1) { await ReplyAsync("Amount can't be higher than 3000 or smaller than 1."); return; } List <string> wins = new List <string> { }; int spins = Convert.ToInt32(amount); SSRPItems.Case selectedCase = SelectCase(casE.ToLower()); StringBuilder sb = new StringBuilder(); sb.Clear(); items.Clear(); wins.Clear(); if (selectedCase == null) { await ReplyAsync("Case not found. Try enclosing the case name in \"quotes\""); } else { for (int i = 0; i < spins; i++) { wins.Add(SelectItem(selectedCase)); } var q = from x in wins group x by x into g let count = g.Count() orderby count descending select new { Value = g.Key, Count = count }; foreach (var x in q) { sb.Append($"{x.Count} - {x.Value}\n"); } EmbedBuilder eb = new EmbedBuilder(); EmbedFooterBuilder fb = new EmbedFooterBuilder(); fb.WithText($"Called by {Context.Message.Author.Username}"); fb.WithIconUrl(Context.Message.Author.GetAvatarUrl()); eb.WithTitle($"{selectedCase.caseName} Case"); eb.AddField("Wins", $"{sb.ToString()}"); eb.WithColor(Color.Blue); eb.WithFooter(fb); await ReplyAsync("", false, eb.Build()); } await Utilities.StatusMessage("case simulation", Context); }