private async void UpdateFiles(bool updateFromNetwork = true) { _logger.LogInformation("正在更新活动列表"); _data.Events = await _client.GetEvents(updateFromNetwork); _logger.LogInformation("活动列表更新完成"); _logger.LogInformation("正在更新卡片列表"); _data.Cards = await _client.GetCards(updateFromNetwork); _logger.LogInformation("卡片列表更新完成"); _logger.LogInformation("正在更新卡池列表"); _data.Gacha = await _client.GetGacha(updateFromNetwork); _logger.LogInformation("卡池列表更新完成"); _logger.LogInformation("正在更新角色列表"); _data.Characters = await _client.GetCharacters(updateFromNetwork); _logger.LogInformation("角色列表更新完成"); _logger.LogInformation("正在更新乐队列表"); _data.Bands = await _client.GetBands(updateFromNetwork); _logger.LogInformation("乐队列表更新完成"); _logger.LogInformation("正在更新当期卡池详情"); var recentList = _data.GetRecentGacha(); var recentDetail = new Dictionary <string, GachaDetail>(); foreach (var item in recentList) { recentDetail.Add(item.Key, await _client.GetGacha(item.Key, updateFromNetwork)); } _data.RecentGachaDetails = recentDetail; _logger.LogInformation("当期卡池详情更新完成"); }
private async Task <(string, Card)> GachaSingle(string id = null, bool tenTimes = false) { GachaDetail gd = !string.IsNullOrWhiteSpace(id) ? await client.GetGacha(id) : data.RecentGachaDetails.FirstOrDefault(i => i.Value.Type == "permanent" || i.Value.Type == "limited").Value; if (gd == null) { gd = data.RecentGachaDetails.Last().Value; } var cards = gd.Details[0].ToList(); var rates = gd.Rates[0].ToList(); // 1. 选择稀有度 double sumRate = rates.Sum(c => c.Value.Rate); double tempRate = 0; List <double> sorted = new List <double>(); rates.ForEach(r => { tempRate += r.Value.Rate; sorted.Add(tempRate / sumRate); }); double next = randomer.NextDouble(); sorted.Add(next); sorted.Sort(); var rate = int.Parse(rates[sorted.IndexOf(next)].Key); // 2. 十连三星保底 if (tenTimes == true && rate == 2) { rate = 3; } // 3. 取出相应卡组 cards = cards.Where(c => c.Value.RarityIndex == rate).ToList(); sorted.Clear(); tempRate = 0; sumRate = 0; // 4. 大于三星时选择概率提升卡组 if (rate > 3) { var pickups = cards.GroupBy(k => k.Value.Pickup).Select(g => new KeyValuePair <bool, double>(g.Key, g.Sum(k => k.Value.Weight))).ToList(); sumRate = pickups.Sum(k => k.Value); pickups.ForEach(p => { tempRate += p.Value; sorted.Add(tempRate / sumRate); }); next = randomer.NextDouble(); sorted.Add(next); sorted.Sort(); var pickup = pickups[sorted.IndexOf(next)].Key; cards = cards.Where(k => k.Value.Pickup == pickup).ToList(); sorted.Clear(); tempRate = 0; sumRate = 0; } // 5. 取出卡片 int nextIndex = randomer.Next(0, cards.Count - 1); return(cards[nextIndex].Key, data.Cards[cards[nextIndex].Key]); }