示例#1
0
        public async Task TradeAsync([Summary("Trade Code")] int code, [Summary("Showdown Set")][Remainder] string content)
        {
            const int gen = 8;

            content = ReusableActions.StripCodeBlock(content);
            var set = new ShowdownSet(content);

            if (set.InvalidLines.Count != 0)
            {
                var msg = $"Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}";
                await ReplyAsync(msg).ConfigureAwait(false);

                return;
            }

            var sav = AutoLegalityWrapper.GetTrainerInfo(gen);

            var pkm     = sav.GetLegal(set, out _);
            var la      = new LegalityAnalysis(pkm);
            var spec    = GameInfo.Strings.Species[set.Species];
            var invalid = !(pkm is PK8) || (!la.Valid && SysCordInstance.Self.Hub.Config.Legality.VerifyLegality);

            if (invalid)
            {
                var imsg = $"Oops! I wasn't able to create something from that. Here's my best attempt for that {spec}!";
                await Context.Channel.SendPKMAsync(pkm, imsg).ConfigureAwait(false);

                return;
            }

            pkm.ResetPartyStats();
            var sudo = Context.User.GetIsSudo();

            await AddTradeToQueueAsync(code, Context.User.Username, (PK8)pkm, sudo).ConfigureAwait(false);
        }
示例#2
0
 public static async Task ReplyWithLegalizedSetAsync(this ISocketMessageChannel channel, string content)
 {
     content = ReusableActions.StripCodeBlock(content);
     var set = new ShowdownSet(content);
     var sav = AutoLegalityWrapper.GetTrainerInfo(set.Format);
     await channel.ReplyWithLegalizedSetAsync(sav, set).ConfigureAwait(false);
 }
示例#3
0
        public async Task TradeAsync([Summary("Showdown Set")][Remainder] string content)
        {
            const int gen = 8;

            content = ReusableActions.StripCodeBlock(content);
            var set = new ShowdownSet(content);
            var sav = AutoLegalityWrapper.GetTrainerInfo(gen);

            var pkm  = sav.GetLegal(set, out var result);
            var la   = new LegalityAnalysis(pkm);
            var spec = GameInfo.Strings.Species[set.Species];
            var msg  = la.Valid
                ? $"Here's your ({result}) legalized PKM for {spec} ({la.EncounterOriginal.Name})!"
                : $"Oops! I wasn't able to create something from that. Here's my best attempt for that {spec}!";

            if ((!la.Valid && SysCordInstance.Self.Hub.Config.VerifyLegality) || !(pkm is PK8 pk8))
            {
                await ReplyAsync(msg).ConfigureAwait(false);

                return;
            }

            pk8.ResetPartyStats();

            var code = Info.GetRandomTradeCode();
            var sudo = Context.User.GetIsSudo();

            await AddTradeToQueueAsync(code, Context.User.Username, pk8, sudo).ConfigureAwait(false);
        }
示例#4
0
        public async Task TradeAsync([Summary("Trade Code")] int code, [Summary("Showdown Set")][Remainder] string content)
        {
            const int gen = 8;

            content = ReusableActions.StripCodeBlock(content);
            SpecifyOT(content, out string specifyOT);
            if (specifyOT != string.Empty)
            {
                content = System.Text.RegularExpressions.Regex.Replace(content, @"OT:(\S*\s?\S*\s?\S*)?$\W?", "", System.Text.RegularExpressions.RegexOptions.Multiline);
            }

            var set      = new ShowdownSet(content);
            var template = AutoLegalityWrapper.GetTemplate(set);

            if (set.InvalidLines.Count != 0)
            {
                var msg = $"Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}";
                await ReplyAsync(msg).ConfigureAwait(false);

                return;
            }

            var sav = AutoLegalityWrapper.GetTrainerInfo(gen);
            var pkm = sav.GetLegal(template, out _);

            if (specifyOT != string.Empty)
            {
                pkm.OT_Name = specifyOT;
            }

            var la      = new LegalityAnalysis(pkm);
            var spec    = GameInfo.Strings.Species[template.Species];
            var invalid = !(pkm is PK8) || (!la.Valid && SysCordInstance.Self.Hub.Config.Legality.VerifyLegality);

            if (invalid && !Info.Hub.Config.Trade.Memes)
            {
                var imsg = $"Oops! I wasn't able to create something from that. Here's my best attempt for that {spec}!";
                await Context.Channel.SendPKMAsync(pkm, imsg).ConfigureAwait(false);

                return;
            }
            else if (Info.Hub.Config.Trade.Memes)
            {
                if (await TrollAsync(invalid, template).ConfigureAwait(false))
                {
                    return;
                }
            }

            pkm.ResetPartyStats();
            var sudo = Context.User.GetIsSudo();

            await AddTradeToQueueAsync(code, Context.User.Username, (PK8)pkm, sudo).ConfigureAwait(false);
        }
