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);
            }
        }
Esempio n. 2
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:"));
                }
            }
        }