Esempio n. 1
0
        /// <summary>
        /// Imports a <see cref="set"/> to create a new <see cref="PKM"/> with a context of <see cref="tr"/>.
        /// </summary>
        /// <param name="tr">Source/Destination trainer</param>
        /// <param name="set">Set data to import</param>
        /// <param name="msg">Result code indicating success or failure</param>
        /// <returns>Legalized PKM (hopefully legal)</returns>
        public static PKM GetLegalFromSet(this ITrainerInfo tr, IBattleTemplate set, out LegalizationResult msg)
        {
            var template = PKMConverter.GetBlank(tr.Generation, (GameVersion)tr.Game);

            template.ApplySetDetails(set);
            return(tr.GetLegalFromSet(set, template, out msg));
        }
Esempio n. 2
0
        /// <summary>
        /// Imports a <see cref="set"/> to create a new <see cref="PKM"/> with a context of <see cref="tr"/>.
        /// </summary>
        /// <param name="tr">Source/Destination trainer</param>
        /// <param name="set">Set data to import</param>
        /// <param name="msg">Result code indicating success or failure</param>
        /// <param name="allowAPI">Use <see cref="Core"/> to find and generate a new pkm</param>
        /// <returns>Legalized PKM (hopefully legal)</returns>
        public static PKM GetLegalFromSet(this ITrainerInfo tr, ShowdownSet set, out LegalizationResult msg, bool allowAPI = true)
        {
            var template = PKMConverter.GetBlank(tr.Generation, (GameVersion)tr.Game);

            template.ApplySetDetails(set);
            return(tr.GetLegalFromSet(set, template, out msg, allowAPI));
        }