示例#5
0
        // Helper functions for commands
        public static bool AddToWaitingList(string setstring, string display, string username, bool sub, out string msg)
        {
            if (!TwitchBot.Info.GetCanQueue())
            {
                msg = "Sorry, I am not currently accepting queue requests!";
                return(false);
            }

            var set = ShowdownUtil.ConvertToShowdown(setstring);

            if (set == null)
            {
                msg = $"Skipping trade, @{username}: Empty nickname provided for the species.";
                return(false);
            }
            var template = AutoLegalityWrapper.GetTemplate(set);

            if (template.Species < 1)
            {
                msg = $"Skipping trade, @{username}: Please read what you are supposed to type as the command argument.";
                return(false);
            }

            if (set.InvalidLines.Count != 0)
            {
                msg = $"Skipping trade, @{username}: Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}";
                return(false);
            }

            var sav = AutoLegalityWrapper.GetTrainerInfo(PKX.Generation);
            PKM pkm = sav.GetLegal(template, out var result);

            if (!pkm.CanBeTraded())
            {
                msg = $"Skipping trade, @{username}: Provided Pokémon content is blocked from trading!";
                return(false);
            }

            var valid = new LegalityAnalysis(pkm).Valid;

            if (valid && pkm is PK8 pk8)
            {
                var tq = new TwitchQueue(pk8, new PokeTradeTrainerInfo(display), username, sub);
                TwitchBot.QueuePool.RemoveAll(z => z.UserName == username); // remove old requests if any
                TwitchBot.QueuePool.Add(tq);
                msg = $"@{username} - added to the waiting list. Please whisper your trade code to me! Your request from the waiting list will be removed if you are too slow!";
                return(true);
            }

            var reason = result == "Timeout" ? "Set took too long to generate." : "Unable to legalize the Pokémon.";

            msg = $"Skipping trade, @{username}: {reason}";
            return(false);
        }
示例#6
0
        public async Task TradeAsync([Summary("Trade Code")] int code, [Summary("Showdown Set")][Remainder] string content)
        {
            const int gen = 8;

            content = ReusableActions.StripCodeBlock(content);
            var set      = new ShowdownSet(content);
            var template = AutoLegalityWrapper.GetTemplate(set);

            if (set.InvalidLines.Count != 0)
            {
                var msg = $"Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}";
                await ReplyAsync(msg).ConfigureAwait(false);

                return;
            }

            var sav = AutoLegalityWrapper.GetTrainerInfo(gen);
            var pkm = sav.GetLegal(template, out _);

            if (Info.Hub.Config.Trade.DittoTrade && pkm.Species == 132)
            {
                TradeExtensions.DittoTrade(pkm);
            }

            if (Info.Hub.Config.Trade.EggTrade && pkm.Nickname == "Egg")
            {
                TradeExtensions.EggTrade((PK8)pkm);
            }

            var la      = new LegalityAnalysis(pkm);
            var spec    = GameInfo.Strings.Species[template.Species];
            var invalid = !(pkm is PK8) || (!la.Valid && SysCordInstance.Self.Hub.Config.Legality.VerifyLegality);

            if (invalid && !Info.Hub.Config.Trade.Memes)
            {
                var imsg = $"Oops! I wasn't able to create something from that. Here's my best attempt for that {spec}!";
                await Context.Channel.SendPKMAsync(pkm, imsg).ConfigureAwait(false);

                return;
            }
            else if (Info.Hub.Config.Trade.Memes)
            {
                if (await TrollAsync(invalid, template).ConfigureAwait(false))
                {
                    return;
                }
            }

            pkm.ResetPartyStats();
            var sig = Context.User.GetFavor();

            await AddTradeToQueueAsync(code, Context.User.Username, (PK8)pkm, sig, Context.User).ConfigureAwait(false);
        }
示例#7
0
        public async Task TradeAsync([Summary("Trade Code")] int code, [Summary("Showdown Set")][Remainder] string content)
        {
            content = ReusableActions.StripCodeBlock(content);
            var set      = new ShowdownSet(content);
            var template = AutoLegalityWrapper.GetTemplate(set);

            if (set.InvalidLines.Count != 0)
            {
                var msg = $"Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}";
                await ReplyAsync(msg).ConfigureAwait(false);

                return;
            }

            try
            {
                var sav  = AutoLegalityWrapper.GetTrainerInfo <T>();
                var pkm  = sav.GetLegal(template, out var result);
                var la   = new LegalityAnalysis(pkm);
                var spec = GameInfo.Strings.Species[template.Species];
                pkm = PKMConverter.ConvertToType(pkm, typeof(T), out _) ?? pkm;
                if (pkm is not T pk || !la.Valid)
                {
                    var reason = result == "Timeout" ? $"That {spec} set took too long to generate." : $"I wasn't able to create a {spec} from that set.";
                    var imsg   = $"Oops! {reason}";
                    if (result == "Failed")
                    {
                        imsg += $"\n{AutoLegalityWrapper.GetLegalizationHint(template, sav, pkm)}";
                    }
                    await ReplyAsync(imsg).ConfigureAwait(false);

                    return;
                }
                pk.ResetPartyStats();

                var sig = Context.User.GetFavor();
                await AddTradeToQueueAsync(code, Context.User.Username, pk, sig, Context.User).ConfigureAwait(false);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                LogUtil.LogSafe(ex, nameof(TradeModule <T>));
                var msg = $"Oops! An unexpected problem happened with this Showdown Set:\n```{string.Join("\n", set.GetSetLines())}```";
                await ReplyAsync(msg).ConfigureAwait(false);
            }
        }
