예제 #1
0
        /// <summary>
        /// Regenerates the set by searching for an encounter that can generate the template.
        /// </summary>
        /// <param name="tr">Trainer Data that was passed in</param>
        /// <param name="set">Showdown set being used</param>
        /// <param name="template">template PKM to legalize</param>
        /// <param name="msg">Legalization result</param>
        /// <returns>Legalized pkm</returns>
        private static PKM GetLegalFromSet(this ITrainerInfo tr, IBattleTemplate set, PKM template, out LegalizationResult msg)
        {
            if (set is ShowdownSet s)
            {
                set = new RegenTemplate(s);
            }

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

            if (success)
            {
                msg = LegalizationResult.Regenerated;
                return(pk);
            }

            msg = LegalizationResult.Failed;
            if (EnableEasterEggs)
            {
                var gen     = EasterEggs.GetGeneration(template.Species);
                var species = (int)EasterEggs.GetMemeSpecies(gen);
                template.Species = species;
                var legalencs = tr.GetRandomEncounter(species, out var legal);
                if (legalencs && legal != null)
                {
                    template = legal;
                }
                template.SetNickname(EasterEggs.GetMemeNickname(gen));
            }
            return(template);
        }
예제 #2
0
        private static PKM GetLegalFromSet(this ITrainerInfo tr, ShowdownSet set, PKM template, out LegalizationResult msg)
        {
            if (AllowAPI)
            {
                bool success = tr.TryAPIConvert(set, template, out PKM pk);
                if (success)
                {
                    msg = LegalizationResult.Regenerated;
                    return(pk);
                }
                if (!AllowBruteForce)
                {
                    msg = LegalizationResult.Failed;
                    return(pk);
                }
            }

            if (AllowBruteForce)
            {
                msg = LegalizationResult.BruteForce;
                return(tr.GetBruteForcedLegalMon(set, template));
            }

            msg = LegalizationResult.Failed;
            return(template);
        }
예제 #3
0
 private static PKM GetLegalFromSet(this ITrainerInfo tr, ShowdownSet set, PKM template, out LegalizationResult msg, bool allowAPI = true)
 {
     if (allowAPI && tr.TryAPIConvert(set, template, out PKM pk))
     {
         msg = LegalizationResult.Regenerated;
         return(pk);
     }
     msg = LegalizationResult.BruteForce;
     return(tr.GetBruteForcedLegalMon(set, template));
 }
예제 #4
0
        /// <summary>
        /// Regenerates the set by searching for an encounter that can generate the template.
        /// </summary>
        /// <param name="tr">Trainer Data that was passed in</param>
        /// <param name="set">Showdown set being used</param>
        /// <param name="template">template PKM to legalize</param>
        /// <param name="msg">Legalization result</param>
        /// <returns>Legalized pkm</returns>
        private static PKM GetLegalFromSet(this ITrainerInfo tr, IBattleTemplate set, PKM template, out LegalizationResult msg)
        {
            if (set is ShowdownSet s)
            {
                set = new RegenTemplate(s, tr.Generation);
            }

            msg = tr.TryAPIConvert(set, template, out PKM pk);
            if (msg == LegalizationResult.Regenerated)
            {
                return(pk);
            }

            if (EnableEasterEggs)
            {
                return(tr.GetEasterEggFromSet(set, template));
            }
            return(template);
        }
예제 #5
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);
            }
        }
예제 #6
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);
        }