コード例 #1
0
        public static void ApplyDetails(PKM pk, EncounterCriteria criteria, Shiny shiny = Shiny.FixedValue, int flawless = -1)
        {
            if (shiny == Shiny.FixedValue)
            {
                shiny = criteria.Shiny is Shiny.Random or Shiny.Never ? Shiny.Never : Shiny.Always;
            }
            if (flawless == -1)
            {
                flawless = 0;
            }

            int       ctr         = 0;
            const int maxAttempts = 50_000;
            var       rnd         = Util.Rand;

            do
            {
                var seed = Util.Rand32(rnd);
                if (TryApplyFromSeed(pk, criteria, shiny, flawless, seed))
                {
                    return;
                }
            } while (++ctr != maxAttempts);
            TryApplyFromSeed(pk, EncounterCriteria.Unrestricted, shiny, flawless, Util.Rand32(rnd));
        }
コード例 #2
0
ファイル: Wild8bRNG.cs プロジェクト: ShadowMario3/PKHeX
        public static void ApplyDetails(PKM pk, EncounterCriteria criteria, Shiny shiny = Shiny.FixedValue, int flawless = -1)
        {
            if (shiny == Shiny.FixedValue)
            {
                shiny = criteria.Shiny is Shiny.Random or Shiny.Never ? Shiny.Never : Shiny.Always;
            }
            if (flawless == -1)
            {
                flawless = 0;
            }

            int       ctr         = 0;
            const int maxAttempts = 50_000;
            var       rnd         = Util.Rand;

            do
            {
                ulong s0   = Util.Rand32(rnd) | (ulong)Util.Rand32(rnd) << 32;
                ulong s1   = Util.Rand32(rnd) | (ulong)Util.Rand32(rnd) << 32;
                var   xors = new XorShift128(s0, s1);
                if (TryApplyFromSeed(pk, criteria, shiny, flawless, xors))
                {
                    return;
                }
            } while (++ctr != maxAttempts);

            {
                ulong s0   = Util.Rand32(rnd) | (ulong)Util.Rand32(rnd) << 32;
                ulong s1   = Util.Rand32(rnd) | (ulong)Util.Rand32(rnd) << 32;
                var   xors = new XorShift128(s0, s1);
                TryApplyFromSeed(pk, EncounterCriteria.Unrestricted, shiny, flawless, xors);
            }
        }
コード例 #3
0
 /// <summary>
 /// Gets randomized EVs for a given generation format
 /// </summary>
 /// <param name="generation">Generation specific formatting option</param>
 /// <returns>Array containing randomized EVs (H/A/B/S/C/D)</returns>
 public static int[] GetRandomEVs(int generation = Generation)
 {
     if (generation > 2)
     {
         var evs = new int[6];
         do
         {
             evs[0] = (byte)Math.Min(Util.Rand32() % 300, 252); // bias two to get maybe 252
             evs[1] = (byte)Math.Min(Util.Rand32() % 300, 252);
             evs[2] = (byte)Math.Min(Util.Rand32() % (510 - evs[0] - evs[1]), 252);
             evs[3] = (byte)Math.Min(Util.Rand32() % (510 - evs[0] - evs[1] - evs[2]), 252);
             evs[4] = (byte)Math.Min(Util.Rand32() % (510 - evs[0] - evs[1] - evs[2] - evs[3]), 252);
             evs[5] = (byte)Math.Min(510 - evs[0] - evs[1] - evs[2] - evs[3] - evs[4], 252);
         } while (evs.Sum(b => b) > 510); // recalculate random EVs...
         Util.Shuffle(evs);
         return(evs);
     }
     else
     {
         var evs = new int[6];
         for (int i = 0; i < evs.Length; i++)
         {
             evs[i] = Util.Rand.Next(ushort.MaxValue + 1);
         }
         return(evs);
     }
 }