示例#8
0
        // Helper functions for commands
        public static bool AddToWaitingList(string setstring, string display, string username, out string msg)
        {
            if (!TwitchBot.Info.GetCanQueue())
            {
                msg = "Sorry, I am not currently accepting queue requests!";
                return(false);
            }

            ShowdownSet set = TwitchShowdownUtil.ConvertToShowdown(setstring);

            if (set.Species < 1)
            {
                msg = $"Skipping trade, @{username}: Please read what you are supposed to type as the command argument.";
                return(false);
            }

            if (set.InvalidLines.Count != 0)
            {
                msg = $"Skipping trade, @{username}: Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}";
                return(false);
            }

            var sav = AutoLegalityWrapper.GetTrainerInfo(PKX.Generation);
            PKM pkm = sav.GetLegal(set, out _);

            if (!pkm.CanBeTraded())
            {
                msg = $"Skipping trade, @{username}: Provided Pokémon content is blocked from trading!";
                return(false);
            }

            var valid = new LegalityAnalysis(pkm).Valid;

            if (valid && pkm is PK8 pk8)
            {
                var tq = new TwitchQueue(pk8, new PokeTradeTrainerInfo(display), username);
                TwitchBot.QueuePool.Add(tq);
                msg = $"@{username} - added to the waiting list. Please whisper to me your trade code! Your request from the waiting list will be removed if you are too slow!";
                return(true);
            }

            msg = $"Skipping trade, @{username}: Unable to legalize the Pokémon.";
            return(false);
        }
        // Helper functions for commands
        public static bool AddToWaitingList(string setstring, string display, string username, out string msg)
        {
            ShowdownSet set   = TwitchShowdownUtil.ConvertToShowdown(setstring);
            var         sav   = AutoLegalityWrapper.GetTrainerInfo(PKX.Generation);
            PKM         pkm   = sav.GetLegal(set, out _);
            var         valid = new LegalityAnalysis(pkm).Valid;

            if (valid && pkm is PK8 p8)
            {
                var tq = new TwitchQueue(p8, new PokeTradeTrainerInfo(display),
                                         username);
                TwitchBot.QueuePool.Add(tq);
                msg = "Added you to the waiting list. Please whisper to me your trade code! Your request from the waiting list will be removed if you are too slow!";
                return(true);
            }

            msg = "Unable to legalize the Pokémon. Skipping Trade.";
            return(false);
        }
