public async Task PlayCard(CommandContext ctx, [Description("Index of the Upgrade in your hand")] int handPos)
        {
            handPos--;
            int index = BotInfoHandler.participantsDiscordIds.IndexOf(ctx.User.Id);

            BotInfoHandler.gameHandler.players[index].ctx = ctx;

            if (handPos >= BotInfoHandler.gameHandler.players[index].hand.LastIndex || handPos < 0)
            {
                //invalid hand position
                await ctx.Message.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":no_entry_sign:")).ConfigureAwait(false);
            }
            else if (!(await BotInfoHandler.gameHandler.players[index].PlayCard(handPos, BotInfoHandler.gameHandler, index, BotInfoHandler.gameHandler.pairsHandler.opponents[index])))
            {
                //upgrade is too expensive
                await ctx.Message.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":no_entry_sign:")).ConfigureAwait(false);
            }
            else
            {
                //valid pos
                await ctx.Message.CreateReactionAsync(DiscordEmoji.FromName(ctx.Client, ":+1:")).ConfigureAwait(false);

                BotInfoHandler.gameHandler.players[index].ready = false;
                BotInfoHandler.RefreshPlayerList(ctx);

                await BotInfoHandler.RefreshUI(ctx, index);
            }
        }
        public async Task ReadyRound(CommandContext ctx)
        {
            int index = BotInfoHandler.participantsDiscordIds.IndexOf(ctx.User.Id);

            DiscordEmbedBuilder responseMessage;

            if (BotInfoHandler.gameHandler.players[index].ready)
            {
                responseMessage = new DiscordEmbedBuilder
                {
                    Title = "You Have Already Readied",
                    Color = DiscordColor.Red
                };
            }
            else
            {
                responseMessage = new DiscordEmbedBuilder
                {
                    Title       = "You Have Readied Successfully",
                    Description = "You can still make changes to your Upgrade but you will need to use >ready again.",
                    Color       = DiscordColor.Green
                };
                BotInfoHandler.gameHandler.players[index].ready = true;
                BotInfoHandler.RefreshPlayerList(ctx);
            }

            await ctx.RespondAsync(embed : responseMessage).ConfigureAwait(false);
        }
Beispiel #3
0
        public async Task <string> SendInteractionAsync(int curPlayer, inputCriteria criteria, string timeOutAnswer)
        {
            if (curPlayer < 0 || curPlayer >= BotInfoHandler.gameHandler.players.Count())
            {
                return(string.Empty);
            }

            BotInfoHandler.RefreshUI(BotInfoHandler.gameHandler.players[curPlayer].ctx, curPlayer);

            var interactivity = BotInfoHandler.gameHandler.players[curPlayer].ctx.Client.GetInteractivity();

            var embedMsg = await BotInfoHandler.gameHandler.players[curPlayer].ctx.Channel.SendMessageAsync(embed: new DiscordEmbedBuilder
            {
                Title       = this.title,
                Description = this.description,
                Color       = DiscordColor.Azure,
                Footer      = new DiscordEmbedBuilder.EmbedFooter {
                    Text = this.footer
                }
            }).ConfigureAwait(false);

            while (true)
            {
                var result = await interactivity.WaitForMessageAsync(x => x.Channel == BotInfoHandler.gameHandler.players[curPlayer].ctx.Channel &&
                                                                     x.Author == BotInfoHandler.gameHandler.players[curPlayer].ctx.User).ConfigureAwait(false);

                if (result.TimedOut)
                {
                    //apply default answer
                    await embedMsg.CreateReactionAsync(DiscordEmoji.FromName(BotInfoHandler.gameHandler.players[curPlayer].ctx.Client, ":clock4:"));

                    await BotInfoHandler.gameHandler.players[curPlayer].ctx.Channel.SendMessageAsync(embed: new DiscordEmbedBuilder {
                        Title       = "Your Interactive Prompt Timed Out",
                        Description = $"As an input has been chosen {timeOutAnswer}.",
                        Color       = DiscordColor.Yellow
                    }).ConfigureAwait(false);
                    return(timeOutAnswer);
                }

                if (criteria(result.Result.Content, BotInfoHandler.gameHandler, curPlayer))
                {
                    //message fits the criteria

                    await result.Result.CreateReactionAsync(DiscordEmoji.FromName(BotInfoHandler.gameHandler.players[curPlayer].ctx.Client, ":+1:"));

                    return(result.Result.Content);
                }
                else
                {
                    await result.Result.CreateReactionAsync(DiscordEmoji.FromName(BotInfoHandler.gameHandler.players[curPlayer].ctx.Client, ":no_entry_sign:"));
                }
            }
        }
        public async Task SendShops(CommandContext ctx)
        {
            DiscordEmbedBuilder responseMessage;

            if (BotInfoHandler.shopsSent == true)
            {
                //shop already sent
                responseMessage = new DiscordEmbedBuilder
                {
                    Title       = "You have already sent the shops to the players",
                    Description = "This is to prevent spam.",
                    Color       = DiscordColor.Red
                };
                await ctx.RespondAsync(embed : responseMessage).ConfigureAwait(false);
            }
            else
            {
                BotInfoHandler.shopsSent = true;
                //shops not sent yet
                responseMessage = new DiscordEmbedBuilder
                {
                    Title       = "Sending Shops to the Players",
                    Description = "This may take a while.",
                    Color       = DiscordColor.Gray
                };

                var msg = await ctx.RespondAsync(embed : responseMessage).ConfigureAwait(false);

                for (int i = 0; i < BotInfoHandler.participantsDiscordIds.Count(); i++)
                {
                    if (BotInfoHandler.gameHandler.players[i].lives <= 0)
                    {
                        continue;
                    }
                    await BotInfoHandler.SendNewUI(ctx, i);

                    await Task.Delay(1000);
                }

                await msg.DeleteAsync().ConfigureAwait(false);

                responseMessage = new DiscordEmbedBuilder
                {
                    Title       = "Shops sent out successfully",
                    Description = "All players have received their shops",
                    Color       = DiscordColor.Green
                };
                await ctx.RespondAsync(embed : responseMessage).ConfigureAwait(false);
            }
        }
        public async Task RemoveDeadPlayers(CommandContext ctx)
        {
            string deadNames = string.Empty;

            for (int i = 0; i < BotInfoHandler.gameHandler.players.Count(); i++)
            {
                if (BotInfoHandler.gameHandler.players[i].lives <= 0)
                {
                    deadNames = $"{deadNames}{BotInfoHandler.gameHandler.players[i].name} ";
                    BotInfoHandler.RemovePlayer(i);
                    i--;
                }
            }

            await ctx.RespondAsync(embed : new DiscordEmbedBuilder {
                Title = $"{deadNames}Have Been Eliminated",
                Color = DiscordColor.Aquamarine
            }).ConfigureAwait(false);
        }
 public async Task CreateInteractivePlayerlist(CommandContext ctx)
 {
     await BotInfoHandler.SendNewPlayerList(ctx);
 }
