Пример #1
0
        public async Task FightAll()
        {
            var fleets = await _rankings.GetTopTanks(128);

            var count = 0;

            foreach (var fleet in fleets)
            {
                count += await _battles.Enqueue(fleet.Fleet);
            }

            await ReplyAsync($"Enqueued {count} battles");
        }
Пример #2
0
        public async Task SubmitFleet([Remainder] string name)
        {
            name = name.Replace("\"", "")
                   .Replace("\\", "")
                   .Replace("//", "")
                   .Replace(".", "");

            if (Context.Message.Attachments.Count == 0)
            {
                await ReplyAsync("Must attach the fleet as a zip file!");

                return;
            }

            if (Context.Message.Attachments.Count > 1)
            {
                await ReplyAsync("Too many attachments!");

                return;
            }

            var file = Context.Message.Attachments.Single();

            if (file.Size > 50000)
            {
                await ReplyAsync("Fleet file is too large (> 50KB)! Contact Martin#2468 to request a larger limit.");

                return;
            }

            using var client = new HttpClient();
            var bytes = await client.GetByteArrayAsync(file.Url);

            // Sanity check that this is a valid fleet
            using (var archive = new System.IO.Compression.ZipArchive(new MemoryStream(bytes), System.IO.Compression.ZipArchiveMode.Read))
            {
                var loaded = ShipCombatCore.Model.Fleet.TryLoadZip(archive);
                if (loaded == null)
                {
                    await ReplyAsync("Failed to load fleet from zip!");

                    return;
                }

                if (loaded.Ships.Count > 1)
                {
                    await ReplyAsync($"Fleet has {loaded.Ships.Count} ships, please only submit fleets with one ship.");

                    return;
                }
            }

            // Store this new fleet in the DB
            var fleet = await _fleets.Store(Context.User.Id, name, bytes);

            // Clear rankings for this fleet (if they exist)
            await _rankings.ResetRankDeviation(fleet);

            // Enqueue battles for this fleet against all other fleets
            await _battles.Enqueue(fleet);

            await ReplyAsync($"Saved fleet `{name}`. Beginning battle simulation.");
        }