Esempio n. 3
0
        private static PKM CreatePKMfromArgs(string[] args)
        {
            // check -i for input and get file path in the next arg
            if (args.Contains("-i"))
            {
                var path = GetArgVal(args, "-i");
                var data = File.ReadAllBytes(path);
                return(PKMConverter.GetPKMfromBytes(data));
            }

            var gameStr = GetArgVal(args, "--version");
            var parsed  = Enum.TryParse <GameVersion>(gameStr, true, out var game);

            if (!parsed)
            {
                Console.WriteLine("Invalid version specified: " + gameStr);
                game = GameVersion.Any;
            }

            var showdownSet = GetArgVal(args, "--set");
            var template    = PKMConverter.GetBlank(game.GetGeneration(), game);

            template.ApplySetDetails(new ShowdownSet(showdownSet.Split(new [] { "\\n" }, StringSplitOptions.None)));
            return(template);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets a legal <see cref="PKM"/> from a random in-game encounter's data.
        /// </summary>
        /// <param name="tr">Trainer Data to use in generating the encounter</param>
        /// <param name="species">Species ID to generate</param>
        /// <param name="pk">Result legal pkm</param>
        /// <returns>True if a valid result was generated, false if the result should be ignored.</returns>
        public static bool GetRandomEncounter(this ITrainerInfo tr, int species, out PKM?pk)
        {
            var blank = PKMConverter.GetBlank(tr.Generation, tr.Game);

            pk = GetRandomEncounter(blank, tr, species);
            if (pk == null)
            {
                return(false);
            }

            pk = PKMConverter.ConvertToType(pk, blank.GetType(), out _);
            return(pk != null);
        }
Esempio n. 5
0
        /// <summary>
        /// Gets a legal <see cref="PKM"/> from a random in-game encounter's data.
        /// </summary>
        /// <param name="tr">Trainer Data to use in generating the encounter</param>
        /// <param name="species">Species ID to generate</param>
        /// <param name="form">Form to generate; if left null, picks first encounter</param>
        /// <param name="shiny"></param>
        /// <param name="alpha"></param>
        /// <param name="attempt"></param>
        /// <param name="pk">Result legal pkm</param>
        /// <returns>True if a valid result was generated, false if the result should be ignored.</returns>
        public static bool GetRandomEncounter(this ITrainerInfo tr, int species, int?form, bool shiny, bool alpha, ref int attempt, out PKM?pk)
        {
            var blank = PKMConverter.GetBlank(tr.Generation, tr.Game);

            pk = GetRandomEncounter(blank, tr, species, form, shiny, alpha, ref attempt);
            if (pk == null)
            {
                return(false);
            }

            pk = PKMConverter.ConvertToType(pk, blank.GetType(), out _);
            return(pk != null);
        }
Esempio n. 6
0
        public void HiddenPowerTest(int h, int a, int b, int c, int d, int s, MoveType type, int power, Type pkmType)
        {
            var pkm = PKMConverter.GetBlank(pkmType);

            pkm.IV_HP  = h;
            pkm.IV_ATK = a;
            pkm.IV_DEF = b;
            pkm.IV_SPA = c;
            pkm.IV_SPD = d;
            pkm.IV_SPE = s;

            pkm.HPType.Should().Be((int)type - 1); // no normal type, down-shift by 1
            pkm.HPPower.Should().Be(power);
        }
Esempio n. 7
0
        public static void HasSmogonSets(Type t, GameVersion game, int species, int form = 0)
        {
            var blank = PKMConverter.GetBlank(t);

            blank.Version = (int)game;
            blank.Species = species;
            blank.Form    = form;

            var smogon = new SmogonSetList(blank);

            smogon.Valid.Should().BeTrue("Sets should exist for this setup");
            var count = smogon.Sets.Count;

            count.Should().BeGreaterThan(0, "At least one set should exist");
            smogon.SetConfig.Count.Should().Be(count, "Unparsed text should be captured and match result count");
            smogon.SetText.Count.Should().Be(count, "Reformatted text should be captured and match result count");
        }
Esempio n. 8
0
 private static void Initialize(string[] args)
 {
     // check -i for input and get file path in the next arg
     if (args.Contains("-i"))
     {
         string path = GetFilePath(args);
         byte[] data = File.ReadAllBytes(path);
         pk = PKMConverter.GetPKMfromBytes(data);
     }
     else
     {
         if (Array.IndexOf(args, "--set") == -1)
         {
             Console.WriteLine("Missing arguments!");
             Environment.Exit(1);
         }
         string set = args[Array.IndexOf(args, "--set") + 1];
         _ = Enum.TryParse <GameVersion>(args[Array.IndexOf(args, "--version") + 1], true, out var game);
         var template = PKMConverter.GetBlank(game.GetGeneration(), game);
         template.ApplySetDetails(new ShowdownSet(set.Split(new string[] { "\\n" }, StringSplitOptions.None)));
         pk = template;
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Gets a legal <see cref="PKM"/> from a random in-game encounter's data.
        /// </summary>
        /// <param name="blank">Template data that will have its properties modified</param>
        /// <param name="tr">Trainer Data to use in generating the encounter</param>
        /// <param name="species">Species ID to generate</param>
        /// <returns>Result legal pkm, null if data should be ignored.</returns>
        private static PKM?GetRandomEncounter(PKM blank, ITrainerInfo tr, int species)
        {
            blank.Species = species;
            blank.Gender  = blank.GetSaneGender();
            if (species is ((int)Species.Meowstic)or((int)Species.Indeedee))
            {
                blank.Form = blank.Gender;
            }

            var legalencs = EncounterMovesetGenerator.GeneratePKMs(blank, tr).Where(z => new LegalityAnalysis(z).Valid);
            var firstenc  = legalencs.FirstOrDefault();

            if (firstenc == null)
            {
                return(null);
            }

            var f = PKMConverter.ConvertToType(firstenc, blank.GetType(), out _);

            if (f == null)
            {
                var template = PKMConverter.GetBlank(tr.Generation, (GameVersion)tr.Game);
                var set      = new ShowdownSet(new ShowdownSet(blank).Text.Split('\r')[0]);
                template.ApplySetDetails(set);
                var success = tr.TryAPIConvert(set, template, out PKM pk);
                return(success == LegalizationResult.Regenerated ? pk : null);
            }
            var an = f.AbilityNumber;

            f.Species = species;
            f.Gender  = f.GetSaneGender();
            if (species is ((int)Species.Meowstic)or((int)Species.Indeedee))
            {
                f.Form = f.Gender;
            }
            f.CurrentLevel = 100;
            f.Nickname     = SpeciesName.GetSpeciesNameGeneration(f.Species, f.Language, f.Format);
            f.IsNicknamed  = false;
            f.SetSuggestedMoves();
            f.SetSuggestedMovePP(0);
            f.SetSuggestedMovePP(1);
            f.SetSuggestedMovePP(2);
            f.SetSuggestedMovePP(3);
            f.RefreshAbility(an >> 1);
            var info = new LegalityAnalysis(f).Info;

            if (info.Generation > 0 && info.EvoChainsAllGens[info.Generation].All(z => z.Species != info.EncounterMatch.Species))
            {
                f.CurrentHandler = 1;
                f.HT_Name        = f.OT_Name;
                if (f is IHandlerLanguage h)
                {
                    h.HT_Language = 1;
                }
            }
            if (f is IFormArgument fa)
            {
                fa.FormArgument = ShowdownEdits.GetSuggestedFormArgument(f, info.EncounterMatch.Species);
            }
            int wIndex = WurmpleUtil.GetWurmpleEvoGroup(f.Species);

            if (wIndex != -1)
            {
                f.EncryptionConstant = WurmpleUtil.GetWurmpleEncryptionConstant(wIndex);
            }
            if (f is IHomeTrack {
                Tracker : 0
            } ht&& APILegality.SetRandomTracker)
            {
                ht.Tracker = APILegality.GetRandomULong();
            }
            if (new LegalityAnalysis(f).Valid)
            {
                return(f);
            }

            // local name clashes!
            {
                var template = PKMConverter.GetBlank(tr.Generation, (GameVersion)tr.Game);
                var set      = new ShowdownSet(new ShowdownSet(blank).Text.Split('\r')[0]);
                template.ApplySetDetails(set);
                var success = tr.TryAPIConvert(set, template, out PKM pk);
                return(success == LegalizationResult.Regenerated ? pk : null);
            }
        }
Esempio n. 10
0
 internal static PKM GetBlank(this IGeneration gen) => PKMConverter.GetBlank(gen.Generation);
Esempio n. 11
0
        /// <summary>
        /// Gets a legal <see cref="PKM"/> from a random in-game encounter's data.
        /// </summary>
        /// <param name="blank">Template data that will have its properties modified</param>
        /// <param name="tr">Trainer Data to use in generating the encounter</param>
        /// <param name="species">Species ID to generate</param>
        /// <param name="form">Form to generate; if left null, picks first encounter</param>
        /// <returns>Result legal pkm, null if data should be ignored.</returns>
        private static PKM?GetRandomEncounter(PKM blank, ITrainerInfo tr, int species, int?form, bool shiny, ref int attempt)
        {
            blank.Species = species;
            blank.Gender  = blank.GetSaneGender();
            if (species is ((int)Species.Meowstic)or((int)Species.Indeedee))
            {
                if (form == null)
                {
                    blank.Form = blank.Gender;
                }
                else
                {
                    blank.Gender = (int)form;
                }
            }

            var template = PKMConverter.GetBlank(tr.Generation, (GameVersion)tr.Game);

            if (form != null)
            {
                blank.Form = (int)form;
                var item = SetFormSpecificItem(tr.Generation, blank.Species, (int)form);
                if (item != null)
                {
                    blank.HeldItem = (int)item;
                }
                if (blank.Species == (int)Species.Keldeo && blank.Form == 1)
                {
                    blank.Move1 = (int)Move.SecretSword;
                }
            }
            if (blank.IgnoreForm(tr, blank.Form))
            {
                return(null);
            }
            attempt += 1;
            var ssettext = new ShowdownSet(blank).Text.Split('\r')[0];

            if (shiny && !SimpleEdits.ShinyLockedSpeciesForm.Contains(new Tuple <Species, int>((Species)blank.Species, blank.Form)))
            {
                ssettext += Environment.NewLine + "Shiny: Yes";
            }
            var sset = new ShowdownSet(ssettext);
            var set  = new RegenTemplate(sset);

            template.ApplySetDetails(set);
            var success = tr.TryAPIConvert(set, template, out PKM pk);

            if (success == LegalizationResult.Regenerated)
            {
                if (form == null)
                {
                    return(pk);
                }
                else if (pk.Form == (int)form)
                {
                    return(pk);
                }
            }

            // just get a legal pkm and return. Only validate form and not shininess.
            var legalencs = EncounterMovesetGenerator.GeneratePKMs(blank, tr).Where(z => new LegalityAnalysis(z).Valid);
            var firstenc  = GetFirstEncounter(legalencs, form);

            if (firstenc == null)
            {
                attempt -= 1;
                return(null);
            }
            var originspecies = firstenc.Species;

            if (originspecies != blank.Species)
            {
                firstenc.Species      = blank.Species;
                firstenc.CurrentLevel = 100;
                if (!firstenc.IsNicknamed)
                {
                    firstenc.Nickname = SpeciesName.GetSpeciesNameGeneration(firstenc.Species, firstenc.Language, firstenc.Format);
                }
                firstenc.SetMoves(firstenc.GetMoveSet(), true);
                firstenc.RefreshAbility(firstenc.AbilityNumber >> 1);
            }
            var second = PKMConverter.ConvertToType(firstenc, blank.GetType(), out _);

            if (second == null)
            {
                return(null);
            }
            second.HeldItem = blank.HeldItem;
            if (form == null || second.Form == (int)form)
            {
                return(second);
            }
            // force form and check legality as a last ditch effort.
            second.Form = (int)form;
            second.SetSuggestedFormArgument(originspecies);
            if (new LegalityAnalysis(second).Valid)
            {
                return(second);
            }
            return(null);
        }