Beispiel #7
0
        public async Task SignUp(CommandContext ctx, [Description("The name of your Mech")][RemainingText] string mechName)
        {
            string retMsg;

            while (mechName[0] == ' ')
            {
                mechName.Remove(0, 1);
            }

            for (int i = 1; i < mechName.Length; i++)
            {
            }

            bool validName = IsMechNameValid(mechName, out retMsg);

            if (!validName)
            {
                await ctx.RespondAsync(embed : new DiscordEmbedBuilder
                {
                    Title       = "Invalid Name",
                    Description = retMsg,
                    Color       = DiscordColor.Red
                }).ConfigureAwait(false);
            }
            else
            {
                DiscordEmbedBuilder responseMessage;

                if (BotInfoHandler.participantsDiscordIds.Contains(ctx.User.Id))
                {
                    //already signed up user
                    responseMessage = new DiscordEmbedBuilder
                    {
                        Title       = "You Have Already Signed Up",
                        Description = "You don't have to do anything else to sign up.",
                        Color       = DiscordColor.Red
                    };
                }
                else if (BotInfoHandler.inGame)
                {
                    //a game has already started
                    responseMessage = new DiscordEmbedBuilder
                    {
                        Title       = "A Game Has Already Started",
                        Description = "You would have to wait for the next game to sign up.",
                        Color       = DiscordColor.Red
                    };
                }
                else
                {
                    bool appeared = false;
                    for (int i = 0; i < BotInfoHandler.gameHandler.players.Count(); i++)
                    {
                        if (BotInfoHandler.gameHandler.players[i].name.Equals(mechName, StringComparison.OrdinalIgnoreCase))
                        {
                            appeared = true; break;
                        }
                    }
                    //new user

                    if (appeared)
                    {
                        //someone's already taken this name
                        responseMessage = new DiscordEmbedBuilder
                        {
                            Title       = "Someone Has Already Chosen This Name",
                            Description = "Choose a different name.",
                            Color       = DiscordColor.Red
                        };
                    }
                    else
                    {
                        //everything's correct
                        BotInfoHandler.AddPlayer(ctx, mechName);

                        responseMessage = new DiscordEmbedBuilder
                        {
                            Title       = "Signed up successfully",
                            Description = $"Your Mech is called \"{mechName}\"",
                            Color       = DiscordColor.Green
                        };

                        await ctx.Client.UpdateStatusAsync(new DiscordActivity
                        {
                            Name         = $"({BotInfoHandler.participantsDiscordIds.Count()}) Waiting to >signup",
                            ActivityType = ActivityType.Playing
                        });
                    }
                }

                await ctx.RespondAsync(embed : responseMessage).ConfigureAwait(false);
            }
        }
        public async Task NewUI(CommandContext ctx)
        {
            int index = BotInfoHandler.participantsDiscordIds.IndexOf(ctx.User.Id);

            await BotInfoHandler.SendNewUI(ctx, index);
        }