コード例 #4
0
ファイル: EncounterEgg.cs プロジェクト: puertoricans/PKHeX
        private static void SetPINGA(PKM pk, EncounterCriteria criteria)
        {
            pk.SetRandomIVs(flawless: 3);
            if (pk.Format <= 2)
            {
                return;
            }

            int gender = criteria.GetGender(-1, pk.PersonalInfo);
            int nature = (int)criteria.GetNature(Nature.Random);

            if (pk.Format <= 5)
            {
                pk.SetPIDGender(gender);
                pk.Gender = gender;
                pk.SetPIDNature(nature);
                pk.Nature = nature;
                pk.RefreshAbility(pk.PIDAbility);
            }
            else
            {
                pk.PID    = Util.Rand32();
                pk.Nature = nature;
                pk.Gender = gender;
                pk.RefreshAbility(Util.Rand.Next(2));
            }
        }
コード例 #5
0
ファイル: EncounterStatic.cs プロジェクト: KiraDank/PKHeX
        protected virtual void ApplyDetails(ITrainerInfo sav, EncounterCriteria criteria, PKM pk)
        {
            pk.EncryptionConstant = Util.Rand32();
            pk.Species            = Species;
            pk.AltForm            = Form;

            int lang    = (int)Language.GetSafeLanguage(Generation, (LanguageID)sav.Language);
            int level   = GetMinimalLevel();
            var version = this.GetCompatibleVersion((GameVersion)sav.Game);

            SanityCheckVersion(ref version);

            pk.Language = lang = GetEdgeCaseLanguage(pk, lang);
            pk.Nickname = SpeciesName.GetSpeciesNameGeneration(Species, lang, Generation);

            pk.CurrentLevel  = level;
            pk.Version       = (int)version;
            pk.Ball          = Ball;
            pk.HeldItem      = HeldItem;
            pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;

            var today = DateTime.Today;

            SetMetData(pk, level, today);
            if (EggEncounter)
            {
                SetEggMetData(pk, sav, today);
            }

            SetPINGA(pk, criteria);
            SetEncounterMoves(pk, version, level);

            if (Fateful)
            {
                pk.FatefulEncounter = true;
            }

            if (pk.Format < 6)
            {
                return;
            }

            if (this is IRelearn relearn)
            {
                pk.SetRelearnMoves(relearn.Relearn);
            }

            sav.ApplyHandlingTrainerInfo(pk);
            pk.SetRandomEC();

            if (this is IGigantamax g && pk is IGigantamax pg)
            {
                pg.CanGigantamax = g.CanGigantamax;
            }
            if (this is IDynamaxLevel d && pk is IDynamaxLevel pd)
            {
                pd.DynamaxLevel = d.DynamaxLevel;
            }
        }
コード例 #6
0
ファイル: PIDGenerator.cs プロジェクト: wyatt8740/PKHeX
        private static void SetRandomWildPID(PKM pk, int nature, int ability, int gender)
        {
            uint seed = Util.Rand32();

            pk.PID    = seed;
            pk.Nature = nature;
            pk.Gender = gender;
            pk.RefreshAbility(ability);
            SetRandomIVs(pk);
        }
コード例 #7
0
        /// <summary>
        /// Gets the Wurmple <see cref="PKM.EncryptionConstant"/> for a given Evolution Value
        /// </summary>
        /// <param name="evoVal">Wurmple Evolution Value</param>
        /// <remarks>0 = Silcoon, 1 = Cascoon</remarks>
        /// <returns>Encryption Constant</returns>
        public static uint GetWurmpleEC(int evoVal)
        {
            uint EC;

            do
            {
                EC = Util.Rand32();
            }while (evoVal != GetWurmpleEvoVal(EC));
            return(EC);
        }
