Example #1
0
 public WarMarble(MarbleBotUser user, string name, int maxHealth, Weapon weapon) : base(user.Id, name, maxHealth)
 {
     DisplayEmoji  = new Emoji(user.WarEmoji);
     Shield        = user.GetShield();
     Spikes        = user.GetSpikes();
     Weapon        = weapon;
     Username      = user.Name;
     Discriminator = user.Discriminator;
 }
Example #2
0
        public async Task SiegeStartCommand([Remainder] string overrideString = "")
        {
            ulong fileId = Context.IsPrivate ? Context.User.Id : Context.Guild.Id;

            if (_gamesService.Sieges.ContainsKey(fileId) && _gamesService.Sieges[fileId].Active)
            {
                await SendErrorAsync("A battle is currently ongoing!");

                return;
            }

            if (!File.Exists($"Data{Path.DirectorySeparatorChar}{fileId}.siege"))
            {
                await SendErrorAsync($"**{Context.User.Username}**, no-one is signed up!");

                return;
            }

            // Get marbles
            List <(ulong id, string name)> rawMarbleData;

            using (var marbleList = new StreamReader($"Data{Path.DirectorySeparatorChar}{fileId}.siege"))
            {
                var formatter = new BinaryFormatter();
                if (marbleList.BaseStream.Length == 0)
                {
                    await SendErrorAsync($"**{Context.User.Username}**, no-one is signed up!");

                    return;
                }

                rawMarbleData = (List <(ulong id, string name)>)formatter.Deserialize(marbleList.BaseStream);
            }

            if (rawMarbleData.Count == 0)
            {
                await SendErrorAsync($"**{Context.User.Username}**, no-one is signed up!");

                return;
            }

            var marbles       = new List <SiegeMarble>();
            var marbleOutput  = new StringBuilder();
            var mentionOutput = new StringBuilder();
            int stageTotal    = 0;

            foreach ((ulong id, string name) in rawMarbleData)
            {
                MarbleBotUser user = MarbleBotUser.Find(Context, id);
                stageTotal += user.Stage;
                marbles.Add(new SiegeMarble(id, name, 0)
                {
                    Shield = user.GetShield(),
                    Spikes = user.GetSpikes()
                });

                marbleOutput.AppendLine($"**{name}** [{user.Name}#{user.Discriminator}]");
                if (user.SiegePing && Context.Client.GetUser(id).Status != UserStatus.Offline)
                {
                    mentionOutput.Append($"<@{user.Id}> ");
                }
            }

            Boss boss;

            if (!_gamesService.Sieges.TryGetValue(fileId, out Siege? currentSiege))
            {
                // Pick boss & set battle stats based on boss
                if (overrideString.Contains("override") &&
                    (_botCredentials.AdminIds.Any(id => id == Context.User.Id) || Context.IsPrivate))
                {
                    boss = Boss.GetBoss(overrideString.Split(' ')[1].RemoveChar(' '));
                }
                else
                {
                    // Choose a stage 1 or stage 2 boss depending on the stage of each participant
                    float stage = stageTotal / (float)marbles.Count;
                    if (Math.Abs(stage - 1f) < float.Epsilon)
                    {
                        boss = ChooseStageOneBoss(marbles);
                    }
                    else if (Math.Abs(stage - 2f) < float.Epsilon)
                    {
                        boss = ChooseStageTwoBoss(marbles);
                    }
                    else
                    {
                        stage--;
                        boss = _randomService.Rand.NextDouble() < stage
                            ? ChooseStageTwoBoss(marbles)
                            : ChooseStageOneBoss(marbles);
                    }
                }

                _gamesService.Sieges.TryAdd(fileId,
                                            currentSiege = new Siege(Context, _gamesService, _randomService, boss, marbles));
            }
            else
            {
                boss = currentSiege.Boss;
                currentSiege.Marbles = marbles;
            }

            int marbleHealth = ((int)boss.Difficulty + 2) * 5;

            foreach (SiegeMarble marble in marbles)
            {
                marble.MaxHealth = marbleHealth;
            }

            var builder = new EmbedBuilder()
                          .WithColor(GetColor(Context))
                          .WithDescription("Get ready! Use `mb/siege attack` to attack and `mb/siege grab` to grab power-ups when they appear!")
                          .WithTitle("The Siege has begun! :crossed_swords:")
                          .WithThumbnailUrl(boss.ImageUrl)
                          .AddField($"Marbles: **{marbles.Count}**", marbleOutput.ToString())
                          .AddField($"Boss: **{boss.Name}**", new StringBuilder()
                                    .AppendLine($"Health: **{boss.Health}**")
                                    .AppendLine($"Attacks: **{boss.Attacks.Length}**")
                                    .AppendLine($"Difficulty: **{boss.Difficulty} {(int)boss.Difficulty}**/10")
                                    .ToString());

            // Siege Start
            IUserMessage countdownMessage = await ReplyAsync("**3**");

            await Task.Delay(1000);

            await countdownMessage.ModifyAsync(m => m.Content = "**2**");

            await Task.Delay(1000);

            await countdownMessage.ModifyAsync(m => m.Content = "**1**");

            await Task.Delay(1000);

            await countdownMessage.ModifyAsync(m => m.Content = "**BEGIN THE SIEGE!**");

            await ReplyAsync(embed : builder.Build());

            currentSiege.Start();

            if (mentionOutput.Length != 0 && _botCredentials.AdminIds.Any(id => id == Context.User.Id) &&
                !overrideString.Contains("noping"))
            {
                await ReplyAsync(mentionOutput.ToString());
            }
        }