public async Task Challenge(SocketUser battler1)
            {
                if (battler1.Id == Context.User.Id)
                {
                    //
                }
                else if (BattleContext.GetBattleContext(Context.User) != null)
                {
                    await Context.Channel.SendMessageAsync($"{Context.User.Username} is already participating in a battle.");
                }
                else if (BattleContext.GetBattleContext(battler1) != null)
                {
                    await Context.Channel.SendMessageAsync($"{battler1.Username} is already participating in a battle.");
                }
                else
                {
                    PBESettings       settings = PBESettings.DefaultSettings;
                    PBEPokemonShell[] team0Party, team1Party;
                    // Completely Randomized Pokémon
                    team0Party = PBEUtils.CreateCompletelyRandomTeam(settings, true);
                    team1Party = PBEUtils.CreateCompletelyRandomTeam(settings, true);

                    var battle = new PBEBattle(PBEBattleFormat.Single, settings, team0Party, team1Party);
                    battle.Teams[0].TrainerName = Context.User.Username;
                    battle.Teams[1].TrainerName = battler1.Username;
                    var battleContext = new BattleContext(battle, Context.User, battler1, Context.Channel);
                }
            }
            public async Task Challenge(SocketUser battler1)
            {
                if (battler1.Id == Context.User.Id)
                {
                    //
                }
                else if (BattleContext.GetBattleContext(Context.User) != null)
                {
                    await Context.Channel.SendMessageAsync($"{Context.User.Username} is already participating in a battle.");
                }
                else if (BattleContext.GetBattleContext(battler1) != null)
                {
                    await Context.Channel.SendMessageAsync($"{battler1.Username} is already participating in a battle.");
                }
                else
                {
                    PBETeamShell team1Shell, team2Shell;
                    // Completely Randomized Pokémon
                    team1Shell = new PBETeamShell(PBESettings.DefaultSettings, PBESettings.DefaultMaxPartySize, true);
                    team2Shell = new PBETeamShell(PBESettings.DefaultSettings, PBESettings.DefaultMaxPartySize, true);

                    var battle = new PBEBattle(PBEBattleFormat.Single, team1Shell, Context.User.Username, team2Shell, battler1.Username);
                    new BattleContext(battle, Context.User, battler1, Context.Channel);
                }
            }
Example #3
0
        public static Task ChallengeUser(SocketCommandContext ctx, SocketUser challengee)
        {
            async Task Do()
            {
                RemoveOldChallenges();

                SocketUser challenger = ctx.User;

                if (challenger.Id == challengee.Id || BattleContext.GetBattleContext(challenger) != null)
                {
                    return;
                }
                else if (BattleContext.GetBattleContext(challengee) != null)
                {
                    await PrintParticipating(challenger, challengee, ctx.Channel);
                }
                else
                {
                    Challenge c = GetChallenge(challenger);
                    if (c != null && c.Challenger.Id == challengee.Id)
                    {
                        await StartBattle(c);
                    }
                    else
                    {
                        c = GetChallenge(challengee);
                        if (c == null)
                        {
                            string msg = $"You were challenged to a Pokémon battle by {challenger.Mention}!\nThe challenge expires in {ChallengeMinuteExpiration} minutes.\nType `!accept` to accept the challenge.";
                            try
                            {
                                await challengee.SendMessageAsync(msg);
                            }
                            catch (Discord.Net.HttpException ex)
                            {
                                if (ex.DiscordCode == 50007)
                                {
                                    await ctx.Channel.SendMessageAsync($"{challenger.Mention} ― Cannot challenge {challengee.Mention} because their DMs are closed.");
                                }
                                Console.WriteLine("Challenge exception:{0}{1}", Environment.NewLine, ex);
                                return;
                            }
                            _challenges.Add(new Challenge(challenger, challengee, ctx.Guild));
                            await ctx.Channel.SendMessageAsync($"{challenger.Mention} ― Your challenge has been sent to {challengee.Username}.");
                        }
                        else
                        {
                            await ctx.Channel.SendMessageAsync($"{challenger.Mention} ― {challengee.Username} already has a pending challenge.");
                        }
                    }
                }
            }

            lock (_matchmakingLockObj)
            {
                return(Do());
            }
        }
Example #4
0
        public static async Task Forfeit(SocketCommandContext ctx)
        {
            SocketUser sucker = ctx.User;
            var        bc     = BattleContext.GetBattleContext(sucker);

            if (bc != null)
            {
                await bc.Forfeit(sucker);
            }
        }
Example #5
0
        public static Task AcceptChallenge(SocketCommandContext ctx)
        {
            async Task Do()
            {
                RemoveOldChallenges();

                SocketUser challengee = ctx.User;

                if (!(BattleContext.GetBattleContext(challengee) == null))
                {
                    return;
                }
                else
                {
                    Challenge c = GetChallenge(challengee);
                    if (c == null)
                    {
                        await ctx.Channel.SendMessageAsync($"{challengee.Mention} ― You have no pending challenges.");
                    }
                    else
                    {
                        SocketUser challenger = c.Challenger;
                        if (!(BattleContext.GetBattleContext(challenger) == null))
                        {
                            await PrintParticipating(challengee, challenger, ctx.Channel);
                        }
                        else
                        {
                            await StartBattle(c);
                        }
                    }
                }
            }

            lock (_matchmakingLockObj)
            {
                return(Do());
            }
        }