コード例 #8
0
        /// <summary>
        /// Gets the Wurmple <see cref="PKM.EncryptionConstant"/> for a given Evolution Value
        /// </summary>
        /// <param name="evoVal">Wurmple Evolution Value</param>
        /// <remarks>0 = Silcoon, 1 = Cascoon</remarks>
        /// <returns>Encryption Constan</returns>
        public static uint GetWurmpleEC(int evoVal)
        {
            uint EC;

            while (true)
            {
                if (evoVal == GetWurmpleEvoVal(EC = Util.Rand32()))
                {
                    return(EC);
                }
            }
        }
コード例 #9
0
ファイル: BatchEditing.cs プロジェクト: shimakiui/PKHeX
        /// <summary>
        /// Sets the <see cref="PKM"/> IV(s) to a random value.
        /// </summary>
        /// <param name="pkm">Pokémon to modify.</param>
        /// <param name="cmd">Modification</param>
        private static void SetRandomIVs(PKM pkm, StringInstruction cmd)
        {
            if (cmd.PropertyName == nameof(pkm.IVs))
            {
                pkm.SetRandomIVs();
                return;
            }

            if (TryGetHasProperty(pkm, cmd.PropertyName, out var pi))
            {
                ReflectUtil.SetValue(pi, pkm, Util.Rand32() & pkm.MaxIV);
            }
        }
コード例 #10
0
ファイル: BatchEditing.cs プロジェクト: rboninsegna/PKHeX
        /// <summary>
        /// Sets the <see cref="PKM"/> property to a non-specific smart value.
        /// </summary>
        /// <param name="pk">Pokémon to modify.</param>
        /// <param name="cmd">Modification</param>
        /// <returns>True if modified, false if no modifications done.</returns>
        private static bool SetComplexProperty(PKM pk, StringInstruction cmd)
        {
            DateTime parseDate(string val) => DateTime.ParseExact(val, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);

            if (cmd.PropertyName == nameof(PKM.MetDate))
            {
                pk.MetDate = parseDate(cmd.PropertyValue);
            }
            else if (cmd.PropertyName == nameof(PKM.EggMetDate))
            {
                pk.EggMetDate = parseDate(cmd.PropertyValue);
            }
            else if (cmd.PropertyName == nameof(PKM.EncryptionConstant) && cmd.PropertyValue == CONST_RAND)
            {
                pk.EncryptionConstant = Util.Rand32();
            }
            else if ((cmd.PropertyName == nameof(PKM.Ability) || cmd.PropertyName == nameof(PKM.AbilityNumber)) && cmd.PropertyValue.StartsWith("$"))
            {
                pk.RefreshAbility(Convert.ToInt16(cmd.PropertyValue[1]) - 0x30);
            }
            else if (cmd.PropertyName == nameof(PKM.PID) && cmd.PropertyValue == CONST_RAND)
            {
                pk.SetPIDGender(pk.Gender);
            }
            else if (cmd.PropertyName == nameof(PKM.EncryptionConstant) && cmd.PropertyValue == nameof(PKM.PID))
            {
                pk.EncryptionConstant = pk.PID;
            }
            else if (cmd.PropertyName == nameof(PKM.PID) && cmd.PropertyValue == CONST_SHINY)
            {
                pk.SetShiny();
            }
            else if (cmd.PropertyName == nameof(PKM.Species) && cmd.PropertyValue == "0")
            {
                pk.Data = new byte[pk.Data.Length];
            }
            else if (cmd.PropertyName.StartsWith("IV") && cmd.PropertyValue == CONST_RAND)
            {
                SetRandomIVs(pk, cmd);
            }
            else if (cmd.PropertyName == nameof(PKM.IsNicknamed) && string.Equals(cmd.PropertyValue, "false", StringComparison.OrdinalIgnoreCase))
            {
                pk.SetDefaultNickname();
            }
            else
            {
                return(false);
            }

            return(true);
        }
