Ejemplo n.º 1
0
        public async Task <IActionResult> OnGet()
        {
            var guild = await CheckUserPrivilege();

            if (guild is null)
            {
                return(RedirectToPage("/Home/Index"));
            }
            Guild = guild;
            var imGuild = await _context.GetGuildAsync(guild.GuildID);

            var stages = await _context.DbContext.BattleStages.OrderBy(s => s.StartLap).ToListAsync();

            FirstLapForStages       = stages.Select(s => s.StartLap).ToArray();
            FirstLapForStagesString = JsonConvert.SerializeObject(FirstLapForStages);

            BossNames = new();
            foreach (var s in stages)
            {
                var bosses = await _context.DbContext.Bosses
                             .Where(b => b.BattleStageID == s.BattleStageID)
                             .OrderBy(b => b.BossID)
                             .Select(b => b.Name)
                             .ToListAsync();

                BossNames.Add(bosses);
            }
            BossNamesString = JsonConvert.SerializeObject(BossNames);

            LastUpdateTime            = imGuild.LastCalculation.ToString("MM-dd HH:mm");
            (CurrentLap, CurrentBoss) = ConvLap(guild.BossIndex);
            CurrentLap      += 1; //convert to 1-based.
            CurrentBoss     += 1;
            CurrentBossRatio = guild.BossDamageRatio;

            PlanRatio = guild.DamageCoefficient;

            return(Page());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            var timer = System.Diagnostics.Stopwatch.StartNew();
            var guild = await CheckUserPrivilege();

            if (guild is null)
            {
                return(RedirectToPage("/Home/Index"));
            }
            Console.WriteLine($"validate {timer.ElapsedMilliseconds} ms");
            var imGuild = await _context.GetGuildAsync(guild.GuildID);

            guild.DamageCoefficient = PlanRatio;

            //TODO cache
            var stages = await _context.DbContext.BattleStages.OrderBy(s => s.StartLap).ToListAsync();

            FirstLapForStages = stages.Select(s => s.StartLap).ToArray();
            BossNames         = new();
            foreach (var s in stages)
            {
                var bosses = await _context.DbContext.Bosses
                             .Where(b => b.BattleStageID == s.BattleStageID)
                             .Select(b => (string)null) //We only need count for boss index conversion.
                             .ToListAsync();

                BossNames.Add(bosses);
            }

            //1. Update guild status.
            var newBossIndex = ConvLap(CurrentLap - 1, CurrentBoss - 1);

            if (!newBossIndex.HasValue)
            {
                return(RedirectToPage());
            }
            if (CurrentBossRatio < 0 || CurrentBossRatio >= 1)
            {
                return(RedirectToPage());
            }
            guild.BossIndex       = newBossIndex.Value;
            guild.BossDamageRatio = CurrentBossRatio;

            //This is the only save we need for this request.
            await _context.DbContext.SaveChangesAsync();

            Console.WriteLine($"guild progress update {timer.ElapsedMilliseconds} ms");

            //2. Refresh users' combo lists.
            var comboCalculator = new FindAllCombos();
            await comboCalculator.UpdateGuildAsync(_context, guild.GuildID, imGuild);

            Console.WriteLine($"user combo refresh {timer.ElapsedMilliseconds} ms");

            //3. Calculate values.
            await CalcComboValues.RunAllAsync(_context.DbContext, guild, imGuild);

            Console.WriteLine($"value calculation {timer.ElapsedMilliseconds} ms");

            return(RedirectToPage("/Home/Index"));
        }