예제 #1
0
파일: PKX.cs 프로젝트: zzzzRuby/PKHeX
        /// <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)
        {
            var rnd = Util.Rand;

            if (generation > 2)
            {
                var evs = new int[6];
                do
                {
                    int max = 510;
                    for (int i = 0; i < evs.Length - 1; i++)
                    {
                        max -= evs[i] = (byte)Math.Min(rnd.Next(Math.Min(300, max)), 252);
                    }
                    evs[5] = max;
                } while (evs[5] > 252);
                Util.Shuffle(evs);
                return(evs);
            }
            else
            {
                var evs = new int[6];
                for (int i = 0; i < evs.Length; i++)
                {
                    evs[i] = rnd.Next(ushort.MaxValue + 1);
                }
                return(evs);
            }
        }
예제 #2
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);
     }
 }
예제 #3
0
        /// <summary>
        /// Gets a moveset for the provided <see cref="PKM"/> data.
        /// </summary>
        /// <param name="la">Precomputed optional</param>
        /// <param name="random">Full movepool &amp; shuffling</param>
        /// <returns>4 moves</returns>
        public static int[] GetMoveSet(this LegalityAnalysis la, bool random = false)
        {
            int[] m = la.GetSuggestedCurrentMoves(random ? MoveSourceType.All : MoveSourceType.Encounter);

            var learn = la.GetSuggestedMovesAndRelearn();

            if (!m.All(z => learn.Contains(z)))
            {
                m = m.Intersect(learn).ToArray();
            }

            if (random && !la.pkm.IsEgg)
            {
                Util.Shuffle(m);
            }

            const int count = 4;

            if (m.Length > count)
            {
                return(m.SliceEnd(m.Length - count));
            }
            Array.Resize(ref m, count);
            return(m);
        }
예제 #4
0
        /// <summary>
        /// Applies a random legal ball value if any exist.
        /// </summary>
        /// <remarks>
        /// Requires checking the <see cref="LegalityAnalysis"/> for every <see cref="Ball"/> that is tried.
        /// </remarks>
        /// <param name="pkm">Pokémon to modify.</param>
        public static int ApplyBallLegalRandom(PKM pkm)
        {
            var balls = GetBallListFromColor(pkm).ToArray();

            Util.Shuffle(balls);
            return(ApplyFirstLegalBall(pkm, balls));
        }
예제 #5
0
        /// <summary>
        /// Gets a moveset for the provided <see cref="PKM"/> data.
        /// </summary>
        /// <param name="pk">PKM to generate for</param>
        /// <param name="la">Precomputed optional</param>
        /// <param name="random">Full movepool &amp; shuffling</param>
        /// <returns>4 moves</returns>
        public static int[] GetMoveSet(this PKM pk, LegalityAnalysis la, bool random = false)
        {
            int[] m = la.GetSuggestedMoves(tm: random, tutor: random, reminder: random);
            if (m == null)
            {
                return(pk.Moves);
            }

            if (!m.All(z => la.AllSuggestedMovesAndRelearn().Contains(z)))
            {
                m = m.Intersect(la.AllSuggestedMovesAndRelearn()).ToArray();
            }

            if (random)
            {
                Util.Shuffle(m);
            }

            const int count = 4;

            if (m.Length > count)
            {
                return(m.SliceEnd(m.Length - count));
            }
            Array.Resize(ref m, count);
            return(m);
        }
예제 #6
0
        static BallRandomizer()
        {
            var exclude  = new[] { None, Poke };
            var end      = new[] { Poke };
            var allBalls = BallList.Except(exclude).ToArray();
            var colors   = (PersonalColor[])Enum.GetValues(typeof(PersonalColor));

            foreach (var c in colors)
            {
                var vals  = BallColors[c];
                var extra = allBalls.Except(vals).ToArray();
                Util.Shuffle(extra);
                BallColors[c] = vals.Concat(extra).Concat(end).ToArray();
            }
        }
예제 #7
0
        static BallApplicator()
        {
            var exclude  = new[] { None, Poke };
            var end      = new[] { Poke };
            var allBalls = BallList.Except(exclude).ToArray();
            var colors   = (PersonalColor[])Enum.GetValues(typeof(PersonalColor));

            foreach (var c in colors)
            {
                var matchingColors = BallColors[c];
                var extra          = allBalls.Except(matchingColors).ToArray();
                Util.Shuffle(extra);
                BallColors[c] = ArrayUtil.ConcatAll(matchingColors, extra, end);
            }
        }