コード例 #11
0
ファイル: BatchEditing.cs プロジェクト: shimakiui/PKHeX
        /// <summary>
        /// Sets the <see cref="PKM"/> property to a non-specific smart value.
        /// </summary>
        /// <param name="pkm">Pokémon to modify.</param>
        /// <param name="cmd">Modification</param>
        private static bool SetComplexProperty(PKM pkm, StringInstruction cmd)
        {
            if (cmd.PropertyName == nameof(pkm.MetDate))
            {
                pkm.MetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
            }
            else if (cmd.PropertyName == nameof(pkm.EggMetDate))
            {
                pkm.EggMetDate = DateTime.ParseExact(cmd.PropertyValue, "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None);
            }
            else if (cmd.PropertyName == nameof(pkm.EncryptionConstant) && cmd.PropertyValue == CONST_RAND)
            {
                pkm.EncryptionConstant = Util.Rand32();
            }
            else if ((cmd.PropertyName == nameof(pkm.Ability) || cmd.PropertyName == nameof(pkm.AbilityNumber)) && cmd.PropertyValue.StartsWith("$"))
            {
                pkm.RefreshAbility(Convert.ToInt16(cmd.PropertyValue[1]) - 0x30);
            }
            else if (cmd.PropertyName == nameof(pkm.PID) && cmd.PropertyValue == CONST_RAND)
            {
                pkm.SetPIDGender(pkm.Gender);
            }
            else if (cmd.PropertyName == nameof(pkm.EncryptionConstant) && cmd.PropertyValue == nameof(pkm.PID))
            {
                pkm.EncryptionConstant = pkm.PID;
            }
            else if (cmd.PropertyName == nameof(pkm.PID) && cmd.PropertyValue == CONST_SHINY)
            {
                pkm.SetShinyPID();
            }
            else if (cmd.PropertyName == nameof(pkm.Species) && cmd.PropertyValue == "0")
            {
                pkm.Data = new byte[pkm.Data.Length];
            }
            else if (cmd.PropertyName.StartsWith("IV") && cmd.PropertyValue == CONST_RAND)
            {
                SetRandomIVs(pkm, cmd);
            }
            else if (cmd.PropertyName == nameof(pkm.IsNicknamed) && string.Equals(cmd.PropertyValue, "false", StringComparison.OrdinalIgnoreCase))
            {
                pkm.IsNicknamed = false; pkm.Nickname = PKX.GetSpeciesNameGeneration(pkm.Species, pkm.Language, pkm.Format);
            }
            else
            {
                return(false);
            }

            return(true);
        }
コード例 #12
0
        private static void SetRandomWildPID5(PKM pk, int nature, int ability, int gender, PIDType specific = PIDType.None)
        {
            var tidbit = (pk.TID ^ pk.SID) & 1;

            pk.RefreshAbility(ability);
            pk.Gender = gender;
            pk.Nature = nature;

            if (ability == 2)
            {
                ability = 0;
            }

            while (true)
            {
                uint seed = Util.Rand32();
                if (specific == PIDType.G5MGShiny)
                {
                    SetValuesFromSeedMG5Shiny(pk, seed);
                    seed = pk.PID;
                }
                else
                {
                    var bitxor = (seed >> 31) ^ (seed & 1);
                    if (bitxor != tidbit)
                    {
                        seed ^= 1;
                    }
                }

                if (seed % 25 != nature)
                {
                    continue;
                }
                if (((seed >> 16) & 1) != ability)
                {
                    continue;
                }

                pk.PID = seed;
                if (pk.GetSaneGender() != gender)
                {
                    continue;
                }

                SetRandomIVs(pk);
                return;
            }
        }
コード例 #13
0
ファイル: ShowdownSet.cs プロジェクト: mmands994/PKHeX
        public void ApplyToPKM(PKM pkm)
        {
            if (Species < 0)
            {
                return;
            }
            pkm.Species = Species;

            if (Nickname != null && Nickname.Length <= pkm.NickLength)
            {
                pkm.Nickname = Nickname;
            }
            else
            {
                pkm.Nickname = PKX.GetSpeciesName(pkm.Species, pkm.Language);
            }

            int gender = PKX.GetGenderFromString(Gender);

            pkm.Gender = Math.Max(0, gender);

            var list    = PKX.GetFormList(pkm.Species, types, forms, genders);
            int formnum = Array.IndexOf(list, Form);

            pkm.AltForm = Math.Max(0, formnum);

            var abils = pkm.PersonalInfo.Abilities;
            int index = Array.IndexOf(abils, Ability);

            pkm.RefreshAbility(Math.Max(0, Math.Min(2, index)));

            if (Shiny && !pkm.IsShiny)
            {
                pkm.SetShinyPID();
            }
            else if (!Shiny && pkm.IsShiny)
            {
                pkm.PID = Util.Rand32();
            }

            pkm.CurrentLevel      = Level;
            pkm.HeldItem          = Math.Max(0, HeldItem);
            pkm.CurrentFriendship = Friendship;
            pkm.Nature            = Nature;
            pkm.EVs   = EVs;
            pkm.IVs   = IVs;
            pkm.Moves = Moves;
        }
コード例 #14
0
        /// <summary>
        /// Gets a random PID according to specifications.
        /// </summary>
        /// <param name="species">National Dex ID</param>
        /// <param name="cg">Current Gender</param>
        /// <param name="origin">Origin Generation</param>
        /// <param name="nature">Nature</param>
        /// <param name="form">AltForm</param>
        /// <param name="OLDPID">Current PID</param>
        /// <remarks>Used to retain ability bits.</remarks>
        /// <returns>Rerolled PID.</returns>
        public static uint GetRandomPID(int species, int cg, int origin, int nature, int form, uint OLDPID)
        {
            uint bits = OLDPID & 0x00010001;
            int  gt   = Personal[species].Gender;

            if (origin >= 24)
            {
                return(Util.Rand32());
            }

            bool g3unown = origin <= 5 && species == 201;

            while (true) // Loop until we find a suitable PID
            {
                uint pid = Util.Rand32();

                // Gen 3/4: Nature derived from PID
                if (origin <= 15 && pid % 25 != nature)
                {
                    continue;
                }

                // Gen 3 Unown: Letter/form derived from PID
                if (g3unown)
                {
                    uint pidLetter = ((pid & 0x3000000) >> 18 | (pid & 0x30000) >> 12 | (pid & 0x300) >> 6 | pid & 0x3) % 28;
                    if (pidLetter != form)
                    {
                        continue;
                    }
                }
                else if (bits != (pid & 0x00010001)) // keep ability bits
                {
                    continue;
                }

                if (gt == 255 || gt == 254 || gt == 0) // Set Gender(less)
                {
                    return(pid);                       // PID can be anything
                }
                // Gen 3/4/5: Gender derived from PID
                if (cg == GetGenderFromPIDAndRatio(pid, gt))
                {
                    return(pid);
                }
            }
        }
コード例 #15
0
ファイル: PIDGenerator.cs プロジェクト: wyatt8740/PKHeX
        private static void SetRandomWildPID4(PKM pk, int nature, int ability, int gender, PIDType specific = PIDType.None)
        {
            pk.RefreshAbility(ability);
            pk.Gender = gender;
            var type   = GetPIDType(pk, specific);
            var method = GetGeneratorMethod(type);

            while (true)
            {
                method(pk, Util.Rand32());
                if (!IsValidCriteria4(pk, nature, ability, gender))
                {
                    continue;
                }
                return;
            }
        }
コード例 #16
0
ファイル: PIDGenerator.cs プロジェクト: wyatt8740/PKHeX
        public static void SetRandomPokeSpotPID(PKM pk, int nature, int gender, int ability, int slot)
        {
            while (true)
            {
                var seed = Util.Rand32();
                if (!MethodFinder.IsPokeSpotActivation(slot, seed, out var _))
                {
                    continue;
                }

                var rng = RNG.XDRNG;
                var D   = rng.Next(seed); // PID
                var E   = rng.Next(D);    // PID

                pk.PID = (D & 0xFFFF0000) | E >> 16;
                if (!IsValidCriteria4(pk, nature, ability, gender))
                {
                    continue;
                }

                pk.SetRandomIVs();
                return;
            }
        }
コード例 #17
0
ファイル: BoxManipBase.cs プロジェクト: vvcln/PKHeX
 new BoxManipSort(BoxManipType.SortRandom, list => list.OrderByCustom(_ => Util.Rand32())),
コード例 #18
0
ファイル: PKX.cs プロジェクト: zzzzRuby/PKHeX
        /// <summary>
        /// Gets a random PID according to specifications.
        /// </summary>
        /// <param name="rnd">RNG to use</param>
        /// <param name="species">National Dex ID</param>
        /// <param name="gender">Current Gender</param>
        /// <param name="origin">Origin Generation</param>
        /// <param name="nature">Nature</param>
        /// <param name="form">AltForm</param>
        /// <param name="oldPID">Current PID</param>
        /// <remarks>Used to retain ability bits.</remarks>
        /// <returns>Rerolled PID.</returns>
        public static uint GetRandomPID(Random rnd, int species, int gender, int origin, int nature, int form, uint oldPID)
        {
            // Gen6+ (and VC) PIDs do not tie PID to Nature/Gender/Ability
            if (origin >= 24)
            {
                return(Util.Rand32(rnd));
            }

            // Below logic handles Gen3-5.

            int  gt         = Personal[species].Gender;
            bool g34        = origin <= 15;
            uint abilBitVal = g34 ? oldPID & 0x0000_0001 : oldPID & 0x0001_0000;

            bool g3unown      = origin <= 5 && species == (int)Species.Unown;
            bool singleGender = gt == 255 || gt == 254 || gt == 0; // skip gender check

            while (true)                                           // Loop until we find a suitable PID
            {
                uint pid = Util.Rand32(rnd);

                // Gen 3/4: Nature derived from PID
                if (g34 && pid % 25 != nature)
                {
                    continue;
                }

                // Gen 3 Unown: Letter/form derived from PID
                if (g3unown)
                {
                    var pidLetter = GetUnownForm(pid);
                    if (pidLetter != form)
                    {
                        continue;
                    }
                }
                else if (g34)
                {
                    if (abilBitVal != (pid & 0x0000_0001)) // keep ability bits
                    {
                        continue;
                    }
                }
                else
                {
                    if (abilBitVal != (pid & 0x0001_0000)) // keep ability bits
                    {
                        continue;
                    }
                }

                if (singleGender) // Set Gender(less)
                {
                    return(pid);  // PID can be anything
                }
                // Gen 3/4/5: Gender derived from PID
                if (gender == GetGenderFromPIDAndRatio(pid, gt))
                {
                    return(pid);
                }
            }
        }
コード例 #19
0
ファイル: EncounterEgg.cs プロジェクト: antwa/PKHeX
        public PKM ConvertToPKM(ITrainerInfo SAV)
        {
            int gen = Version.GetGeneration();

            if (gen < 2)
            {
                gen     = 2;
                Version = GameVersion.C;
            }
            var pk = PKMConverter.GetBlank(gen);

            SAV.ApplyToPKM(pk);

            pk.Species      = Species;
            pk.Nickname     = PKX.GetSpeciesNameGeneration(Species, SAV.Language, gen);
            pk.CurrentLevel = Level;
            pk.Version      = (int)Version;
            int[] moves = GetCurrentEggMoves(pk);
            pk.Moves = moves;
            pk.SetMaximumPPCurrent(moves);
            pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;

            pk.SetRandomIVs(flawless: 3);

            if (pk.Format <= 2 && Version != GameVersion.C)
            {
                return(pk);
            }

            pk.Met_Level    = EncounterSuggestion.GetSuggestedEncounterEggMetLevel(pk);
            pk.Met_Location = Math.Max(0, EncounterSuggestion.GetSuggestedEggMetLocation(pk));

            if (pk.Format < 3)
            {
                return(pk);
            }

            pk.Ball = 4;

            int gender = pk.PersonalInfo.RandomGender;
            int nature = Util.Rand.Next(25);

            if (pk.Format <= 5)
            {
                pk.SetPIDGender(gender);
                pk.Gender = gender;
                pk.SetPIDNature(nature);
                pk.Nature = nature;
                pk.RefreshAbility(pk.PIDAbility);
            }
            else
            {
                pk.PID    = Util.Rand32();
                pk.Nature = nature;
                pk.Gender = gender;
                pk.RefreshAbility(Util.Rand.Next(2));
            }

            bool traded = (int)Version == SAV.Game;
            var  today  = pk.MetDate = DateTime.Today;

            if (pk.GenNumber >= 4)
            {
                pk.Egg_Location = EncounterSuggestion.GetSuggestedEncounterEggLocationEgg(pk, traded);
                pk.EggMetDate   = today;
            }

            if (pk.Format < 6)
            {
                return(pk);
            }
            if (pk.Gen6)
            {
                pk.SetHatchMemory6();
            }

            switch (Species)
            {
            case 774:     // Minior
                pk.AltForm = Util.Rand.Next(7, 14);
                break;

            case 664:     // Scatterbug
                pk.AltForm = Legal.GetVivillonPattern(SAV.Country, SAV.SubRegion);
                break;
            }

            pk.SetRandomEC();
            pk.RelearnMoves = moves;

            return(pk);
        }
コード例 #20
0
        public PKM ConvertToPKM(ITrainerInfo SAV)
        {
            int gen = Math.Max(2, Version.GetGeneration());
            var pk  = PKMConverter.GetBlank(gen);

            SAV.ApplyToPKM(pk);

            pk.Species      = Species;
            pk.Nickname     = PKX.GetSpeciesNameGeneration(Species, SAV.Language, gen);
            pk.CurrentLevel = Level;
            pk.Version      = (int)Version;

            var moves = Legal.GetEggMoves(pk, Species, pk.AltForm, Version);

            if (moves.Length == 0)
            {
                moves = Legal.GetEncounterMoves(pk, Level, Version);
            }
            pk.Moves = moves;
            pk.SetMaximumPPCurrent(moves);
            pk.OT_Friendship = pk.PersonalInfo.BaseFriendship;

            pk.SetRandomIVs(flawless: 3);

            if (pk.Format <= 2 && Version != GameVersion.C)
            {
                return(pk);
            }

            pk.Met_Level    = EncounterSuggestion.GetSuggestedEncounterEggMetLevel(pk);
            pk.Met_Location = Math.Max(0, EncounterSuggestion.GetSuggestedEggMetLocation(pk));

            if (pk.Format < 3)
            {
                return(pk);
            }

            pk.Ball = 4;

            int gender = Util.Rand.Next(2);
            int nature = Util.Rand.Next(25);

            gender = pk.GetSaneGender(gender);
            if (pk.Format <= 5)
            {
                pk.SetPIDGender(gender);
                pk.SetPIDNature(nature);
                pk.RefreshAbility(pk.PIDAbility);
            }
            else
            {
                pk.PID    = Util.Rand32();
                pk.Nature = nature;
                pk.Gender = gender;
                pk.RefreshAbility(Util.Rand.Next(2));
            }

            bool traded = (int)Version == SAV.Game;
            var  today  = pk.MetDate = DateTime.Today;

            if (pk.GenNumber >= 4)
            {
                pk.Egg_Location = EncounterSuggestion.GetSuggestedEncounterEggLocationEgg(pk, traded);
                pk.EggMetDate   = today;
            }

            if (pk.Format < 6)
            {
                return(pk);
            }
            if (pk.Gen6)
            {
                pk.SetHatchMemory6();
            }

            pk.SetRandomEC();
            pk.RelearnMoves = moves;

            return(pk);
        }