示例#10
0
        public async Task TradeAsync([Summary("Trade Code")] int code, [Summary("Showdown Set")][Remainder] string content)
        {
            const int gen = 8;

            content = ReusableActions.StripCodeBlock(content);

            var set      = new ShowdownSet(content);
            var template = AutoLegalityWrapper.GetTemplate(set);

            if (set.InvalidLines.Count != 0)
            {
                var msg = $"Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}";
                await ReplyAsync(msg).ConfigureAwait(false);

                return;
            }

            var sav = AutoLegalityWrapper.GetTrainerInfo(gen);
            var pkm = sav.GetLegal(template, out var result);

            if (Info.Hub.Config.Trade.DittoTrade && pkm.Species == 132)
            {
                TradeExtensions.DittoTrade(pkm);
            }

            if (Info.Hub.Config.Trade.EggTrade && pkm.Nickname == "Egg")
            {
                TradeExtensions.EggTrade((PK8)pkm);
            }

            var la   = new LegalityAnalysis(pkm);
            var spec = GameInfo.Strings.Species[template.Species];

            pkm = PKMConverter.ConvertToType(pkm, typeof(PK8), out _) ?? pkm;
            if (Info.Hub.Config.Trade.Memes && await TrollAsync(pkm is not PK8 || !la.Valid, template).ConfigureAwait(false))
            {
                return;
            }
示例#11
0
        public async Task TradeAsync([Summary("Trade Code")] int code, [Summary("Showdown Set")][Remainder] string content)
        {
            const int gen = 8;

            content = ReusableActions.StripCodeBlock(content);
            var set      = new ShowdownSet(content);
            var template = AutoLegalityWrapper.GetTemplate(set);

            if (set.InvalidLines.Count != 0)
            {
                var msg = $"Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}";
                await ReplyAsync(msg).ConfigureAwait(false);

                return;
            }

            var sav = AutoLegalityWrapper.GetTrainerInfo(gen);

            var pkm  = sav.GetLegal(template, out var result);
            var la   = new LegalityAnalysis(pkm);
            var spec = GameInfo.Strings.Species[template.Species];

            pkm = PKMConverter.ConvertToType(pkm, typeof(PK8), out _) ?? pkm;
            if (pkm is not PK8 || !la.Valid)
            {
                var reason = result == "Timeout" ? "That set took too long to generate." : "I wasn't able to create something from that.";
                var imsg   = $"Oops! {reason} Here's my best attempt for that {spec}!";
                await Context.Channel.SendPKMAsync(pkm, imsg).ConfigureAwait(false);

                return;
            }

            pkm.ResetPartyStats();
            var sig = Context.User.GetFavor();

            await AddTradeToQueueAsync(code, Context.User.Username, (PK8)pkm, sig, Context.User).ConfigureAwait(false);
        }
        // Helper functions for commands
        public static bool AddToWaitingList(string setstring, string display, string username, ulong mUserId, bool sub, out string msg)
        {
            if (!TwitchBot <T> .Info.GetCanQueue())
            {
                msg = "Sorry, I am not currently accepting queue requests!";
                return(false);
            }

            var set = ShowdownUtil.ConvertToShowdown(setstring);

            if (set == null)
            {
                msg = $"Skipping trade, @{username}: Empty nickname provided for the species.";
                return(false);
            }
            var template = AutoLegalityWrapper.GetTemplate(set);

            if (template.Species < 1)
            {
                msg = $"Skipping trade, @{username}: Please read what you are supposed to type as the command argument.";
                return(false);
            }

            if (set.InvalidLines.Count != 0)
            {
                msg = $"Skipping trade, @{username}: Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}";
                return(false);
            }

            try
            {
                var sav = AutoLegalityWrapper.GetTrainerInfo <T>();
                PKM pkm = sav.GetLegal(template, out var result);

                var nickname = pkm.Nickname.ToLower();
                if (nickname == "egg" && Breeding.CanHatchAsEgg(pkm.Species))
                {
                    TradeExtensions <T> .EggTrade(pkm);
                }

                if (pkm.Species == 132 && (nickname.Contains("atk") || nickname.Contains("spa") || nickname.Contains("spe") || nickname.Contains("6iv")))
                {
                    TradeExtensions <T> .DittoTrade(pkm);
                }

                if (!pkm.CanBeTraded())
                {
                    msg = $"Skipping trade, @{username}: Provided Pokémon content is blocked from trading!";
                    return(false);
                }

                if (pkm is T pk)
                {
                    var valid = new LegalityAnalysis(pkm).Valid;
                    if (valid)
                    {
                        var tq = new TwitchQueue <T>(pk, new PokeTradeTrainerInfo(display, mUserId), username, sub);
                        TwitchBot <T> .QueuePool.RemoveAll(z => z.UserName == username); // remove old requests if any

                        TwitchBot <T> .QueuePool.Add(tq);

                        msg = $"@{username} - added to the waiting list. Please whisper your trade code to me! Your request from the waiting list will be removed if you are too slow!";
                        return(true);
                    }
                }

                var reason = result == "Timeout" ? "Set took too long to generate." : "Unable to legalize the Pokémon.";
                msg = $"Skipping trade, @{username}: {reason}";
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                LogUtil.LogSafe(ex, nameof(TwitchCommandsHelper <T>));
                msg = $"Skipping trade, @{username}: An unexpected problem occurred.";
            }
            return(false);
        }
示例#13
0
        public async Task EggRaffleAsync()
        {
            if (!Info.Hub.Config.Trade.EggRaffle)
            {
                await ReplyAsync($"EggRaffle is currently disabled!").ConfigureAwait(false);

                return;
            }
            else if (!Info.Hub.Config.Trade.EggRaffleChannels.Contains(Context.Channel.Id.ToString()) && !Info.Hub.Config.Trade.EggRaffleChannels.Equals(""))
            {
                await ReplyAsync($"You're typing the command in the wrong channel!").ConfigureAwait(false);

                return;
            }

            if (Info.Hub.Config.Trade.EggRaffleCooldown < 0)
            {
                Info.Hub.Config.Trade.EggRaffleCooldown = default;
            }

            if (!System.IO.File.Exists("EggRngBlacklist.txt"))
            {
                System.IO.File.Create("EggRngBlacklist.txt").Close();
            }

            System.IO.StreamReader reader = new System.IO.StreamReader("EggRngBlacklist.txt");
            var content = reader.ReadToEnd();

            reader.Close();

            var id    = $"{Context.Message.Author.Id}";
            var parse = System.Text.RegularExpressions.Regex.Match(content, @"(" + id + @") - (\S*\ \S*\ \w*)", System.Text.RegularExpressions.RegexOptions.Multiline);

            if (content.Contains($"{Context.Message.Author.Id}"))
            {
                var timer         = System.DateTime.Parse(parse.Groups[2].Value).AddHours(Info.Hub.Config.Trade.EggRaffleCooldown);
                var timeremaining = timer - System.DateTime.Now;
                if (System.DateTime.Now >= timer)
                {
                    content = content.Replace(parse.Groups[0].Value, $"{id} - {System.DateTime.Now}").TrimEnd();
                    System.IO.StreamWriter writer = new System.IO.StreamWriter("EggRngBlacklist.txt");
                    writer.WriteLine(content);
                    writer.Close();
                }
                else
                {
                    await ReplyAsync($"{Context.User.Mention}, please try again in {timeremaining.Hours:N0}h : {timeremaining.Minutes:N0}m : {timeremaining.Seconds:N0}s!").ConfigureAwait(false);

                    return;
                }
            }
            else
            {
                System.IO.File.AppendAllText("EggRngBlacklist.txt", $"{Context.Message.Author.Id} - {System.DateTime.Now}{System.Environment.NewLine}");
            }

            var code = Info.GetRandomTradeCode();

            int[] validEgg = { 1,     4,   7,  10,  27,  37,  43,  50,  52,  54,  58,  60,  63,  66,  72,
                               77,   79,  81,  83,  90,  92,  95,  98, 102, 104, 108, 109, 111, 114, 115,
                               116, 118, 120, 122, 123, 127, 128, 129, 131, 133, 137, 163, 170, 172, 173,
                               174, 175, 177, 194, 206, 211, 213, 214, 215, 220, 222, 223, 225, 227, 236,
                               241, 246, 263, 270, 273, 278, 280, 290, 293, 298, 302, 303, 309, 318, 320,
                               324, 328, 337, 338, 339, 341, 343, 349, 355, 360, 361, 403, 406, 415, 420,
                               422, 425, 427, 434, 436, 438, 439, 440, 446, 447, 449, 451, 453, 458, 459,
                               479, 506, 509, 517, 519, 524, 527, 529, 532, 535, 538, 539, 543, 546, 548,
                               550, 551, 554, 556, 557, 559, 561, 562, 568, 570, 572, 574, 577, 582, 587,
                               588, 590, 592, 595, 597, 599, 605, 606, 607, 610, 613, 616, 618, 619, 621,
                               622, 624, 626, 627, 629, 631, 632, 633, 636, 659, 661, 674, 677, 679, 682,
                               684, 686, 688, 690, 692, 694, 701, 702, 704, 707, 708, 710, 712, 714, 722,
                               725, 728, 736, 742, 744, 746, 747, 749, 751, 753, 755, 757, 759, 761, 764,
                               765, 766, 767, 769, 771, 776, 777, 778, 780, 781, 782, 810, 813, 816, 819,
                               821, 824, 827, 829, 831, 833, 835, 837, 840, 843, 845, 846, 848, 850, 852,
                               854, 856, 859, 868, 870, 871, 872, 874, 875, 876, 877, 878, 884, 885 };

            int[] regional = { 27, 37, 50, 52, 77, 79, 83, 122, 222, 263, 554, 562, 618 };

            int[] shinyOdds = { 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
                                3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
                                3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
                                5, 5, 5, 5, 5, 5, 5, 6, 6, 6 };

            int[] abilityIndex = { 0, 1, 2 };
            int[] formIndex1   = { 0, 1 };
            int[] formIndex2   = { 0, 1, 2 };

            var rng        = new System.Random();
            int shinyRng   = rng.Next(0, shinyOdds.Length);
            int abilityRng = rng.Next(0, abilityIndex.Length);
            var set        = new ShowdownSet($"Egg({SpeciesName.GetSpeciesName(rng.Next(new Zukan8Index(Zukan8Type.None, 1).Index, GameUtil.GetMaxSpeciesID(GameVersion.SWSH)), 2)})");

            while (!validEgg.ToList().Contains(set.Species))
            {
                set = new ShowdownSet($"Egg({SpeciesName.GetSpeciesName(rng.Next(new Zukan8Index(Zukan8Type.None, 1).Index, GameUtil.GetMaxSpeciesID(GameVersion.SWSH)), 2)})");
            }

            var template = AutoLegalityWrapper.GetTemplate(set);
            var sav      = AutoLegalityWrapper.GetTrainerInfo(8);
            var pkm      = (PK8)sav.GetLegal(template, out _);

            if (regional.ToList().Contains(pkm.Species))
            {
                int formRng  = rng.Next(0, formIndex1.Length);
                int formRng2 = rng.Next(0, formIndex2.Length);

                if (pkm.Species != 52)
                {
                    pkm.SetAltForm(formIndex1[formRng]);
                }
                else
                {
                    pkm.SetAltForm(formIndex2[formRng2]);
                }

                if (pkm.AltForm != 0)
                {
                    if (pkm.Species == 27)
                    {
                        pkm.RelearnMove3 = 10;
                    }
                    else if (pkm.Species == 37)
                    {
                        pkm.RelearnMove4 = 39;
                    }
                    else if (pkm.Species == 52)
                    {
                        pkm.RelearnMove2 = 252;
                        pkm.RelearnMove3 = 45;
                    }
                    else if (pkm.Species == 83)
                    {
                        pkm.RelearnMove1 = 64;
                        pkm.RelearnMove4 = 28;
                    }
                    else if (pkm.Species == 222)
                    {
                        pkm.RelearnMove1 = 33;
                    }
                    else if (pkm.Species == 263)
                    {
                        pkm.RelearnMove2 = 43;
                        pkm.RelearnMove3 = 0;
                        pkm.RelearnMove4 = 0;
                    }
                }
            }

            EggTrade(pkm);
            pkm.Nature     = rng.Next(0, 24);
            pkm.StatNature = pkm.Nature;
            pkm.SetAbilityIndex(abilityIndex[abilityRng]);
            pkm.IVs = pkm.SetRandomIVs(3);
            BallApplicator.ApplyBallLegalRandom(pkm);

            if (shinyOdds[shinyRng] == 3)
            {
                CommonEdits.SetShiny(pkm, Shiny.Never);
                pkm.SetUnshiny();
            }
            else if (shinyOdds[shinyRng] == 5)
            {
                CommonEdits.SetShiny(pkm, Shiny.AlwaysStar);
            }
            else
            {
                CommonEdits.SetShiny(pkm, Shiny.AlwaysSquare);
            }

            var la      = new LegalityAnalysis(pkm);
            var spec    = GameInfo.Strings.Species[template.Species];
            var invalid = !(pkm is PK8) || (!la.Valid && SysCordInstance.Self.Hub.Config.Legality.VerifyLegality);

            if (invalid)
            {
                var imsg = $"Oops! I scrambled your egg! Don't tell Ramsay! Here's my best attempt for that {spec}!";
                await Context.Channel.SendPKMAsync(pkm, imsg).ConfigureAwait(false);

                return;
            }

            pkm.ResetPartyStats();
            var sudo = Context.User.GetIsSudo();

            await AddTradeToQueueAsync(code, Context.User.Username, pkm, sudo).ConfigureAwait(false);
        }
示例#14
0
        public async Task TradeAsync([Summary("Trade Code")] int code, [Summary("Showdown Set")][Remainder] string content)
        {
            content = ReusableActions.StripCodeBlock(content);
            var set      = new ShowdownSet(content);
            var template = AutoLegalityWrapper.GetTemplate(set);

            if (set.InvalidLines.Count != 0)
            {
                var msg = $"Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}";
                await ReplyAsync(msg).ConfigureAwait(false);

                return;
            }

            try
            {
                var sav = AutoLegalityWrapper.GetTrainerInfo <T>();
                var pkm = sav.GetLegal(template, out var result);
                if (pkm.Species == 132)
                {
                    TradeExtensions <T> .DittoTrade(pkm);
                }

                if (pkm.Nickname.ToLower() == "egg" && Breeding.CanHatchAsEgg(pkm.Species))
                {
                    TradeExtensions <T> .EggTrade(pkm);
                }

                var la   = new LegalityAnalysis(pkm);
                var spec = GameInfo.Strings.Species[template.Species];
                pkm = EntityConverter.ConvertToType(pkm, typeof(T), out _) ?? pkm;
                bool memes = Info.Hub.Config.Trade.Memes && await TradeAdditionsModule <T> .TrollAsync(Context, pkm is not T || !la.Valid, pkm).ConfigureAwait(false);

                if (memes)
                {
                    return;
                }

                if (pkm is not T pk || !la.Valid)
                {
                    var reason = result == "Timeout" ? $"That {spec} set took too long to generate." : $"I wasn't able to create a {spec} from that set.";
                    var imsg   = $"Oops! {reason}";
                    if (result == "Failed")
                    {
                        imsg += $"\n{AutoLegalityWrapper.GetLegalizationHint(template, sav, pkm)}";
                    }
                    await ReplyAsync(imsg).ConfigureAwait(false);

                    return;
                }
                pk.ResetPartyStats();

                var sig = Context.User.GetFavor();
                await AddTradeToQueueAsync(code, Context.User.Username, pk, sig, Context.User).ConfigureAwait(false);
            }
            catch (Exception ex)
            {
                LogUtil.LogSafe(ex, nameof(TradeModule <T>));
                var msg = $"Oops! An unexpected problem happened with this Showdown Set:\n```{string.Join("\n", set.GetSetLines())}```";
                await ReplyAsync(msg).ConfigureAwait(false);
            }
        }
示例#15
0
        public async Task LanRollAsync([Summary("User Requested IGN")][Remainder] string ign = "")
        {
            if (ign.Length > 12)
            {
                await ReplyAsync("IGN cannot exceed 12 characters.").ConfigureAwait(false);

                return;
            }

            var code = Info.GetRandomTradeCode();

            int[] existantMon =
            { 1,         2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,  25,  26,  27,  28,  29, 30, 31, 32,
              33,   34,  35,  36,  37,  38,  39,  40,  41,  42,  43,  44,  45,  50,  51,  52,  53, 54,
              55,   58,  59,  60,  61,  62,  63,  64,  65,  66,  67,  68,  72,  73,  77,  78,  79, 80,
              81,   82,  83,  90,  91,  92,  93,  94,  95,  98,  99, 102, 103, 104, 105, 106, 107,
              108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122,
              123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137,
              138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 163,
              164, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 182, 183, 184, 185,
              186, 194, 195, 196, 197, 199, 202, 206, 208, 211, 212, 213, 214, 215, 220,
              221, 222, 223, 224, 225, 226, 227, 230, 233, 236, 237, 238, 239, 240, 241,
              242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256,
              257, 258, 259, 260, 263, 264, 270, 271, 272, 273, 274, 275, 278, 279, 280,
              281, 282, 290, 291, 292, 293, 294, 295, 298, 302, 303, 304, 305, 306, 309,
              310, 315, 318, 319, 320, 321, 324, 328, 329, 330, 333, 334, 337, 338, 339,
              340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 355, 356, 359, 360,
              361, 362, 363, 364, 365, 369, 371, 372, 373, 374, 375, 376, 377, 378, 379,
              380, 381, 382, 383, 384, 385, 403, 404, 405, 406, 407, 415, 416, 420, 421,
              422, 423, 425, 426, 427, 428, 434, 436, 437, 438, 439, 440, 442, 443, 444,
              445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 458, 459, 460, 461, 462,
              463, 464, 465, 466, 467, 468, 470, 471, 473, 474, 475, 477, 478, 479, 480,
              481, 482, 483, 484, 485, 486, 487, 488, 494, 506, 507, 508, 509, 510, 517,
              518, 519, 520, 521, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534,
              535, 536, 537, 538, 539, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552,
              553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567,
              568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 582, 583, 584,
              587, 588, 589, 590, 591, 592, 593, 595, 596, 597, 598, 599, 600, 601, 605,
              606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620,
              621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635,
              636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 649, 659, 660,
              661, 662, 663, 674, 675, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686,
              687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701,
              702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716,
              717, 718, 719, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 736, 737,
              738, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755,
              756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770,
              771, 772, 773, 776, 777, 778, 780, 781, 782, 783, 784, 785, 786, 787, 788,
              789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803,
              804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818,
              819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, 832, 833,
              834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848,
              849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863,
              864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878,
              879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, 892, 893,
              894, 895, 896, 897, 898 };

            var rng = new System.Random();
            var set = new ShowdownSet($"Egg({SpeciesName.GetSpeciesName(rng.Next(new Zukan8Index(Zukan8Type.None, 1).Index, GameUtil.GetMaxSpeciesID(GameVersion.SWSH)), 2)})");

            while (!existantMon.ToList().Contains(set.Species))
            {
                set = new ShowdownSet($"Egg({SpeciesName.GetSpeciesName(rng.Next(new Zukan8Index(Zukan8Type.None, 1).Index, GameUtil.GetMaxSpeciesID(GameVersion.SWSH)), 2)})");
            }

            var template = AutoLegalityWrapper.GetTemplate(set);
            var sav      = AutoLegalityWrapper.GetTrainerInfo(gen);
            var pkm      = (PK8)sav.GetLegal(template, out _);;

            LanRollTrade(pkm);

            pkm.ClearRecordFlags();
            pkm.GetSuggestedRelearnMoves();

            pkm.ResetPartyStats();
            var sig = Context.User.GetFavor();
            await Context.AddToQueueAsync(code, Context.User.Username, sig, pkm, PokeRoutineType.LanRoll, PokeTradeType.LanRoll, Context.User, ign).ConfigureAwait(false);
        }
示例#16
0
        public async Task EggRollAsync()
        {
            if (!Info.Hub.Config.Trade.EggRollChannels.Contains(Context.Channel.Id.ToString()) && !Info.Hub.Config.Trade.EggRollChannels.Equals(""))
            {
                await ReplyAsync($"You're typing the command in the wrong channel!").ConfigureAwait(false);

                return;
            }

            if (Info.Hub.Config.Trade.EggRollCooldown < 0)
            {
                Info.Hub.Config.Trade.EggRollCooldown = default;
            }

            var id   = Context.User.Id.ToString();
            var line = TradeExtensions.EggRollCooldown.FirstOrDefault(z => z.Contains(id));

            System.DateTime.TryParse(line != null ? line.Split(',')[1] : string.Empty, out System.DateTime time);
            var timer         = time.AddHours(Info.Hub.Config.Trade.EggRollCooldown);
            var timeRemaining = timer - System.DateTime.Now;

            if (System.DateTime.Now < timer)
            {
                await ReplyAsync($"{Context.User.Mention}, please try again in {timeRemaining.Hours:N0}h : {timeRemaining.Minutes:N0}m : {timeRemaining.Seconds:N0}s!").ConfigureAwait(false);

                return;
            }

            var code       = Info.GetRandomTradeCode();
            var rng        = new System.Random();
            int shinyRng   = rng.Next(0, TradeExtensions.shinyOdds.Length);
            int abilityRng = rng.Next(0, TradeExtensions.abilityIndex.Length);
            var set        = new ShowdownSet($"Egg({SpeciesName.GetSpeciesName((int)TradeExtensions.validEgg.GetValue(rng.Next(0, TradeExtensions.validEgg.Length)), 2)})");
            var template   = AutoLegalityWrapper.GetTemplate(set);
            var sav        = AutoLegalityWrapper.GetTrainerInfo(8);
            var pkm        = (PK8)sav.GetLegal(template, out _);

            if (TradeExtensions.regional.ToList().Contains(pkm.Species))
            {
                int formRng  = rng.Next(0, TradeExtensions.formIndex1.Length);
                int formRng2 = rng.Next(0, TradeExtensions.formIndex2.Length);

                if (pkm.Species != 52)
                {
                    pkm.SetAltForm(TradeExtensions.formIndex1[formRng]);
                }
                else
                {
                    pkm.SetAltForm(TradeExtensions.formIndex2[formRng2]);
                }

                if (pkm.AltForm != 0)
                {
                    switch (pkm.Species)
                    {
                    case 27: pkm.RelearnMove3 = 10; break;

                    case 37: pkm.RelearnMove4 = 39; break;

                    case 52: pkm.RelearnMove2 = 252; pkm.RelearnMove3 = 45; break;

                    case 83: pkm.RelearnMove1 = 64; pkm.RelearnMove4 = 28; break;

                    case 222: pkm.RelearnMove1 = 33; break;

                    case 263: pkm.RelearnMove2 = 43; pkm.RelearnMove3 = 0; pkm.RelearnMove4 = 0; break;
                    }
                    ;
                }
            }

            TradeExtensions.EggTrade(pkm);
            pkm.Nature     = rng.Next(0, 24);
            pkm.StatNature = pkm.Nature;
            pkm.SetAbilityIndex(TradeExtensions.abilityIndex[abilityRng]);
            pkm.IVs = pkm.SetRandomIVs(3);
            BallApplicator.ApplyBallLegalRandom(pkm);

            switch (TradeExtensions.shinyOdds[shinyRng])
            {
            case 3: CommonEdits.SetShiny(pkm, Shiny.Never); pkm.SetUnshiny(); break;

            case 5: CommonEdits.SetShiny(pkm, Shiny.AlwaysStar); break;

            case 6: CommonEdits.SetShiny(pkm, Shiny.AlwaysSquare); break;
            }
            ;

            var la      = new LegalityAnalysis(pkm);
            var spec    = GameInfo.Strings.Species[template.Species];
            var invalid = !(pkm is PK8) || (!la.Valid && SysCordInstance.Self.Hub.Config.Legality.VerifyLegality);

            if (invalid)
            {
                var imsg = $"Oops! I scrambled your egg! Don't tell Ramsay! Here's my best attempt for that {spec}!";
                await Context.Channel.SendPKMAsync(pkm, imsg).ConfigureAwait(false);

                return;
            }

            pkm.ResetPartyStats();
            var sudo = Context.User.GetIsSudo();
            await Context.AddToQueueAsync(code, Context.User.Username, sudo, pkm, PokeRoutineType.EggRoll, PokeTradeType.EggRoll).ConfigureAwait(false);
        }
示例#17
0
        public static bool AddToWaitingList(string setstring, string username, ulong mUserId, out string msg)
        {
            if (!MiraiQQBot <T> .Info.GetCanQueue())
            {
                msg = "Sorry, I am not currently accepting queue requests!";
                return(false);
            }

            var set = ShowdownUtil.ConvertToShowdown(setstring);

            if (set == null)
            {
                msg = $"Skipping trade, @{username}: Empty nickname provided for the species.";
                return(false);
            }

            var template = AutoLegalityWrapper.GetTemplate(set);

            if (template.Species < 1)
            {
                msg =
                    $"Skipping trade, @{username}: Please read what you are supposed to type as the command argument.";
                return(false);
            }

            if (set.InvalidLines.Count != 0)
            {
                msg =
                    $"Skipping trade, @{username}: Unable to parse Showdown Set:\n{string.Join("\n", set.InvalidLines)}";
                return(false);
            }

            try
            {
                var sav = AutoLegalityWrapper.GetTrainerInfo <T>();
                var pkm = sav.GetLegal(template, out var result);

                if (!pkm.CanBeTraded())
                {
                    msg = $"Skipping trade, @{username}: Provided Pokemon content is blocked from trading!";
                    return(false);
                }

                if (pkm is T pk)
                {
                    var valid = new LegalityAnalysis(pkm).Valid;
                    if (valid)
                    {
                        var tq = new MiraiQQQueue <T>(pk, new PokeTradeTrainerInfo(username, mUserId), mUserId);
                        MiraiQQBot <T> .QueuePool.RemoveAll(z => z.QQ == mUserId); // remove old requests if any

                        MiraiQQBot <T> .QueuePool.Add(tq);

                        msg =
                            $"@{username} - added to the waiting list. Your request from the waiting list will be removed if you are too slow!";
                        return(true);
                    }
                }

                var reason = result == "Timeout" ? "Set took too long to generate." : "Unable to legalize the Pokemon.";
                msg = $"Skipping trade, @{username}: {reason}";
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception ex)
#pragma warning restore CA1031 // Do not catch general exception types
            {
                LogUtil.LogSafe(ex, nameof(MiraiQQCommandsHelper <T>));
                msg = $"Skipping trade, @{username}: An unexpected problem occurred.";
            }

            return(false);
        }