예제 #8
0
        /// <summary>
        /// Sets the <see cref="PKM"/> data with a suggested value based on its <see cref="LegalityAnalysis"/>.
        /// </summary>
        /// <param name="name">Property to modify.</param>
        /// <param name="info">Cached info storing Legal data.</param>
        private static ModifyResult SetSuggestedPKMProperty(string name, PKMInfo info)
        {
            var PKM = info.pkm;

            switch (name)
            {
            case nameof(PKM.HyperTrainFlags):
                PKM.SetSuggestedHyperTrainingData();
                return(ModifyResult.Modified);

            case nameof(PKM.RelearnMoves):
                PKM.RelearnMoves = info.SuggestedRelearn;
                return(ModifyResult.Modified);

            case nameof(PKM.Met_Location):
                var encounter = info.SuggestedEncounter;
                if (encounter == null)
                {
                    return(ModifyResult.Error);
                }

                int level    = encounter.Level;
                int location = encounter.Location;
                int minlvl   = Legal.GetLowestLevel(PKM, encounter.LevelMin);

                PKM.Met_Level    = level;
                PKM.Met_Location = location;
                PKM.CurrentLevel = Math.Max(minlvl, level);

                return(ModifyResult.Modified);

            case nameof(PKM.Moves):
                var moves = info.SuggestedMoves;
                Util.Shuffle(moves);
                PKM.SetMoves(moves);
                return(ModifyResult.Modified);

            default:
                return(ModifyResult.Error);
            }
        }
예제 #9
0
파일: PK1.cs 프로젝트: SnowPhoenix/PKHeX
        public PK7 convertToPK7()
        {
            var pk7 = new PK7
            {
                EncryptionConstant = Util.rnd32(),
                Species            = Species,
                TID          = TID,
                CurrentLevel = CurrentLevel,
                EXP          = EXP,
                Met_Level    = CurrentLevel,
                Nature       = (int)(EXP % 25),
                PID          = Util.rnd32(),
                Ball         = 4,
                MetDate      = DateTime.Now,
                Version      = (int)GameVersion.RD, // Default to red, for now?
                Move1        = Move1,
                Move2        = Move2,
                Move3        = Move3,
                Move4        = Move4,
                Move1_PPUps  = Move1_PPUps,
                Move2_PPUps  = Move2_PPUps,
                Move3_PPUps  = Move3_PPUps,
                Move4_PPUps  = Move4_PPUps,
                Move1_PP     = Move1_PP,
                Move2_PP     = Move2_PP,
                Move3_PP     = Move3_PP,
                Move4_PP     = Move4_PP,
                Met_Location = 30013, // "Kanto region", hardcoded.
                Gender       = PersonalTable.SM[Species].RandomGender,
                OT_Name      = PKX.getG1ConvertedString(otname, Japanese),
                IsNicknamed  = false,

                Country        = PKMConverter.Country,
                Region         = PKMConverter.Region,
                ConsoleRegion  = PKMConverter.ConsoleRegion,
                CurrentHandler = 1,
                HT_Name        = PKMConverter.OT_Name,
                HT_Gender      = PKMConverter.OT_Gender,
                Language       = PKMConverter.Language,
                Geo1_Country   = PKMConverter.Country,
                Geo1_Region    = PKMConverter.Region
            };

            pk7.Nickname = PKX.getSpeciesNameGeneration(pk7.Species, pk7.Language, pk7.Format);
            if (otname[0] == 0x5D) // Ingame Trade
            {
                var s = PKX.getG1Char(0x5D, Japanese);
                pk7.OT_Name = s.Substring(0, 1) + s.Substring(1).ToLower();
            }
            pk7.OT_Friendship = pk7.HT_Friendship = PersonalTable.SM[Species].BaseFriendship;

            // IVs
            var new_ivs  = new int[6];
            int flawless = Species == 151 ? 5 : 3;

            for (var i = 0; i < new_ivs.Length; i++)
            {
                new_ivs[i] = (int)(Util.rnd32() & 31);
            }
            for (var i = 0; i < flawless; i++)
            {
                new_ivs[i] = 31;
            }
            Util.Shuffle(new_ivs);
            pk7.IVs = new_ivs;

            // Really? :(
            if (IsShiny)
            {
                pk7.setShinyPID();
            }

            int abil = 2; // Hidden

            if (Legal.TransferSpeciesDefaultAbility_1.Contains(Species))
            {
                abil = 0;             // Reset
            }
            pk7.RefreshAbility(abil); // 0/1/2 (not 1/2/4)

            if (Species == 151)       // Mew gets special treatment.
            {
                pk7.FatefulEncounter = true;
            }
            else if (IsNicknamedBank)
            {
                pk7.IsNicknamed = true;
                pk7.Nickname    = PKX.getG1ConvertedString(nick, Japanese);
            }

            pk7.TradeMemory(Bank: true); // oh no, memories on gen7 pkm

            if (pk7.Species == 150)      // Pay Day Mewtwo
            {
                var moves = pk7.Moves;
                var index = Array.IndexOf(moves, 6);
                if (index != -1)
                {
                    moves[index] = 0;
                    pk7.Moves    = moves;
                    pk7.FixMoves();
                }
            }

            pk7.RefreshChecksum();
            return(pk7);
        }